Skip to content

Cookbook

Common tasks as code you can run right away. Every example uses mock trading (is_mock=True) and reads the keys from the KIWOOM_APP_KEY · KIWOOM_APP_SECRET environment variables (KiwoomAPI.from_env).

pip install 'kiwoom-client[pandas]'
export KIWOOM_APP_KEY=...  KIWOOM_APP_SECRET=...   # a mock-trading key
Recipe Uses
Daily bars as a DataFrame ka10081, to_dataframe()
Paging through a continuation query cont_yn·next_key, request_all()
Account balance and valuation summary kt00018, kt00001
Concurrent queries with asyncio AsyncKiwoomAPI, asyncio.gather
Tick-aligned limit orders, mock trading round_to_tick()·add_ticks(), kt10000–kt10003
Real-time trades and order book over WebSocket 0B·0D, ws.on()·ws.subscribe()
Condition search results in real time CNSRLST·CNSRREQ·CNSRCLR
Handling rate limits (429) rate_limit·max_retries, KiwoomRateLimitError

To find the TR you need, see the endpoint reference; for fields, the field reference. Wrong request field names can be caught before sending with KiwoomAPI.from_env(is_mock=True, validate_params="warn").

The tests actually run the REST examples on these pages against fake responses built from Kiwoom's official spec (tests/test_cookbook_exec.py). WebSocket examples are checked for syntax and names only.