kiwoom-client
AGENTS.md3 starsChanged 5 days agoMITView on GitHub
Instructions for AI coding agents (Codex, Claude Code, Cursor, Copilot, …) that use kiwoom-client in someone's code, or work on this repository. Humans: see README and CONTRIBUTING. kiwoom-client is a Python client for the Kiwoom Securities (키움증권) REST API and WebSocket — 182 REST endpoints, 4 condition-search calls, 19 real-time types. It can place real orders on a real brokerage account, so the safety rules below come first. Where to look things up: A safe starting point (paper trading, keys…
In this repository6 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/kiwoom-client.mdcCursor rule
- llms-full.txtllms.txt
- llms.txtllms.txt
- kiwoom-clientSkill
The file
Files
<!-- 자동 생성 파일 — scripts/templates/AGENTS.md (와 usage-rules.md) 를 고치고 `python scripts/gen_docs.py` 로 다시 만듭니다. -->AGENTS.md
Instructions for AI coding agents (Codex, Claude Code, Cursor, Copilot, …) that use kiwoom-client in someone's code, or work on this repository. Humans: see README and CONTRIBUTING.
kiwoom-client is a Python client for the Kiwoom Securities (키움증권) REST API and WebSocket — 182 REST endpoints, 4 condition-search calls, 19 real-time types. It can place real orders on a real brokerage account, so the safety rules below come first.
Writing code that uses kiwoom-client
KiwoomAPI(app_key, app_secret, is_mock=False)—is_mockdefaults toFalse, the live server. Passis_mock=Truefor paper trading (모의투자, mockapi.kiwoom.com). Live and paper keys are different; a key used against the wrong server is rejected (Kiwoom error 8030/8031, raised asKiwoomServerMismatchError).KiwoomAPI.from_env(is_mock=True)readsKIWOOM_APP_KEY/KIWOOM_APP_SECRET/KIWOOM_IS_MOCK(the same variables as the MCP server). Never hard-code or print keys.api.order.*andapi.credit_order.*place real, irreversible orders whenis_mock=False. Nothing in the Python API blocks them; only the MCP server has an opt-in guard (KIWOOM_MCP_ALLOW_LIVE_ORDERS). Do not run order code against a live account unless the user explicitly asks.api.logout()revokes the access token. Other processes sharing the same app key may lose their session — do not call it casually.- Every REST method has the same signature
(cont_yn="N", next_key="", **fields). Pass Kiwoom's own request field names as keyword arguments with string values (stk_cd="005930",ord_qty="10"). Find the method for an api_id (ka10081) or a Korean TR name in the endpoint reference; look fields up withkiwoom_client.spec.get("ka10081").required_fieldsor Kiwoom's guide. Do not invent method names. - Coded fields have named constants in
kiwoom_client.codes(OrderType.LIMIT,Exchange.KRX, …). - Responses are plain dicts whose values are strings (
"+70000","1,234").to_dataframe()/normalize()/to_number()convert them; codes and dates stay strings. A non-zeroreturn_coderaisesKiwoomAPIError(code, message, response)or one of its subclasses inkiwoom_client.errors. - Continuation: a response carries
"cont-yn"and"next-key"; call again withcont_yn="Y", next_key=..., or useapi._client.request_all(url, api_id, body). - Rate limits are per api_id (about 1 req/s, burst 2) and handled by the client; different api_ids run concurrently under
AsyncKiwoomAPI. - Limit prices must be on the KRX tick grid:
round_to_tick(price). - Real-time:
ws = api.create_websocket(),await ws.connect(),ws.on("0B", cb),await ws.subscribe("0B", "005930"),await ws.listen().valueskeys are Kiwoom FID numbers ("10"= current price).
Where to look things up:
| Need | Look here |
Method for an api_id (ka10081) or a Korean TR name (주식일봉차트조회요청) | docs/endpoints.md |
| Request/response fields of a TR | kiwoom_client.spec.get("ka10081"), spec.search("일봉"), spec.for_method("chart", "stock_daily_chart"), or Kiwoom's guide |
| Every public signature and docstring in one file | llms-full.txt |
Coming from OpenAPI+ (OCX) / pykiwoom (opt10001, SendOrder, SetRealReg) | docs/migration-from-openapi-plus.md |
| Using it as MCP tools instead of Python | README, "MCP 서버로 사용하기" / "MCP server" |
A safe starting point (paper trading, keys from the environment):
from kiwoom_client import KiwoomAPI, to_dataframe
api = KiwoomAPI.from_env(is_mock=True)
resp = api.chart.stock_daily_chart(stk_cd="005930", base_dt="20260326", upd_stkpc_tp="1")
df = to_dataframe(resp)Working on this repository
CONTRIBUTING.md has the full rules. The ones an agent is most likely to break:
- No live servers, no real keys. Unit tests mock HTTP with
pytest-httpx; never send requests toapi.kiwoom.comormockapi.kiwoom.com. Do not runtests/integration_*_smoke.py(live-server scripts, not collected by pytest) orexamples/*.py, and never calllogout()/revoke_token. - Add, don't change. Trading daemons install new releases automatically (
kiwoom-client>=…). Keeprequest()/request_all(), token issue/refresh, the rate limiter,tick_size/round_to_tickresults, theis_mock=Falsedefault and existing method signatures exactly as they are. New behaviour goes behind a new function or an option whose default is the old behaviour. - Never weaken the live-order guards: the MCP opt-in (
KIWOOM_MCP_ALLOW_LIVE_ORDERS,src/kiwoom_client/mcp/guard.py,GUARDED_MODULES) and.claude/hooks/live_order_guard.py. If a guard blocks you, show the command to the user instead of working around it. - Generated files — after changing endpoints, docstrings or
__all__, regenerate and commit them together; CI compares them with the code:python scripts/gen_docs.py(docs/endpoints.md, llms.txt, llms-full.txt, AGENTS.md, the skill, Cursor/Copilot rules) andpython scripts/build_stubs.py(domestic/*.pyi). - Docs code is tested: Python blocks must compile,
api.<module>.<method>(and api_ids must exist, and examples underdocs/must build clients withis_mock=True(tests/test_docs_code_blocks.py). - Public repository: no account numbers, keys or e-mail addresses in code, docs or commits. Do not bump the version, tag or publish — releases are the maintainer's.
Adding an endpoint: one method on the module class in src/kiwoom_client/domestic/ with the docstring
"한글 TR 이름 (English name)", a mocked test in tests/test_modules.py, then regenerate. The MCP tool
(<module>_<method>) appears on its own.
uv run --extra dev --extra mcp pytest tests/ -q
uv run --extra dev --extra mcp ruff check src tests examples
uv run --extra dev --extra mcp mypyDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

