kiwoomRest 0.0.2__tar.gz
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.
- kiwoomrest-0.0.2/.gitignore +368 -0
- kiwoomrest-0.0.2/LICENSE +22 -0
- kiwoomrest-0.0.2/PKG-INFO +317 -0
- kiwoomrest-0.0.2/README.md +304 -0
- kiwoomrest-0.0.2/kiwoomRest.pyproj +47 -0
- kiwoomrest-0.0.2/pyproject.toml +25 -0
- kiwoomrest-0.0.2/src/kiwoomRest/__init__.py +6 -0
- kiwoomrest-0.0.2/src/kiwoomRest/rest_api.py +469 -0
- kiwoomrest-0.0.2/src/kiwoomRest/tr_code_to_path.py +398 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
## Ignore Visual Studio temporary files, build results, and
|
|
2
|
+
## files generated by popular Visual Studio add-ons.
|
|
3
|
+
##
|
|
4
|
+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
|
5
|
+
|
|
6
|
+
# User-specific files
|
|
7
|
+
*.rsuser
|
|
8
|
+
*.suo
|
|
9
|
+
*.user
|
|
10
|
+
*.userosscache
|
|
11
|
+
*.sln.docstates
|
|
12
|
+
**env
|
|
13
|
+
build/
|
|
14
|
+
dist/
|
|
15
|
+
*.egg-info/
|
|
16
|
+
app_keys.py
|
|
17
|
+
|
|
18
|
+
# User-specific files (MonoDevelop/Xamarin Studio)
|
|
19
|
+
*.userprefs
|
|
20
|
+
|
|
21
|
+
# Mono auto generated files
|
|
22
|
+
mono_crash.*
|
|
23
|
+
|
|
24
|
+
# Build results
|
|
25
|
+
[Dd]ebug/
|
|
26
|
+
[Dd]ebugPublic/
|
|
27
|
+
[Rr]elease/
|
|
28
|
+
[Rr]eleases/
|
|
29
|
+
x64/
|
|
30
|
+
x86/
|
|
31
|
+
[Ww][Ii][Nn]32/
|
|
32
|
+
[Aa][Rr][Mm]/
|
|
33
|
+
[Aa][Rr][Mm]64/
|
|
34
|
+
bld/
|
|
35
|
+
[Bb]in/
|
|
36
|
+
[Oo]bj/
|
|
37
|
+
[Oo]ut/
|
|
38
|
+
[Ll]og/
|
|
39
|
+
[Ll]ogs/
|
|
40
|
+
|
|
41
|
+
# Visual Studio 2015/2017 cache/options directory
|
|
42
|
+
.vs/
|
|
43
|
+
# Uncomment if you have tasks that create the project's static files in wwwroot
|
|
44
|
+
#wwwroot/
|
|
45
|
+
|
|
46
|
+
# Visual Studio 2017 auto generated files
|
|
47
|
+
Generated\ Files/
|
|
48
|
+
|
|
49
|
+
# MSTest test Results
|
|
50
|
+
[Tt]est[Rr]esult*/
|
|
51
|
+
[Bb]uild[Ll]og.*
|
|
52
|
+
|
|
53
|
+
# NUnit
|
|
54
|
+
*.VisualState.xml
|
|
55
|
+
TestResult.xml
|
|
56
|
+
nunit-*.xml
|
|
57
|
+
|
|
58
|
+
# Build Results of an ATL Project
|
|
59
|
+
[Dd]ebugPS/
|
|
60
|
+
[Rr]eleasePS/
|
|
61
|
+
dlldata.c
|
|
62
|
+
|
|
63
|
+
# Benchmark Results
|
|
64
|
+
BenchmarkDotNet.Artifacts/
|
|
65
|
+
|
|
66
|
+
# .NET Core
|
|
67
|
+
project.lock.json
|
|
68
|
+
project.fragment.lock.json
|
|
69
|
+
artifacts/
|
|
70
|
+
|
|
71
|
+
# ASP.NET Scaffolding
|
|
72
|
+
ScaffoldingReadMe.txt
|
|
73
|
+
|
|
74
|
+
# StyleCop
|
|
75
|
+
StyleCopReport.xml
|
|
76
|
+
|
|
77
|
+
# Files built by Visual Studio
|
|
78
|
+
*_i.c
|
|
79
|
+
*_p.c
|
|
80
|
+
*_h.h
|
|
81
|
+
*.ilk
|
|
82
|
+
*.meta
|
|
83
|
+
*.obj
|
|
84
|
+
*.iobj
|
|
85
|
+
*.pch
|
|
86
|
+
*.pdb
|
|
87
|
+
*.ipdb
|
|
88
|
+
*.pgc
|
|
89
|
+
*.pgd
|
|
90
|
+
*.rsp
|
|
91
|
+
*.sbr
|
|
92
|
+
*.tlb
|
|
93
|
+
*.tli
|
|
94
|
+
*.tlh
|
|
95
|
+
*.tmp
|
|
96
|
+
*.tmp_proj
|
|
97
|
+
*_wpftmp.csproj
|
|
98
|
+
*.log
|
|
99
|
+
*.vspscc
|
|
100
|
+
*.vssscc
|
|
101
|
+
.builds
|
|
102
|
+
*.pidb
|
|
103
|
+
*.svclog
|
|
104
|
+
*.scc
|
|
105
|
+
|
|
106
|
+
# Chutzpah Test files
|
|
107
|
+
_Chutzpah*
|
|
108
|
+
|
|
109
|
+
# Visual C++ cache files
|
|
110
|
+
ipch/
|
|
111
|
+
*.aps
|
|
112
|
+
*.ncb
|
|
113
|
+
*.opendb
|
|
114
|
+
*.opensdf
|
|
115
|
+
*.sdf
|
|
116
|
+
*.cachefile
|
|
117
|
+
*.VC.db
|
|
118
|
+
*.VC.VC.opendb
|
|
119
|
+
|
|
120
|
+
# Visual Studio profiler
|
|
121
|
+
*.psess
|
|
122
|
+
*.vsp
|
|
123
|
+
*.vspx
|
|
124
|
+
*.sap
|
|
125
|
+
|
|
126
|
+
# Visual Studio Trace Files
|
|
127
|
+
*.e2e
|
|
128
|
+
|
|
129
|
+
# TFS 2012 Local Workspace
|
|
130
|
+
$tf/
|
|
131
|
+
|
|
132
|
+
# Guidance Automation Toolkit
|
|
133
|
+
*.gpState
|
|
134
|
+
|
|
135
|
+
# ReSharper is a .NET coding add-in
|
|
136
|
+
_ReSharper*/
|
|
137
|
+
*.[Rr]e[Ss]harper
|
|
138
|
+
*.DotSettings.user
|
|
139
|
+
|
|
140
|
+
# TeamCity is a build add-in
|
|
141
|
+
_TeamCity*
|
|
142
|
+
|
|
143
|
+
# DotCover is a Code Coverage Tool
|
|
144
|
+
*.dotCover
|
|
145
|
+
|
|
146
|
+
# AxoCover is a Code Coverage Tool
|
|
147
|
+
.axoCover/*
|
|
148
|
+
!.axoCover/settings.json
|
|
149
|
+
|
|
150
|
+
# Coverlet is a free, cross platform Code Coverage Tool
|
|
151
|
+
coverage*.json
|
|
152
|
+
coverage*.xml
|
|
153
|
+
coverage*.info
|
|
154
|
+
|
|
155
|
+
# Visual Studio code coverage results
|
|
156
|
+
*.coverage
|
|
157
|
+
*.coveragexml
|
|
158
|
+
|
|
159
|
+
# NCrunch
|
|
160
|
+
_NCrunch_*
|
|
161
|
+
.*crunch*.local.xml
|
|
162
|
+
nCrunchTemp_*
|
|
163
|
+
|
|
164
|
+
# MightyMoose
|
|
165
|
+
*.mm.*
|
|
166
|
+
AutoTest.Net/
|
|
167
|
+
|
|
168
|
+
# Web workbench (sass)
|
|
169
|
+
.sass-cache/
|
|
170
|
+
|
|
171
|
+
# Installshield output folder
|
|
172
|
+
[Ee]xpress/
|
|
173
|
+
|
|
174
|
+
# DocProject is a documentation generator add-in
|
|
175
|
+
DocProject/buildhelp/
|
|
176
|
+
DocProject/Help/*.HxT
|
|
177
|
+
DocProject/Help/*.HxC
|
|
178
|
+
DocProject/Help/*.hhc
|
|
179
|
+
DocProject/Help/*.hhk
|
|
180
|
+
DocProject/Help/*.hhp
|
|
181
|
+
DocProject/Help/Html2
|
|
182
|
+
DocProject/Help/html
|
|
183
|
+
|
|
184
|
+
# Click-Once directory
|
|
185
|
+
publish/
|
|
186
|
+
|
|
187
|
+
# Publish Web Output
|
|
188
|
+
*.[Pp]ublish.xml
|
|
189
|
+
*.azurePubxml
|
|
190
|
+
# Note: Comment the next line if you want to checkin your web deploy settings,
|
|
191
|
+
# but database connection strings (with potential passwords) will be unencrypted
|
|
192
|
+
*.pubxml
|
|
193
|
+
*.publishproj
|
|
194
|
+
|
|
195
|
+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
|
196
|
+
# checkin your Azure Web App publish settings, but sensitive information contained
|
|
197
|
+
# in these scripts will be unencrypted
|
|
198
|
+
PublishScripts/
|
|
199
|
+
|
|
200
|
+
# NuGet Packages
|
|
201
|
+
*.nupkg
|
|
202
|
+
# NuGet Symbol Packages
|
|
203
|
+
*.snupkg
|
|
204
|
+
# The packages folder can be ignored because of Package Restore
|
|
205
|
+
**/[Pp]ackages/*
|
|
206
|
+
# except build/, which is used as an MSBuild target.
|
|
207
|
+
!**/[Pp]ackages/build/
|
|
208
|
+
# Uncomment if necessary however generally it will be regenerated when needed
|
|
209
|
+
#!**/[Pp]ackages/repositories.config
|
|
210
|
+
# NuGet v3's project.json files produces more ignorable files
|
|
211
|
+
*.nuget.props
|
|
212
|
+
*.nuget.targets
|
|
213
|
+
|
|
214
|
+
# Microsoft Azure Build Output
|
|
215
|
+
csx/
|
|
216
|
+
*.build.csdef
|
|
217
|
+
|
|
218
|
+
# Microsoft Azure Emulator
|
|
219
|
+
ecf/
|
|
220
|
+
rcf/
|
|
221
|
+
|
|
222
|
+
# Windows Store app package directories and files
|
|
223
|
+
AppPackages/
|
|
224
|
+
BundleArtifacts/
|
|
225
|
+
Package.StoreAssociation.xml
|
|
226
|
+
_pkginfo.txt
|
|
227
|
+
*.appx
|
|
228
|
+
*.appxbundle
|
|
229
|
+
*.appxupload
|
|
230
|
+
|
|
231
|
+
# Visual Studio cache files
|
|
232
|
+
# files ending in .cache can be ignored
|
|
233
|
+
*.[Cc]ache
|
|
234
|
+
# but keep track of directories ending in .cache
|
|
235
|
+
!?*.[Cc]ache/
|
|
236
|
+
|
|
237
|
+
# Others
|
|
238
|
+
ClientBin/
|
|
239
|
+
~$*
|
|
240
|
+
*~
|
|
241
|
+
*.dbmdl
|
|
242
|
+
*.dbproj.schemaview
|
|
243
|
+
*.jfm
|
|
244
|
+
*.pfx
|
|
245
|
+
*.publishsettings
|
|
246
|
+
orleans.codegen.cs
|
|
247
|
+
|
|
248
|
+
# Including strong name files can present a security risk
|
|
249
|
+
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
|
250
|
+
#*.snk
|
|
251
|
+
|
|
252
|
+
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
|
253
|
+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
|
254
|
+
#bower_components/
|
|
255
|
+
|
|
256
|
+
# RIA/Silverlight projects
|
|
257
|
+
Generated_Code/
|
|
258
|
+
|
|
259
|
+
# Backup & report files from converting an old project file
|
|
260
|
+
# to a newer Visual Studio version. Backup files are not needed,
|
|
261
|
+
# because we have git ;-)
|
|
262
|
+
_UpgradeReport_Files/
|
|
263
|
+
Backup*/
|
|
264
|
+
UpgradeLog*.XML
|
|
265
|
+
UpgradeLog*.htm
|
|
266
|
+
ServiceFabricBackup/
|
|
267
|
+
*.rptproj.bak
|
|
268
|
+
|
|
269
|
+
# SQL Server files
|
|
270
|
+
*.mdf
|
|
271
|
+
*.ldf
|
|
272
|
+
*.ndf
|
|
273
|
+
|
|
274
|
+
# Business Intelligence projects
|
|
275
|
+
*.rdl.data
|
|
276
|
+
*.bim.layout
|
|
277
|
+
*.bim_*.settings
|
|
278
|
+
*.rptproj.rsuser
|
|
279
|
+
*- [Bb]ackup.rdl
|
|
280
|
+
*- [Bb]ackup ([0-9]).rdl
|
|
281
|
+
*- [Bb]ackup ([0-9][0-9]).rdl
|
|
282
|
+
|
|
283
|
+
# Microsoft Fakes
|
|
284
|
+
FakesAssemblies/
|
|
285
|
+
|
|
286
|
+
# GhostDoc plugin setting file
|
|
287
|
+
*.GhostDoc.xml
|
|
288
|
+
|
|
289
|
+
# Node.js Tools for Visual Studio
|
|
290
|
+
.ntvs_analysis.dat
|
|
291
|
+
node_modules/
|
|
292
|
+
|
|
293
|
+
# Visual Studio 6 build log
|
|
294
|
+
*.plg
|
|
295
|
+
|
|
296
|
+
# Visual Studio 6 workspace options file
|
|
297
|
+
*.opt
|
|
298
|
+
|
|
299
|
+
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
|
300
|
+
*.vbw
|
|
301
|
+
|
|
302
|
+
# Visual Studio LightSwitch build output
|
|
303
|
+
**/*.HTMLClient/GeneratedArtifacts
|
|
304
|
+
**/*.DesktopClient/GeneratedArtifacts
|
|
305
|
+
**/*.DesktopClient/ModelManifest.xml
|
|
306
|
+
**/*.Server/GeneratedArtifacts
|
|
307
|
+
**/*.Server/ModelManifest.xml
|
|
308
|
+
_Pvt_Extensions
|
|
309
|
+
|
|
310
|
+
# Paket dependency manager
|
|
311
|
+
.paket/paket.exe
|
|
312
|
+
paket-files/
|
|
313
|
+
|
|
314
|
+
# FAKE - F# Make
|
|
315
|
+
.fake/
|
|
316
|
+
|
|
317
|
+
# CodeRush personal settings
|
|
318
|
+
.cr/personal
|
|
319
|
+
|
|
320
|
+
# Python Tools for Visual Studio (PTVS)
|
|
321
|
+
__pycache__/
|
|
322
|
+
*.pyc
|
|
323
|
+
|
|
324
|
+
# Cake - Uncomment if you are using it
|
|
325
|
+
# tools/**
|
|
326
|
+
# !tools/packages.config
|
|
327
|
+
|
|
328
|
+
# Tabs Studio
|
|
329
|
+
*.tss
|
|
330
|
+
|
|
331
|
+
# Telerik's JustMock configuration file
|
|
332
|
+
*.jmconfig
|
|
333
|
+
|
|
334
|
+
# BizTalk build output
|
|
335
|
+
*.btp.cs
|
|
336
|
+
*.btm.cs
|
|
337
|
+
*.odx.cs
|
|
338
|
+
*.xsd.cs
|
|
339
|
+
|
|
340
|
+
# OpenCover UI analysis results
|
|
341
|
+
OpenCover/
|
|
342
|
+
|
|
343
|
+
# Azure Stream Analytics local run output
|
|
344
|
+
ASALocalRun/
|
|
345
|
+
|
|
346
|
+
# MSBuild Binary and Structured Log
|
|
347
|
+
*.binlog
|
|
348
|
+
|
|
349
|
+
# NVidia Nsight GPU debugger configuration file
|
|
350
|
+
*.nvuser
|
|
351
|
+
|
|
352
|
+
# MFractors (Xamarin productivity tool) working folder
|
|
353
|
+
.mfractor/
|
|
354
|
+
|
|
355
|
+
# Local History for Visual Studio
|
|
356
|
+
.localhistory/
|
|
357
|
+
|
|
358
|
+
# BeatPulse healthcheck temp database
|
|
359
|
+
healthchecksdb
|
|
360
|
+
|
|
361
|
+
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
|
362
|
+
MigrationBackup/
|
|
363
|
+
|
|
364
|
+
# Ionide (cross platform F# VS Code tools) working folder
|
|
365
|
+
.ionide/
|
|
366
|
+
|
|
367
|
+
# Fody - auto-generated XML schema
|
|
368
|
+
FodyWeavers.xsd
|
kiwoomrest-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 teranum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: kiwoomRest
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: package for Kiwoom RestAPI
|
|
5
|
+
Project-URL: Homepage, https://github.com/teranum/python-packages/tree/master/kiwoomRest
|
|
6
|
+
Author-email: teranum <teranum@gmail.com>
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Requires-Dist: aiohttp
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# kiwoomRest
|
|
15
|
+
|
|
16
|
+
> 키움증권 OpenAPI REST 서비스를 위한 비동기 Python 클라이언트 패키지
|
|
17
|
+
|
|
18
|
+
[](https://pypi.org/project/kiwoomRest/)
|
|
19
|
+
[](https://pypi.org/project/kiwoomRest/)
|
|
20
|
+
[](LICENSE)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 목차
|
|
25
|
+
|
|
26
|
+
- [설치](#설치)
|
|
27
|
+
- [빠른 시작](#빠른-시작)
|
|
28
|
+
- [사용 예제](#사용-예제)
|
|
29
|
+
- [국내주식 조회 / 연속조회](#국내주식-조회--연속조회)
|
|
30
|
+
- [미국주식 조회](#미국주식-조회)
|
|
31
|
+
- [조건검색 조회 / 실시간](#조건검색-조회--실시간)
|
|
32
|
+
- [실시간 시세 등록 / 해제](#실시간-시세-등록--해제)
|
|
33
|
+
- [API 레퍼런스](#api-레퍼런스)
|
|
34
|
+
- [프로퍼티](#프로퍼티)
|
|
35
|
+
- [메소드](#메소드)
|
|
36
|
+
- [이벤트](#이벤트)
|
|
37
|
+
- [ResponseData](#responsedata)
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 설치
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install kiwoomRest
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 빠른 시작
|
|
50
|
+
|
|
51
|
+
> **⚠️ 모든 요청은 비동기(`async/await`)로 처리됩니다.**
|
|
52
|
+
> 로그인은 반드시 다른 요청보다 먼저 수행되어야 합니다.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import asyncio
|
|
56
|
+
from kiwoomRest import KwRestApi
|
|
57
|
+
from app_keys import appkey, secretkey # app_keys.py에 appkey, secretkey 변수를 정의하세요
|
|
58
|
+
|
|
59
|
+
async def main():
|
|
60
|
+
api = KwRestApi()
|
|
61
|
+
|
|
62
|
+
# 실시간 이벤트 핸들러 등록
|
|
63
|
+
api.on_realtime.connect(lambda data: print(f"실시간: {data}"))
|
|
64
|
+
|
|
65
|
+
# 국내주식 실거래 로그인 (모의투자: is_simulation=True)
|
|
66
|
+
if not await api.login(appkey, secretkey, is_simulation=False):
|
|
67
|
+
print(f"로그인 실패: {api.last_message}")
|
|
68
|
+
return
|
|
69
|
+
print("로그인 성공")
|
|
70
|
+
|
|
71
|
+
# 작업 수행...
|
|
72
|
+
await asyncio.sleep(5)
|
|
73
|
+
|
|
74
|
+
await api.close()
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**미국주식 로그인**
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
# 미국주식 실거래 로그인 (모의투자: is_simulation=True)
|
|
83
|
+
if not await api.login(appkey, secretkey, is_simulation=False, is_us=True):
|
|
84
|
+
print(f"로그인 실패: {api.last_message}")
|
|
85
|
+
return
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## 사용 예제
|
|
91
|
+
|
|
92
|
+
### 국내주식 조회 / 연속조회
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# 종목정보 리스트 조회
|
|
96
|
+
inputs = {
|
|
97
|
+
"mrkt_tp": "0" # 0:코스피, 10:코스닥, 3:ELW, 8:ETF, 30:K-OTC, 50:코넥스
|
|
98
|
+
}
|
|
99
|
+
response = await api.request("ka10099", inputs)
|
|
100
|
+
|
|
101
|
+
# 주식 종목정보 조회 (삼성전자)
|
|
102
|
+
inputs = {"stk_cd": "005930"}
|
|
103
|
+
response = await api.request("ka10001", inputs)
|
|
104
|
+
|
|
105
|
+
# 주식 일봉 차트 조회
|
|
106
|
+
inputs = {
|
|
107
|
+
"stk_cd": "005930", # 종목코드
|
|
108
|
+
"base_dt": "00000000", # 기준일자 (00000000: 현재일)
|
|
109
|
+
"upd_stkpc_tp": "1" # 수정주가 적용여부 (0:미적용, 1:적용)
|
|
110
|
+
}
|
|
111
|
+
response = await api.request("ka10081", inputs)
|
|
112
|
+
|
|
113
|
+
# 연속조회
|
|
114
|
+
while response.return_code == 0 and response.cont_yn == "Y":
|
|
115
|
+
response = await api.request("ka10081", inputs,
|
|
116
|
+
cont_yn=response.cont_yn,
|
|
117
|
+
next_key=response.next_key)
|
|
118
|
+
|
|
119
|
+
# 결과 확인
|
|
120
|
+
if response.return_code == 0:
|
|
121
|
+
print("조회 성공:", response.body)
|
|
122
|
+
else:
|
|
123
|
+
print(f"조회 실패: {response.return_msg}")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### 미국주식 조회
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
# 미국주식 조건검색 목록 조회
|
|
132
|
+
inputs = {"trnm": "GCNSRLST"}
|
|
133
|
+
response = await api.request("usa20280", inputs)
|
|
134
|
+
|
|
135
|
+
if response.return_code == 0:
|
|
136
|
+
print("조회 성공:", response.body)
|
|
137
|
+
else:
|
|
138
|
+
print(f"조회 실패: {response.return_msg}")
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### 조건검색 조회 / 실시간
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
# 서버저장 조건 리스트 조회
|
|
147
|
+
response = await api.request("ka10171", {"trnm": "CNSRLST"})
|
|
148
|
+
|
|
149
|
+
# 조건검색 일반 조회
|
|
150
|
+
inputs = {
|
|
151
|
+
"trnm": "CNSRREQ", # 고정값
|
|
152
|
+
"seq": "4", # 조건검색식 일련번호
|
|
153
|
+
"search_type": "0", # 0:일반조회
|
|
154
|
+
"stex_tp": "K", # K:KRX
|
|
155
|
+
"cont_yn": "N", # Y:연속조회, N:단순조회
|
|
156
|
+
"next_key": ""
|
|
157
|
+
}
|
|
158
|
+
response = await api.request("ka10172", inputs)
|
|
159
|
+
|
|
160
|
+
# 조건검색 실시간 등록
|
|
161
|
+
api.on_realtime.connect(print)
|
|
162
|
+
inputs = {
|
|
163
|
+
"trnm": "CNSRREQ",
|
|
164
|
+
"seq": "4",
|
|
165
|
+
"search_type": "1", # 1:조건검색+실시간
|
|
166
|
+
"stex_tp": "K"
|
|
167
|
+
}
|
|
168
|
+
response = await api.realtime(inputs)
|
|
169
|
+
|
|
170
|
+
if response.return_code != 0:
|
|
171
|
+
print(f"실시간 등록 실패: {response.return_msg}")
|
|
172
|
+
else:
|
|
173
|
+
print("실시간 등록 성공")
|
|
174
|
+
await asyncio.sleep(60) # 60초 수신
|
|
175
|
+
|
|
176
|
+
# 실시간 해제
|
|
177
|
+
await api.realtime({"trnm": "CNSRCLR", "seq": "4"})
|
|
178
|
+
print("실시간 해제 완료")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
### 실시간 시세 등록 / 해제
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
def on_realtime(data):
|
|
187
|
+
print(f"실시간 이벤트: {data}")
|
|
188
|
+
|
|
189
|
+
api.on_realtime.connect(on_realtime)
|
|
190
|
+
|
|
191
|
+
# 삼성전자 실시간 체결시세 등록
|
|
192
|
+
inputs = {
|
|
193
|
+
"trnm": "REG",
|
|
194
|
+
"grp_no": "1",
|
|
195
|
+
"refresh": "1",
|
|
196
|
+
"data": [{
|
|
197
|
+
" item": ["005930"], # 종목코드 (복수: ["005930", "000660"])
|
|
198
|
+
" type": ["0B"] # 0B:체결시세, 0C:우선호가시세
|
|
199
|
+
}]
|
|
200
|
+
}
|
|
201
|
+
response = await api.realtime(inputs)
|
|
202
|
+
|
|
203
|
+
await asyncio.sleep(60) # 60초 수신
|
|
204
|
+
|
|
205
|
+
# 실시간 시세 해제
|
|
206
|
+
inputs["trnm"] = "REMOVE"
|
|
207
|
+
await api.realtime(inputs)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## API 레퍼런스
|
|
213
|
+
|
|
214
|
+
### 프로퍼티
|
|
215
|
+
|
|
216
|
+
| 프로퍼티 | 타입 | 설명 |
|
|
217
|
+
|---|---|---|
|
|
218
|
+
| `connected` | `bool` | 연결 여부 (`True`: 연결됨) |
|
|
219
|
+
| `is_simulation` | `bool` | 모의투자 여부 (`True`: 모의투자) |
|
|
220
|
+
| `is_us` | `bool` | 미국주식 여부 (`True`: 미국주식) |
|
|
221
|
+
| `access_token` | `str` | 발급된 액세스 토큰 |
|
|
222
|
+
| `last_message` | `str` | 마지막 메시지 (로그인/요청 실패 시 사유) |
|
|
223
|
+
| `last_response` | `ResponseData \| None` | 마지막 요청의 응답 데이터 |
|
|
224
|
+
| `timeout` | `int` | 요청 타임아웃(초), 기본값: `5` |
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
### 메소드
|
|
229
|
+
|
|
230
|
+
#### `login`
|
|
231
|
+
```python
|
|
232
|
+
await api.login(appkey, secretkey, is_simulation=False, is_us=False) -> bool
|
|
233
|
+
```
|
|
234
|
+
| 파라미터 | 타입 | 설명 |
|
|
235
|
+
|---|---|---|
|
|
236
|
+
| `appkey` | `str` | 앱키 |
|
|
237
|
+
| `secretkey` | `str` | 앱 시크릿키 |
|
|
238
|
+
| `is_simulation` | `bool` | 모의투자 서버 사용 여부, 기본값: `False` |
|
|
239
|
+
| `is_us` | `bool` | 미국주식 서버 사용 여부, 기본값: `False` |
|
|
240
|
+
| **return** | `bool` | 성공: `True`, 실패: `False` (실패 사유는 `last_message` 참조) |
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
#### `request`
|
|
245
|
+
```python
|
|
246
|
+
await api.request(api_id, indatas, *, cont_yn='N', next_key='', path=None) -> ResponseData
|
|
247
|
+
```
|
|
248
|
+
| 파라미터 | 타입 | 설명 |
|
|
249
|
+
|---|---|---|
|
|
250
|
+
| `api_id` | `str` | TR 코드 (api-id) |
|
|
251
|
+
| `indatas` | `dict` | 요청 데이터 |
|
|
252
|
+
| `cont_yn` | `str` | 연속조회 여부 (`Y`/`N`), 기본값: `N` |
|
|
253
|
+
| `next_key` | `str` | 연속조회 키, 기본값: `""` |
|
|
254
|
+
| `path` | `str \| None` | 요청 경로 (생략 시 자동 설정), ex) `'/api/dostk/stkinfo'` |
|
|
255
|
+
| **return** | `ResponseData` | 응답 데이터 (`return_code == 0`: 성공) |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
#### `realtime`
|
|
260
|
+
```python
|
|
261
|
+
await api.realtime(indatas) -> ResponseData
|
|
262
|
+
```
|
|
263
|
+
| 파라미터 | 타입 | 설명 |
|
|
264
|
+
|---|---|---|
|
|
265
|
+
| `indatas` | `dict` | 실시간 요청 데이터 (`trnm` 필드 필수) |
|
|
266
|
+
| **return** | `ResponseData` | 응답 데이터 (`return_code == 0`: 성공) |
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
#### `close`
|
|
271
|
+
```python
|
|
272
|
+
await api.close() -> None
|
|
273
|
+
```
|
|
274
|
+
웹소켓 및 HTTP 세션 연결을 종료합니다.
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
### 이벤트
|
|
279
|
+
|
|
280
|
+
#### `on_message`
|
|
281
|
+
웹소켓 오류/연결 종료 시 발생합니다.
|
|
282
|
+
```python
|
|
283
|
+
api.on_message.connect(callback) # callback(msg: str)
|
|
284
|
+
```
|
|
285
|
+
| 발생 상황 | 메시지 형식 |
|
|
286
|
+
|---|---|
|
|
287
|
+
| 예외 발생 | `'websocket exception. {e}'` |
|
|
288
|
+
| 연결 종료 | `'websocket closed. {msg}'` |
|
|
289
|
+
| 오류 발생 | `'websocket error. {msg}'` |
|
|
290
|
+
|
|
291
|
+
#### `on_realtime`
|
|
292
|
+
실시간 데이터 수신 시 발생합니다.
|
|
293
|
+
```python
|
|
294
|
+
api.on_realtime.connect(callback) # callback(realdatas: dict)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**이벤트 핸들러 연결/해제**
|
|
298
|
+
```python
|
|
299
|
+
api.on_message.connect(my_handler) # 연결
|
|
300
|
+
api.on_message.disconnect(my_handler) # 해제
|
|
301
|
+
api.on_message.disconnect_all() # 전체 해제
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
### ResponseData
|
|
307
|
+
|
|
308
|
+
| 필드 | 타입 | 설명 |
|
|
309
|
+
|---|---|---|
|
|
310
|
+
| `return_code` | `int` | 응답 코드 (`0`: 성공, 그 외: 실패) |
|
|
311
|
+
| `return_msg` | `str` | 응답 메시지 |
|
|
312
|
+
| `body` | `dict` | 응답 데이터 (조회 결과) |
|
|
313
|
+
| `cont_yn` | `str` | 연속조회 여부 (`Y`: 다음 페이지 있음) |
|
|
314
|
+
| `next_key` | `str` | 연속조회 키 |
|
|
315
|
+
| `api_id` | `str` | 요청 TR 코드 |
|
|
316
|
+
| `path` | `str` | 요청 경로 (URL) |
|
|
317
|
+
| `elapsed_ms` | `float` | 요청 소요 시간 (ms) |
|