@0xarchive/sdk 0.1.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/README.md +301 -0
- package/dist/index.d.mts +856 -0
- package/dist/index.d.ts +856 -0
- package/dist/index.js +763 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +734 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,856 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the 0xarchive client
|
|
3
|
+
*/
|
|
4
|
+
interface ClientOptions {
|
|
5
|
+
/** Your 0xarchive API key */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Base URL for the API (defaults to https://api.0xarchive.io) */
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
/** Request timeout in milliseconds (defaults to 30000) */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Standard API response wrapper
|
|
14
|
+
*/
|
|
15
|
+
interface ApiResponse<T> {
|
|
16
|
+
success: boolean;
|
|
17
|
+
data: T;
|
|
18
|
+
count: number;
|
|
19
|
+
request_id: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Pagination parameters for list endpoints
|
|
23
|
+
*/
|
|
24
|
+
interface PaginationParams {
|
|
25
|
+
/** Maximum number of results to return */
|
|
26
|
+
limit?: number;
|
|
27
|
+
/** Number of results to skip */
|
|
28
|
+
offset?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Time range parameters for historical queries
|
|
32
|
+
*/
|
|
33
|
+
interface TimeRangeParams extends PaginationParams {
|
|
34
|
+
/** Start timestamp (Unix ms or ISO string) */
|
|
35
|
+
start?: number | string;
|
|
36
|
+
/** End timestamp (Unix ms or ISO string) */
|
|
37
|
+
end?: number | string;
|
|
38
|
+
}
|
|
39
|
+
/** A price level in the order book [price, size] */
|
|
40
|
+
type PriceLevel = [string, string];
|
|
41
|
+
/**
|
|
42
|
+
* Order book snapshot
|
|
43
|
+
*/
|
|
44
|
+
interface OrderBook {
|
|
45
|
+
coin: string;
|
|
46
|
+
timestamp: number;
|
|
47
|
+
bids: PriceLevel[];
|
|
48
|
+
asks: PriceLevel[];
|
|
49
|
+
mid_price: string;
|
|
50
|
+
spread: string;
|
|
51
|
+
spread_bps: string;
|
|
52
|
+
}
|
|
53
|
+
interface GetOrderBookParams {
|
|
54
|
+
/** Timestamp to get order book at (Unix ms or ISO string) */
|
|
55
|
+
timestamp?: number | string;
|
|
56
|
+
/** Number of price levels to return per side */
|
|
57
|
+
depth?: number;
|
|
58
|
+
}
|
|
59
|
+
interface OrderBookHistoryParams extends TimeRangeParams {
|
|
60
|
+
/** Number of price levels to return per side */
|
|
61
|
+
depth?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Trade/fill record
|
|
65
|
+
*/
|
|
66
|
+
interface Trade {
|
|
67
|
+
id: string;
|
|
68
|
+
coin: string;
|
|
69
|
+
side: 'buy' | 'sell';
|
|
70
|
+
price: string;
|
|
71
|
+
size: string;
|
|
72
|
+
value: string;
|
|
73
|
+
timestamp: number;
|
|
74
|
+
trade_type: string;
|
|
75
|
+
}
|
|
76
|
+
interface GetTradesParams extends TimeRangeParams {
|
|
77
|
+
/** Filter by side */
|
|
78
|
+
side?: 'buy' | 'sell';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* OHLCV candle
|
|
82
|
+
*/
|
|
83
|
+
interface Candle {
|
|
84
|
+
coin: string;
|
|
85
|
+
interval: string;
|
|
86
|
+
timestamp: number;
|
|
87
|
+
open: string;
|
|
88
|
+
high: string;
|
|
89
|
+
low: string;
|
|
90
|
+
close: string;
|
|
91
|
+
volume: string;
|
|
92
|
+
trades: number;
|
|
93
|
+
}
|
|
94
|
+
type CandleInterval = '1m' | '5m' | '15m' | '1h' | '4h' | '1d';
|
|
95
|
+
interface GetCandlesParams extends TimeRangeParams {
|
|
96
|
+
/** Candle interval */
|
|
97
|
+
interval?: CandleInterval;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Trading instrument metadata
|
|
101
|
+
*/
|
|
102
|
+
interface Instrument {
|
|
103
|
+
coin: string;
|
|
104
|
+
name: string;
|
|
105
|
+
sz_decimals: number;
|
|
106
|
+
max_leverage: number;
|
|
107
|
+
only_isolated: boolean;
|
|
108
|
+
is_active: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Funding rate record
|
|
112
|
+
*/
|
|
113
|
+
interface FundingRate {
|
|
114
|
+
coin: string;
|
|
115
|
+
funding_rate: string;
|
|
116
|
+
premium: string;
|
|
117
|
+
timestamp: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Open interest record
|
|
121
|
+
*/
|
|
122
|
+
interface OpenInterest {
|
|
123
|
+
coin: string;
|
|
124
|
+
open_interest: string;
|
|
125
|
+
timestamp: number;
|
|
126
|
+
}
|
|
127
|
+
/** WebSocket channel types */
|
|
128
|
+
type WsChannel = 'orderbook' | 'trades' | 'ticker' | 'all_tickers' | 'candles' | 'funding' | 'openinterest';
|
|
129
|
+
/** Subscribe message from client */
|
|
130
|
+
interface WsSubscribe {
|
|
131
|
+
op: 'subscribe';
|
|
132
|
+
channel: WsChannel;
|
|
133
|
+
coin?: string;
|
|
134
|
+
}
|
|
135
|
+
/** Unsubscribe message from client */
|
|
136
|
+
interface WsUnsubscribe {
|
|
137
|
+
op: 'unsubscribe';
|
|
138
|
+
channel: WsChannel;
|
|
139
|
+
coin?: string;
|
|
140
|
+
}
|
|
141
|
+
/** Ping message from client */
|
|
142
|
+
interface WsPing {
|
|
143
|
+
op: 'ping';
|
|
144
|
+
}
|
|
145
|
+
/** Replay message from client - replays historical data with timing preserved */
|
|
146
|
+
interface WsReplay {
|
|
147
|
+
op: 'replay';
|
|
148
|
+
channel: WsChannel;
|
|
149
|
+
coin?: string;
|
|
150
|
+
/** Start timestamp (Unix ms) */
|
|
151
|
+
start: number;
|
|
152
|
+
/** End timestamp (Unix ms, defaults to now) */
|
|
153
|
+
end?: number;
|
|
154
|
+
/** Playback speed multiplier (1 = real-time, 10 = 10x faster) */
|
|
155
|
+
speed?: number;
|
|
156
|
+
}
|
|
157
|
+
/** Replay control messages */
|
|
158
|
+
interface WsReplayPause {
|
|
159
|
+
op: 'replay.pause';
|
|
160
|
+
}
|
|
161
|
+
interface WsReplayResume {
|
|
162
|
+
op: 'replay.resume';
|
|
163
|
+
}
|
|
164
|
+
interface WsReplaySeek {
|
|
165
|
+
op: 'replay.seek';
|
|
166
|
+
timestamp: number;
|
|
167
|
+
}
|
|
168
|
+
interface WsReplayStop {
|
|
169
|
+
op: 'replay.stop';
|
|
170
|
+
}
|
|
171
|
+
/** Stream message from client - bulk download historical data */
|
|
172
|
+
interface WsStream {
|
|
173
|
+
op: 'stream';
|
|
174
|
+
channel: WsChannel;
|
|
175
|
+
coin?: string;
|
|
176
|
+
/** Start timestamp (Unix ms) */
|
|
177
|
+
start: number;
|
|
178
|
+
/** End timestamp (Unix ms) */
|
|
179
|
+
end: number;
|
|
180
|
+
/** Batch size (records per message) */
|
|
181
|
+
batch_size?: number;
|
|
182
|
+
}
|
|
183
|
+
/** Stream control messages */
|
|
184
|
+
interface WsStreamStop {
|
|
185
|
+
op: 'stream.stop';
|
|
186
|
+
}
|
|
187
|
+
/** Client message union type */
|
|
188
|
+
type WsClientMessage = WsSubscribe | WsUnsubscribe | WsPing | WsReplay | WsReplayPause | WsReplayResume | WsReplaySeek | WsReplayStop | WsStream | WsStreamStop;
|
|
189
|
+
/** Subscription confirmed from server */
|
|
190
|
+
interface WsSubscribed {
|
|
191
|
+
type: 'subscribed';
|
|
192
|
+
channel: WsChannel;
|
|
193
|
+
coin?: string;
|
|
194
|
+
}
|
|
195
|
+
/** Unsubscription confirmed from server */
|
|
196
|
+
interface WsUnsubscribed {
|
|
197
|
+
type: 'unsubscribed';
|
|
198
|
+
channel: WsChannel;
|
|
199
|
+
coin?: string;
|
|
200
|
+
}
|
|
201
|
+
/** Pong response from server */
|
|
202
|
+
interface WsPong {
|
|
203
|
+
type: 'pong';
|
|
204
|
+
}
|
|
205
|
+
/** Error from server */
|
|
206
|
+
interface WsError {
|
|
207
|
+
type: 'error';
|
|
208
|
+
message: string;
|
|
209
|
+
}
|
|
210
|
+
/** Data message from server */
|
|
211
|
+
interface WsData<T = unknown> {
|
|
212
|
+
type: 'data';
|
|
213
|
+
channel: WsChannel;
|
|
214
|
+
coin: string;
|
|
215
|
+
data: T;
|
|
216
|
+
}
|
|
217
|
+
/** Replay started response */
|
|
218
|
+
interface WsReplayStarted {
|
|
219
|
+
type: 'replay_started';
|
|
220
|
+
channel: WsChannel;
|
|
221
|
+
coin: string;
|
|
222
|
+
start: number;
|
|
223
|
+
end: number;
|
|
224
|
+
speed: number;
|
|
225
|
+
total_records: number;
|
|
226
|
+
}
|
|
227
|
+
/** Replay paused response */
|
|
228
|
+
interface WsReplayPaused {
|
|
229
|
+
type: 'replay_paused';
|
|
230
|
+
current_timestamp: number;
|
|
231
|
+
}
|
|
232
|
+
/** Replay resumed response */
|
|
233
|
+
interface WsReplayResumed {
|
|
234
|
+
type: 'replay_resumed';
|
|
235
|
+
current_timestamp: number;
|
|
236
|
+
}
|
|
237
|
+
/** Replay completed response */
|
|
238
|
+
interface WsReplayCompleted {
|
|
239
|
+
type: 'replay_completed';
|
|
240
|
+
channel: WsChannel;
|
|
241
|
+
coin: string;
|
|
242
|
+
records_sent: number;
|
|
243
|
+
}
|
|
244
|
+
/** Replay stopped response */
|
|
245
|
+
interface WsReplayStopped {
|
|
246
|
+
type: 'replay_stopped';
|
|
247
|
+
}
|
|
248
|
+
/** Historical data point (replay mode) */
|
|
249
|
+
interface WsHistoricalData<T = unknown> {
|
|
250
|
+
type: 'historical_data';
|
|
251
|
+
channel: WsChannel;
|
|
252
|
+
coin: string;
|
|
253
|
+
timestamp: number;
|
|
254
|
+
data: T;
|
|
255
|
+
}
|
|
256
|
+
/** Stream started response */
|
|
257
|
+
interface WsStreamStarted {
|
|
258
|
+
type: 'stream_started';
|
|
259
|
+
channel: WsChannel;
|
|
260
|
+
coin: string;
|
|
261
|
+
start: number;
|
|
262
|
+
end: number;
|
|
263
|
+
batch_size: number;
|
|
264
|
+
total_records: number;
|
|
265
|
+
}
|
|
266
|
+
/** Stream progress response */
|
|
267
|
+
interface WsStreamProgress {
|
|
268
|
+
type: 'stream_progress';
|
|
269
|
+
records_sent: number;
|
|
270
|
+
total_records: number;
|
|
271
|
+
progress_pct: number;
|
|
272
|
+
}
|
|
273
|
+
/** Stream batch (bulk data) */
|
|
274
|
+
interface WsHistoricalBatch<T = unknown> {
|
|
275
|
+
type: 'historical_batch';
|
|
276
|
+
channel: WsChannel;
|
|
277
|
+
coin: string;
|
|
278
|
+
batch_index: number;
|
|
279
|
+
records: Array<{
|
|
280
|
+
timestamp: number;
|
|
281
|
+
data: T;
|
|
282
|
+
}>;
|
|
283
|
+
}
|
|
284
|
+
/** Stream completed response */
|
|
285
|
+
interface WsStreamCompleted {
|
|
286
|
+
type: 'stream_completed';
|
|
287
|
+
channel: WsChannel;
|
|
288
|
+
coin: string;
|
|
289
|
+
records_sent: number;
|
|
290
|
+
}
|
|
291
|
+
/** Stream stopped response */
|
|
292
|
+
interface WsStreamStopped {
|
|
293
|
+
type: 'stream_stopped';
|
|
294
|
+
}
|
|
295
|
+
/** Server message union type */
|
|
296
|
+
type WsServerMessage = WsSubscribed | WsUnsubscribed | WsPong | WsError | WsData | WsReplayStarted | WsReplayPaused | WsReplayResumed | WsReplayCompleted | WsReplayStopped | WsHistoricalData | WsStreamStarted | WsStreamProgress | WsHistoricalBatch | WsStreamCompleted | WsStreamStopped;
|
|
297
|
+
/** WebSocket connection options */
|
|
298
|
+
interface WsOptions {
|
|
299
|
+
/** API key for authentication */
|
|
300
|
+
apiKey: string;
|
|
301
|
+
/** WebSocket URL (defaults to wss://ws.0xarchive.io) */
|
|
302
|
+
wsUrl?: string;
|
|
303
|
+
/** Auto-reconnect on disconnect (defaults to true) */
|
|
304
|
+
autoReconnect?: boolean;
|
|
305
|
+
/** Reconnect delay in ms (defaults to 1000) */
|
|
306
|
+
reconnectDelay?: number;
|
|
307
|
+
/** Maximum reconnect attempts (defaults to 10) */
|
|
308
|
+
maxReconnectAttempts?: number;
|
|
309
|
+
/** Ping interval in ms (defaults to 30000) */
|
|
310
|
+
pingInterval?: number;
|
|
311
|
+
}
|
|
312
|
+
/** WebSocket connection state */
|
|
313
|
+
type WsConnectionState = 'connecting' | 'connected' | 'disconnected' | 'reconnecting';
|
|
314
|
+
/** WebSocket event handlers */
|
|
315
|
+
interface WsEventHandlers {
|
|
316
|
+
onOpen?: () => void;
|
|
317
|
+
onClose?: (code: number, reason: string) => void;
|
|
318
|
+
onError?: (error: Error) => void;
|
|
319
|
+
onMessage?: (message: WsServerMessage) => void;
|
|
320
|
+
onStateChange?: (state: WsConnectionState) => void;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* API error response
|
|
324
|
+
*/
|
|
325
|
+
interface ApiError {
|
|
326
|
+
code: number;
|
|
327
|
+
error: string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* SDK error class
|
|
331
|
+
*/
|
|
332
|
+
declare class OxArchiveError extends Error {
|
|
333
|
+
code: number;
|
|
334
|
+
requestId?: string;
|
|
335
|
+
constructor(message: string, code: number, requestId?: string);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
interface HttpClientOptions {
|
|
339
|
+
baseUrl: string;
|
|
340
|
+
apiKey: string;
|
|
341
|
+
timeout: number;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Internal HTTP client for making API requests
|
|
345
|
+
*/
|
|
346
|
+
declare class HttpClient {
|
|
347
|
+
private baseUrl;
|
|
348
|
+
private apiKey;
|
|
349
|
+
private timeout;
|
|
350
|
+
constructor(options: HttpClientOptions);
|
|
351
|
+
/**
|
|
352
|
+
* Make a GET request to the API
|
|
353
|
+
*/
|
|
354
|
+
get<T>(path: string, params?: Record<string, unknown>): Promise<T>;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Order book API resource
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* // Get current order book
|
|
363
|
+
* const orderbook = await client.orderbook.get('BTC');
|
|
364
|
+
*
|
|
365
|
+
* // Get order book at specific timestamp
|
|
366
|
+
* const historical = await client.orderbook.get('ETH', {
|
|
367
|
+
* timestamp: 1704067200000,
|
|
368
|
+
* depth: 10
|
|
369
|
+
* });
|
|
370
|
+
*
|
|
371
|
+
* // Get order book history
|
|
372
|
+
* const history = await client.orderbook.history('BTC', {
|
|
373
|
+
* start: Date.now() - 86400000,
|
|
374
|
+
* end: Date.now(),
|
|
375
|
+
* limit: 100
|
|
376
|
+
* });
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare class OrderBookResource {
|
|
380
|
+
private http;
|
|
381
|
+
constructor(http: HttpClient);
|
|
382
|
+
/**
|
|
383
|
+
* Get order book snapshot for a coin
|
|
384
|
+
*
|
|
385
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
386
|
+
* @param params - Optional parameters
|
|
387
|
+
* @returns Order book snapshot
|
|
388
|
+
*/
|
|
389
|
+
get(coin: string, params?: GetOrderBookParams): Promise<OrderBook>;
|
|
390
|
+
/**
|
|
391
|
+
* Get historical order book snapshots
|
|
392
|
+
*
|
|
393
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
394
|
+
* @param params - Time range and pagination parameters
|
|
395
|
+
* @returns Array of order book snapshots
|
|
396
|
+
*/
|
|
397
|
+
history(coin: string, params?: OrderBookHistoryParams): Promise<OrderBook[]>;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Trades API resource
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* // Get recent trades
|
|
406
|
+
* const trades = await client.trades.recent('BTC');
|
|
407
|
+
*
|
|
408
|
+
* // Get trade history with time range
|
|
409
|
+
* const history = await client.trades.list('ETH', {
|
|
410
|
+
* start: Date.now() - 3600000,
|
|
411
|
+
* end: Date.now(),
|
|
412
|
+
* limit: 500
|
|
413
|
+
* });
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
declare class TradesResource {
|
|
417
|
+
private http;
|
|
418
|
+
constructor(http: HttpClient);
|
|
419
|
+
/**
|
|
420
|
+
* Get trade history for a coin
|
|
421
|
+
*
|
|
422
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
423
|
+
* @param params - Time range and pagination parameters
|
|
424
|
+
* @returns Array of trades
|
|
425
|
+
*/
|
|
426
|
+
list(coin: string, params?: GetTradesParams): Promise<Trade[]>;
|
|
427
|
+
/**
|
|
428
|
+
* Get most recent trades for a coin
|
|
429
|
+
*
|
|
430
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
431
|
+
* @param limit - Number of trades to return (default: 100)
|
|
432
|
+
* @returns Array of recent trades
|
|
433
|
+
*/
|
|
434
|
+
recent(coin: string, limit?: number): Promise<Trade[]>;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Candles (OHLCV) API resource
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* // Get hourly candles
|
|
443
|
+
* const candles = await client.candles.list('BTC', {
|
|
444
|
+
* interval: '1h',
|
|
445
|
+
* start: Date.now() - 86400000,
|
|
446
|
+
* end: Date.now()
|
|
447
|
+
* });
|
|
448
|
+
*
|
|
449
|
+
* // Get daily candles
|
|
450
|
+
* const daily = await client.candles.list('ETH', {
|
|
451
|
+
* interval: '1d',
|
|
452
|
+
* limit: 30
|
|
453
|
+
* });
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
declare class CandlesResource {
|
|
457
|
+
private http;
|
|
458
|
+
constructor(http: HttpClient);
|
|
459
|
+
/**
|
|
460
|
+
* Get OHLCV candles for a coin
|
|
461
|
+
*
|
|
462
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
463
|
+
* @param params - Interval, time range, and pagination parameters
|
|
464
|
+
* @returns Array of candles
|
|
465
|
+
*/
|
|
466
|
+
list(coin: string, params?: GetCandlesParams): Promise<Candle[]>;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Instruments API resource
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* ```typescript
|
|
474
|
+
* // List all instruments
|
|
475
|
+
* const instruments = await client.instruments.list();
|
|
476
|
+
*
|
|
477
|
+
* // Get specific instrument
|
|
478
|
+
* const btc = await client.instruments.get('BTC');
|
|
479
|
+
* ```
|
|
480
|
+
*/
|
|
481
|
+
declare class InstrumentsResource {
|
|
482
|
+
private http;
|
|
483
|
+
constructor(http: HttpClient);
|
|
484
|
+
/**
|
|
485
|
+
* List all available trading instruments
|
|
486
|
+
*
|
|
487
|
+
* @returns Array of instruments
|
|
488
|
+
*/
|
|
489
|
+
list(): Promise<Instrument[]>;
|
|
490
|
+
/**
|
|
491
|
+
* Get a specific instrument by coin symbol
|
|
492
|
+
*
|
|
493
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
494
|
+
* @returns Instrument details
|
|
495
|
+
*/
|
|
496
|
+
get(coin: string): Promise<Instrument>;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Funding rates API resource
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* // Get current funding rate
|
|
505
|
+
* const current = await client.funding.current('BTC');
|
|
506
|
+
*
|
|
507
|
+
* // Get funding rate history
|
|
508
|
+
* const history = await client.funding.history('ETH', {
|
|
509
|
+
* start: Date.now() - 86400000 * 7,
|
|
510
|
+
* end: Date.now()
|
|
511
|
+
* });
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
declare class FundingResource {
|
|
515
|
+
private http;
|
|
516
|
+
constructor(http: HttpClient);
|
|
517
|
+
/**
|
|
518
|
+
* Get funding rate history for a coin
|
|
519
|
+
*
|
|
520
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
521
|
+
* @param params - Time range and pagination parameters
|
|
522
|
+
* @returns Array of funding rate records
|
|
523
|
+
*/
|
|
524
|
+
history(coin: string, params?: TimeRangeParams): Promise<FundingRate[]>;
|
|
525
|
+
/**
|
|
526
|
+
* Get current funding rate for a coin
|
|
527
|
+
*
|
|
528
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
529
|
+
* @returns Current funding rate
|
|
530
|
+
*/
|
|
531
|
+
current(coin: string): Promise<FundingRate>;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Open interest API resource
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* ```typescript
|
|
539
|
+
* // Get current open interest
|
|
540
|
+
* const current = await client.openInterest.current('BTC');
|
|
541
|
+
*
|
|
542
|
+
* // Get open interest history
|
|
543
|
+
* const history = await client.openInterest.history('ETH', {
|
|
544
|
+
* start: Date.now() - 86400000,
|
|
545
|
+
* end: Date.now(),
|
|
546
|
+
* limit: 100
|
|
547
|
+
* });
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
declare class OpenInterestResource {
|
|
551
|
+
private http;
|
|
552
|
+
constructor(http: HttpClient);
|
|
553
|
+
/**
|
|
554
|
+
* Get open interest history for a coin
|
|
555
|
+
*
|
|
556
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
557
|
+
* @param params - Time range and pagination parameters
|
|
558
|
+
* @returns Array of open interest records
|
|
559
|
+
*/
|
|
560
|
+
history(coin: string, params?: TimeRangeParams): Promise<OpenInterest[]>;
|
|
561
|
+
/**
|
|
562
|
+
* Get current open interest for a coin
|
|
563
|
+
*
|
|
564
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
565
|
+
* @returns Current open interest
|
|
566
|
+
*/
|
|
567
|
+
current(coin: string): Promise<OpenInterest>;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* 0xarchive API client
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```typescript
|
|
575
|
+
* import { OxArchive } from '@0xarchive/sdk';
|
|
576
|
+
*
|
|
577
|
+
* const client = new OxArchive({ apiKey: 'ox_your_api_key' });
|
|
578
|
+
*
|
|
579
|
+
* // Get current order book
|
|
580
|
+
* const orderbook = await client.orderbook.get('BTC');
|
|
581
|
+
* console.log(`BTC mid price: ${orderbook.mid_price}`);
|
|
582
|
+
*
|
|
583
|
+
* // Get historical data
|
|
584
|
+
* const history = await client.orderbook.history('ETH', {
|
|
585
|
+
* start: Date.now() - 86400000,
|
|
586
|
+
* end: Date.now(),
|
|
587
|
+
* limit: 100
|
|
588
|
+
* });
|
|
589
|
+
*
|
|
590
|
+
* // List all instruments
|
|
591
|
+
* const instruments = await client.instruments.list();
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
declare class OxArchive {
|
|
595
|
+
private http;
|
|
596
|
+
/**
|
|
597
|
+
* Order book data (L2 snapshots from April 2023)
|
|
598
|
+
*/
|
|
599
|
+
readonly orderbook: OrderBookResource;
|
|
600
|
+
/**
|
|
601
|
+
* Trade/fill history
|
|
602
|
+
*/
|
|
603
|
+
readonly trades: TradesResource;
|
|
604
|
+
/**
|
|
605
|
+
* OHLCV candles
|
|
606
|
+
*/
|
|
607
|
+
readonly candles: CandlesResource;
|
|
608
|
+
/**
|
|
609
|
+
* Trading instruments metadata
|
|
610
|
+
*/
|
|
611
|
+
readonly instruments: InstrumentsResource;
|
|
612
|
+
/**
|
|
613
|
+
* Funding rates
|
|
614
|
+
*/
|
|
615
|
+
readonly funding: FundingResource;
|
|
616
|
+
/**
|
|
617
|
+
* Open interest
|
|
618
|
+
*/
|
|
619
|
+
readonly openInterest: OpenInterestResource;
|
|
620
|
+
/**
|
|
621
|
+
* Create a new 0xarchive client
|
|
622
|
+
*
|
|
623
|
+
* @param options - Client configuration options
|
|
624
|
+
*/
|
|
625
|
+
constructor(options: ClientOptions);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* WebSocket client for 0xarchive real-time streaming, replay, and bulk download
|
|
630
|
+
*
|
|
631
|
+
* @example Real-time streaming
|
|
632
|
+
* ```typescript
|
|
633
|
+
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
634
|
+
* ws.connect({
|
|
635
|
+
* onMessage: (msg) => console.log(msg)
|
|
636
|
+
* });
|
|
637
|
+
* ws.subscribeOrderbook('BTC');
|
|
638
|
+
* ```
|
|
639
|
+
*
|
|
640
|
+
* @example Historical replay (like Tardis.dev)
|
|
641
|
+
* ```typescript
|
|
642
|
+
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
643
|
+
* ws.connect();
|
|
644
|
+
* ws.onHistoricalData((coin, timestamp, data) => {
|
|
645
|
+
* console.log(`${new Date(timestamp)}: ${data.mid_price}`);
|
|
646
|
+
* });
|
|
647
|
+
* ws.replay('orderbook', 'BTC', {
|
|
648
|
+
* start: Date.now() - 86400000,
|
|
649
|
+
* speed: 10 // 10x speed
|
|
650
|
+
* });
|
|
651
|
+
* ```
|
|
652
|
+
*
|
|
653
|
+
* @example Bulk streaming (like Databento)
|
|
654
|
+
* ```typescript
|
|
655
|
+
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
656
|
+
* ws.connect();
|
|
657
|
+
* const batches: OrderBook[] = [];
|
|
658
|
+
* ws.onBatch((coin, records) => {
|
|
659
|
+
* batches.push(...records.map(r => r.data));
|
|
660
|
+
* });
|
|
661
|
+
* ws.onStreamComplete((channel, coin, count) => {
|
|
662
|
+
* console.log(`Downloaded ${count} records`);
|
|
663
|
+
* });
|
|
664
|
+
* ws.stream('orderbook', 'ETH', {
|
|
665
|
+
* start: Date.now() - 3600000,
|
|
666
|
+
* end: Date.now(),
|
|
667
|
+
* batchSize: 1000
|
|
668
|
+
* });
|
|
669
|
+
* ```
|
|
670
|
+
*/
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* WebSocket client for real-time data streaming
|
|
674
|
+
*/
|
|
675
|
+
declare class OxArchiveWs {
|
|
676
|
+
private ws;
|
|
677
|
+
private options;
|
|
678
|
+
private handlers;
|
|
679
|
+
private subscriptions;
|
|
680
|
+
private state;
|
|
681
|
+
private reconnectAttempts;
|
|
682
|
+
private pingTimer;
|
|
683
|
+
private reconnectTimer;
|
|
684
|
+
constructor(options: WsOptions);
|
|
685
|
+
/**
|
|
686
|
+
* Connect to the WebSocket server
|
|
687
|
+
*/
|
|
688
|
+
connect(handlers?: WsEventHandlers): void;
|
|
689
|
+
/**
|
|
690
|
+
* Disconnect from the WebSocket server
|
|
691
|
+
*/
|
|
692
|
+
disconnect(): void;
|
|
693
|
+
/**
|
|
694
|
+
* Subscribe to a channel
|
|
695
|
+
*/
|
|
696
|
+
subscribe(channel: WsChannel, coin?: string): void;
|
|
697
|
+
/**
|
|
698
|
+
* Subscribe to order book updates for a coin
|
|
699
|
+
*/
|
|
700
|
+
subscribeOrderbook(coin: string): void;
|
|
701
|
+
/**
|
|
702
|
+
* Subscribe to trades for a coin
|
|
703
|
+
*/
|
|
704
|
+
subscribeTrades(coin: string): void;
|
|
705
|
+
/**
|
|
706
|
+
* Subscribe to ticker updates for a coin
|
|
707
|
+
*/
|
|
708
|
+
subscribeTicker(coin: string): void;
|
|
709
|
+
/**
|
|
710
|
+
* Subscribe to all tickers
|
|
711
|
+
*/
|
|
712
|
+
subscribeAllTickers(): void;
|
|
713
|
+
/**
|
|
714
|
+
* Unsubscribe from a channel
|
|
715
|
+
*/
|
|
716
|
+
unsubscribe(channel: WsChannel, coin?: string): void;
|
|
717
|
+
/**
|
|
718
|
+
* Unsubscribe from order book updates for a coin
|
|
719
|
+
*/
|
|
720
|
+
unsubscribeOrderbook(coin: string): void;
|
|
721
|
+
/**
|
|
722
|
+
* Unsubscribe from trades for a coin
|
|
723
|
+
*/
|
|
724
|
+
unsubscribeTrades(coin: string): void;
|
|
725
|
+
/**
|
|
726
|
+
* Unsubscribe from ticker updates for a coin
|
|
727
|
+
*/
|
|
728
|
+
unsubscribeTicker(coin: string): void;
|
|
729
|
+
/**
|
|
730
|
+
* Unsubscribe from all tickers
|
|
731
|
+
*/
|
|
732
|
+
unsubscribeAllTickers(): void;
|
|
733
|
+
/**
|
|
734
|
+
* Start historical replay with timing preserved
|
|
735
|
+
*
|
|
736
|
+
* @param channel - Data channel to replay
|
|
737
|
+
* @param coin - Trading pair (e.g., 'BTC', 'ETH')
|
|
738
|
+
* @param options - Replay options
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
* ```typescript
|
|
742
|
+
* ws.replay('orderbook', 'BTC', {
|
|
743
|
+
* start: Date.now() - 86400000, // 24 hours ago
|
|
744
|
+
* speed: 10 // 10x faster than real-time
|
|
745
|
+
* });
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
748
|
+
replay(channel: WsChannel, coin: string, options: {
|
|
749
|
+
start: number;
|
|
750
|
+
end?: number;
|
|
751
|
+
speed?: number;
|
|
752
|
+
}): void;
|
|
753
|
+
/**
|
|
754
|
+
* Pause the current replay
|
|
755
|
+
*/
|
|
756
|
+
replayPause(): void;
|
|
757
|
+
/**
|
|
758
|
+
* Resume a paused replay
|
|
759
|
+
*/
|
|
760
|
+
replayResume(): void;
|
|
761
|
+
/**
|
|
762
|
+
* Seek to a specific timestamp in the replay
|
|
763
|
+
* @param timestamp - Unix timestamp in milliseconds
|
|
764
|
+
*/
|
|
765
|
+
replaySeek(timestamp: number): void;
|
|
766
|
+
/**
|
|
767
|
+
* Stop the current replay
|
|
768
|
+
*/
|
|
769
|
+
replayStop(): void;
|
|
770
|
+
/**
|
|
771
|
+
* Start bulk streaming for fast data download
|
|
772
|
+
*
|
|
773
|
+
* @param channel - Data channel to stream
|
|
774
|
+
* @param coin - Trading pair (e.g., 'BTC', 'ETH')
|
|
775
|
+
* @param options - Stream options
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* ```typescript
|
|
779
|
+
* ws.stream('orderbook', 'ETH', {
|
|
780
|
+
* start: Date.now() - 3600000, // 1 hour ago
|
|
781
|
+
* end: Date.now(),
|
|
782
|
+
* batchSize: 1000
|
|
783
|
+
* });
|
|
784
|
+
* ```
|
|
785
|
+
*/
|
|
786
|
+
stream(channel: WsChannel, coin: string, options: {
|
|
787
|
+
start: number;
|
|
788
|
+
end: number;
|
|
789
|
+
batchSize?: number;
|
|
790
|
+
}): void;
|
|
791
|
+
/**
|
|
792
|
+
* Stop the current bulk stream
|
|
793
|
+
*/
|
|
794
|
+
streamStop(): void;
|
|
795
|
+
/**
|
|
796
|
+
* Handle historical data points (replay mode)
|
|
797
|
+
*/
|
|
798
|
+
onHistoricalData<T = unknown>(handler: (coin: string, timestamp: number, data: T) => void): void;
|
|
799
|
+
/**
|
|
800
|
+
* Handle batched data (bulk stream mode)
|
|
801
|
+
*/
|
|
802
|
+
onBatch<T = unknown>(handler: (coin: string, records: Array<{
|
|
803
|
+
timestamp: number;
|
|
804
|
+
data: T;
|
|
805
|
+
}>) => void): void;
|
|
806
|
+
/**
|
|
807
|
+
* Handle replay started event
|
|
808
|
+
*/
|
|
809
|
+
onReplayStart(handler: (channel: WsChannel, coin: string, totalRecords: number, speed: number) => void): void;
|
|
810
|
+
/**
|
|
811
|
+
* Handle replay completed event
|
|
812
|
+
*/
|
|
813
|
+
onReplayComplete(handler: (channel: WsChannel, coin: string, recordsSent: number) => void): void;
|
|
814
|
+
/**
|
|
815
|
+
* Handle stream started event
|
|
816
|
+
*/
|
|
817
|
+
onStreamStart(handler: (channel: WsChannel, coin: string, totalRecords: number) => void): void;
|
|
818
|
+
/**
|
|
819
|
+
* Handle stream progress event
|
|
820
|
+
*/
|
|
821
|
+
onStreamProgress(handler: (recordsSent: number, totalRecords: number, progressPct: number) => void): void;
|
|
822
|
+
/**
|
|
823
|
+
* Handle stream completed event
|
|
824
|
+
*/
|
|
825
|
+
onStreamComplete(handler: (channel: WsChannel, coin: string, recordsSent: number) => void): void;
|
|
826
|
+
/**
|
|
827
|
+
* Get current connection state
|
|
828
|
+
*/
|
|
829
|
+
getState(): WsConnectionState;
|
|
830
|
+
/**
|
|
831
|
+
* Check if connected
|
|
832
|
+
*/
|
|
833
|
+
isConnected(): boolean;
|
|
834
|
+
/**
|
|
835
|
+
* Set event handlers after construction
|
|
836
|
+
*/
|
|
837
|
+
on<K extends keyof WsEventHandlers>(event: K, handler: WsEventHandlers[K]): void;
|
|
838
|
+
/**
|
|
839
|
+
* Helper to handle typed orderbook data
|
|
840
|
+
*/
|
|
841
|
+
onOrderbook(handler: (coin: string, data: OrderBook) => void): void;
|
|
842
|
+
/**
|
|
843
|
+
* Helper to handle typed trade data
|
|
844
|
+
*/
|
|
845
|
+
onTrades(handler: (coin: string, data: Trade[]) => void): void;
|
|
846
|
+
private send;
|
|
847
|
+
private setState;
|
|
848
|
+
private startPing;
|
|
849
|
+
private stopPing;
|
|
850
|
+
private subscriptionKey;
|
|
851
|
+
private resubscribe;
|
|
852
|
+
private scheduleReconnect;
|
|
853
|
+
private clearReconnectTimer;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
export { type ApiError, type ApiResponse, type Candle, type CandleInterval, type ClientOptions, type FundingRate, type GetCandlesParams, type GetOrderBookParams, type GetTradesParams, type Instrument, type OpenInterest, type OrderBook, type OrderBookHistoryParams, OxArchive, OxArchiveError, OxArchiveWs, type PaginationParams, type PriceLevel, type TimeRangeParams, type Trade, type WsChannel, type WsClientMessage, type WsConnectionState, type WsData, type WsError, type WsEventHandlers, type WsHistoricalBatch, type WsHistoricalData, type WsOptions, type WsPing, type WsPong, type WsReplay, type WsReplayCompleted, type WsReplayPause, type WsReplayPaused, type WsReplayResume, type WsReplayResumed, type WsReplaySeek, type WsReplayStarted, type WsReplayStop, type WsReplayStopped, type WsServerMessage, type WsStream, type WsStreamCompleted, type WsStreamProgress, type WsStreamStarted, type WsStreamStop, type WsStreamStopped, type WsSubscribe, type WsSubscribed, type WsUnsubscribe, type WsUnsubscribed, OxArchive as default };
|