@vike-io/cli 0.24.0 → 0.25.0
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.
- package/CHANGELOG.md +16 -0
- package/README.md +7 -5
- package/package.json +1 -1
- package/skills/vike/SKILL.md +11 -1
- package/skills/vike-perp-carry/SKILL.md +24 -1
- package/skills/vike-perp-funding/SKILL.md +23 -1
- package/skills/vike-perp-overview/SKILL.md +7 -1
- package/src/commands/md.js +61 -8
- package/src/commands/tool-command.js +3 -2
- package/src/format.js +10 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f375e7a: New `md` commands and fields for the `/v1/marketdata` routes added since 0.24.0:
|
|
8
|
+
|
|
9
|
+
- `md spreads-history <symbol> --a <venue> --b <venue>`: one pair's price spread over time from `GET /v1/marketdata/perp/spreads/history`, leg A's price over leg B's in basis points per bucket (`(A / B - 1) x 10,000`), any two venues, perp or spot (`--market-a`, `--market-b`), since 2026-05-30. `--interval 1h|4h|1d`, `--start`, `--end` (default: the last 7 days); `--a` and `--b` are required. Rows: `ts`, `open_bps`, `close_bps`, `avg_bps`, `high_bps_bound` / `low_bps_bound` (bounds, not observed values), `samples_a` / `samples_b`, `book_bps_a` / `book_bps_b`.
|
|
10
|
+
- `md basis [symbol]`: every live dated future (quarterly, monthly, weekly) on binance, bybit, okx, deribit, gate and kraken from `GET /v1/marketdata/futures/basis`, with `basis` against `--ref index|spot|perp` (default `index`) and `apr`, the cash-and-carry yield to expiry before fees. `--exchange`, `--sort apr|expiry`, `--limit`.
|
|
11
|
+
- `md funding-oi [symbol]`: each coin's current funding averaged across venues by open interest from `GET /v1/marketdata/perp/funding/oi-weighted` (`rate_8h`, `apr`, `oi_usd`, `venues`), largest open interest first. `--limit` up to 500.
|
|
12
|
+
- `md funding-now`: the table shows the new fields. Per venue: `avg_apr_7d` / `avg_apr_30d`, `cum_1d` / `cum_7d` / `cum_30d` and `oi_usd`. On arbitrage pairs: `opportunity_age_h`, `stability_7d`, `spread_avg_7d_daily_pct` / `spread_avg_30d_daily_pct` and each leg's `next_daily_pct`.
|
|
13
|
+
- In the table view of `md funding-now`, `md carry` and `md spreads`, a venue that is delisting or reduce-only is marked after its name, e.g. `binance (delisting 2026-12-08)` or `bybit (reduce_only)`. `--json` keeps the raw `market_status` and `delist_ts`.
|
|
14
|
+
|
|
15
|
+
- Table output (every command, never `--json` or piped output) prints numbers below a thousand at up to 6 significant digits, with the float noise gone: `0.10950000000000001` prints as `0.1095`, and `0.0000259` stays `0.0000259`.
|
|
16
|
+
|
|
17
|
+
The `vike`, `vike-perp-funding`, `vike-perp-overview` and `vike-perp-carry` skills name them.
|
|
18
|
+
|
|
3
19
|
## 0.24.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -18,8 +18,9 @@ for the wallet and token tools. The same data is served three ways: an **MCP ser
|
|
|
18
18
|
this CLI calls), a **REST API** at `https://data.vike.io/v1/`, and the **Parquet archive** at
|
|
19
19
|
`https://data.vike.io/archive/`. A key allows 20,000 requests an hour, and an account can hold up
|
|
20
20
|
to 5 keys; archive downloads are not counted. The archive manifest and a sample market need no key
|
|
21
|
-
at all.
|
|
22
|
-
interest, long/short, liquidations, a carry screener) is served at
|
|
21
|
+
at all. Derivatives market data from centralised exchanges (perp funding, cross-venue spreads, open
|
|
22
|
+
interest, long/short, liquidations, a carry screener, dated-futures basis) is served at
|
|
23
|
+
`https://data.vike.io/v1/marketdata/` (`vike-data md`).
|
|
23
24
|
|
|
24
25
|
## Install
|
|
25
26
|
|
|
@@ -151,7 +152,7 @@ exposes, with its parameters.
|
|
|
151
152
|
| `vike-data candles` | `hl <symbol>` (Hyperliquid perp or spot, from executed fills; `--view export`, or `--view latest` for the newest bar of every symbol), `polymarket <token_id>` (one outcome token); live bars: `stream hl --channel hl.candles` | `hl_ohlcv`, `polymarket_ohlcv` |
|
|
152
153
|
| `vike-data polymarket` (`pm`) | `markets`, `market <condition_id>`, `wallet <address>`, `smart-money`, `leaderboard`, `market-trades <condition_id>`, `tape`, `orderbook <token_id>`, `market-stats <token_id>`, `settlement <condition_id>`, `settlements`, `chainlink-prices <symbol>` (the Chainlink prices the crypto up/down markets resolve on), `archive` | `polymarket_markets`, `polymarket_market_detail`, `polymarket_wallet`, `polymarket_smart_money`, `polymarket_leaderboard`, `polymarket_market_trades`, `polymarket_tape`, `polymarket_orderbook`, `polymarket_market_stats`, `polymarket_settlement`, `polymarket_settlements_bulk`, `polymarket_chainlink_prices`, `polymarket_archive` |
|
|
153
154
|
| `vike-data predictfun` (`pf`) | `overview`, `markets`, `market <market_id>`, `orderbook <market_id>`, `market-trades <market_id>`, `wallet <address>` (positions and P&L), `wallet-trades <address>`, `wallet-flows <address>` (USDT deposits and withdrawals), `leaderboard` | `predictfun_overview`, `predictfun_markets`, `predictfun_market_detail`, `predictfun_market_book`, `predictfun_market_trades`, `predictfun_wallet_positions`, `predictfun_wallet_trades`, `predictfun_leaderboard` |
|
|
154
|
-
| `vike-data marketdata` (`md`) | CEX
|
|
155
|
+
| `vike-data marketdata` (`md`) | CEX derivatives: `funding <symbol>` (history, newest first: `--exchange`, `--start`, `--end`, `--limit` up to 5000), `funding-now [symbol]` (each venue now, with `avg_apr_7d`/`_30d`, `cum_1d`/`_7d`/`_30d` and `oi_usd`; no symbol: the top 5 funding-arbitrage pairs, with `opportunity_age_h`, `stability_7d`, `spread_avg_7d`/`_30d_daily_pct` and each leg's `next_daily_pct`), `funding-oi [symbol]` (each coin's funding averaged across venues by open interest: `rate_8h`, `apr`, `oi_usd`, `venues`; `--limit` up to 500), `spreads [symbol]` (the 10 widest cross-venue price gaps), `spreads-history <symbol> --a <venue> --b <venue>` (leg A's price over leg B's per bucket in bps since 2026-05-30, perp or spot legs: `--market-a`, `--market-b`, `--interval 1h\|4h\|1d`, `--start`, `--end`; rows carry `open_bps`, `close_bps`, `avg_bps`, `high_bps_bound`/`low_bps_bound`, `samples_a`/`_b`, `book_bps_a`/`_b`), `oi <symbol>` and `long-short <symbol>` (`--exchange`, `--hours` 1-168 for an hourly series), `liquidations [symbol]` (forced liquidations on binance, bybit, okx, deribit and aster, newest first: `--exchange`, `--side long\|short`, `--start`, `--end`, `--interval 1m\|5m\|15m\|1h\|4h\|1d` for long/short totals per bucket, `--limit`; `coverage` says which venues undercount), `carry` (the carry screener, by default the list on vike.io/perp/carry: `--legs all\|perp_perp\|perp_spot`, `--direction funding\|convergence`, `--costs none\|fees\|fees_slippage`, `--fee-bps`, `--slippage-bps`, `--horizon <hours>`, `--min-spread-pct` (default 0), `--sort net\|gross`, `--limit` up to 500; rows carry `gross_apr` and `net_apr` as fractions, `fees_usd` and `net_usd` per $1,000 a leg, `breakeven_h`), `basis [symbol]` (every live dated future on binance, bybit, okx, deribit, gate and kraken: `basis` against `--ref index\|spot\|perp` and `apr`, the cash-and-carry yield to expiry before fees; `--exchange`, `--sort apr\|expiry`, `--limit`). In the table view of `funding-now`, `carry` and `spreads`, a rate at its venue's cap or floor prints as `<rate> capped`, the funding interval as published (`8h assumed` where the venue publishes none), and a venue that is delisting or reduce-only as `binance (delisting 2026-12-08)` / `bybit (reduce_only)`; `--json` keeps the raw `capped`, `interval_src`, `market_status` and `delist_ts`. An undeclared parameter is a 400. | REST, not MCP: `GET /v1/marketdata/perp/funding`, `/funding/current`, `/funding/oi-weighted`, `/spreads`, `/spreads/history`, `/oi`, `/long-short`, `/liquidations`, `/carry`; `/v1/marketdata/futures/basis` |
|
|
155
156
|
| `vike-data alerts` | `list`, `channels`, `create`, `edit`, `delete`, `events`, `resend`, `register-webhook`, `test-webhook`, `rotate-secret`: transfer alerts (a token or one wallet, on eth, bsc, base, hyperevm) Hyperliquid alerts (`--type hl_wallet`, `hl_cohort_fill`, `hl_liquidation`, `hl_cohort_bias`, `hl_liq_proximity`, `hl_wallet_orders`: one wallet's orders placed or gone, `--side`, `--events placed gone`) and Polymarket alerts (`--type pm_wallet_trade`, `pm_market_trade`, `pm_price_move`, `pm_resolution`), by email or an HTTPS webhook, HMAC-signed; at most 200 active alerts per account; `events` pages by `--cursor` while `has_more` is true (a page ends at about 2 MB) | `alerts_*` |
|
|
156
157
|
| `vike-data stream <path>` | live events from `wss://stream.vike.io/v1/stream/<path>` (`hl`, `hl-cohorts`, `onchain`, `polymarket`) as NDJSON: `--channel` (one or more), `--filter key=value`, `--cursor` | WebSocket, not MCP |
|
|
157
158
|
| `vike-data stream` | `info`, `check <channel>` (the server's validator), `events <channel>` (stored events, 3 days), `connections` (yours) | `stream_info`, `stream_check_filter`, `stream_events`, `stream_connections` |
|
|
@@ -165,8 +166,9 @@ be published (charts, tables, screenshots, aggregated results and up to 100 rows
|
|
|
165
166
|
data and full datasets may not, and commercial use needs a written agreement. Plans and limits:
|
|
166
167
|
[Pricing](https://vike.io/pricing); an API key: [API](https://vike.io/data/api).
|
|
167
168
|
|
|
168
|
-
Output is a table on a terminal and JSON with `--json` or whenever stdout is piped.
|
|
169
|
-
|
|
169
|
+
Output is a table on a terminal and JSON with `--json` or whenever stdout is piped. The table rounds numbers
|
|
170
|
+
below a thousand to 6 significant digits and shortens larger ones to K/M/B; JSON carries every value exactly as
|
|
171
|
+
served. A tool that refuses its input exits 1 in every mode:
|
|
170
172
|
|
|
171
173
|
```bash
|
|
172
174
|
vike-data token search BTC --json | jq '.'
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.25.0",
|
|
7
7
|
"description": "CLI, agent skills and MCP client for the free Vike Data API: a Polymarket full-L2 order-book archive in Parquet, Hyperliquid positions, fills and cohorts, and labelled Ethereum/BNB wallets",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "src/index.js",
|
package/skills/vike/SKILL.md
CHANGED
|
@@ -212,7 +212,17 @@ Chains: every token and wallet tool takes `chain` = `ethereum` | `bsc` | `base`
|
|
|
212
212
|
|
|
213
213
|
Open interest and long/short: `vike-data md oi BTC --hours 24`, `md long-short BTC` (`--exchange`, `--hours` 1-168). None returns bid/ask per venue. "Spread" here is perp vs perp across venues, not spot vs perp.
|
|
214
214
|
|
|
215
|
-
`vike-data md` is the REST API `/v1/marketdata`, one GET each (`--json` is the route's body). `md funding-now [symbol]`, `md spreads [symbol]`, `md oi` and `md long-short` give the same answer as the four tools above. `md liquidations [symbol]` lists forced liquidations on binance, bybit, okx, deribit and aster, newest first. `side` is the LIQUIDATED position, `notional_usd` = price x qty. `--interval 1h` (or 1m to 1d) gives long and short totals per bucket. Read `coverage`: binance and aster publish at most one per symbol per second, so their totals undercount, and nothing exists before recording started. Two more have no tool row here: `md funding <symbol>` is the funding history, newest first (`--exchange`, `--start`, `--end`, `--limit` up to 5000), each row with `rate`, `interval_h`, `rate_8h` and `apr` (a fraction: 0.11 = 11 % a year). `md carry` is the carry screener. By default it pairs perp-perp and spot-perp legs (`--legs`), longs the lower funding rate and shorts the higher (`--direction funding`; `convergence` longs the cheaper price instead), and applies no minimum gap. Rows carry `gross_apr` and `net_apr` (fractions), `fees_usd` and `net_usd` for $1,000 a leg, and `breakeven_h`. Each leg carries `market`, `interval_src` and `capped` (the rate is at the venue's cap or floor). See `vike-perp-carry`.
|
|
215
|
+
`vike-data md` is the REST API `/v1/marketdata`, one GET each (`--json` is the route's body). `md funding-now [symbol]`, `md spreads [symbol]`, `md oi` and `md long-short` give the same answer as the four tools above. `md spreads-history <symbol> --a <venue> --b <venue>` is one pair's price gap over time: leg A over leg B in bps per `--interval 1h|4h|1d` bucket, perp or spot legs, since 2026-05-30 (`high_bps_bound`/`low_bps_bound` are bounds, not observed values). `md liquidations [symbol]` lists forced liquidations on binance, bybit, okx, deribit and aster, newest first. `side` is the LIQUIDATED position, `notional_usd` = price x qty. `--interval 1h` (or 1m to 1d) gives long and short totals per bucket. Read `coverage`: binance and aster publish at most one per symbol per second, so their totals undercount, and nothing exists before recording started. Two more have no tool row here: `md funding <symbol>` is the funding history, newest first (`--exchange`, `--start`, `--end`, `--limit` up to 5000), each row with `rate`, `interval_h`, `rate_8h` and `apr` (a fraction: 0.11 = 11 % a year). `md carry` is the carry screener. By default it pairs perp-perp and spot-perp legs (`--legs`), longs the lower funding rate and shorts the higher (`--direction funding`; `convergence` longs the cheaper price instead), and applies no minimum gap. Rows carry `gross_apr` and `net_apr` (fractions), `fees_usd` and `net_usd` for $1,000 a leg, and `breakeven_h`. Each leg carries `market`, `interval_src` and `capped` (the rate is at the venue's cap or floor). See `vike-perp-carry`.
|
|
216
|
+
|
|
217
|
+
Further `md` commands:
|
|
218
|
+
- `md funding-oi [symbol]`: each coin's funding averaged across venues by open interest (`rate_8h`, `apr`, `oi_usd`, `venues`).
|
|
219
|
+
- `md basis [symbol]`: dated futures on binance, bybit, okx, deribit, gate and kraken, with `basis` against `--ref index|spot|perp` and `apr`, the cash-and-carry yield to expiry before fees (`null` under 2 days).
|
|
220
|
+
|
|
221
|
+
`md funding-now` rows also carry:
|
|
222
|
+
- per venue: `avg_apr_7d`/`_30d`, `cum_1d`/`_7d`/`_30d` (settled funding) and `oi_usd`;
|
|
223
|
+
- on arbitrage pairs: `opportunity_age_h`, `stability_7d` and `spread_avg_7d`/`_30d_daily_pct`.
|
|
224
|
+
|
|
225
|
+
Funding, spread and carry rows carry `market_status` (`delisting`, `reduce_only`, or `null`) and `delist_ts`. Never present a leg on a delisting or reduce-only venue as a trade.
|
|
216
226
|
|
|
217
227
|
### Hyperliquid
|
|
218
228
|
| Tool | Returns |
|
|
@@ -46,7 +46,30 @@ What the funding-leg fields mean:
|
|
|
46
46
|
|
|
47
47
|
- **`capped: true`** means that leg's rate sits at its venue's published cap or floor. The real pressure may be larger, and the rate can stay pinned there. `null` means the venue publishes no cap.
|
|
48
48
|
- **`interval_src`** says where `interval_h` comes from: `venue` (the venue publishes it for the symbol), `fixed` (the venue settles hourly for every market) or `default` (nothing published, 8 h assumed). Treat a `default` leg's `rate_8h` and `apr` as an estimate.
|
|
49
|
-
-
|
|
49
|
+
- **`market_status`** on a perp leg is `delisting` (the venue has set a date, `delist_ts` in unix seconds) or `reduce_only` (it takes only orders that close or reduce a position). It is `null` while the market trades normally and on a spot leg. Never present a row with such a leg as a trade: the position can be force-closed or cannot be opened.
|
|
50
|
+
- In the table view (no `--json`):
|
|
51
|
+
- a capped rate prints as `0.002 capped`;
|
|
52
|
+
- the interval prints as published, e.g. `4h`, or `8h assumed` for `default`;
|
|
53
|
+
- a leg's venue with a status prints as `binance (delisting 2026-12-08)` or `bybit (reduce_only)`.
|
|
54
|
+
|
|
55
|
+
`--json` keeps the raw `capped`, `interval_src`, `market_status` and `delist_ts` fields.
|
|
56
|
+
|
|
57
|
+
## Dated futures: the cash-and-carry basis
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
vike-data md basis BTC --json # every live dated BTC future, highest apr first; basis against the index
|
|
61
|
+
vike-data md basis ETH --ref spot --sort expiry --json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Each row in `futures` describes one contract:
|
|
65
|
+
- `exchange`, `instrument`, `expiry` (unix seconds), `days_to_expiry`, `type` (`linear` or `inverse`) with `contract_size`;
|
|
66
|
+
- `price` and `price_src` (book mid, else mark, else last);
|
|
67
|
+
- `index_price`, `spot_price`, `perp_price` and `ref_price` (the one `--ref` picks);
|
|
68
|
+
- `basis` = (price - ref_price) / ref_price, a fraction;
|
|
69
|
+
- `apr` = basis x 365 / days_to_expiry, the yield of buying the underlying and selling the future to expiry, before fees. It is `null` under 2 days;
|
|
70
|
+
- `vol_24h_usd` and `oi_usd`.
|
|
71
|
+
|
|
72
|
+
Covers binance (USDT-M), bybit, okx, deribit, gate and kraken; not Binance COIN-M. Unlike a funding carry, this yield is locked in at entry if held to expiry. A short horizon still inflates the APR, so quote `basis` next to it.
|
|
50
73
|
|
|
51
74
|
How to read it:
|
|
52
75
|
|
|
@@ -49,13 +49,35 @@ Both modes above are a snapshot. The REST API `/v1/marketdata` (`vike-data md`,
|
|
|
49
49
|
vike-data md funding BTC --exchange bybit --start 2026-11-23 --json # settled funding since a date, newest first, one venue or all
|
|
50
50
|
vike-data md funding-now BTC --json # every venue now (no symbol: the top-5 arb list)
|
|
51
51
|
vike-data md carry --costs fees_slippage --horizon 48 --json # cross-venue pairs: gross_apr vs net_apr, breakeven_h
|
|
52
|
+
vike-data md funding-oi --limit 20 --json # each coin's funding averaged across venues by open interest
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
`md funding` rows carry `rate` (one settlement), `interval_h`, `rate_8h` (the rate scaled to 8 hours, so 1h and 8h venues compare) and `apr` (a fraction: 0.11 = 11 % a year). `md funding-now BTC` rows carry `rate_8h` and `apr` too. Arbitrage rows (no symbol) carry `long_`/`short_` versions of the last two fields below. Two more fields on each venue's rate:
|
|
55
56
|
- `capped: true`: the rate sits at the venue's published cap or floor, so the real pressure may be larger. `null` means the venue publishes no cap.
|
|
56
57
|
- `interval_src`: `venue` (published for the symbol), `fixed` (the venue settles hourly for every market) or `default` (nothing published, 8 h assumed, so `rate_8h` and `apr` are an estimate).
|
|
57
58
|
|
|
58
|
-
The
|
|
59
|
+
The settled history behind the snapshot is in the same answer. All of it covers funding settled up to the start of the current UTC hour, and is `null` when nothing settled in the window.
|
|
60
|
+
- Per venue (`md funding-now BTC`):
|
|
61
|
+
- `avg_apr_7d` and `avg_apr_30d`: the average settled rate, a year, as a fraction.
|
|
62
|
+
- `cum_1d`, `cum_7d` and `cum_30d`: the sum of settled rates, what a long paid per unit of notional; negative means it was paid.
|
|
63
|
+
- `oi_usd`: open interest in USD.
|
|
64
|
+
- On arbitrage pairs (no symbol):
|
|
65
|
+
- `opportunity_age_h`: how many hours in a row the gap held at 0.3 %/day or more; 720 means all 30 days.
|
|
66
|
+
- `stability_7d`: the share of the last 7 days' hours in which it held, 0 to 1.
|
|
67
|
+
- `spread_avg_7d_daily_pct` and `spread_avg_30d_daily_pct`: the average gap.
|
|
68
|
+
- each leg's `next_daily_pct`: the rate quoted for its next settlement.
|
|
69
|
+
- **Prefer a pair with a long `opportunity_age_h` and a high `stability_7d`.** A pair at age 0 or with a low stability is one hour's print.
|
|
70
|
+
|
|
71
|
+
`md funding-oi` gives one funding number per coin: its venues' rates weighted by open interest. Positive means longs pay. Venues without dollar open interest (deribit, bingx, gate, lighter, mexc, weex) carry no weight.
|
|
72
|
+
|
|
73
|
+
`market_status` (`delisting`, `reduce_only` or `null`) and `delist_ts` on each venue or leg come from the venue's own API (binance, bybit, okx, bitget, gate, kucoin, aster). A funding gap on a delisting or reduce-only venue is not a trade.
|
|
74
|
+
|
|
75
|
+
The table view prints:
|
|
76
|
+
- a capped rate as `0.0075 capped`;
|
|
77
|
+
- the interval as `4h`, or `8h assumed`;
|
|
78
|
+
- a venue with a status as `binance (delisting 2026-12-08)` or `bybit (reduce_only)`.
|
|
79
|
+
|
|
80
|
+
Whether a pair pays after fees: `vike-perp-carry`.
|
|
59
81
|
|
|
60
82
|
## Venue comparison (one symbol)
|
|
61
83
|
|
|
@@ -32,9 +32,15 @@ Pass the base asset (`BTC`, not `BTCUSDT`); `--exchange` is lower case.
|
|
|
32
32
|
vike-data perp spreads --json # up to 10 symbols with a cross-venue price gap >= 0.5%
|
|
33
33
|
vike-data perp spreads --symbol BTC --json # the same list, filtered to one symbol
|
|
34
34
|
vike-data md spreads --json # the same answer from the REST API /v1/marketdata
|
|
35
|
+
vike-data md spreads-history BTC --a binance --b okx --interval 4h --json # one pair's gap over time, in bps
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
`md spreads-history` is leg A's price over leg B's per bucket, in basis points: `(A / B - 1) x 10,000`, positive when A is the dearer. It covers any two venues, perp or spot (`--market-a`, `--market-b`), since 2026-05-30, over the last 7 days unless `--start`/`--end` say otherwise.
|
|
39
|
+
- `high_bps_bound` and `low_bps_bound` only BOUND the bucket's extremes, because each leg's extreme can fall on a different minute. Don't quote them as observed spreads.
|
|
40
|
+
- `book_bps_a` and `book_bps_b` are each leg's mean bid-ask width.
|
|
41
|
+
- A bucket where one leg was unpriced has no row.
|
|
42
|
+
|
|
43
|
+
Rows: `symbol`, `buy_exchange`, `buy_price`, `sell_exchange`, `sell_price`, `spread_pct`, and for `buy_` and `sell_` the venue's `market_status` (`delisting`, `reduce_only`, or `null`) and `delist_ts`. Pre-ranked: cite the rows directly, except a row with a delisting or reduce-only leg: its gap is often the delisting itself, not a trade. The `md spreads` table prints such a venue as `binance (delisting 2026-12-08)`.
|
|
38
44
|
|
|
39
45
|
- **"Spread" is perp vs perp across venues, not spot vs perp.** `buy_exchange` is the cheapest venue and `sell_exchange` the dearest for that symbol.
|
|
40
46
|
- **`--symbol` only filters the global top 10.** An empty answer means the symbol is not among today's widest gaps, not that its venues agree. Don't answer "where's X cheapest" from an empty result; say the tool only lists the 10 widest gaps.
|
package/src/commands/md.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { addTool } from './tool-command.js';
|
|
2
|
+
import { fmtNum } from '../format.js';
|
|
2
3
|
|
|
3
4
|
// Each subcommand is one GET of the REST namespace /v1/marketdata (not an MCP tool): the flags are
|
|
4
5
|
// exactly its query parameters (the server refuses any other with a 400), and --json prints the
|
|
@@ -7,7 +8,7 @@ export function registerMarketdata(program) {
|
|
|
7
8
|
const cmd = program
|
|
8
9
|
.command('marketdata')
|
|
9
10
|
.alias('md')
|
|
10
|
-
.description('CEX
|
|
11
|
+
.description('CEX derivatives market data from the REST API /v1/marketdata: funding history, now and OI-weighted, spreads and their history, open interest, long/short, liquidations, carry screener, dated-futures basis');
|
|
11
12
|
|
|
12
13
|
const P = '/v1/marketdata/perp';
|
|
13
14
|
const EXCHANGE = ['--exchange <venue>', 'Only this venue, lower case (e.g. binance); omit for every venue'];
|
|
@@ -28,14 +29,40 @@ export function registerMarketdata(program) {
|
|
|
28
29
|
addTool(cmd, 'funding-now [symbol]', {
|
|
29
30
|
path: `${P}/funding/current`,
|
|
30
31
|
args: ['symbol'],
|
|
31
|
-
desc: 'Current funding
|
|
32
|
+
desc: 'Current funding of one symbol on each venue (with 7/30-day average APR, 1/7/30-day sums, oi_usd); without a symbol, the top 5 cross-venue funding-arbitrage pairs (with age, 7-day stability, 7/30-day average spread). Marks a capped rate and a delisting or reduce-only venue',
|
|
32
33
|
human: (r) => (Array.isArray(r) ? r.map(markLegs) : r),
|
|
33
34
|
});
|
|
34
35
|
|
|
36
|
+
addTool(cmd, 'funding-oi [symbol]', {
|
|
37
|
+
path: `${P}/funding/oi-weighted`,
|
|
38
|
+
args: ['symbol'],
|
|
39
|
+
desc: 'Each coin\'s current funding averaged across venues by open interest (rate_8h, apr, oi_usd, venues), largest open interest first; a symbol for one coin',
|
|
40
|
+
options: [['--limit <n>', 'Coins, 1-500 (default 50)']],
|
|
41
|
+
human: rowsOr('rows'),
|
|
42
|
+
});
|
|
43
|
+
|
|
35
44
|
addTool(cmd, 'spreads [symbol]', {
|
|
36
45
|
path: `${P}/spreads`,
|
|
37
46
|
args: ['symbol'],
|
|
38
|
-
desc: 'The 10 widest cross-venue price gaps (>= 0.5%): buy on one venue, sell the dearer perp; a symbol filters those 10',
|
|
47
|
+
desc: 'The 10 widest cross-venue price gaps (>= 0.5%): buy on one venue, sell the dearer perp; a symbol filters those 10. Marks a delisting or reduce-only venue',
|
|
48
|
+
human: (r) => (Array.isArray(r) ? r.map(markLegs) : r),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
addTool(cmd, 'spreads-history <symbol>', {
|
|
52
|
+
path: `${P}/spreads/history`,
|
|
53
|
+
args: ['symbol'],
|
|
54
|
+
desc: 'Price of leg A over leg B per bucket, in bps ((A / B - 1) x 10,000), since 2026-05-30: open, close, avg, high/low bounds, samples, bid-ask width',
|
|
55
|
+
options: [
|
|
56
|
+
['--a <venue>', 'Leg A\'s venue, lower case (e.g. binance)', true],
|
|
57
|
+
['--b <venue>', 'Leg B\'s venue, lower case (e.g. okx)', true],
|
|
58
|
+
['--market-a <m>', 'perp (default) | spot'],
|
|
59
|
+
['--market-b <m>', 'perp (default) | spot'],
|
|
60
|
+
['--interval <i>', '1h (default) | 4h | 1d; 4h and 1d buckets start at 00:00 UTC'],
|
|
61
|
+
['--start <time>', 'From this time, inclusive: ISO-8601 or unix seconds, floored to the interval (default: 7 days before --end)'],
|
|
62
|
+
['--end <time>', 'Before this time, exclusive; same forms (default: now)'],
|
|
63
|
+
],
|
|
64
|
+
names: { a: 'exchange_a', b: 'exchange_b' },
|
|
65
|
+
human: rowsOr('rows'),
|
|
39
66
|
});
|
|
40
67
|
|
|
41
68
|
addTool(cmd, 'oi <symbol>', {
|
|
@@ -68,7 +95,7 @@ export function registerMarketdata(program) {
|
|
|
68
95
|
|
|
69
96
|
addTool(cmd, 'carry', {
|
|
70
97
|
path: `${P}/carry`,
|
|
71
|
-
desc: 'Carry screener: long one leg, short the other on another venue; price gap plus funding over the horizon as gross_apr and net_apr (fractions), fees_usd, breakeven_h.
|
|
98
|
+
desc: 'Carry screener: long one leg, short the other on another venue; price gap plus funding over the horizon as gross_apr and net_apr (fractions), fees_usd, breakeven_h. Marks a capped rate and a delisting or reduce-only venue',
|
|
72
99
|
options: [
|
|
73
100
|
['--legs <l>', 'all (default) | perp_perp (a perp on each venue) | perp_spot (spot bought, a perp shorted)'],
|
|
74
101
|
['--direction <d>', 'funding (default: long the lower funding rate, short the higher) | convergence (long the cheaper price, short the dearer)'],
|
|
@@ -83,21 +110,47 @@ export function registerMarketdata(program) {
|
|
|
83
110
|
names: { horizon: 'horizon_h' },
|
|
84
111
|
human: (r) => (Array.isArray(r?.rows) ? r.rows.map(markLegs) : r),
|
|
85
112
|
});
|
|
113
|
+
|
|
114
|
+
addTool(cmd, 'basis [symbol]', {
|
|
115
|
+
path: '/v1/marketdata/futures/basis',
|
|
116
|
+
args: ['symbol'],
|
|
117
|
+
desc: 'Dated futures (quarterly, monthly, weekly) on binance, bybit, okx, deribit, gate and kraken: basis against --ref and apr, the cash-and-carry yield to expiry before fees',
|
|
118
|
+
options: [
|
|
119
|
+
['--exchange <venue>', 'Only this venue: binance, bybit, okx, deribit, gate or kraken; omit for every venue'],
|
|
120
|
+
['--ref <r>', 'What the basis is measured against: index (default, the index the contract settles on) | spot | perp (the same venue\'s)'],
|
|
121
|
+
['--sort <s>', 'apr (default, highest first) | expiry (soonest first)'],
|
|
122
|
+
['--limit <n>', 'Rows, 1-5000 (default 500)'],
|
|
123
|
+
],
|
|
124
|
+
human: rowsOr('futures'),
|
|
125
|
+
});
|
|
86
126
|
}
|
|
87
127
|
|
|
88
|
-
// Table view of
|
|
89
|
-
|
|
128
|
+
// Table view of the rows under `key`; with none, the whole answer, so its `note` shows.
|
|
129
|
+
const rowsOr = (key) => (r) => (r?.[key]?.length ? r[key] : r);
|
|
130
|
+
|
|
131
|
+
// Table view of a leg: "capped" after a rate at the venue's published cap or floor, the interval as
|
|
132
|
+
// published ("8h assumed" when the venue publishes none), and the venue's market status after its name
|
|
133
|
+
// ("binance (delisting 2026-12-05)", "bybit (reduce_only)"). --json keeps the raw fields.
|
|
90
134
|
export function markLegs(row) {
|
|
91
135
|
const out = { ...row };
|
|
92
|
-
for (const p of ['', 'long_', 'short_']) {
|
|
136
|
+
for (const p of ['', 'long_', 'short_', 'buy_', 'sell_']) {
|
|
93
137
|
const rate = [`${p}funding_rate`, `${p}daily_pct`].find((k) => k in out);
|
|
94
|
-
if (out[`${p}capped`] === true && rate) out[rate] = `${out[rate]} capped`;
|
|
138
|
+
if (out[`${p}capped`] === true && rate) out[rate] = `${typeof out[rate] === 'number' ? fmtNum(out[rate]) : out[rate]} capped`;
|
|
95
139
|
delete out[`${p}capped`];
|
|
96
140
|
if (`${p}interval_src` in out) {
|
|
97
141
|
const h = out[`${p}interval_h`];
|
|
98
142
|
out[`${p}interval_h`] = h == null ? null : `${h}h${out[`${p}interval_src`] === 'default' ? ' assumed' : ''}`;
|
|
99
143
|
delete out[`${p}interval_src`];
|
|
100
144
|
}
|
|
145
|
+
const venue = [`${p}exchange`, `${p}venue`].find((k) => k in out);
|
|
146
|
+
if (venue && (`${p}market_status` in out || `${p}delist_ts` in out)) {
|
|
147
|
+
const status = out[`${p}market_status`];
|
|
148
|
+
const ts = out[`${p}delist_ts`];
|
|
149
|
+
const date = ts ? new Date(ts * 1000).toISOString().slice(0, 10) : null;
|
|
150
|
+
if (status || date) out[venue] = `${out[venue]} (${[status ?? 'delisting', date].filter(Boolean).join(' ')})`;
|
|
151
|
+
delete out[`${p}market_status`];
|
|
152
|
+
delete out[`${p}delist_ts`];
|
|
153
|
+
}
|
|
101
154
|
}
|
|
102
155
|
return out;
|
|
103
156
|
}
|
|
@@ -7,10 +7,11 @@ import { emit, emitError, isJsonMode } from '../format.js';
|
|
|
7
7
|
// (--from-ms -> from_ms), or the name `names` gives it, and an unset flag is not sent: a view-based
|
|
8
8
|
// tool refuses a parameter its view does not take, and the server's defaults stay the defaults.
|
|
9
9
|
// Values go as typed; the server casts them and names the fix when one is wrong. `human` reshapes the
|
|
10
|
-
// answer for the table only; --json and a pipe get it as served.
|
|
10
|
+
// answer for the table only; --json and a pipe get it as served. An option whose third element is true
|
|
11
|
+
// is required (commander refuses the call without it).
|
|
11
12
|
export function addTool(group, spec, { tool, path, desc, args = [], options = [], names = {}, human }) {
|
|
12
13
|
const cmd = group.command(spec).description(desc);
|
|
13
|
-
for (const [flags, text] of options) cmd
|
|
14
|
+
for (const [flags, text, required] of options) cmd[required ? 'requiredOption' : 'option'](flags, text);
|
|
14
15
|
cmd.option('--json', 'Emit JSON');
|
|
15
16
|
cmd.action(async (...received) => {
|
|
16
17
|
received.pop(); // the Command
|
package/src/format.js
CHANGED
|
@@ -59,14 +59,18 @@ function printTable(rows) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// A number in a table cell (never JSON): K/M/B from a thousand up, else at most 6 significant digits with the
|
|
63
|
+
// float noise gone (0.10950000000000001 -> 0.1095; 0.0000259 stays 0.0000259, an integer stays whole).
|
|
64
|
+
export function fmtNum(v) {
|
|
65
|
+
if (Math.abs(v) >= 1e9) return (v / 1e9).toFixed(2) + 'B';
|
|
66
|
+
if (Math.abs(v) >= 1e6) return (v / 1e6).toFixed(2) + 'M';
|
|
67
|
+
if (Math.abs(v) >= 1e3) return (v / 1e3).toFixed(2) + 'K';
|
|
68
|
+
return Number.isInteger(v) ? String(v) : String(Number(v.toPrecision(6)));
|
|
69
|
+
}
|
|
70
|
+
|
|
62
71
|
function fmt(v) {
|
|
63
72
|
if (v === null || v === undefined) return '';
|
|
64
|
-
if (typeof v === 'number')
|
|
65
|
-
if (Math.abs(v) >= 1e9) return (v / 1e9).toFixed(2) + 'B';
|
|
66
|
-
if (Math.abs(v) >= 1e6) return (v / 1e6).toFixed(2) + 'M';
|
|
67
|
-
if (Math.abs(v) >= 1e3) return (v / 1e3).toFixed(2) + 'K';
|
|
68
|
-
return String(v);
|
|
69
|
-
}
|
|
73
|
+
if (typeof v === 'number') return fmtNum(v);
|
|
70
74
|
if (typeof v === 'object') return JSON.stringify(v);
|
|
71
75
|
const s = String(v);
|
|
72
76
|
return s.length > 80 ? s.slice(0, 77) + '...' : s;
|