@0xarchive/sdk 0.3.6 → 0.3.8
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/dist/index.d.mts +13 -20
- package/dist/index.d.ts +13 -20
- package/dist/index.js +50 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -96,8 +96,6 @@ interface OrderBookHistoryParams extends TimeRangeParams {
|
|
|
96
96
|
type TradeSide = 'A' | 'B';
|
|
97
97
|
/** Position direction (can include 'Open Long', 'Close Short', 'Long > Short', etc.) */
|
|
98
98
|
type TradeDirection = string;
|
|
99
|
-
/** Data source: 's3' (historical), 'api' (REST backfill), 'ws' (websocket), 'live' (real-time ingestion) */
|
|
100
|
-
type DataSource = 's3' | 'ws' | 'api' | 'live';
|
|
101
99
|
/**
|
|
102
100
|
* Trade/fill record with full execution details
|
|
103
101
|
*/
|
|
@@ -130,8 +128,6 @@ interface Trade {
|
|
|
130
128
|
direction?: TradeDirection;
|
|
131
129
|
/** Position size before this trade */
|
|
132
130
|
startPosition?: string;
|
|
133
|
-
/** Data source */
|
|
134
|
-
source?: DataSource;
|
|
135
131
|
/** User's wallet address (for fill-level data from REST API) */
|
|
136
132
|
userAddress?: string;
|
|
137
133
|
/** Maker's wallet address (for market-level WebSocket trades) */
|
|
@@ -778,19 +774,18 @@ declare class OxArchive {
|
|
|
778
774
|
* @example Real-time streaming
|
|
779
775
|
* ```typescript
|
|
780
776
|
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
781
|
-
* ws.connect(
|
|
782
|
-
*
|
|
783
|
-
* });
|
|
777
|
+
* await ws.connect();
|
|
778
|
+
* ws.onOrderbook((coin, ob) => console.log(`${coin}: ${ob.midPrice}`));
|
|
784
779
|
* ws.subscribeOrderbook('BTC');
|
|
785
780
|
* ```
|
|
786
781
|
*
|
|
787
782
|
* @example Historical replay (like Tardis.dev)
|
|
788
783
|
* ```typescript
|
|
789
784
|
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
790
|
-
* ws.connect();
|
|
791
785
|
* ws.onHistoricalData((coin, timestamp, data) => {
|
|
792
786
|
* console.log(`${new Date(timestamp)}: ${data.mid_price}`);
|
|
793
787
|
* });
|
|
788
|
+
* await ws.connect();
|
|
794
789
|
* ws.replay('orderbook', 'BTC', {
|
|
795
790
|
* start: Date.now() - 86400000,
|
|
796
791
|
* speed: 10 // 10x speed
|
|
@@ -800,7 +795,6 @@ declare class OxArchive {
|
|
|
800
795
|
* @example Bulk streaming (like Databento)
|
|
801
796
|
* ```typescript
|
|
802
797
|
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
803
|
-
* ws.connect();
|
|
804
798
|
* const batches: OrderBook[] = [];
|
|
805
799
|
* ws.onBatch((coin, records) => {
|
|
806
800
|
* batches.push(...records.map(r => r.data));
|
|
@@ -808,6 +802,7 @@ declare class OxArchive {
|
|
|
808
802
|
* ws.onStreamComplete((channel, coin, count) => {
|
|
809
803
|
* console.log(`Downloaded ${count} records`);
|
|
810
804
|
* });
|
|
805
|
+
* await ws.connect();
|
|
811
806
|
* ws.stream('orderbook', 'ETH', {
|
|
812
807
|
* start: Date.now() - 3600000,
|
|
813
808
|
* end: Date.now(),
|
|
@@ -846,8 +841,15 @@ declare class OxArchiveWs {
|
|
|
846
841
|
constructor(options: WsOptions);
|
|
847
842
|
/**
|
|
848
843
|
* Connect to the WebSocket server
|
|
844
|
+
*
|
|
845
|
+
* @returns Promise that resolves when connected
|
|
846
|
+
* @example
|
|
847
|
+
* ```typescript
|
|
848
|
+
* await ws.connect();
|
|
849
|
+
* ws.subscribeOrderbook('BTC');
|
|
850
|
+
* ```
|
|
849
851
|
*/
|
|
850
|
-
connect(handlers?: WsEventHandlers): void
|
|
852
|
+
connect(handlers?: WsEventHandlers): Promise<void>;
|
|
851
853
|
/**
|
|
852
854
|
* Disconnect from the WebSocket server
|
|
853
855
|
*/
|
|
@@ -1175,7 +1177,6 @@ declare const OrderBookSchema: z.ZodObject<{
|
|
|
1175
1177
|
}>;
|
|
1176
1178
|
declare const TradeSideSchema: z.ZodEnum<["A", "B"]>;
|
|
1177
1179
|
declare const TradeDirectionSchema: z.ZodString;
|
|
1178
|
-
declare const DataSourceSchema: z.ZodEnum<["s3", "ws", "api", "live"]>;
|
|
1179
1180
|
declare const TradeSchema: z.ZodObject<{
|
|
1180
1181
|
coin: z.ZodString;
|
|
1181
1182
|
side: z.ZodEnum<["A", "B"]>;
|
|
@@ -1191,7 +1192,6 @@ declare const TradeSchema: z.ZodObject<{
|
|
|
1191
1192
|
closedPnl: z.ZodOptional<z.ZodString>;
|
|
1192
1193
|
direction: z.ZodOptional<z.ZodString>;
|
|
1193
1194
|
startPosition: z.ZodOptional<z.ZodString>;
|
|
1194
|
-
source: z.ZodOptional<z.ZodEnum<["s3", "ws", "api", "live"]>>;
|
|
1195
1195
|
userAddress: z.ZodOptional<z.ZodString>;
|
|
1196
1196
|
makerAddress: z.ZodOptional<z.ZodString>;
|
|
1197
1197
|
takerAddress: z.ZodOptional<z.ZodString>;
|
|
@@ -1210,7 +1210,6 @@ declare const TradeSchema: z.ZodObject<{
|
|
|
1210
1210
|
closedPnl?: string | undefined;
|
|
1211
1211
|
direction?: string | undefined;
|
|
1212
1212
|
startPosition?: string | undefined;
|
|
1213
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
1214
1213
|
userAddress?: string | undefined;
|
|
1215
1214
|
makerAddress?: string | undefined;
|
|
1216
1215
|
takerAddress?: string | undefined;
|
|
@@ -1229,7 +1228,6 @@ declare const TradeSchema: z.ZodObject<{
|
|
|
1229
1228
|
closedPnl?: string | undefined;
|
|
1230
1229
|
direction?: string | undefined;
|
|
1231
1230
|
startPosition?: string | undefined;
|
|
1232
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
1233
1231
|
userAddress?: string | undefined;
|
|
1234
1232
|
makerAddress?: string | undefined;
|
|
1235
1233
|
takerAddress?: string | undefined;
|
|
@@ -2037,7 +2035,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2037
2035
|
closedPnl: z.ZodOptional<z.ZodString>;
|
|
2038
2036
|
direction: z.ZodOptional<z.ZodString>;
|
|
2039
2037
|
startPosition: z.ZodOptional<z.ZodString>;
|
|
2040
|
-
source: z.ZodOptional<z.ZodEnum<["s3", "ws", "api", "live"]>>;
|
|
2041
2038
|
userAddress: z.ZodOptional<z.ZodString>;
|
|
2042
2039
|
makerAddress: z.ZodOptional<z.ZodString>;
|
|
2043
2040
|
takerAddress: z.ZodOptional<z.ZodString>;
|
|
@@ -2056,7 +2053,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2056
2053
|
closedPnl?: string | undefined;
|
|
2057
2054
|
direction?: string | undefined;
|
|
2058
2055
|
startPosition?: string | undefined;
|
|
2059
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2060
2056
|
userAddress?: string | undefined;
|
|
2061
2057
|
makerAddress?: string | undefined;
|
|
2062
2058
|
takerAddress?: string | undefined;
|
|
@@ -2075,7 +2071,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2075
2071
|
closedPnl?: string | undefined;
|
|
2076
2072
|
direction?: string | undefined;
|
|
2077
2073
|
startPosition?: string | undefined;
|
|
2078
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2079
2074
|
userAddress?: string | undefined;
|
|
2080
2075
|
makerAddress?: string | undefined;
|
|
2081
2076
|
takerAddress?: string | undefined;
|
|
@@ -2109,7 +2104,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2109
2104
|
closedPnl?: string | undefined;
|
|
2110
2105
|
direction?: string | undefined;
|
|
2111
2106
|
startPosition?: string | undefined;
|
|
2112
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2113
2107
|
userAddress?: string | undefined;
|
|
2114
2108
|
makerAddress?: string | undefined;
|
|
2115
2109
|
takerAddress?: string | undefined;
|
|
@@ -2136,7 +2130,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2136
2130
|
closedPnl?: string | undefined;
|
|
2137
2131
|
direction?: string | undefined;
|
|
2138
2132
|
startPosition?: string | undefined;
|
|
2139
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2140
2133
|
userAddress?: string | undefined;
|
|
2141
2134
|
makerAddress?: string | undefined;
|
|
2142
2135
|
takerAddress?: string | undefined;
|
|
@@ -2585,4 +2578,4 @@ type ValidatedFundingRate = z.infer<typeof FundingRateSchema>;
|
|
|
2585
2578
|
type ValidatedOpenInterest = z.infer<typeof OpenInterestSchema>;
|
|
2586
2579
|
type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
|
|
2587
2580
|
|
|
2588
|
-
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type ClientOptions, type CursorResponse, type
|
|
2581
|
+
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type ClientOptions, type CursorResponse, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, type GetTradesParams, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type OpenInterest, OpenInterestArrayResponseSchema, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookResponseSchema, OrderBookSchema, OxArchive, OxArchiveError, OxArchiveWs, type PaginationParams, type PriceLevel, PriceLevelSchema, type TimeRangeParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -96,8 +96,6 @@ interface OrderBookHistoryParams extends TimeRangeParams {
|
|
|
96
96
|
type TradeSide = 'A' | 'B';
|
|
97
97
|
/** Position direction (can include 'Open Long', 'Close Short', 'Long > Short', etc.) */
|
|
98
98
|
type TradeDirection = string;
|
|
99
|
-
/** Data source: 's3' (historical), 'api' (REST backfill), 'ws' (websocket), 'live' (real-time ingestion) */
|
|
100
|
-
type DataSource = 's3' | 'ws' | 'api' | 'live';
|
|
101
99
|
/**
|
|
102
100
|
* Trade/fill record with full execution details
|
|
103
101
|
*/
|
|
@@ -130,8 +128,6 @@ interface Trade {
|
|
|
130
128
|
direction?: TradeDirection;
|
|
131
129
|
/** Position size before this trade */
|
|
132
130
|
startPosition?: string;
|
|
133
|
-
/** Data source */
|
|
134
|
-
source?: DataSource;
|
|
135
131
|
/** User's wallet address (for fill-level data from REST API) */
|
|
136
132
|
userAddress?: string;
|
|
137
133
|
/** Maker's wallet address (for market-level WebSocket trades) */
|
|
@@ -778,19 +774,18 @@ declare class OxArchive {
|
|
|
778
774
|
* @example Real-time streaming
|
|
779
775
|
* ```typescript
|
|
780
776
|
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
781
|
-
* ws.connect(
|
|
782
|
-
*
|
|
783
|
-
* });
|
|
777
|
+
* await ws.connect();
|
|
778
|
+
* ws.onOrderbook((coin, ob) => console.log(`${coin}: ${ob.midPrice}`));
|
|
784
779
|
* ws.subscribeOrderbook('BTC');
|
|
785
780
|
* ```
|
|
786
781
|
*
|
|
787
782
|
* @example Historical replay (like Tardis.dev)
|
|
788
783
|
* ```typescript
|
|
789
784
|
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
790
|
-
* ws.connect();
|
|
791
785
|
* ws.onHistoricalData((coin, timestamp, data) => {
|
|
792
786
|
* console.log(`${new Date(timestamp)}: ${data.mid_price}`);
|
|
793
787
|
* });
|
|
788
|
+
* await ws.connect();
|
|
794
789
|
* ws.replay('orderbook', 'BTC', {
|
|
795
790
|
* start: Date.now() - 86400000,
|
|
796
791
|
* speed: 10 // 10x speed
|
|
@@ -800,7 +795,6 @@ declare class OxArchive {
|
|
|
800
795
|
* @example Bulk streaming (like Databento)
|
|
801
796
|
* ```typescript
|
|
802
797
|
* const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
803
|
-
* ws.connect();
|
|
804
798
|
* const batches: OrderBook[] = [];
|
|
805
799
|
* ws.onBatch((coin, records) => {
|
|
806
800
|
* batches.push(...records.map(r => r.data));
|
|
@@ -808,6 +802,7 @@ declare class OxArchive {
|
|
|
808
802
|
* ws.onStreamComplete((channel, coin, count) => {
|
|
809
803
|
* console.log(`Downloaded ${count} records`);
|
|
810
804
|
* });
|
|
805
|
+
* await ws.connect();
|
|
811
806
|
* ws.stream('orderbook', 'ETH', {
|
|
812
807
|
* start: Date.now() - 3600000,
|
|
813
808
|
* end: Date.now(),
|
|
@@ -846,8 +841,15 @@ declare class OxArchiveWs {
|
|
|
846
841
|
constructor(options: WsOptions);
|
|
847
842
|
/**
|
|
848
843
|
* Connect to the WebSocket server
|
|
844
|
+
*
|
|
845
|
+
* @returns Promise that resolves when connected
|
|
846
|
+
* @example
|
|
847
|
+
* ```typescript
|
|
848
|
+
* await ws.connect();
|
|
849
|
+
* ws.subscribeOrderbook('BTC');
|
|
850
|
+
* ```
|
|
849
851
|
*/
|
|
850
|
-
connect(handlers?: WsEventHandlers): void
|
|
852
|
+
connect(handlers?: WsEventHandlers): Promise<void>;
|
|
851
853
|
/**
|
|
852
854
|
* Disconnect from the WebSocket server
|
|
853
855
|
*/
|
|
@@ -1175,7 +1177,6 @@ declare const OrderBookSchema: z.ZodObject<{
|
|
|
1175
1177
|
}>;
|
|
1176
1178
|
declare const TradeSideSchema: z.ZodEnum<["A", "B"]>;
|
|
1177
1179
|
declare const TradeDirectionSchema: z.ZodString;
|
|
1178
|
-
declare const DataSourceSchema: z.ZodEnum<["s3", "ws", "api", "live"]>;
|
|
1179
1180
|
declare const TradeSchema: z.ZodObject<{
|
|
1180
1181
|
coin: z.ZodString;
|
|
1181
1182
|
side: z.ZodEnum<["A", "B"]>;
|
|
@@ -1191,7 +1192,6 @@ declare const TradeSchema: z.ZodObject<{
|
|
|
1191
1192
|
closedPnl: z.ZodOptional<z.ZodString>;
|
|
1192
1193
|
direction: z.ZodOptional<z.ZodString>;
|
|
1193
1194
|
startPosition: z.ZodOptional<z.ZodString>;
|
|
1194
|
-
source: z.ZodOptional<z.ZodEnum<["s3", "ws", "api", "live"]>>;
|
|
1195
1195
|
userAddress: z.ZodOptional<z.ZodString>;
|
|
1196
1196
|
makerAddress: z.ZodOptional<z.ZodString>;
|
|
1197
1197
|
takerAddress: z.ZodOptional<z.ZodString>;
|
|
@@ -1210,7 +1210,6 @@ declare const TradeSchema: z.ZodObject<{
|
|
|
1210
1210
|
closedPnl?: string | undefined;
|
|
1211
1211
|
direction?: string | undefined;
|
|
1212
1212
|
startPosition?: string | undefined;
|
|
1213
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
1214
1213
|
userAddress?: string | undefined;
|
|
1215
1214
|
makerAddress?: string | undefined;
|
|
1216
1215
|
takerAddress?: string | undefined;
|
|
@@ -1229,7 +1228,6 @@ declare const TradeSchema: z.ZodObject<{
|
|
|
1229
1228
|
closedPnl?: string | undefined;
|
|
1230
1229
|
direction?: string | undefined;
|
|
1231
1230
|
startPosition?: string | undefined;
|
|
1232
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
1233
1231
|
userAddress?: string | undefined;
|
|
1234
1232
|
makerAddress?: string | undefined;
|
|
1235
1233
|
takerAddress?: string | undefined;
|
|
@@ -2037,7 +2035,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2037
2035
|
closedPnl: z.ZodOptional<z.ZodString>;
|
|
2038
2036
|
direction: z.ZodOptional<z.ZodString>;
|
|
2039
2037
|
startPosition: z.ZodOptional<z.ZodString>;
|
|
2040
|
-
source: z.ZodOptional<z.ZodEnum<["s3", "ws", "api", "live"]>>;
|
|
2041
2038
|
userAddress: z.ZodOptional<z.ZodString>;
|
|
2042
2039
|
makerAddress: z.ZodOptional<z.ZodString>;
|
|
2043
2040
|
takerAddress: z.ZodOptional<z.ZodString>;
|
|
@@ -2056,7 +2053,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2056
2053
|
closedPnl?: string | undefined;
|
|
2057
2054
|
direction?: string | undefined;
|
|
2058
2055
|
startPosition?: string | undefined;
|
|
2059
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2060
2056
|
userAddress?: string | undefined;
|
|
2061
2057
|
makerAddress?: string | undefined;
|
|
2062
2058
|
takerAddress?: string | undefined;
|
|
@@ -2075,7 +2071,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2075
2071
|
closedPnl?: string | undefined;
|
|
2076
2072
|
direction?: string | undefined;
|
|
2077
2073
|
startPosition?: string | undefined;
|
|
2078
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2079
2074
|
userAddress?: string | undefined;
|
|
2080
2075
|
makerAddress?: string | undefined;
|
|
2081
2076
|
takerAddress?: string | undefined;
|
|
@@ -2109,7 +2104,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2109
2104
|
closedPnl?: string | undefined;
|
|
2110
2105
|
direction?: string | undefined;
|
|
2111
2106
|
startPosition?: string | undefined;
|
|
2112
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2113
2107
|
userAddress?: string | undefined;
|
|
2114
2108
|
makerAddress?: string | undefined;
|
|
2115
2109
|
takerAddress?: string | undefined;
|
|
@@ -2136,7 +2130,6 @@ declare const TradeArrayResponseSchema: z.ZodObject<{
|
|
|
2136
2130
|
closedPnl?: string | undefined;
|
|
2137
2131
|
direction?: string | undefined;
|
|
2138
2132
|
startPosition?: string | undefined;
|
|
2139
|
-
source?: "s3" | "ws" | "api" | "live" | undefined;
|
|
2140
2133
|
userAddress?: string | undefined;
|
|
2141
2134
|
makerAddress?: string | undefined;
|
|
2142
2135
|
takerAddress?: string | undefined;
|
|
@@ -2585,4 +2578,4 @@ type ValidatedFundingRate = z.infer<typeof FundingRateSchema>;
|
|
|
2585
2578
|
type ValidatedOpenInterest = z.infer<typeof OpenInterestSchema>;
|
|
2586
2579
|
type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
|
|
2587
2580
|
|
|
2588
|
-
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type ClientOptions, type CursorResponse, type
|
|
2581
|
+
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type ClientOptions, type CursorResponse, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, type GetTradesParams, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type OpenInterest, OpenInterestArrayResponseSchema, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookResponseSchema, OrderBookSchema, OxArchive, OxArchiveError, OxArchiveWs, type PaginationParams, type PriceLevel, PriceLevelSchema, type TimeRangeParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default };
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,6 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ApiMetaSchema: () => ApiMetaSchema,
|
|
24
24
|
ApiResponseSchema: () => ApiResponseSchema,
|
|
25
|
-
DataSourceSchema: () => DataSourceSchema,
|
|
26
25
|
FundingRateArrayResponseSchema: () => FundingRateArrayResponseSchema,
|
|
27
26
|
FundingRateResponseSchema: () => FundingRateResponseSchema,
|
|
28
27
|
FundingRateSchema: () => FundingRateSchema,
|
|
@@ -215,7 +214,6 @@ var OrderBookSchema = import_zod.z.object({
|
|
|
215
214
|
});
|
|
216
215
|
var TradeSideSchema = import_zod.z.enum(["A", "B"]);
|
|
217
216
|
var TradeDirectionSchema = import_zod.z.string();
|
|
218
|
-
var DataSourceSchema = import_zod.z.enum(["s3", "ws", "api", "live"]);
|
|
219
217
|
var TradeSchema = import_zod.z.object({
|
|
220
218
|
coin: import_zod.z.string(),
|
|
221
219
|
side: TradeSideSchema,
|
|
@@ -231,7 +229,6 @@ var TradeSchema = import_zod.z.object({
|
|
|
231
229
|
closedPnl: import_zod.z.string().optional(),
|
|
232
230
|
direction: TradeDirectionSchema.optional(),
|
|
233
231
|
startPosition: import_zod.z.string().optional(),
|
|
234
|
-
source: DataSourceSchema.optional(),
|
|
235
232
|
userAddress: import_zod.z.string().optional(),
|
|
236
233
|
makerAddress: import_zod.z.string().optional(),
|
|
237
234
|
takerAddress: import_zod.z.string().optional()
|
|
@@ -768,41 +765,57 @@ var OxArchiveWs = class {
|
|
|
768
765
|
}
|
|
769
766
|
/**
|
|
770
767
|
* Connect to the WebSocket server
|
|
768
|
+
*
|
|
769
|
+
* @returns Promise that resolves when connected
|
|
770
|
+
* @example
|
|
771
|
+
* ```typescript
|
|
772
|
+
* await ws.connect();
|
|
773
|
+
* ws.subscribeOrderbook('BTC');
|
|
774
|
+
* ```
|
|
771
775
|
*/
|
|
772
776
|
connect(handlers) {
|
|
773
777
|
if (handlers) {
|
|
774
778
|
this.handlers = handlers;
|
|
775
779
|
}
|
|
776
780
|
this.setState("connecting");
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
this.
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
this.
|
|
789
|
-
|
|
790
|
-
this.
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
781
|
+
return new Promise((resolve, reject) => {
|
|
782
|
+
const url = `${this.options.wsUrl}?apiKey=${encodeURIComponent(this.options.apiKey)}`;
|
|
783
|
+
this.ws = new WebSocket(url);
|
|
784
|
+
this.ws.onopen = () => {
|
|
785
|
+
this.reconnectAttempts = 0;
|
|
786
|
+
this.setState("connected");
|
|
787
|
+
this.startPing();
|
|
788
|
+
this.resubscribe();
|
|
789
|
+
this.handlers.onOpen?.();
|
|
790
|
+
resolve();
|
|
791
|
+
};
|
|
792
|
+
this.ws.onclose = (event) => {
|
|
793
|
+
this.stopPing();
|
|
794
|
+
const wasConnecting = this.state === "connecting";
|
|
795
|
+
this.handlers.onClose?.(event.code, event.reason);
|
|
796
|
+
if (wasConnecting) {
|
|
797
|
+
this.setState("disconnected");
|
|
798
|
+
reject(new Error(`WebSocket closed before connecting (code: ${event.code})`));
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
if (this.options.autoReconnect && this.state !== "disconnected") {
|
|
802
|
+
this.scheduleReconnect();
|
|
803
|
+
} else {
|
|
804
|
+
this.setState("disconnected");
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
this.ws.onerror = () => {
|
|
808
|
+
const error = new Error("WebSocket connection error");
|
|
809
|
+
this.handlers.onError?.(error);
|
|
810
|
+
};
|
|
811
|
+
this.ws.onmessage = (event) => {
|
|
812
|
+
try {
|
|
813
|
+
const message = JSON.parse(event.data);
|
|
814
|
+
this.handleMessage(message);
|
|
815
|
+
} catch {
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
});
|
|
806
819
|
}
|
|
807
820
|
/**
|
|
808
821
|
* Disconnect from the WebSocket server
|
|
@@ -1087,7 +1100,11 @@ var OxArchiveWs = class {
|
|
|
1087
1100
|
this.reconnectAttempts++;
|
|
1088
1101
|
const delay = this.options.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1);
|
|
1089
1102
|
this.reconnectTimer = setTimeout(() => {
|
|
1090
|
-
this.connect()
|
|
1103
|
+
this.connect().catch(() => {
|
|
1104
|
+
if (this.reconnectAttempts < this.options.maxReconnectAttempts) {
|
|
1105
|
+
this.scheduleReconnect();
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1091
1108
|
}, delay);
|
|
1092
1109
|
}
|
|
1093
1110
|
clearReconnectTimer() {
|
|
@@ -1169,7 +1186,6 @@ var OxArchiveWs = class {
|
|
|
1169
1186
|
0 && (module.exports = {
|
|
1170
1187
|
ApiMetaSchema,
|
|
1171
1188
|
ApiResponseSchema,
|
|
1172
|
-
DataSourceSchema,
|
|
1173
1189
|
FundingRateArrayResponseSchema,
|
|
1174
1190
|
FundingRateResponseSchema,
|
|
1175
1191
|
FundingRateSchema,
|