kiwoom-cli 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gejyn14
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.
@@ -0,0 +1,425 @@
1
+ Metadata-Version: 2.4
2
+ Name: kiwoom-cli
3
+ Version: 0.1.0
4
+ Summary: User-friendly CLI for the Kiwoom Securities REST API (키움증권)
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/gejyn14/kiwoom-cli
7
+ Project-URL: Repository, https://github.com/gejyn14/kiwoom-cli
8
+ Project-URL: Issues, https://github.com/gejyn14/kiwoom-cli/issues
9
+ Keywords: kiwoom,stock,trading,cli,korea,finance
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Office/Business :: Financial :: Investment
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: click>=8.1
23
+ Requires-Dist: httpx>=0.27
24
+ Requires-Dist: rich>=13.0
25
+ Requires-Dist: tomli>=2.0; python_version < "3.11"
26
+ Requires-Dist: tomli-w>=1.0
27
+ Requires-Dist: websockets>=12.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8.0; extra == "dev"
30
+ Requires-Dist: pytest-httpx>=0.30; extra == "dev"
31
+ Requires-Dist: ruff>=0.4; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # kiwoom-cli
35
+
36
+ 키움증권 REST API를 터미널에서 사용하기 위한 CLI 도구.
37
+
38
+ - 207개 API 전체 지원 (188 REST + 19 WebSocket 실시간)
39
+ - 종목 조회, 호가, 차트, 계좌, 주문, 순위, 업종, 테마, ETF, ELW, 금현물
40
+ - 출력 형식: Rich 테이블 / JSON / CSV (`-f json`, `-f csv`)
41
+ - 실시간 WebSocket 스트리밍 (체결, 호가, VI, 잔고 등)
42
+ - AI 에이전트 친화적: 구조화된 JSON 출력, exit code (0/1/2/3)
43
+
44
+ ## 설치
45
+
46
+ ```bash
47
+ git clone https://github.com/gejyn14/kiwoom-cli.git
48
+ cd kiwoom-cli
49
+ pip install -e .
50
+ ```
51
+
52
+ ## 시작하기
53
+
54
+ ```bash
55
+ # 1. 초기 설정 (키움 Open API에서 발급받은 appkey, secretkey 입력)
56
+ kiwoom config setup
57
+
58
+ # 2. 토큰 발급
59
+ kiwoom auth login
60
+
61
+ # 3. 사용
62
+ kiwoom stock info 005930
63
+ ```
64
+
65
+ ### 모의투자 vs 실거래
66
+
67
+ `config setup` 시 도메인을 선택합니다. 이후 변경:
68
+
69
+ ```bash
70
+ kiwoom config domain mock # 모의투자 (기본값, 테스트용)
71
+ kiwoom config domain prod # 실거래
72
+
73
+ kiwoom config show # 현재 설정 확인
74
+ ```
75
+
76
+ 모의투자는 KRX만 지원됩니다. 실거래 전환 후에는 `kiwoom auth login`으로 토큰을 재발급하세요.
77
+
78
+ ## 명령어 구조
79
+
80
+ ```
81
+ kiwoom [--format table|json|csv] [--no-color]
82
+ ├── config 설정 (setup / show / domain)
83
+ ├── auth 인증 (login / logout / status)
84
+ ├── stock 종목 조회 (info / orderbook / chart / compare ...)
85
+ ├── account 계좌 조회 (balance / deposit / returns / pnl ...)
86
+ ├── order 주문 (buy / sell / modify / cancel / credit / gold)
87
+ ├── market 시장 정보 (rank / sector / theme / etf / elw / gold)
88
+ ├── stream 실시간 스트리밍 (quote / orderbook / order / vi ...)
89
+ ├── dashboard 대시보드 (계좌 + 거래량 상위 한눈에)
90
+ └── api Raw API 호출
91
+ ```
92
+
93
+ ---
94
+
95
+ ## stock - 종목 조회
96
+
97
+ ```bash
98
+ kiwoom stock info 005930 # 기본정보 (PER, PBR, 시가총액 등)
99
+ kiwoom stock price 005930 # 현재가 한 줄
100
+ kiwoom stock orderbook 005930 # 10단계 호가창
101
+ kiwoom stock daily 005930 # 일별 시세
102
+ kiwoom stock daily 005930 --type week # 주별 시세
103
+ kiwoom stock exec 005930 # 체결정보
104
+ kiwoom stock trader 005930 # 거래원
105
+ kiwoom stock foreign 005930 # 외국인 매매동향
106
+ kiwoom stock institution 005930 # 기관 매매동향
107
+ kiwoom stock short 005930 --from 20260101 --to 20260330 # 공매도 추이
108
+ kiwoom stock search --market 0 # 코스피 종목 리스트
109
+ kiwoom stock watchlist "005930|000660" # 관심종목
110
+ ```
111
+
112
+ ### 차트
113
+
114
+ ```bash
115
+ kiwoom stock chart tick 005930 --range 1 # 틱
116
+ kiwoom stock chart minute 005930 --range 5 # 5분봉
117
+ kiwoom stock chart day 005930 --date 20260301 # 일봉
118
+ kiwoom stock chart week 005930 --date 20260301 # 주봉
119
+ kiwoom stock chart month 005930 --date 20260301 # 월봉
120
+ kiwoom stock chart year 005930 --date 20260301 # 년봉
121
+ ```
122
+
123
+ ### 투자자/분석
124
+
125
+ ```bash
126
+ kiwoom stock investor daily-trade --from 20260301 --to 20260330
127
+ kiwoom stock investor by-stock 005930 --date 20260301
128
+ kiwoom stock investor program-top
129
+ kiwoom stock analysis vi-trigger
130
+ kiwoom stock analysis per-rank --type low-per
131
+ kiwoom stock lending trend
132
+ kiwoom stock credit trend 005930 --date 20260301 --type loan
133
+ ```
134
+
135
+ <details>
136
+ <summary>전체 stock 하위 명령어</summary>
137
+
138
+ | 명령 | 설명 |
139
+ |------|------|
140
+ | `info` | 종목 기본정보 |
141
+ | `price` | 현재가 한 줄 |
142
+ | `detail` | 종목정보 상세 |
143
+ | `orderbook` | 10단계 호가창 |
144
+ | `daily` | 일/주/월별 시세 |
145
+ | `timeprice` | 시분 시세 |
146
+ | `daily-price` | 일별주가 |
147
+ | `after-hours` | 시간외단일가 |
148
+ | `quote-info` | 시세표성정보 |
149
+ | `exec` | 체결정보 |
150
+ | `trader` | 거래원 |
151
+ | `today-exec` | 당일/전일 체결 |
152
+ | `today-volume` | 당일/전일 체결량 |
153
+ | `tick-strength` | 체결강도 시간별 |
154
+ | `daily-strength` | 체결강도 일별 |
155
+ | `foreign` | 외국인 매매동향 |
156
+ | `institution` | 기관 매매동향 |
157
+ | `short` | 공매도 추이 |
158
+ | `search` | 종목 리스트/검색 |
159
+ | `watchlist` | 관심종목 |
160
+ | `brokers` | 회원사 리스트 |
161
+ | `chart *` | 틱/분봉/일봉/주봉/월봉/년봉, 투자자별 차트 |
162
+ | `investor *` | 기관매매, 투자자별매매, 프로그램매매 등 10개 |
163
+ | `analysis *` | 거래상세, 거래량갱신, 매물대, PER, VI, 증권사 등 10개 |
164
+ | `lending *` | 대차거래 추이/상위/종목별/내역 |
165
+ | `credit *` | 신용매매동향, 신용융자 가능 |
166
+
167
+ </details>
168
+
169
+ ---
170
+
171
+ ## account - 계좌 조회
172
+
173
+ ```bash
174
+ kiwoom account list # 계좌번호
175
+ kiwoom account balance # 잔고 + 보유종목 + 손익
176
+ kiwoom account deposit # 예수금
177
+ kiwoom account asset # 추정자산
178
+ kiwoom account today # 당일현황
179
+ kiwoom account returns summary # 수익률
180
+ kiwoom account pnl today 005930 # 당일 실현손익
181
+ kiwoom account orders pending # 미체결 주문
182
+ kiwoom account orders executed # 체결 내역
183
+ kiwoom account holdings eval # 잔고내역
184
+ kiwoom account orderable amount 005930 --trade buy --price 70000
185
+ ```
186
+
187
+ <details>
188
+ <summary>전체 account 하위 명령어</summary>
189
+
190
+ | 그룹 | 명령 | 설명 |
191
+ |------|------|------|
192
+ | - | `list` | 계좌번호 조회 |
193
+ | - | `balance` | 계좌 평가현황 |
194
+ | - | `deposit` | 예수금 상세 |
195
+ | - | `asset` | 추정자산 |
196
+ | - | `today` | 당일현황 |
197
+ | - | `margin-detail` | 증거금 세부내역 |
198
+ | `returns` | `summary` | 계좌 수익률 |
199
+ | `returns` | `daily-balance` | 일별 잔고수익률 |
200
+ | `returns` | `daily-detail` | 일별 수익률 상세 |
201
+ | `returns` | `daily-asset` | 일별 예탁자산 |
202
+ | `pnl` | `today` | 당일 실현손익 |
203
+ | `pnl` | `by-date` | 일자별 실현손익 |
204
+ | `pnl` | `by-period` | 기간별 실현손익 |
205
+ | `pnl` | `daily` | 일자별 실현손익 |
206
+ | `orders` | `pending` | 미체결 주문 |
207
+ | `orders` | `executed` | 체결 내역 |
208
+ | `orders` | `detail` | 주문체결 상세 |
209
+ | `orders` | `status` | 주문체결 현황 |
210
+ | `orders` | `split-detail` | 분할주문 상세 |
211
+ | `holdings` | `eval` | 계좌평가 잔고 |
212
+ | `holdings` | `settled` | 체결잔고 |
213
+ | `holdings` | `next-settle` | 익일결제예정 |
214
+ | `orderable` | `amount` | 주문가능 금액 |
215
+ | `orderable` | `margin-qty` | 증거금율별 수량 |
216
+ | `orderable` | `credit-qty` | 신용보증금율별 수량 |
217
+ | `history` | `transactions` | 위탁종합 거래내역 |
218
+ | `history` | `journal` | 당일 매매일지 |
219
+
220
+ </details>
221
+
222
+ ---
223
+
224
+ ## order - 주문
225
+
226
+ 모든 주문에 `--confirm` 필수.
227
+
228
+ ```bash
229
+ # 주식
230
+ kiwoom order buy 005930 10 --type market --confirm # 시장가 매수
231
+ kiwoom order buy 005930 10 --price 70000 --type limit --confirm # 지정가 매수
232
+ kiwoom order sell 005930 10 --type market --confirm # 매도
233
+ kiwoom order modify 0000139 005930 1 70000 --confirm # 정정
234
+ kiwoom order cancel 0000140 005930 --confirm # 취소
235
+
236
+ # 신용
237
+ kiwoom order credit buy 005930 10 --type market --confirm
238
+ kiwoom order credit sell 005930 10 --type market --confirm
239
+
240
+ # 금현물
241
+ kiwoom order gold buy M04020000 1 --type market --confirm
242
+ kiwoom order gold balance # 잔고
243
+ kiwoom order gold pending # 미체결
244
+
245
+ # 조건검색
246
+ kiwoom order condition list
247
+ kiwoom order condition search 001 --confirm
248
+ ```
249
+
250
+ 주문유형: `limit` `market` `conditional` `after-hours` `pre-market` `single` `best` `first` `ioc` `market-ioc` `best-ioc` `fok` `market-fok` `best-fok` `stop` `mid` `mid-ioc` `mid-fok`
251
+
252
+ ---
253
+
254
+ ## market - 시장 정보
255
+
256
+ ### 순위
257
+
258
+ ```bash
259
+ kiwoom market rank volume # 거래량 상위
260
+ kiwoom market rank amount # 거래대금 상위
261
+ kiwoom market rank change # 등락률 상위
262
+ kiwoom market rank surge # 가격 급등락
263
+ kiwoom market rank hot # 실시간 조회 순위
264
+ kiwoom market rank limit # 상하한가
265
+ kiwoom market rank foreign-period # 외인 기간별 매매
266
+ kiwoom market rank foreign-inst # 외국인/기관 매매
267
+ ```
268
+
269
+ <details>
270
+ <summary>전체 rank 명령어 (28개)</summary>
271
+
272
+ `volume` `prev-volume` `amount` `change` `expected-change` `surge` `hot` `limit` `new-highlow` `near-highlow` `volume-surge` `orderbook-top` `orderbook-surge` `balance-rate-surge` `credit-ratio` `foreign-period` `foreign-consecutive` `foreign-exhaust` `foreign-broker` `foreign-inst` `investor-top` `broker-by-stock` `broker-top` `major-trader` `net-buyer` `top-exit` `same-net-trade` `afterhours-change`
273
+
274
+ </details>
275
+
276
+ ### 업종 / 테마 / ETF / ELW / 금현물 / 프로그램
277
+
278
+ ```bash
279
+ kiwoom market sector current 001 # 업종 현재가
280
+ kiwoom market sector index # 전업종 지수
281
+ kiwoom market sector chart day 001 --date 20260301
282
+
283
+ kiwoom market theme groups # 테마 그룹
284
+ kiwoom market theme stocks THEMA001 # 테마 구성종목
285
+
286
+ kiwoom market etf all # ETF 전체 시세
287
+ kiwoom market etf info 069500 # ETF 종목정보
288
+
289
+ kiwoom market elw detail 580001 # ELW 상세정보
290
+ kiwoom market elw search # ELW 조건검색
291
+
292
+ kiwoom market gold price # 금현물 시세
293
+ kiwoom market gold orderbook # 금현물 호가
294
+
295
+ kiwoom market program time-trend --date 20260301
296
+ kiwoom market program stock-daily 005930
297
+ ```
298
+
299
+ ---
300
+
301
+ ## stream - 실시간 스트리밍
302
+
303
+ WebSocket 실시간 시세. Ctrl+C로 종료.
304
+
305
+ ```bash
306
+ kiwoom stream quote 005930 # 체결 실시간
307
+ kiwoom stream orderbook 005930 # 호가 실시간
308
+ kiwoom stream order # 주문체결 (계좌)
309
+ kiwoom stream balance # 잔고 변동 (계좌)
310
+ kiwoom stream vi 005930 # VI 발동/해제
311
+ kiwoom stream multi 005930 # 체결+호가 동시
312
+ kiwoom stream quote 005930 000660 035420 # 복수 종목
313
+ kiwoom stream custom 0B,0D 005930 # 타입 직접 지정
314
+ kiwoom stream types # 타입 코드 목록
315
+ ```
316
+
317
+ | 코드 | 명령 | 설명 |
318
+ |------|------|------|
319
+ | 00 | `order` | 주문체결 |
320
+ | 04 | `balance` | 잔고 |
321
+ | 0A | `price` | 주식기세 |
322
+ | 0B | `quote` | 주식체결 |
323
+ | 0C | `best-bid` | 우선호가 |
324
+ | 0D | `orderbook` | 호가잔량 |
325
+ | 0E | `after-hours` | 시간외호가 |
326
+ | 0F | `trader` | 당일거래원 |
327
+ | 0G | `etf-nav` | ETF NAV |
328
+ | 0H | `expected` | 예상체결 |
329
+ | 0I | `gold` | 국제금환산 |
330
+ | 0J | `sector-index` | 업종지수 |
331
+ | 0U | `sector-change` | 업종등락 |
332
+ | 0g | `stock-info` | 종목정보 |
333
+ | 0m | `elw-theory` | ELW 이론가 |
334
+ | 0s | `market-time` | 장시작시간 |
335
+ | 0u | `elw-indicator` | ELW 지표 |
336
+ | 0w | `program` | 프로그램매매 |
337
+ | 1h | `vi` | VI발동/해제 |
338
+
339
+ ---
340
+
341
+ ## Raw API
342
+
343
+ ```bash
344
+ kiwoom api ka10001 '{"stk_cd":"005930"}' # 테이블 출력
345
+ kiwoom api ka10001 '{"stk_cd":"005930"}' --raw # JSON 원본
346
+ ```
347
+
348
+ ---
349
+
350
+ ## dashboard - 대시보드
351
+
352
+ ```bash
353
+ kiwoom dashboard # 계좌 요약 + 거래량 상위 한눈에
354
+ ```
355
+
356
+ ## 종목 비교
357
+
358
+ ```bash
359
+ kiwoom stock compare 005930 000660 # 삼성전자 vs SK하이닉스
360
+ kiwoom stock compare 005930 000660 035420 # 3종목 비교
361
+ kiwoom -f json stock compare 005930 000660 # JSON 출력
362
+ ```
363
+
364
+ ---
365
+
366
+ ## 출력 형식
367
+
368
+ 모든 명령에 `-f` / `--format` 옵션 사용 가능:
369
+
370
+ ```bash
371
+ kiwoom stock info 005930 # 기본: Rich 테이블
372
+ kiwoom -f json stock info 005930 # JSON (파이핑, AI 에이전트용)
373
+ kiwoom -f csv stock daily 005930 # CSV (엑셀, 데이터 분석용)
374
+ kiwoom --no-color stock info 005930 # 색상 없이 (파일 저장용)
375
+ ```
376
+
377
+ ```bash
378
+ # jq로 필터링
379
+ kiwoom -f json market rank volume | jq '.[].stk_nm'
380
+
381
+ # CSV를 파일로 저장
382
+ kiwoom -f csv stock daily 005930 > samsung_daily.csv
383
+ ```
384
+
385
+ ## Shell 자동완성
386
+
387
+ ```bash
388
+ # Bash
389
+ eval "$(_KIWOOM_COMPLETE=bash_source kiwoom)"
390
+
391
+ # Zsh
392
+ eval "$(_KIWOOM_COMPLETE=zsh_source kiwoom)"
393
+
394
+ # Fish
395
+ eval (env _KIWOOM_COMPLETE=fish_source kiwoom)
396
+ ```
397
+
398
+ ## Exit Codes
399
+
400
+ | 코드 | 의미 |
401
+ |------|------|
402
+ | 0 | 성공 |
403
+ | 1 | 입력 오류 (잘못된 인자) |
404
+ | 2 | API/네트워크 오류 |
405
+ | 3 | 인증 필요 (토큰 만료) |
406
+
407
+ ## 참고
408
+
409
+ | 항목 | 값 |
410
+ |------|------|
411
+ | 설정 파일 | `~/.kiwoom/config.toml` |
412
+ | 토큰 파일 | `~/.kiwoom/token` |
413
+ | 운영 도메인 | `https://api.kiwoom.com` |
414
+ | 모의투자 도메인 | `https://mockapi.kiwoom.com` |
415
+ | WebSocket | `wss://api.kiwoom.com:10000` |
416
+
417
+ - `kiwoom <명령> --help`로 상세 옵션 확인
418
+ - 모의투자 먼저 테스트: `kiwoom config domain mock`
419
+ - 연속조회(페이지네이션) 자동 처리
420
+ - 종목코드 6자리: `005930` (삼성전자)
421
+ - 금현물: `M04020000` (1kg), `M04020100` (미니 100g)
422
+
423
+ ## License
424
+
425
+ MIT