forked from Soju06/python-kis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_quote.py
More file actions
65 lines (48 loc) ยท 1.75 KB
/
get_quote.py
File metadata and controls
65 lines (48 loc) ยท 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""๊ธฐ๋ณธ ์์ธ ์กฐํ ์์ .
์ด ์์ ๋ config.yaml์์ ์ธ์ฆ ์ ๋ณด๋ฅผ ๋ก๋ํ ๋ค
์ผ์ฑ์ ์(005930) ์์ธ๋ฅผ ์กฐํํด ์ถ๋ ฅํฉ๋๋ค.
"""
import yaml
from pykis import PyKis, KisAuth
def load_config(path: str = "config.yaml", profile: str | None = None) -> dict:
"""Load configuration.
Supports two formats:
- legacy flat config (id, account, ...)
- multi-profile config with top-level `configs` mapping and `default` key
Profile selection order:
1. explicit `profile` argument
2. environment `PYKIS_PROFILE`
3. `default` key in multi-config
4. fallback to 'virtual'
"""
import os
profile = profile or os.environ.get("PYKIS_PROFILE")
with open(path, "r", encoding="utf-8") as f:
cfg = yaml.safe_load(f)
if isinstance(cfg, dict) and "configs" in cfg:
sel = profile or cfg.get("default") or "virtual"
selected = cfg["configs"].get(sel)
if not selected:
raise ValueError(f"Profile '{sel}' not found in {path}")
return selected
return cfg
def main() -> None:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--config", default="config.yaml", help="path to config file")
parser.add_argument("--profile", help="config profile name (virtual|real)")
args = parser.parse_args()
cfg = load_config(path=args.config, profile=args.profile)
auth = KisAuth(
id=cfg["id"],
account=cfg["account"],
appkey=cfg["appkey"],
secretkey=cfg["secretkey"],
virtual=cfg.get("virtual", False),
)
kis = PyKis(auth, keep_token=True)
stock = kis.stock("005930") # ์ผ์ฑ์ ์
quote = stock.quote()
print(quote)
if __name__ == "__main__":
main()