forked from Soju06/python-kis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_balance.py
More file actions
52 lines (37 loc) · 1.34 KB
/
Copy pathget_balance.py
File metadata and controls
52 lines (37 loc) · 1.34 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
"""기본 잔고 조회 예제.
config.yaml의 인증 정보를 사용해 계좌 잔고를 조회합니다.
"""
import yaml
from pykis import PyKis, KisAuth
def load_config(path: str = "config.yaml", profile: str | None = None) -> dict:
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)
account = kis.account()
balance = account.balance()
print(balance)
if __name__ == "__main__":
main()