forked from Soju06/python-kis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplace_order.py
More file actions
59 lines (42 loc) ยท 1.64 KB
/
Copy pathplace_order.py
File metadata and controls
59 lines (42 loc) ยท 1.64 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
"""๊ธฐ๋ณธ ์ฃผ๋ฌธ ์์ (์์ ์ฅ์น ํฌํจ).
- ์ค๊ณ์ข ์ฃผ๋ฌธ ์ ALLOW_LIVE_TRADES=1 ํ๊ฒฝ ๋ณ์๋ฅผ ์ค์ ํด์ผ ํฉ๋๋ค.
- ๋ชจ์ํฌ์ ๊ณ์ ์ผ๋ก ๋จผ์ ๊ฒ์ฆํ๊ณ , config.yaml ์ค์ ํ ์ฃผ๋ฌธ์ ์ํํฉ๋๋ค.
"""
import os
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
import os
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)
allow_live = os.environ.get("ALLOW_LIVE_TRADES") == "1"
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") # ์ผ์ฑ์ ์
# ์์: ์์ฅ๊ฐ ๋งค์ 1์ฃผ (์ค๊ณ์ข/๋ชจ์ํฌ์ ์ค์ ์ ๋ฐ๋ผ ์คํ)
order = stock.buy(qty=1)
print(order)
if __name__ == "__main__":
main()