1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! BitMEX URL constants and endpoint helpers.
/// Mainnet WebSocket URL.
pub const WS_URL: &str = "wss://ws.bitmex.com/realtime";
/// Testnet WebSocket URL.
pub const WS_URL_TESTNET: &str = "wss://ws.testnet.bitmex.com/realtime";
/// Mainnet REST base URL.
pub const REST_URL: &str = "https://www.bitmex.com/api/v1";
/// Testnet REST base URL.
pub const REST_URL_TESTNET: &str = "https://testnet.bitmex.com/api/v1";
// ─────────────────────────────────────────────────────────────────────────────
// REST path constants (relative to REST_URL / REST_URL_TESTNET)
// ─────────────────────────────────────────────────────────────────────────────
/// Public recent trades — `GET /api/v1/trade`
///
/// Query params: `symbol`, `count`, `reverse=true`.
/// Each row: `{timestamp, symbol, side, size, price, trdMatchID, …}`.
/// `timestamp` is ISO-8601 string (NOT epoch ms).
pub const PATH_TRADE: &str = "/trade";
/// OHLCV bucketed trade data — `GET /api/v1/trade/bucketed`
///
/// Query params: `symbol`, `binSize` (1m/5m/1h/1d), `count`, `reverse=true`.
/// Each row: `{timestamp, open, high, low, close, volume, trades, homeNotional, …}`.
/// NOTE: BitMEX bucket `timestamp` = **end** of the period, NOT the open time.
/// We store it as `open_time` = `timestamp − binSize_ms` to match Kline convention.
pub const PATH_TRADE_BUCKETED: &str = "/trade/bucketed";
/// Historical funding rate snapshots — `GET /api/v1/funding`
///
/// Query params: `symbol`, `count`, `reverse=true`.
/// Each row: `{timestamp, symbol, fundingInterval, fundingRate, fundingRateDaily}`.
pub const PATH_FUNDING: &str = "/funding";
/// Historical liquidation events — `GET /api/v1/liquidation`
///
/// Query params: `symbol`, `count`, `reverse=true`.
/// The endpoint returns `[]` when no forced liquidations occurred recently —
/// that is normal BitMEX behaviour, not an error.
/// Each row: `{orderID, symbol, side, price, leavesQty}`.
pub const PATH_LIQUIDATION: &str = "/liquidation";
// ─────────────────────────────────────────────────────────────────────────────
// Interval → BitMEX binSize mapping
// ─────────────────────────────────────────────────────────────────────────────
/// Convert a canonical interval string to the BitMEX `binSize` query parameter.
///
/// Returns `None` for intervals not supported by BitMEX bucketed trade endpoint.
/// BitMEX supports only four bucket sizes: `1m`, `5m`, `1h`, `1d`.
/// Return the duration of a BitMEX binSize in milliseconds.
///
/// Used to convert the bucket-close timestamp to an open-time by subtracting
/// the bucket duration. Panics are impossible here because callers only pass
/// strings previously validated by `interval_to_bin_size`.