pyqqq 0.12.198__py3-none-any.whl → 0.12.199__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyqqq might be problematic. Click here for more details.
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import datetime as dtm
|
|
1
2
|
from decimal import Decimal
|
|
2
3
|
from typing import Dict, List, Optional
|
|
4
|
+
|
|
3
5
|
from pyqqq.brokerage.kis.oauth import KISAuth
|
|
4
6
|
from pyqqq.brokerage.kis.tr_client import KISTRClient
|
|
5
|
-
import datetime as dtm
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class KISOverseasStock:
|
|
@@ -15,7 +16,7 @@ class KISOverseasStock:
|
|
|
15
16
|
return self.tr_client.request(*args, **kwargs)
|
|
16
17
|
|
|
17
18
|
def get_price(self, market: str, symbol: str) -> dict:
|
|
18
|
-
|
|
19
|
+
"""(해외주식현재가) 해외주식 현재 체결가 [v1_해외주식-009]
|
|
19
20
|
|
|
20
21
|
Args:
|
|
21
22
|
market (str): 거래소코드
|
|
@@ -37,42 +38,38 @@ class KISOverseasStock:
|
|
|
37
38
|
|
|
38
39
|
Raises:
|
|
39
40
|
ValueError: API 호출 실패시 발생
|
|
40
|
-
|
|
41
|
-
path =
|
|
42
|
-
query = {
|
|
43
|
-
|
|
44
|
-
'EXCD': market,
|
|
45
|
-
'SYMB': symbol
|
|
46
|
-
}
|
|
47
|
-
tr_id = 'HHDFS00000300'
|
|
41
|
+
"""
|
|
42
|
+
path = "/uapi/overseas-price/v1/quotations/price"
|
|
43
|
+
query = {"AUTH": "", "EXCD": market, "SYMB": symbol}
|
|
44
|
+
tr_id = "HHDFS00000300"
|
|
48
45
|
body, resp_header = self._tr_request(path, tr_id, params=query)
|
|
49
46
|
|
|
50
|
-
if body[
|
|
47
|
+
if body["rt_cd"] != "0":
|
|
51
48
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
52
49
|
|
|
53
|
-
output = body[
|
|
50
|
+
output = body["output"]
|
|
54
51
|
for k in output.keys():
|
|
55
52
|
if len(output[k]) == 0:
|
|
56
53
|
pass
|
|
57
|
-
elif k in [
|
|
54
|
+
elif k in ["rsym", "ordy"]:
|
|
58
55
|
pass
|
|
59
|
-
elif k in [
|
|
56
|
+
elif k in ["pvol", "sign", "tvol", "tamt"]:
|
|
60
57
|
output[k] = int(output[k])
|
|
61
58
|
else:
|
|
62
59
|
output[k] = Decimal(output[k])
|
|
63
60
|
|
|
64
61
|
return {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
"tr_id": resp_header["tr_id"],
|
|
63
|
+
"tr_cont": resp_header["tr_cont"],
|
|
64
|
+
"gt_uid": resp_header["gt_uid"],
|
|
65
|
+
"rt_cd": body["rt_cd"],
|
|
66
|
+
"msg_cd": body["msg_cd"],
|
|
67
|
+
"msg1": body["msg1"],
|
|
68
|
+
"output": output,
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
def get_dailyprice(self, excd: str, symb: str, gubn: str, modp: str, bymd: str =
|
|
75
|
-
|
|
71
|
+
def get_dailyprice(self, excd: str, symb: str, gubn: str, modp: str, bymd: str = "", keyb: str = "", tr_cont: str = ""):
|
|
72
|
+
"""
|
|
76
73
|
(해외주식현재가) 해외주식 기간별시세[v1_해외주식-010]
|
|
77
74
|
|
|
78
75
|
Args:
|
|
@@ -113,30 +110,22 @@ class KISOverseasStock:
|
|
|
113
110
|
|
|
114
111
|
Raises:
|
|
115
112
|
ValueError: API 호출 실패시 발생
|
|
116
|
-
|
|
113
|
+
"""
|
|
117
114
|
|
|
118
|
-
path =
|
|
119
|
-
params = {
|
|
120
|
-
'AUTH': '',
|
|
121
|
-
'EXCD': excd,
|
|
122
|
-
'SYMB': symb,
|
|
123
|
-
'GUBN': gubn,
|
|
124
|
-
'BYMD': bymd,
|
|
125
|
-
'MODP': modp,
|
|
126
|
-
'KEYB': keyb
|
|
127
|
-
}
|
|
115
|
+
path = "/uapi/overseas-price/v1/quotations/dailyprice"
|
|
116
|
+
params = {"AUTH": "", "EXCD": excd, "SYMB": symb, "GUBN": gubn, "BYMD": bymd, "MODP": modp, "KEYB": keyb}
|
|
128
117
|
|
|
129
|
-
tr_id =
|
|
118
|
+
tr_id = "HHDFS76240000"
|
|
130
119
|
body, header = self._tr_request(path, tr_id, tr_cont, params)
|
|
131
120
|
|
|
132
|
-
if body[
|
|
121
|
+
if body["rt_cd"] != "0":
|
|
133
122
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
134
123
|
|
|
135
|
-
output1 = body[
|
|
136
|
-
output1[
|
|
137
|
-
output1[
|
|
124
|
+
output1 = body["output1"]
|
|
125
|
+
output1["nrec"] = int(output1["nrec"])
|
|
126
|
+
output1["zdiv"] = int(output1["zdiv"])
|
|
138
127
|
output2 = []
|
|
139
|
-
for data in body[
|
|
128
|
+
for data in body["output2"]:
|
|
140
129
|
output2.append(
|
|
141
130
|
{
|
|
142
131
|
"xymd": dtm.datetime.strptime(data["xymd"], "%Y%m%d").date(), # 일자
|
|
@@ -156,19 +145,10 @@ class KISOverseasStock:
|
|
|
156
145
|
}
|
|
157
146
|
)
|
|
158
147
|
|
|
159
|
-
return {
|
|
160
|
-
'tr_id': header['tr_id'],
|
|
161
|
-
'tr_cont': header['tr_cont'],
|
|
162
|
-
'gt_uid': header['gt_uid'],
|
|
163
|
-
'rt_cd': body['rt_cd'],
|
|
164
|
-
'msg_cd': body['msg_cd'],
|
|
165
|
-
'msg1': body['msg1'],
|
|
166
|
-
'output1': output1,
|
|
167
|
-
'output2': output2
|
|
168
|
-
}
|
|
148
|
+
return {"tr_id": header["tr_id"], "tr_cont": header["tr_cont"], "gt_uid": header["gt_uid"], "rt_cd": body["rt_cd"], "msg_cd": body["msg_cd"], "msg1": body["msg1"], "output1": output1, "output2": output2}
|
|
169
149
|
|
|
170
150
|
def inquire_daily_chartprice(self, fid_cond_mrkt_div_code: str, fid_input_iscd: str, fid_input_date_1: dtm.date, fid_input_date_2: dtm.date, fid_period_div_code: str, tr_cont: str = ""):
|
|
171
|
-
|
|
151
|
+
"""
|
|
172
152
|
(해외주식현재가) 해외주식 종목/지수/환율기간별시세(일/주/월/년)[v1_해외주식-012]
|
|
173
153
|
|
|
174
154
|
Args:
|
|
@@ -205,92 +185,88 @@ class KISOverseasStock:
|
|
|
205
185
|
- ovrs_nmix_lwpr: 최저가
|
|
206
186
|
- acml_vol: 누적 거래량
|
|
207
187
|
- mod_yn: 변경 여부
|
|
208
|
-
|
|
188
|
+
"""
|
|
209
189
|
|
|
210
|
-
assert fid_cond_mrkt_div_code in [
|
|
211
|
-
assert fid_period_div_code in [
|
|
190
|
+
assert fid_cond_mrkt_div_code in ["N", "X"]
|
|
191
|
+
assert fid_period_div_code in ["D", "W", "M", "Y"]
|
|
212
192
|
|
|
213
|
-
path =
|
|
193
|
+
path = "/uapi/overseas-price/v1/quotations/inquire-daily-chartprice"
|
|
214
194
|
params = {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
195
|
+
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code,
|
|
196
|
+
"FID_INPUT_ISCD": fid_input_iscd,
|
|
197
|
+
"FID_INPUT_DATE_1": fid_input_date_1.strftime("%Y%m%d"),
|
|
198
|
+
"FID_INPUT_DATE_2": fid_input_date_2.strftime("%Y%m%d"),
|
|
199
|
+
"FID_PERIOD_DIV_CODE": fid_period_div_code,
|
|
220
200
|
}
|
|
221
|
-
tr_id =
|
|
201
|
+
tr_id = "FHKST03030100"
|
|
222
202
|
|
|
223
203
|
body, header = self._tr_request(path, tr_id, tr_cont, params)
|
|
224
204
|
|
|
225
|
-
if body[
|
|
205
|
+
if body["rt_cd"] != "0":
|
|
226
206
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
227
207
|
|
|
228
|
-
output1 = body[
|
|
208
|
+
output1 = body["output1"]
|
|
229
209
|
output1 = {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
210
|
+
"ovrs_nmix_prdy_vrss": Decimal(output1["ovrs_nmix_prdy_vrss"]),
|
|
211
|
+
"prdy_vrss_sign": int(output1["prdy_vrss_sign"]),
|
|
212
|
+
"prdy_ctrt": Decimal(output1["prdy_ctrt"]),
|
|
213
|
+
"ovrs_nmix_prdy_clpr": Decimal(output1["ovrs_nmix_prdy_clpr"]),
|
|
214
|
+
"acml_vol": int(output1["acml_vol"]),
|
|
215
|
+
"hts_kor_isnm": output1["hts_kor_isnm"],
|
|
216
|
+
"ovrs_nmix_prpr": Decimal(output1["ovrs_nmix_prpr"]),
|
|
217
|
+
"stck_shrn_iscd": output1["stck_shrn_iscd"],
|
|
218
|
+
"ovrs_prod_oprc": Decimal(output1["ovrs_prod_oprc"]),
|
|
219
|
+
"ovrs_prod_hgpr": Decimal(output1["ovrs_prod_hgpr"]),
|
|
220
|
+
"ovrs_prod_lwpr": Decimal(output1["ovrs_prod_lwpr"]),
|
|
241
221
|
}
|
|
242
222
|
output2 = []
|
|
243
|
-
for el in body[
|
|
244
|
-
output2.append(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
223
|
+
for el in body["output2"]:
|
|
224
|
+
output2.append(
|
|
225
|
+
{
|
|
226
|
+
"stck_bsop_date": dtm.datetime.strptime(el["stck_bsop_date"], "%Y%m%d").date(),
|
|
227
|
+
"ovrs_nmix_prpr": Decimal(el["ovrs_nmix_prpr"]),
|
|
228
|
+
"ovrs_nmix_oprc": Decimal(el["ovrs_nmix_oprc"]),
|
|
229
|
+
"ovrs_nmix_hgpr": Decimal(el["ovrs_nmix_hgpr"]),
|
|
230
|
+
"ovrs_nmix_lwpr": Decimal(el["ovrs_nmix_lwpr"]),
|
|
231
|
+
"acml_vol": int(el["acml_vol"]),
|
|
232
|
+
"mod_yn": el["mod_yn"],
|
|
233
|
+
}
|
|
234
|
+
)
|
|
253
235
|
|
|
254
|
-
result = {
|
|
255
|
-
'tr_id': header['tr_id'],
|
|
256
|
-
'tr_cont': header['tr_cont'],
|
|
257
|
-
'rt_cd': body['rt_cd'],
|
|
258
|
-
'msg_cd': body['msg_cd'],
|
|
259
|
-
'msg1': body['msg1'],
|
|
260
|
-
'output1': output1,
|
|
261
|
-
'output2': output2
|
|
262
|
-
}
|
|
236
|
+
result = {"tr_id": header["tr_id"], "tr_cont": header["tr_cont"], "rt_cd": body["rt_cd"], "msg_cd": body["msg_cd"], "msg1": body["msg1"], "output1": output1, "output2": output2}
|
|
263
237
|
|
|
264
238
|
return result
|
|
265
239
|
|
|
266
|
-
def inquire_search(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
240
|
+
def inquire_search(
|
|
241
|
+
self,
|
|
242
|
+
excd: str,
|
|
243
|
+
co_yn_pricecur: str = "",
|
|
244
|
+
co_st_pricecur: str = "",
|
|
245
|
+
co_en_pricecur: str = "",
|
|
246
|
+
co_yn_rate: str = "",
|
|
247
|
+
co_st_rate: str = "",
|
|
248
|
+
co_en_rate: str = "",
|
|
249
|
+
co_yn_volume: str = "",
|
|
250
|
+
co_st_volume: str = "",
|
|
251
|
+
co_en_volume: str = "",
|
|
252
|
+
co_yn_per: str = "",
|
|
253
|
+
co_st_per: str = "",
|
|
254
|
+
co_en_per: str = "",
|
|
255
|
+
co_yn_eps: str = "",
|
|
256
|
+
co_st_eps: str = "",
|
|
257
|
+
co_en_eps: str = "",
|
|
258
|
+
co_yn_amt: str = "",
|
|
259
|
+
co_st_amt: str = "",
|
|
260
|
+
co_en_amt: str = "",
|
|
261
|
+
co_yn_shar: str = "",
|
|
262
|
+
co_st_shar: str = "",
|
|
263
|
+
co_en_shar: str = "",
|
|
264
|
+
co_yn_valx: str = "",
|
|
265
|
+
co_st_valx: str = "",
|
|
266
|
+
co_en_valx: str = "",
|
|
267
|
+
tr_cont: str = "",
|
|
268
|
+
):
|
|
269
|
+
"""
|
|
294
270
|
(해외주식현재가) 해외주식 종목검색[v1_해외주식-015]
|
|
295
271
|
|
|
296
272
|
해외주식 조건검색 API입니다.
|
|
@@ -365,96 +341,88 @@ class KISOverseasStock:
|
|
|
365
341
|
|
|
366
342
|
Raises:
|
|
367
343
|
ValueError - API 호출 에러 발생 시
|
|
368
|
-
|
|
344
|
+
"""
|
|
369
345
|
|
|
370
|
-
assert excd in [
|
|
346
|
+
assert excd in ["NAS", "NYS", "AMS", "HKS", "SHS", "SZS", "HSX", "HNX", "TSE"]
|
|
371
347
|
|
|
372
|
-
path =
|
|
348
|
+
path = "/uapi/overseas-price/v1/quotations/inquire-search"
|
|
373
349
|
params = {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
350
|
+
"AUTH": "",
|
|
351
|
+
"EXCD": excd,
|
|
352
|
+
"CO_YN_PRICECUR": co_yn_pricecur,
|
|
353
|
+
"CO_ST_PRICECUR": co_st_pricecur,
|
|
354
|
+
"CO_EN_PRICECUR": co_en_pricecur,
|
|
355
|
+
"CO_YN_RATE": co_yn_rate,
|
|
356
|
+
"CO_ST_RATE": co_st_rate,
|
|
357
|
+
"CO_EN_RATE": co_en_rate,
|
|
358
|
+
"CO_YN_VOLUME": co_yn_volume,
|
|
359
|
+
"CO_ST_VOLUME": co_st_volume,
|
|
360
|
+
"CO_EN_VOLUME": co_en_volume,
|
|
361
|
+
"CO_YN_PER": co_yn_per,
|
|
362
|
+
"CO_ST_PER": co_st_per,
|
|
363
|
+
"CO_EN_PER": co_en_per,
|
|
364
|
+
"CO_YN_EPS": co_yn_eps,
|
|
365
|
+
"CO_ST_EPS": co_st_eps,
|
|
366
|
+
"CO_EN_EPS": co_en_eps,
|
|
367
|
+
"CO_YN_AMT": co_yn_amt,
|
|
368
|
+
"CO_ST_AMT": co_st_amt,
|
|
369
|
+
"CO_EN_AMT": co_en_amt,
|
|
370
|
+
"CO_YN_SHAR": co_yn_shar,
|
|
371
|
+
"CO_ST_SHAR": co_st_shar,
|
|
372
|
+
"CO_EN_SHAR": co_en_shar,
|
|
373
|
+
"CO_YN_VALX": co_yn_valx,
|
|
374
|
+
"CO_ST_VALX": co_st_valx,
|
|
375
|
+
"CO_EN_VALX": co_en_valx,
|
|
376
|
+
"KEYB": "",
|
|
401
377
|
}
|
|
402
|
-
tr_id =
|
|
378
|
+
tr_id = "HHDFS76410000"
|
|
403
379
|
body, header = self._tr_request(path, tr_id, tr_cont, params)
|
|
404
380
|
|
|
405
|
-
if body[
|
|
381
|
+
if body["rt_cd"] != "0":
|
|
406
382
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
407
383
|
|
|
408
|
-
output1 = body[
|
|
384
|
+
output1 = body["output1"]
|
|
409
385
|
output1 = {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
386
|
+
"zdiv": int(output1["zdiv"]),
|
|
387
|
+
"stat": output1["stat"],
|
|
388
|
+
"crec": int(output1["crec"]),
|
|
389
|
+
"trec": int(output1["trec"]),
|
|
390
|
+
"nrec": int(output1["nrec"]),
|
|
415
391
|
}
|
|
416
392
|
|
|
417
393
|
output2 = []
|
|
418
|
-
for el in body[
|
|
419
|
-
output2.append(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
394
|
+
for el in body["output2"]:
|
|
395
|
+
output2.append(
|
|
396
|
+
{
|
|
397
|
+
"rsym": el["rsym"],
|
|
398
|
+
"excd": el["excd"],
|
|
399
|
+
"name": el["name"],
|
|
400
|
+
"symb": el["symb"],
|
|
401
|
+
"last": Decimal(el["last"]),
|
|
402
|
+
"shar": int(el["shar"]),
|
|
403
|
+
"valx": Decimal(el["valx"]),
|
|
404
|
+
"plow": Decimal(el["plow"]),
|
|
405
|
+
"phigh": Decimal(el["phigh"]),
|
|
406
|
+
"popen": Decimal(el["popen"]),
|
|
407
|
+
"tvol": int(el["tvol"]),
|
|
408
|
+
"rate": Decimal(el["rate"]),
|
|
409
|
+
"diff": Decimal(el["diff"]),
|
|
410
|
+
"sign": int(el["sign"]),
|
|
411
|
+
"avol": int(el["avol"]),
|
|
412
|
+
"eps": Decimal(el["eps"]),
|
|
413
|
+
"per": Decimal(el["per"]),
|
|
414
|
+
"rank": int(el["rank"]),
|
|
415
|
+
"ename": el["ename"],
|
|
416
|
+
"e_ordyn": el["e_ordyn"],
|
|
417
|
+
}
|
|
418
|
+
)
|
|
441
419
|
|
|
442
|
-
result = {
|
|
443
|
-
'tr_id': header['tr_id'],
|
|
444
|
-
'tr_cont': header['tr_cont'],
|
|
445
|
-
'rt_cd': body['rt_cd'],
|
|
446
|
-
'msg_cd': body['msg_cd'],
|
|
447
|
-
'msg1': body['msg1'],
|
|
448
|
-
'output1': output1,
|
|
449
|
-
'output2': output2
|
|
450
|
-
}
|
|
420
|
+
result = {"tr_id": header["tr_id"], "tr_cont": header["tr_cont"], "rt_cd": body["rt_cd"], "msg_cd": body["msg_cd"], "msg1": body["msg1"], "output1": output1, "output2": output2}
|
|
451
421
|
|
|
452
422
|
return result
|
|
453
423
|
|
|
454
|
-
def get_price_detail(self,
|
|
455
|
-
|
|
456
|
-
symb: str):
|
|
457
|
-
'''
|
|
424
|
+
def get_price_detail(self, excd: str, symb: str):
|
|
425
|
+
"""
|
|
458
426
|
(해외주식현재가) 해외주식 현재가 상세정보[v1_해외주식-029]
|
|
459
427
|
|
|
460
428
|
해외주식 현재가상세 API입니다.
|
|
@@ -525,44 +493,33 @@ class KISOverseasStock:
|
|
|
525
493
|
|
|
526
494
|
Raise:
|
|
527
495
|
ValueError: API 호출 실패시
|
|
528
|
-
|
|
496
|
+
"""
|
|
529
497
|
|
|
530
|
-
path =
|
|
531
|
-
tr_id =
|
|
532
|
-
tr_cont =
|
|
533
|
-
params = {
|
|
534
|
-
'AUTH': '',
|
|
535
|
-
'EXCD': excd,
|
|
536
|
-
'SYMB': symb
|
|
537
|
-
}
|
|
498
|
+
path = "/uapi/overseas-price/v1/quotations/price-detail"
|
|
499
|
+
tr_id = "HHDFS76200200"
|
|
500
|
+
tr_cont = ""
|
|
501
|
+
params = {"AUTH": "", "EXCD": excd, "SYMB": symb}
|
|
538
502
|
|
|
539
503
|
body, header = self._tr_request(path, tr_id, tr_cont, params)
|
|
540
504
|
|
|
541
|
-
if body[
|
|
505
|
+
if body["rt_cd"] != "0":
|
|
542
506
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
543
507
|
|
|
544
|
-
output = body[
|
|
508
|
+
output = body["output"]
|
|
545
509
|
|
|
546
510
|
for k in output.keys():
|
|
547
511
|
if len(output[k]) == 0:
|
|
548
512
|
pass
|
|
549
|
-
elif k in [
|
|
513
|
+
elif k in ["rsym", "curr", "e_ordyn", "e_icod", "etyp_nm"]:
|
|
550
514
|
pass
|
|
551
|
-
elif k in [
|
|
515
|
+
elif k in ["pvol", "shar", "vnit", "tvol", "tamt", "zdiv", "t_xsgn", "p_xsng"]:
|
|
552
516
|
output[k] = int(output[k])
|
|
553
|
-
elif k in [
|
|
554
|
-
output[k] = dtm.datetime.strptime(output[k],
|
|
517
|
+
elif k in ["h52d", "l52d"]:
|
|
518
|
+
output[k] = dtm.datetime.strptime(output[k], "%Y%m%d").date()
|
|
555
519
|
else:
|
|
556
520
|
output[k] = Decimal(output[k])
|
|
557
521
|
|
|
558
|
-
result = {
|
|
559
|
-
'tr_id': header['tr_id'],
|
|
560
|
-
'tr_cont': header['tr_cont'],
|
|
561
|
-
'rt_cd': body['rt_cd'],
|
|
562
|
-
'msg_cd': body['msg_cd'],
|
|
563
|
-
'msg1': body['msg1'],
|
|
564
|
-
'output': output
|
|
565
|
-
}
|
|
522
|
+
result = {"tr_id": header["tr_id"], "tr_cont": header["tr_cont"], "rt_cd": body["rt_cd"], "msg_cd": body["msg_cd"], "msg1": body["msg1"], "output": output}
|
|
566
523
|
|
|
567
524
|
return result
|
|
568
525
|
|
|
@@ -628,7 +585,7 @@ class KISOverseasStock:
|
|
|
628
585
|
assert nmin > 0
|
|
629
586
|
assert pinc == 0 or pinc == 1
|
|
630
587
|
|
|
631
|
-
path =
|
|
588
|
+
path = "/uapi/overseas-price/v1/quotations/inquire-time-itemchartprice"
|
|
632
589
|
tr_id = "HHDFS76950200"
|
|
633
590
|
tr_cont = ""
|
|
634
591
|
|
|
@@ -646,10 +603,10 @@ class KISOverseasStock:
|
|
|
646
603
|
|
|
647
604
|
body, header = self._tr_request(path, tr_id, tr_cont, params)
|
|
648
605
|
|
|
649
|
-
if body[
|
|
606
|
+
if body["rt_cd"] != "0":
|
|
650
607
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
651
608
|
|
|
652
|
-
output1 = body[
|
|
609
|
+
output1 = body["output1"]
|
|
653
610
|
|
|
654
611
|
output1 = {
|
|
655
612
|
"rsym": output1["rsym"],
|
|
@@ -665,39 +622,29 @@ class KISOverseasStock:
|
|
|
665
622
|
|
|
666
623
|
output2 = []
|
|
667
624
|
|
|
668
|
-
for el in body[
|
|
669
|
-
output2.append(
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
625
|
+
for el in body["output2"]:
|
|
626
|
+
output2.append(
|
|
627
|
+
{
|
|
628
|
+
"tymd": dtm.datetime.strptime(el["tymd"], "%Y%m%d").date(),
|
|
629
|
+
"xymd": dtm.datetime.strptime(el["xymd"], "%Y%m%d").date(),
|
|
630
|
+
"xhms": dtm.datetime.strptime(el["xhms"], "%H%M%S").time(),
|
|
631
|
+
"kymd": dtm.datetime.strptime(el["kymd"], "%Y%m%d").date(),
|
|
632
|
+
"khms": dtm.datetime.strptime(el["khms"], "%H%M%S").time(),
|
|
633
|
+
"open": Decimal(el["open"]),
|
|
634
|
+
"high": Decimal(el["high"]),
|
|
635
|
+
"low": Decimal(el["low"]),
|
|
636
|
+
"last": Decimal(el["last"]),
|
|
637
|
+
"evol": int(el["evol"]),
|
|
638
|
+
"eamt": int(el["eamt"]),
|
|
639
|
+
}
|
|
640
|
+
)
|
|
682
641
|
|
|
683
|
-
result = {
|
|
684
|
-
'tr_id': header['tr_id'],
|
|
685
|
-
'tr_cont': header['tr_cont'],
|
|
686
|
-
'rt_cd': body['rt_cd'],
|
|
687
|
-
'msg_cd': body['msg_cd'],
|
|
688
|
-
'msg1': body['msg1'],
|
|
689
|
-
'output1': output1,
|
|
690
|
-
'output2': output2
|
|
691
|
-
}
|
|
642
|
+
result = {"tr_id": header["tr_id"], "tr_cont": header["tr_cont"], "rt_cd": body["rt_cd"], "msg_cd": body["msg_cd"], "msg1": body["msg1"], "output1": output1, "output2": output2}
|
|
692
643
|
|
|
693
644
|
return result
|
|
694
645
|
|
|
695
|
-
def inquire_time_indexchartprice(self,
|
|
696
|
-
|
|
697
|
-
fid_input_iscd: str,
|
|
698
|
-
fid_hour_cls_code: str,
|
|
699
|
-
fid_pw_data_incu_yn: str):
|
|
700
|
-
'''
|
|
646
|
+
def inquire_time_indexchartprice(self, fid_cond_mrkt_div_code: str, fid_input_iscd: str, fid_hour_cls_code: str, fid_pw_data_incu_yn: str):
|
|
647
|
+
"""
|
|
701
648
|
(해외주식현재가) 해외지수분봉조회[v1_해외주식-031]
|
|
702
649
|
|
|
703
650
|
| 해외지수분봉조회 API입니다.
|
|
@@ -734,79 +681,63 @@ class KISOverseasStock:
|
|
|
734
681
|
- optn_lwpr: 최저가
|
|
735
682
|
- cntg_vol: 거래량
|
|
736
683
|
|
|
737
|
-
|
|
684
|
+
"""
|
|
738
685
|
|
|
739
|
-
assert fid_cond_mrkt_div_code in [
|
|
740
|
-
assert fid_hour_cls_code in [
|
|
741
|
-
assert fid_pw_data_incu_yn in [
|
|
686
|
+
assert fid_cond_mrkt_div_code in ["N", "X", "KX"]
|
|
687
|
+
assert fid_hour_cls_code in ["0", "1"]
|
|
688
|
+
assert fid_pw_data_incu_yn in ["Y", "N"]
|
|
742
689
|
|
|
743
|
-
path =
|
|
744
|
-
tr_id =
|
|
745
|
-
tr_cont =
|
|
690
|
+
path = "/uapi/overseas-price/v1/quotations/inquire-time-indexchartprice"
|
|
691
|
+
tr_id = "FHKST03030200"
|
|
692
|
+
tr_cont = ""
|
|
746
693
|
|
|
747
694
|
params = {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
695
|
+
"FID_COND_MRKT_DIV_CODE": fid_cond_mrkt_div_code,
|
|
696
|
+
"FID_INPUT_ISCD": fid_input_iscd,
|
|
697
|
+
"FID_HOUR_CLS_CODE": fid_hour_cls_code,
|
|
698
|
+
"FID_PW_DATA_INCU_YN": fid_pw_data_incu_yn,
|
|
752
699
|
}
|
|
753
700
|
|
|
754
701
|
body, header = self._tr_request(path, tr_id, tr_cont, params)
|
|
755
702
|
|
|
756
|
-
if body[
|
|
703
|
+
if body["rt_cd"] != "0":
|
|
757
704
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
758
705
|
|
|
759
|
-
output1 = body[
|
|
706
|
+
output1 = body["output1"]
|
|
760
707
|
output1 = {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
708
|
+
"ovrs_nmix_prdy_vrss": Decimal(output1["ovrs_nmix_prdy_vrss"]),
|
|
709
|
+
"prdy_vrss_sign": int(output1["prdy_vrss_sign"]),
|
|
710
|
+
"hts_kor_isnm": output1["hts_kor_isnm"],
|
|
711
|
+
"prdy_ctrt": Decimal(output1["prdy_ctrt"]),
|
|
712
|
+
"ovrs_nmix_prdy_clpr": Decimal(output1["ovrs_nmix_prdy_clpr"]),
|
|
713
|
+
"acml_vol": int(output1["acml_vol"]),
|
|
714
|
+
"ovrs_nmix_prpr": Decimal(output1["ovrs_nmix_prpr"]),
|
|
715
|
+
"stck_shrn_iscd": output1["stck_shrn_iscd"],
|
|
716
|
+
"ovrs_prod_oprc": Decimal(output1["ovrs_prod_oprc"]),
|
|
717
|
+
"ovrs_prod_hgpr": Decimal(output1["ovrs_prod_hgpr"]),
|
|
718
|
+
"ovrs_prod_lwpr": Decimal(output1["ovrs_prod_lwpr"]),
|
|
772
719
|
}
|
|
773
720
|
|
|
774
721
|
output2 = []
|
|
775
|
-
for el in body[
|
|
776
|
-
output2.append(
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
722
|
+
for el in body["output2"]:
|
|
723
|
+
output2.append(
|
|
724
|
+
{
|
|
725
|
+
"stck_bsop_date": dtm.datetime.strptime(el["stck_bsop_date"], "%Y%m%d").date(),
|
|
726
|
+
"stck_cntg_hour": dtm.datetime.strptime(el["stck_cntg_hour"], "%H%M%S").time(),
|
|
727
|
+
"optn_prpr": Decimal(el["optn_prpr"]),
|
|
728
|
+
"optn_oprc": Decimal(el["optn_oprc"]),
|
|
729
|
+
"optn_hgpr": Decimal(el["optn_hgpr"]),
|
|
730
|
+
"optn_lwpr": Decimal(el["optn_lwpr"]),
|
|
731
|
+
"cntg_vol": int(el["cntg_vol"]),
|
|
732
|
+
}
|
|
733
|
+
)
|
|
785
734
|
|
|
786
|
-
result = {
|
|
787
|
-
'tr_id': header['tr_id'],
|
|
788
|
-
'tr_cont': header['tr_cont'],
|
|
789
|
-
'rt_cd': body['rt_cd'],
|
|
790
|
-
'msg_cd': body['msg_cd'],
|
|
791
|
-
'msg1': body['msg1'],
|
|
792
|
-
'output1': output1,
|
|
793
|
-
'output2': output2
|
|
794
|
-
}
|
|
735
|
+
result = {"tr_id": header["tr_id"], "tr_cont": header["tr_cont"], "rt_cd": body["rt_cd"], "msg_cd": body["msg_cd"], "msg1": body["msg1"], "output1": output1, "output2": output2}
|
|
795
736
|
|
|
796
737
|
return result
|
|
797
738
|
|
|
798
|
-
def order(self,
|
|
799
|
-
|
|
800
|
-
actn_prdt_cd: str,
|
|
801
|
-
ovrs_excg_cd: str,
|
|
802
|
-
pdno: str,
|
|
803
|
-
ord_qty: int,
|
|
804
|
-
ovrs_ord_unpr: Decimal,
|
|
805
|
-
sll_type: str,
|
|
806
|
-
ord_dvsn: str,
|
|
807
|
-
ctac_tlno: str = None,
|
|
808
|
-
mgco_aptm_odno: str = None):
|
|
809
|
-
'''
|
|
739
|
+
def order(self, cano: str, actn_prdt_cd: str, ovrs_excg_cd: str, pdno: str, ord_qty: int, ovrs_ord_unpr: Decimal, sll_type: str, ord_dvsn: str, ctac_tlno: str = None, mgco_aptm_odno: str = None):
|
|
740
|
+
"""
|
|
810
741
|
(해외주식주문) 해외주식 주문[v1_해외주식-001]
|
|
811
742
|
|
|
812
743
|
해외주식 주문 API입니다.
|
|
@@ -873,85 +804,75 @@ class KISOverseasStock:
|
|
|
873
804
|
- krx_fwdg_ord_orgno: 한국거래소전송주문조직번호
|
|
874
805
|
- odno: 주문번호
|
|
875
806
|
- ord_tmd: 주문시각
|
|
876
|
-
|
|
807
|
+
"""
|
|
877
808
|
|
|
878
|
-
assert ovrs_excg_cd in [
|
|
809
|
+
assert ovrs_excg_cd in ["NASD", "NYSE", "AMEX", "SEHK", "SHAA", "SZAA", "HASE", "VNSE", "TKSE"]
|
|
879
810
|
|
|
880
811
|
def __infer_tr_id():
|
|
881
|
-
pair = (
|
|
882
|
-
paper_trading_pair = (
|
|
883
|
-
|
|
884
|
-
if ovrs_excg_cd in [
|
|
885
|
-
pair = (
|
|
886
|
-
paper_trading_pair = (
|
|
887
|
-
elif ovrs_excg_cd ==
|
|
888
|
-
pair = (
|
|
889
|
-
paper_trading_pair = (
|
|
890
|
-
elif ovrs_excg_cd ==
|
|
891
|
-
pair = (
|
|
892
|
-
paper_trading_pair = (
|
|
893
|
-
elif ovrs_excg_cd ==
|
|
894
|
-
pair = (
|
|
895
|
-
paper_trading_pair = (
|
|
896
|
-
elif ovrs_excg_cd ==
|
|
897
|
-
pair = (
|
|
898
|
-
paper_trading_pair = (
|
|
899
|
-
elif ovrs_excg_cd in [
|
|
900
|
-
pair = (
|
|
901
|
-
paper_trading_pair = (
|
|
902
|
-
|
|
903
|
-
idx = 1 if sll_type ==
|
|
812
|
+
pair = ("매수", "매도")
|
|
813
|
+
paper_trading_pair = ("매수", "매도")
|
|
814
|
+
|
|
815
|
+
if ovrs_excg_cd in ["NASD", "NYSE", "AMEX"]: # 미국
|
|
816
|
+
pair = ("TTTT1002U", "TTTT1006U")
|
|
817
|
+
paper_trading_pair = ("VTTT1002U", "VTTT1001U")
|
|
818
|
+
elif ovrs_excg_cd == "TKSE": # 일본
|
|
819
|
+
pair = ("TTTS0308U", "TTTS0307U")
|
|
820
|
+
paper_trading_pair = ("VTTS0308U", "VTTS0307U")
|
|
821
|
+
elif ovrs_excg_cd == "SEHK": # 홍콩
|
|
822
|
+
pair = ("TTTS1002U", "TTTS1001U")
|
|
823
|
+
paper_trading_pair = ("VTTS1002U", "VTTS1001U")
|
|
824
|
+
elif ovrs_excg_cd == "SHAA": # 상해
|
|
825
|
+
pair = ("TTTS0202U", "TTTS1005U")
|
|
826
|
+
paper_trading_pair = ("VTTS0202U", "VTTS1005U")
|
|
827
|
+
elif ovrs_excg_cd == "SZAA": # 심천
|
|
828
|
+
pair = ("TTTS0305U", "TTTS0304U")
|
|
829
|
+
paper_trading_pair = ("VTTS0305U", "VTTS0304U")
|
|
830
|
+
elif ovrs_excg_cd in ["HASE", "VNSE"]: # 베트남
|
|
831
|
+
pair = ("TTTS0311U", "TTTS0310U")
|
|
832
|
+
paper_trading_pair = ("VTTS0311U", "VTTS0310U")
|
|
833
|
+
|
|
834
|
+
idx = 1 if sll_type == "00" else 0
|
|
904
835
|
|
|
905
836
|
if self.auth.paper_trading:
|
|
906
837
|
return paper_trading_pair[idx]
|
|
907
838
|
else:
|
|
908
839
|
return pair[idx]
|
|
909
840
|
|
|
910
|
-
path =
|
|
841
|
+
path = "/uapi/overseas-stock/v1/trading/order"
|
|
911
842
|
tr_id = __infer_tr_id()
|
|
912
|
-
tr_cont =
|
|
843
|
+
tr_cont = ""
|
|
913
844
|
|
|
914
845
|
body = {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
846
|
+
"CANO": cano,
|
|
847
|
+
"ACNT_PRDT_CD": actn_prdt_cd,
|
|
848
|
+
"OVRS_EXCG_CD": ovrs_excg_cd,
|
|
849
|
+
"PDNO": pdno,
|
|
850
|
+
"ORD_QTY": str(ord_qty),
|
|
851
|
+
"OVRS_ORD_UNPR": str(ovrs_ord_unpr),
|
|
852
|
+
"ORD_SVR_DVSN_CD": "0",
|
|
922
853
|
}
|
|
923
854
|
|
|
924
|
-
body[
|
|
925
|
-
body[
|
|
926
|
-
if sll_type ==
|
|
927
|
-
body[
|
|
855
|
+
body["CTAC_TLNO"] = ctac_tlno or ""
|
|
856
|
+
body["MGCO_APTM_ODNO"] = mgco_aptm_odno or ""
|
|
857
|
+
if sll_type == "00":
|
|
858
|
+
body["SLL_TYPE"] = sll_type
|
|
928
859
|
if ord_dvsn:
|
|
929
|
-
body[
|
|
860
|
+
body["ORD_DVSN"] = ord_dvsn
|
|
930
861
|
|
|
931
|
-
body, _ = self._tr_request(path, tr_id, tr_cont, body=body, method=
|
|
862
|
+
body, _ = self._tr_request(path, tr_id, tr_cont, body=body, method="POST")
|
|
932
863
|
|
|
933
|
-
if body[
|
|
864
|
+
if body["rt_cd"] != "0":
|
|
934
865
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
935
866
|
|
|
936
867
|
return {
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
868
|
+
"rt_cd": body["rt_cd"],
|
|
869
|
+
"msg_cd": body["msg_cd"],
|
|
870
|
+
"msg1": body["msg1"],
|
|
871
|
+
"output": body["output"],
|
|
941
872
|
}
|
|
942
873
|
|
|
943
|
-
def order_rvsecncl(self,
|
|
944
|
-
|
|
945
|
-
acnt_prdt_cd: str,
|
|
946
|
-
ovrs_excg_cd: str,
|
|
947
|
-
pdno: str,
|
|
948
|
-
orgn_odno: str,
|
|
949
|
-
rvse_cncl_dvsn_cd: str,
|
|
950
|
-
ord_qty: int,
|
|
951
|
-
ovrs_ord_unpr: Decimal,
|
|
952
|
-
mgco_aptm_odno: str = None):
|
|
953
|
-
|
|
954
|
-
'''
|
|
874
|
+
def order_rvsecncl(self, cano: str, acnt_prdt_cd: str, ovrs_excg_cd: str, pdno: str, orgn_odno: str, rvse_cncl_dvsn_cd: str, ord_qty: int, ovrs_ord_unpr: Decimal, mgco_aptm_odno: str = None):
|
|
875
|
+
"""
|
|
955
876
|
(해외주식주문) 해외주식 정정취소주문[v1_해외주식-002]
|
|
956
877
|
|
|
957
878
|
| 접수된 해외주식 주문을 정정하거나 취소하기 위한 API입니다.
|
|
@@ -1000,61 +921,61 @@ class KISOverseasStock:
|
|
|
1000
921
|
- ODNO: 주문번호 - 주문시 한국투자증권 시스템에서 채번된 주문번호
|
|
1001
922
|
- ORD_TMD: 주문시각 - 주문시각(시분초HHMMSS)
|
|
1002
923
|
|
|
1003
|
-
|
|
924
|
+
"""
|
|
1004
925
|
|
|
1005
|
-
assert ovrs_excg_cd in [
|
|
926
|
+
assert ovrs_excg_cd in ["NASD", "NYSE", "AMEX", "SEHK", "SHAA", "SZAA", "HASE", "VNSE", "TKSE"]
|
|
1006
927
|
|
|
1007
928
|
def __infer_tr_id():
|
|
1008
|
-
if ovrs_excg_cd in [
|
|
1009
|
-
live =
|
|
1010
|
-
paper =
|
|
1011
|
-
elif ovrs_excg_cd ==
|
|
1012
|
-
live =
|
|
1013
|
-
paper =
|
|
1014
|
-
elif ovrs_excg_cd ==
|
|
1015
|
-
live =
|
|
1016
|
-
paper =
|
|
1017
|
-
elif ovrs_excg_cd ==
|
|
1018
|
-
live =
|
|
1019
|
-
paper =
|
|
1020
|
-
elif ovrs_excg_cd ==
|
|
1021
|
-
live =
|
|
1022
|
-
paper =
|
|
1023
|
-
elif ovrs_excg_cd in [
|
|
1024
|
-
live =
|
|
1025
|
-
paper =
|
|
929
|
+
if ovrs_excg_cd in ["NASD", "NYSE", "AMEX"]: # 미국
|
|
930
|
+
live = "TTTT1004U"
|
|
931
|
+
paper = "VTTT1004U"
|
|
932
|
+
elif ovrs_excg_cd == "TKSE": # 일본
|
|
933
|
+
live = "TTTS0309U"
|
|
934
|
+
paper = "VTTS0309U"
|
|
935
|
+
elif ovrs_excg_cd == "SEHK": # 홍콩
|
|
936
|
+
live = "TTTS1003U"
|
|
937
|
+
paper = "VTTS1003U"
|
|
938
|
+
elif ovrs_excg_cd == "SHAA": # 상해
|
|
939
|
+
live = "TTTS0302U"
|
|
940
|
+
paper = "VTTS0302U"
|
|
941
|
+
elif ovrs_excg_cd == "SZAA": # 심천
|
|
942
|
+
live = "TTTS0306U"
|
|
943
|
+
paper = "VTTS0306U"
|
|
944
|
+
elif ovrs_excg_cd in ["HASE", "VNSE"]: # 베트남
|
|
945
|
+
live = "TTTS0312U"
|
|
946
|
+
paper = "VTTS0312U"
|
|
1026
947
|
|
|
1027
948
|
if self.auth.paper_trading:
|
|
1028
949
|
return paper
|
|
1029
950
|
else:
|
|
1030
951
|
return live
|
|
1031
952
|
|
|
1032
|
-
path =
|
|
953
|
+
path = "/uapi/overseas-stock/v1/trading/order-rvsecncl"
|
|
1033
954
|
tr_id = __infer_tr_id()
|
|
1034
|
-
tr_cont =
|
|
955
|
+
tr_cont = ""
|
|
1035
956
|
req_body = {
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
957
|
+
"CANO": cano,
|
|
958
|
+
"ACNT_PRDT_CD": acnt_prdt_cd,
|
|
959
|
+
"OVRS_EXCG_CD": ovrs_excg_cd,
|
|
960
|
+
"PDNO": pdno,
|
|
961
|
+
"ORGN_ODNO": orgn_odno,
|
|
962
|
+
"RVSE_CNCL_DVSN_CD": rvse_cncl_dvsn_cd,
|
|
963
|
+
"ORD_QTY": str(ord_qty),
|
|
964
|
+
"OVRS_ORD_UNPR": str(ovrs_ord_unpr),
|
|
965
|
+
"ORD_SVR_DVSN_CD": "0",
|
|
1045
966
|
}
|
|
1046
967
|
if mgco_aptm_odno:
|
|
1047
|
-
req_body[
|
|
968
|
+
req_body["MGCO_APTM_ODNO"] = mgco_aptm_odno
|
|
1048
969
|
|
|
1049
|
-
body, _ = self._tr_request(path, tr_id, tr_cont, body=req_body, method=
|
|
1050
|
-
if body[
|
|
970
|
+
body, _ = self._tr_request(path, tr_id, tr_cont, body=req_body, method="POST")
|
|
971
|
+
if body["rt_cd"] != "0":
|
|
1051
972
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
1052
973
|
|
|
1053
974
|
result = {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
975
|
+
"rt_cd": body["rt_cd"],
|
|
976
|
+
"msg_cd": body["msg_cd"],
|
|
977
|
+
"msg1": body["msg1"],
|
|
978
|
+
"output": body["output"],
|
|
1058
979
|
}
|
|
1059
980
|
|
|
1060
981
|
return result
|
|
@@ -1418,14 +1339,8 @@ class KISOverseasStock:
|
|
|
1418
1339
|
"output": output,
|
|
1419
1340
|
}
|
|
1420
1341
|
|
|
1421
|
-
def inquire_balance(self,
|
|
1422
|
-
|
|
1423
|
-
acnt_prdt_cd: str,
|
|
1424
|
-
ovrs_excg_cd: str,
|
|
1425
|
-
tr_crcy_cd: str,
|
|
1426
|
-
ctx_area_fk200: str = "",
|
|
1427
|
-
ctx_area_nk200: str = ""):
|
|
1428
|
-
'''
|
|
1342
|
+
def inquire_balance(self, cano: str, acnt_prdt_cd: str, ovrs_excg_cd: str, tr_crcy_cd: str, ctx_area_fk200: str = "", ctx_area_nk200: str = ""):
|
|
1343
|
+
"""
|
|
1429
1344
|
(해외주식주문) 해외주식 잔고조회[v1_해외주식-006]
|
|
1430
1345
|
|
|
1431
1346
|
| 해외주식 잔고를 조회하는 API 입니다.
|
|
@@ -1484,55 +1399,55 @@ class KISOverseasStock:
|
|
|
1484
1399
|
|
|
1485
1400
|
Raises:
|
|
1486
1401
|
ValueError: API 호출 실패시 발생
|
|
1487
|
-
|
|
1402
|
+
"""
|
|
1488
1403
|
|
|
1489
|
-
path =
|
|
1490
|
-
tr_id =
|
|
1491
|
-
tr_cont =
|
|
1404
|
+
path = "/uapi/overseas-stock/v1/trading/inquire-balance"
|
|
1405
|
+
tr_id = "VTTS3012R" if self.auth.paper_trading else "TTTS3012R"
|
|
1406
|
+
tr_cont = ""
|
|
1492
1407
|
|
|
1493
1408
|
params = {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1409
|
+
"CANO": cano,
|
|
1410
|
+
"ACNT_PRDT_CD": acnt_prdt_cd,
|
|
1411
|
+
"OVRS_EXCG_CD": ovrs_excg_cd,
|
|
1412
|
+
"TR_CRCY_CD": tr_crcy_cd,
|
|
1413
|
+
"CTX_AREA_FK200": ctx_area_fk200,
|
|
1414
|
+
"CTX_AREA_NK200": ctx_area_nk200,
|
|
1500
1415
|
}
|
|
1501
1416
|
|
|
1502
1417
|
body, _ = self._tr_request(path, tr_id, tr_cont, params)
|
|
1503
|
-
if body[
|
|
1418
|
+
if body["rt_cd"] != "0":
|
|
1504
1419
|
raise ValueError(f"Error: ({body['msg_cd']}) {body['msg1']}")
|
|
1505
1420
|
|
|
1506
1421
|
output1 = []
|
|
1507
|
-
for el in body[
|
|
1422
|
+
for el in body["output1"]:
|
|
1508
1423
|
copied = el.copy()
|
|
1509
|
-
for k in [
|
|
1424
|
+
for k in ["frcr_evlu_pfls_amt", "evlu_pfls_rt", "pchs_avg_pric", "frcr_pchs_amt1", "ovrs_stck_evlu_amt", "now_pric2"]:
|
|
1510
1425
|
if copied.get(k) is not None and len(copied[k]) > 0:
|
|
1511
1426
|
copied[k] = Decimal(copied[k])
|
|
1512
1427
|
|
|
1513
|
-
for k in [
|
|
1428
|
+
for k in ["ovrs_cblc_qty", "ord_psbl_qty"]:
|
|
1514
1429
|
if copied.get(k) is not None and len(copied[k]) > 0:
|
|
1515
1430
|
copied[k] = int(copied[k])
|
|
1516
1431
|
|
|
1517
|
-
for k in [
|
|
1432
|
+
for k in ["loan_dt", "expd_dt"]:
|
|
1518
1433
|
if copied.get(k) is not None and len(copied[k]) > 0:
|
|
1519
|
-
copied[k] = dtm.datetime.strptime(copied[k],
|
|
1434
|
+
copied[k] = dtm.datetime.strptime(copied[k], "%Y%m%d").date()
|
|
1520
1435
|
|
|
1521
1436
|
output1.append(copied)
|
|
1522
1437
|
|
|
1523
|
-
output2 = body[
|
|
1438
|
+
output2 = body["output2"].copy()
|
|
1524
1439
|
for k in output2.keys():
|
|
1525
1440
|
if output2.get(k) is not None and len(output2[k]):
|
|
1526
1441
|
output2[k] = Decimal(output2[k])
|
|
1527
1442
|
|
|
1528
1443
|
result = {
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1444
|
+
"rt_cd": body["rt_cd"],
|
|
1445
|
+
"msg_cd": body["msg_cd"],
|
|
1446
|
+
"msg1": body["msg1"],
|
|
1447
|
+
"output1": output1,
|
|
1448
|
+
"output2": output2,
|
|
1449
|
+
"ctx_area_fk200": body["ctx_area_fk200"],
|
|
1450
|
+
"ctx_area_nk200": body["ctx_area_nk200"],
|
|
1536
1451
|
}
|
|
1537
1452
|
|
|
1538
1453
|
return result
|
|
@@ -1552,7 +1467,7 @@ class KISOverseasStock:
|
|
|
1552
1467
|
ctx_area_nk200: str = "",
|
|
1553
1468
|
tr_cont: str = "",
|
|
1554
1469
|
):
|
|
1555
|
-
|
|
1470
|
+
"""
|
|
1556
1471
|
(해외주식주문) 해외주식 주문체결내역[v1_해외주식-007]
|
|
1557
1472
|
|
|
1558
1473
|
| 일정 기간의 해외주식 주문 체결 내역을 확인하는 API입니다.
|
|
@@ -1625,52 +1540,52 @@ class KISOverseasStock:
|
|
|
1625
1540
|
|
|
1626
1541
|
Raise:
|
|
1627
1542
|
ValueError: API 호출 실패시 발생
|
|
1628
|
-
|
|
1543
|
+
"""
|
|
1629
1544
|
|
|
1630
|
-
assert sll_buy_dvsn in [
|
|
1631
|
-
assert ccld_nccs_dvsn in [
|
|
1632
|
-
assert sort_sqn in [
|
|
1545
|
+
assert sll_buy_dvsn in ["00", "01", "02"]
|
|
1546
|
+
assert ccld_nccs_dvsn in ["00", "01", "02"]
|
|
1547
|
+
assert sort_sqn in ["DS", "AS"]
|
|
1633
1548
|
|
|
1634
1549
|
if pdno is None:
|
|
1635
|
-
pdno =
|
|
1550
|
+
pdno = "" if self.auth.paper_trading else "%"
|
|
1636
1551
|
|
|
1637
|
-
path =
|
|
1552
|
+
path = "/uapi/overseas-stock/v1/trading/inquire-ccnl"
|
|
1638
1553
|
tr_id = "VTTS3035R" if self.auth.paper_trading else "TTTS3035R"
|
|
1639
1554
|
params = {
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1555
|
+
"CANO": cano,
|
|
1556
|
+
"ACNT_PRDT_CD": acnt_prdt_cd,
|
|
1557
|
+
"PDNO": pdno,
|
|
1558
|
+
"ORD_STRT_DT": ord_strt_dt.strftime("%Y%m%d"),
|
|
1559
|
+
"ORD_END_DT": ord_end_dt.strftime("%Y%m%d"),
|
|
1560
|
+
"SLL_BUY_DVSN": sll_buy_dvsn,
|
|
1561
|
+
"CCLD_NCCS_DVSN": ccld_nccs_dvsn,
|
|
1562
|
+
"OVRS_EXCG_CD": ovrs_excg_cd,
|
|
1563
|
+
"SORT_SQN": sort_sqn,
|
|
1564
|
+
"ORD_DT": "",
|
|
1565
|
+
"ORD_GNO_BRNO": "",
|
|
1566
|
+
"ODNO": "",
|
|
1567
|
+
"CTX_AREA_FK200": ctx_area_fk200,
|
|
1568
|
+
"CTX_AREA_NK200": ctx_area_nk200,
|
|
1654
1569
|
}
|
|
1655
1570
|
|
|
1656
1571
|
res_body, res_header = self._tr_request(path, tr_id, tr_cont, params)
|
|
1657
|
-
if res_body[
|
|
1572
|
+
if res_body["rt_cd"] != "0":
|
|
1658
1573
|
raise ValueError(f"Error: ({res_body['msg_cd']}) {res_body['msg1']}")
|
|
1659
1574
|
|
|
1660
1575
|
output = []
|
|
1661
|
-
for el in res_body[
|
|
1576
|
+
for el in res_body["output"]:
|
|
1662
1577
|
copied = el.copy()
|
|
1663
1578
|
for k in ["ord_dt", "loan_dt", "dmst_ord_dt"]:
|
|
1664
1579
|
if copied.get(k) is not None and len(copied[k]) > 0:
|
|
1665
|
-
copied[k] = dtm.datetime.strptime(copied[k],
|
|
1666
|
-
for k in [
|
|
1580
|
+
copied[k] = dtm.datetime.strptime(copied[k], "%Y%m%d").date()
|
|
1581
|
+
for k in ["ft_ord_qty", "ft_ccld_qty", "nccs_qty"]:
|
|
1667
1582
|
if copied.get(k) is not None:
|
|
1668
1583
|
copied[k] = int(copied[k])
|
|
1669
|
-
for k in [
|
|
1584
|
+
for k in ["ft_ord_unpr3", "ft_ccld_unpr3", "ft_ccld_amt3"]:
|
|
1670
1585
|
if copied.get(k) is not None:
|
|
1671
1586
|
copied[k] = Decimal(copied[k])
|
|
1672
1587
|
|
|
1673
|
-
copied[
|
|
1588
|
+
copied["ord_tmd"] = dtm.datetime.strptime(copied["ord_tmd"], "%H%M%S").time()
|
|
1674
1589
|
|
|
1675
1590
|
output.append(copied)
|
|
1676
1591
|
|
|
@@ -1686,13 +1601,8 @@ class KISOverseasStock:
|
|
|
1686
1601
|
|
|
1687
1602
|
return result
|
|
1688
1603
|
|
|
1689
|
-
def inquire_psamount(self,
|
|
1690
|
-
|
|
1691
|
-
acnt_prdt_cd: str,
|
|
1692
|
-
ovrs_excg_cd: str,
|
|
1693
|
-
ovrs_ord_unpr: Decimal,
|
|
1694
|
-
item_cd: str):
|
|
1695
|
-
'''
|
|
1604
|
+
def inquire_psamount(self, cano: str, acnt_prdt_cd: str, ovrs_excg_cd: str, ovrs_ord_unpr: Decimal, item_cd: str):
|
|
1605
|
+
"""
|
|
1696
1606
|
(해외주식주문) 해외주식 매수가능금액조회[v1_해외주식-014]
|
|
1697
1607
|
|
|
1698
1608
|
| 해외주식 매수가능금액조회 API입니다.
|
|
@@ -1730,56 +1640,59 @@ class KISOverseasStock:
|
|
|
1730
1640
|
|
|
1731
1641
|
Raises:
|
|
1732
1642
|
ValueError: API 호출 실패시 발생
|
|
1733
|
-
|
|
1643
|
+
"""
|
|
1734
1644
|
|
|
1735
1645
|
assert self.auth.paper_trading is False, "모의투자에서는 사용할 수 없는 API입니다."
|
|
1736
1646
|
|
|
1737
|
-
url_path =
|
|
1738
|
-
tr_id =
|
|
1739
|
-
tr_cont =
|
|
1647
|
+
url_path = "/uapi/overseas-stock/v1/trading/inquire-psamount"
|
|
1648
|
+
tr_id = "TTTS3007R"
|
|
1649
|
+
tr_cont = ""
|
|
1740
1650
|
params = {
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1651
|
+
"CANO": cano,
|
|
1652
|
+
"ACNT_PRDT_CD": acnt_prdt_cd,
|
|
1653
|
+
"OVRS_EXCG_CD": ovrs_excg_cd,
|
|
1654
|
+
"OVRS_ORD_UNPR": str(ovrs_ord_unpr),
|
|
1655
|
+
"ITEM_CD": item_cd,
|
|
1746
1656
|
}
|
|
1747
1657
|
|
|
1748
1658
|
res_body, _ = self._tr_request(url_path, tr_id, tr_cont, params)
|
|
1749
|
-
if res_body[
|
|
1659
|
+
if res_body["rt_cd"] != "0":
|
|
1750
1660
|
raise ValueError(f"Error: ({res_body['msg_cd']}) {res_body['msg1']}")
|
|
1751
1661
|
|
|
1752
|
-
output = res_body[
|
|
1662
|
+
output = res_body["output"].copy()
|
|
1753
1663
|
|
|
1754
|
-
for k in [
|
|
1664
|
+
for k in ["ord_psbl_frcr_amt", "sll_ruse_psbl_amt", "ovrs_ord_psbl_amt", "echm_af_ord_psbl_amt", "exrt", "frcr_ord_psbl_amt1"]:
|
|
1755
1665
|
if output.get(k) is not None and len(output.get(k)) > 0:
|
|
1756
1666
|
output[k] = Decimal(output[k])
|
|
1757
1667
|
|
|
1758
|
-
for k in [
|
|
1668
|
+
for k in ["max_ord_psbl_qty", "echm_af_ord_psbl_qty", "ord_psbl_qty", "ovrs_max_ord_psbl_qty"]:
|
|
1759
1669
|
if output.get(k) is not None and len(output.get(k)) > 0:
|
|
1760
1670
|
output[k] = int(output[k])
|
|
1761
1671
|
|
|
1762
1672
|
result = {
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1673
|
+
"rt_cd": res_body["rt_cd"],
|
|
1674
|
+
"msg_cd": res_body["msg_cd"],
|
|
1675
|
+
"msg1": res_body["msg1"],
|
|
1676
|
+
"output": res_body["output"],
|
|
1767
1677
|
}
|
|
1768
1678
|
|
|
1769
1679
|
return result
|
|
1770
1680
|
|
|
1771
|
-
def inquire_period_profit(
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1681
|
+
def inquire_period_profit(
|
|
1682
|
+
self,
|
|
1683
|
+
cano: str,
|
|
1684
|
+
acnt_prdt_cd: str,
|
|
1685
|
+
inqr_strt_dt: dtm.date,
|
|
1686
|
+
inqr_end_dt: dtm.date,
|
|
1687
|
+
wcrc_frcr_dvsn_cd: str,
|
|
1688
|
+
ovrs_excg_cd: str = "",
|
|
1689
|
+
crcy_cd: str = "",
|
|
1690
|
+
pdno: str = "",
|
|
1691
|
+
ctx_area_fk200: str = "",
|
|
1692
|
+
ctx_area_nk200: str = "",
|
|
1693
|
+
tr_cont: str = "",
|
|
1694
|
+
):
|
|
1695
|
+
"""
|
|
1783
1696
|
(해외주식주문) 해외주식 기간손익[v1_해외주식-032]
|
|
1784
1697
|
|
|
1785
1698
|
해외주식 기간손익 API입니다.
|
|
@@ -1798,6 +1711,7 @@ class KISOverseasStock:
|
|
|
1798
1711
|
pdno (str): 상품번호 - 공란:전체
|
|
1799
1712
|
ctx_area_fk200 (str): 연속조회검색조건200 - 초기조회 시 공백, 다음페이지 조회시 이전 조회 결과의 CTX_AREA_FK200값
|
|
1800
1713
|
ctx_area_nk200 (str): 연속조회키200 - 초기조회 시 공백, 다음페이지 조회시 이전 조회 결과의 CTX_AREA_NK200값
|
|
1714
|
+
tr_cont (str): 연속조회여부 - 공란:최초 조회시. 'N':연속조회시
|
|
1801
1715
|
|
|
1802
1716
|
Returns:
|
|
1803
1717
|
dict:
|
|
@@ -1835,14 +1749,13 @@ class KISOverseasStock:
|
|
|
1835
1749
|
|
|
1836
1750
|
Raises:
|
|
1837
1751
|
ValueError - API 호출 실패시 발생
|
|
1838
|
-
|
|
1752
|
+
"""
|
|
1839
1753
|
|
|
1840
1754
|
assert self.auth.paper_trading is False, "모의투자에서는 사용할 수 없는 API입니다."
|
|
1841
1755
|
assert wcrc_frcr_dvsn_cd in ["01", "02"], "원화외화구분코드는 01(원화) 또는 02(외화)만 가능합니다."
|
|
1842
1756
|
|
|
1843
1757
|
url_path = "/uapi/overseas-stock/v1/trading/inquire-period-profit"
|
|
1844
1758
|
tr_id = "TTTS3039R"
|
|
1845
|
-
tr_cont = ""
|
|
1846
1759
|
params = {
|
|
1847
1760
|
"CANO": cano,
|
|
1848
1761
|
"ACNT_PRDT_CD": acnt_prdt_cd,
|
|
@@ -1858,37 +1771,37 @@ class KISOverseasStock:
|
|
|
1858
1771
|
}
|
|
1859
1772
|
|
|
1860
1773
|
res_body, res_header = self._tr_request(url_path, tr_id, tr_cont, params)
|
|
1861
|
-
if res_body[
|
|
1774
|
+
if res_body["rt_cd"] != "0":
|
|
1862
1775
|
raise ValueError(f"Error: ({res_body['msg_cd']}) {res_body['msg1']}")
|
|
1863
1776
|
|
|
1864
1777
|
output1 = []
|
|
1865
|
-
for el in res_body[
|
|
1778
|
+
for el in res_body["output1"]:
|
|
1866
1779
|
copied = el.copy()
|
|
1867
|
-
copied[
|
|
1868
|
-
copied[
|
|
1869
|
-
for k in [
|
|
1780
|
+
copied["trad_day"] = dtm.datetime.strptime(copied["trad_day"], "%Y%m%d").date()
|
|
1781
|
+
copied["slcl_qty"] = int(copied["slcl_qty"])
|
|
1782
|
+
for k in ["pchs_avg_pric", "frcr_pchs_amt1", "avg_sll_unpr", "frcr_sll_amt_smtl1", "stck_sll_tlex", "ovrs_rlzt_pfls_amt", "pftrt", "exrt", "frst_bltn_exrt"]:
|
|
1870
1783
|
if copied.get(k) is not None and len(copied[k]) > 0:
|
|
1871
1784
|
copied[k] = Decimal(copied[k])
|
|
1872
1785
|
|
|
1873
1786
|
output1.append(copied)
|
|
1874
1787
|
|
|
1875
|
-
output2 = res_body[
|
|
1876
|
-
for k in [
|
|
1788
|
+
output2 = res_body["output2"].copy()
|
|
1789
|
+
for k in ["stck_sll_amt_smtl", "stck_buy_amt_smtl", "smtl_fee1", "excc_dfrm_amt", "ovrs_rlzt_pfls_tot_amt", "tot_pftrt", "exrt"]:
|
|
1877
1790
|
if output2.get(k) is not None and len(output2[k]) > 0:
|
|
1878
1791
|
output2[k] = Decimal(output2[k])
|
|
1879
1792
|
|
|
1880
|
-
if output2.get(
|
|
1881
|
-
output2[
|
|
1793
|
+
if output2.get("base_dt") is not None and len(output2["base_dt"]) > 0:
|
|
1794
|
+
output2["base_dt"] = dtm.datetime.strptime(output2["base_dt"], "%Y%m%d").date()
|
|
1882
1795
|
|
|
1883
1796
|
result = {
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1797
|
+
"rt_cd": res_body["rt_cd"],
|
|
1798
|
+
"msg_cd": res_body["msg_cd"],
|
|
1799
|
+
"msg1": res_body["msg1"],
|
|
1800
|
+
"tr_cont": res_header["tr_cont"],
|
|
1801
|
+
"output1": output1,
|
|
1802
|
+
"output2": output2,
|
|
1803
|
+
"ctx_area_fk200": res_body.get("ctx_area_fk200", ""),
|
|
1804
|
+
"ctx_area_nk200": res_body.get("ctx_area_nk200", ""),
|
|
1892
1805
|
}
|
|
1893
1806
|
|
|
1894
1807
|
return result
|