feat: Stockbit login for the order book, live quotes and daily history

Opt-in, with the user's own Stockbit session from a pasted
credentialStorage cookie (or IDX_STOCKBIT_REFRESH_TOKEN):

- idx stockbit login/status/logout; session file 0600, tokens never shown
- rotating refresh under a cross-process lock; one refresh+retry on 401
- stocks orderbook: depth with lots and orders, OHLC, value, foreign flow
- --provider stockbit quotes from the session API when logged in
- --history-provider stockbit, and auto under the stockbit provider for
  5d-1y daily windows
- MCP get_orderbook and stockbit_status (17 tools)

Endpoints, units and recorded responses from fzn0x/idx (MIT).
This commit is contained in:
hermes 2026-10-23 08:35:57 +00:00
commit b5ae9b98de
61 changed files with 2882 additions and 129 deletions

View file

@ -22,6 +22,7 @@ Commands:
config Manage configuration
cache Manage local cache
ownership Ownership intelligence (bootstrap with `ownership sync`)
stockbit Your Stockbit session (opt-in: order book, live quotes)
completions Generate shell completions
version Show idx-cli version
help Print this message or the help of the given subcommand(s)
@ -66,6 +67,7 @@ Usage: idx stocks [OPTIONS] <COMMAND>
Commands:
quote Get real-time stock quotes
intraday Today's session price by the minute (Stockbit)
orderbook Order book depth and foreign flow (Stockbit login)
history Get historical OHLC data
technical Run technical analysis on a stock
growth Run growth analysis on a stock
@ -170,6 +172,57 @@ Examples:
idx -o json stocks intraday BBCA | jq '.points[-1]'
```
### `idx stocks orderbook`
```text
The order book of one IDX stock from your own Stockbit session (`idx stockbit login`): bid and offer levels with lots and queued orders, the session's OHLC, volume, value and foreign buy, sell and net. Outside trading it is the book as the market left it, and the output says so.
Usage: idx stocks orderbook [OPTIONS] <SYMBOL>
Arguments:
<SYMBOL>
Single ticker symbol (e.g. BBCA)
Options:
--depth <DEPTH>
Price levels per side (1-50)
[default: 10]
-o, --output <OUTPUT>
Output format [default: auto = table on a terminal, json when piped]
[possible values: auto, table, json, jsonl]
--no-color
Disable colored output
-q, --quiet
Suppress non-essential output
-v, --verbose...
Increase verbosity (-v, -vv)
--provider <PROVIDER>
Market data provider [default: general.provider, else msn]
[possible values: yahoo, msn, stockbit]
--offline
Run without network requests
--no-cache
Bypass local cache
-h, --help
Print help (see a summary with '-h')
Examples:
idx stocks orderbook BBCA
idx stocks orderbook BBRI --depth 5
idx -o json stocks orderbook TLKM | jq '.offers[0]'
```
### `idx stocks history`
```text
@ -190,7 +243,7 @@ Options:
--no-color
Disable colored output
--history-provider <HISTORY_PROVIDER>
[possible values: auto, yahoo, msn]
[possible values: auto, yahoo, msn, stockbit]
-q, --quiet
Suppress non-essential output
-v, --verbose...
@ -221,7 +274,7 @@ Arguments:
Options:
--history-provider <HISTORY_PROVIDER>
[possible values: auto, yahoo, msn]
[possible values: auto, yahoo, msn, stockbit]
-o, --output <OUTPUT>
Output format [default: auto = table on a terminal, json when piped] [possible values: auto, table, json, jsonl]
--no-color
@ -1494,6 +1547,128 @@ Options:
-h, --help Print help
```
## `idx stockbit`
```text
Your own Stockbit session, for `stocks orderbook`, live `--provider stockbit` quotes and Stockbit daily history. Opt-in and personal: idx uses your account's tokens, stored in the config directory with owner-only permissions, and never logs them. Stockbit rotates the refresh token on every refresh, so a browser sharing the session is logged out once idx refreshes: log in through a separate browser profile for idx. Stockbit's terms allow personal, non-commercial use.
Usage: idx stockbit [OPTIONS] <COMMAND>
Commands:
login Store a session pasted on stdin and check it with Stockbit
status Show whether a session is stored and when its tokens expire
logout Delete the stored session
help Print this message or the help of the given subcommand(s)
Options:
-o, --output <OUTPUT>
Output format [default: auto = table on a terminal, json when piped]
[possible values: auto, table, json, jsonl]
--no-color
Disable colored output
-q, --quiet
Suppress non-essential output
-v, --verbose...
Increase verbosity (-v, -vv)
--provider <PROVIDER>
Market data provider [default: general.provider, else msn]
[possible values: yahoo, msn, stockbit]
--offline
Run without network requests
--no-cache
Bypass local cache
-h, --help
Print help (see a summary with '-h')
Examples:
idx stockbit login # paste the credentialStorage cookie
pbpaste | idx stockbit login
idx stockbit status
idx stockbit logout
```
### `idx stockbit login`
```text
Reads, on stdin, the value of stockbit.com's `credentialStorage` cookie (in a logged-in browser: DevTools, Application, Cookies, https://stockbit.com) or a refresh token, stores it, and checks it with one request. Servers can set IDX_STOCKBIT_REFRESH_TOKEN instead.
Usage: idx stockbit login [OPTIONS]
Options:
-o, --output <OUTPUT>
Output format [default: auto = table on a terminal, json when piped]
[possible values: auto, table, json, jsonl]
--no-color
Disable colored output
-q, --quiet
Suppress non-essential output
-v, --verbose...
Increase verbosity (-v, -vv)
--provider <PROVIDER>
Market data provider [default: general.provider, else msn]
[possible values: yahoo, msn, stockbit]
--offline
Run without network requests
--no-cache
Bypass local cache
-h, --help
Print help (see a summary with '-h')
```
### `idx stockbit status`
```text
Show whether a session is stored and when its tokens expire
Usage: idx stockbit status [OPTIONS]
Options:
-o, --output <OUTPUT> Output format [default: auto = table on a terminal, json when piped] [possible values: auto, table, json, jsonl]
--no-color Disable colored output
-q, --quiet Suppress non-essential output
-v, --verbose... Increase verbosity (-v, -vv)
--provider <PROVIDER> Market data provider [default: general.provider, else msn] [possible values: yahoo, msn, stockbit]
--offline Run without network requests
--no-cache Bypass local cache
-h, --help Print help
```
### `idx stockbit logout`
```text
Delete the stored session
Usage: idx stockbit logout [OPTIONS]
Options:
-o, --output <OUTPUT> Output format [default: auto = table on a terminal, json when piped] [possible values: auto, table, json, jsonl]
--no-color Disable colored output
-q, --quiet Suppress non-essential output
-v, --verbose... Increase verbosity (-v, -vv)
--provider <PROVIDER> Market data provider [default: general.provider, else msn] [possible values: yahoo, msn, stockbit]
--offline Run without network requests
--no-cache Bypass local cache
-h, --help Print help
```
## `idx completions`
```text