krx — fetch one day of a service
Take a KRX service (a group name pair, e.g. index kospi, stock daily) and a
trade date, and print that day's rows. The command mirrors the Python call:
krx.index.kospi("20200414") is krx fetch index kospi 20200414. The request, the
KRX status contract, and parsing live in the krx-openapi package (on PyPI); this
skill is a thin wrapper that calls its CLI and relays the result. A rejected key, an
un-applied service, or a quota error comes back as a one-line krx: <message> --
relay it as-is rather than throwing a stack trace.
One date, not a range. Every KRX endpoint is a per-date snapshot: one call
returns that whole market on that one day (all stocks, all bonds, ...), not a time
series. For a range, call once per trading day.
Prerequisite
This plugin calls the krx CLI, so the package must be installed and an API key set:
pipx install krx-openapi # or: pip install krx-openapi
export KRX_API_KEY=... # a free key from https://openapi.krx.co.kr
The key can also be stored in ~/.config/krx-openapi/credentials.json as
{"KRX_API_KEY": "..."}. A key alone is not enough -- each service must also be
applied for and approved under "서비스 이용" on the KRX account, or the call returns 401.
(The list and fields skills need no key at all -- they are offline.)
Running
krx fetch <GROUP> <NAME> <YYYYMMDD> [--market M] [--json]
GROUP NAME is the readable service pair -- index kospi, stock daily,
bond treasury, derivatives futures, etp etf, ... Get it from the list
skill (krx list).
- The date is a
YYYYMMDD trade date (a past business day).
--market applies only to four services (KOSPI default; case-insensitive):
stock daily and stock info take KOSPI|KOSDAQ|KONEX; derivatives stock_futures
and derivatives stock_options take KOSPI|KOSDAQ (KONEX has no stock derivatives).
Every other service rejects --market with a usage error (exit 2).
--json emits the full rows; the text view shows an aligned table (first 20 rows)
and a total count.
Procedure
- Get the
group name. If the user gave a concept ("코스피 지수", "국채 시세") but no
names, use the list skill first (krx list), then come back here.
- Pick a valid date. KRX serves the previous business day's data from 08:00 KST
the next morning; a weekend, holiday, same-day, or pre-08:00 date returns empty
(not an error). Default to the last completed trading day.
- Run.
krx fetch index kospi 20200414
krx fetch stock daily 20200414 --market KOSDAQ
- Relay the result. Show the CLI's stdout. You may trim a long table, but keep
the count line. Use
--json when the user wants the whole day or machine-readable
data.
- Error handling. Relay the one-line
krx: <message> from stderr as-is. Common
ones:
command not found: krx -> not installed; point the user at pipx install krx-openapi.
no KRX API key ... -> no key was found (env var and config file both empty).
KRX 401: ... -> the key was rejected or the service was not applied for; tell
the user to apply for that API under "서비스 이용" and wait for approval.
KRX daily call quota exceeded ... -> the 10,000-calls-per-key-per-day limit (429);
wait until midnight KST.
- An empty table (
(no rows)) is not an error -- it usually means a non-trading date
or data not yet published; suggest an earlier business day.
What this skill does not do
- It does not re-implement fetching or parsing (the package does); it always calls the CLI.
- It returns one day of one service -- to discover the groups and methods use the
list skill, and for a service's columns use the fields skill. It cannot
return investor trading, short selling, PER/PBR, adjusted prices, or intraday data
(the KRX Open API does not serve those).
1---2name: fetch-23description: Fetch one day of KRX market data from the KRX Open API, by the same readable names the Python client uses. Holds no logic of its own -- it calls the krx-openapi package's CLI (`krx fetch <group> <name> <date>`) and shows the result to the user. Needs a group + method (find them with the list skill) and a trade date. Trigger phrases: KRX 시세 가져와, KRX 일별 데이터, 코스피 전종목 시세, KRX 지수 조회, 국채 시세, fetch KRX data, KRX daily prices, KOSPI stocks on a date, KRX index for.4---56# krx — fetch one day of a service78Take a KRX service (a `group name` pair, e.g. `index kospi`, `stock daily`) and a9trade date, and print that day's rows. The command mirrors the Python call:10`krx.index.kospi("20200414")` is `krx fetch index kospi 20200414`. The request, the11KRX status contract, and parsing live in the krx-openapi package (on PyPI); this12skill is a thin wrapper that calls its CLI and relays the result. A rejected key, an13un-applied service, or a quota error comes back as a one-line `krx: <message>` --14relay it as-is rather than throwing a stack trace.1516**One date, not a range.** Every KRX endpoint is a per-date snapshot: one call17returns that whole market on that one day (all stocks, all bonds, ...), not a time18series. For a range, call once per trading day.1920## Prerequisite2122This plugin calls the `krx` CLI, so the package must be installed and an API key set:2324```25pipx install krx-openapi # or: pip install krx-openapi26export KRX_API_KEY=... # a free key from https://openapi.krx.co.kr27```2829The key can also be stored in `~/.config/krx-openapi/credentials.json` as30`{"KRX_API_KEY": "..."}`. **A key alone is not enough** -- each service must also be31applied for and approved under "서비스 이용" on the KRX account, or the call returns 401.32(The **list** and **fields** skills need no key at all -- they are offline.)3334## Running3536```37krx fetch <GROUP> <NAME> <YYYYMMDD> [--market M] [--json]38```3940- `GROUP NAME` is the readable service pair -- `index kospi`, `stock daily`,41 `bond treasury`, `derivatives futures`, `etp etf`, ... Get it from the **list**42 skill (`krx list`).43- The date is a `YYYYMMDD` trade date (a past business day).44- `--market` applies only to four services (KOSPI default; case-insensitive):45 `stock daily` and `stock info` take `KOSPI|KOSDAQ|KONEX`; `derivatives stock_futures`46 and `derivatives stock_options` take `KOSPI|KOSDAQ` (KONEX has no stock derivatives).47 Every other service rejects `--market` with a usage error (exit 2).48- `--json` emits the full rows; the text view shows an aligned table (first 20 rows)49 and a total count.5051## Procedure52531. **Get the `group name`.** If the user gave a concept ("코스피 지수", "국채 시세") but no54 names, use the **list** skill first (`krx list`), then come back here.552. **Pick a valid date.** KRX serves the previous business day's data from 08:00 KST56 the next morning; a weekend, holiday, same-day, or pre-08:00 date returns empty57 (not an error). Default to the last completed trading day.583. **Run.**59 ```bash60 krx fetch index kospi 2020041461 krx fetch stock daily 20200414 --market KOSDAQ62 ```634. **Relay the result.** Show the CLI's stdout. You may trim a long table, but keep64 the count line. Use `--json` when the user wants the whole day or machine-readable65 data.665. **Error handling.** Relay the one-line `krx: <message>` from stderr as-is. Common67 ones:68 - `command not found: krx` -> not installed; point the user at `pipx install krx-openapi`.69 - `no KRX API key ...` -> no key was found (env var and config file both empty).70 - `KRX 401: ...` -> the key was rejected **or the service was not applied for**; tell71 the user to apply for that API under "서비스 이용" and wait for approval.72 - `KRX daily call quota exceeded ...` -> the 10,000-calls-per-key-per-day limit (429);73 wait until midnight KST.74 - An empty table (`(no rows)`) is not an error -- it usually means a non-trading date75 or data not yet published; suggest an earlier business day.7677## What this skill does not do7879- It does not re-implement fetching or parsing (the package does); it always calls the CLI.80- It returns one day of one service -- to discover the groups and methods use the81 **list** skill, and for a service's columns use the **fields** skill. It cannot82 return investor trading, short selling, PER/PBR, adjusted prices, or intraday data83 (the KRX Open API does not serve those).