@0xarchive/sdk 0.3.4 → 0.3.6

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.mjs CHANGED
@@ -11,6 +11,25 @@ var OxArchiveError = class extends Error {
11
11
  };
12
12
 
13
13
  // src/http.ts
14
+ function snakeToCamel(str) {
15
+ return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
16
+ }
17
+ function transformKeys(obj) {
18
+ if (obj === null || obj === void 0) {
19
+ return obj;
20
+ }
21
+ if (Array.isArray(obj)) {
22
+ return obj.map(transformKeys);
23
+ }
24
+ if (typeof obj === "object") {
25
+ const result = {};
26
+ for (const [key, value] of Object.entries(obj)) {
27
+ result[snakeToCamel(key)] = transformKeys(value);
28
+ }
29
+ return result;
30
+ }
31
+ return obj;
32
+ }
14
33
  var HttpClient = class {
15
34
  baseUrl;
16
35
  apiKey;
@@ -58,22 +77,25 @@ var HttpClient = class {
58
77
  signal: controller.signal
59
78
  });
60
79
  clearTimeout(timeoutId);
61
- const data = await response.json();
80
+ const rawData = await response.json();
81
+ const data = transformKeys(rawData);
62
82
  if (!response.ok) {
63
83
  const error = data;
84
+ const apiResponse = data;
64
85
  throw new OxArchiveError(
65
86
  error.error || `Request failed with status ${response.status}`,
66
87
  response.status,
67
- data.meta?.request_id
88
+ apiResponse.meta?.requestId
68
89
  );
69
90
  }
70
91
  if (this.validate && schema) {
71
92
  const result = schema.safeParse(data);
72
93
  if (!result.success) {
94
+ const apiResponse = data;
73
95
  throw new OxArchiveError(
74
96
  `Response validation failed: ${result.error.message}`,
75
97
  422,
76
- data.meta?.request_id
98
+ apiResponse.meta?.requestId
77
99
  );
78
100
  }
79
101
  return result.data;
@@ -99,8 +121,8 @@ var HttpClient = class {
99
121
  import { z } from "zod";
100
122
  var ApiMetaSchema = z.object({
101
123
  count: z.number(),
102
- next_cursor: z.string().optional(),
103
- request_id: z.string()
124
+ nextCursor: z.string().optional(),
125
+ requestId: z.string()
104
126
  });
105
127
  var ApiResponseSchema = (dataSchema) => z.object({
106
128
  success: z.boolean(),
@@ -117,9 +139,9 @@ var OrderBookSchema = z.object({
117
139
  timestamp: z.string(),
118
140
  bids: z.array(PriceLevelSchema),
119
141
  asks: z.array(PriceLevelSchema),
120
- mid_price: z.string().optional(),
142
+ midPrice: z.string().optional(),
121
143
  spread: z.string().optional(),
122
- spread_bps: z.string().optional()
144
+ spreadBps: z.string().optional()
123
145
  });
124
146
  var TradeSideSchema = z.enum(["A", "B"]);
125
147
  var TradeDirectionSchema = z.string();
@@ -130,19 +152,19 @@ var TradeSchema = z.object({
130
152
  price: z.string(),
131
153
  size: z.string(),
132
154
  timestamp: z.string(),
133
- tx_hash: z.string().optional(),
134
- trade_id: z.number().optional(),
135
- order_id: z.number().optional(),
155
+ txHash: z.string().optional(),
156
+ tradeId: z.number().optional(),
157
+ orderId: z.number().optional(),
136
158
  crossed: z.boolean().optional(),
137
159
  fee: z.string().optional(),
138
- fee_token: z.string().optional(),
139
- closed_pnl: z.string().optional(),
160
+ feeToken: z.string().optional(),
161
+ closedPnl: z.string().optional(),
140
162
  direction: TradeDirectionSchema.optional(),
141
- start_position: z.string().optional(),
163
+ startPosition: z.string().optional(),
142
164
  source: DataSourceSchema.optional(),
143
- user_address: z.string().optional(),
144
- maker_address: z.string().optional(),
145
- taker_address: z.string().optional()
165
+ userAddress: z.string().optional(),
166
+ makerAddress: z.string().optional(),
167
+ takerAddress: z.string().optional()
146
168
  });
147
169
  var InstrumentTypeSchema = z.enum(["perp", "spot"]);
148
170
  var InstrumentSchema = z.object({
@@ -156,20 +178,20 @@ var InstrumentSchema = z.object({
156
178
  var FundingRateSchema = z.object({
157
179
  coin: z.string(),
158
180
  timestamp: z.string(),
159
- funding_rate: z.string(),
181
+ fundingRate: z.string(),
160
182
  premium: z.string().optional()
161
183
  });
162
184
  var OpenInterestSchema = z.object({
163
185
  coin: z.string(),
164
186
  timestamp: z.string(),
165
- open_interest: z.string(),
166
- mark_price: z.string().optional(),
167
- oracle_price: z.string().optional(),
168
- day_ntl_volume: z.string().optional(),
169
- prev_day_price: z.string().optional(),
170
- mid_price: z.string().optional(),
171
- impact_bid_price: z.string().optional(),
172
- impact_ask_price: z.string().optional()
187
+ openInterest: z.string(),
188
+ markPrice: z.string().optional(),
189
+ oraclePrice: z.string().optional(),
190
+ dayNtlVolume: z.string().optional(),
191
+ prevDayPrice: z.string().optional(),
192
+ midPrice: z.string().optional(),
193
+ impactBidPrice: z.string().optional(),
194
+ impactAskPrice: z.string().optional()
173
195
  });
174
196
  var WsChannelSchema = z.enum(["orderbook", "trades", "ticker", "all_tickers"]);
175
197
  var WsConnectionStateSchema = z.enum(["connecting", "connected", "disconnected", "reconnecting"]);
@@ -206,17 +228,17 @@ var WsReplayStartedSchema = z.object({
206
228
  });
207
229
  var WsReplayPausedSchema = z.object({
208
230
  type: z.literal("replay_paused"),
209
- current_timestamp: z.number()
231
+ currentTimestamp: z.number()
210
232
  });
211
233
  var WsReplayResumedSchema = z.object({
212
234
  type: z.literal("replay_resumed"),
213
- current_timestamp: z.number()
235
+ currentTimestamp: z.number()
214
236
  });
215
237
  var WsReplayCompletedSchema = z.object({
216
238
  type: z.literal("replay_completed"),
217
239
  channel: WsChannelSchema,
218
240
  coin: z.string(),
219
- snapshots_sent: z.number()
241
+ snapshotsSent: z.number()
220
242
  });
221
243
  var WsReplayStoppedSchema = z.object({
222
244
  type: z.literal("replay_stopped")
@@ -237,7 +259,7 @@ var WsStreamStartedSchema = z.object({
237
259
  });
238
260
  var WsStreamProgressSchema = z.object({
239
261
  type: z.literal("stream_progress"),
240
- snapshots_sent: z.number()
262
+ snapshotsSent: z.number()
241
263
  });
242
264
  var TimestampedRecordSchema = z.object({
243
265
  timestamp: z.number(),
@@ -253,11 +275,11 @@ var WsStreamCompletedSchema = z.object({
253
275
  type: z.literal("stream_completed"),
254
276
  channel: WsChannelSchema,
255
277
  coin: z.string(),
256
- snapshots_sent: z.number()
278
+ snapshotsSent: z.number()
257
279
  });
258
280
  var WsStreamStoppedSchema = z.object({
259
281
  type: z.literal("stream_stopped"),
260
- snapshots_sent: z.number()
282
+ snapshotsSent: z.number()
261
283
  });
262
284
  var WsServerMessageSchema = z.discriminatedUnion("type", [
263
285
  WsSubscribedSchema,
@@ -367,7 +389,7 @@ var TradesResource = class {
367
389
  );
368
390
  return {
369
391
  data: response.data,
370
- nextCursor: response.meta.next_cursor
392
+ nextCursor: response.meta.nextCursor
371
393
  };
372
394
  }
373
395
  /**
@@ -595,11 +617,11 @@ function transformTrade(coin, raw) {
595
617
  price: px ?? "0",
596
618
  size: sz ?? "0",
597
619
  timestamp: time ? new Date(time).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
598
- tx_hash: hash,
599
- trade_id: tid,
600
- maker_address,
601
- taker_address,
602
- user_address
620
+ txHash: hash,
621
+ tradeId: tid,
622
+ makerAddress: maker_address,
623
+ takerAddress: taker_address,
624
+ userAddress: user_address
603
625
  };
604
626
  }
605
627
  function transformTrades(coin, rawTrades) {
@@ -624,25 +646,25 @@ function transformOrderbook(coin, raw) {
624
646
  asks.push({ px: level.px, sz: level.sz, n: level.n });
625
647
  }
626
648
  }
627
- let mid_price;
649
+ let midPrice;
628
650
  let spread;
629
- let spread_bps;
651
+ let spreadBps;
630
652
  if (bids.length > 0 && asks.length > 0) {
631
653
  const bestBid = parseFloat(bids[0].px);
632
654
  const bestAsk = parseFloat(asks[0].px);
633
655
  const mid = (bestBid + bestAsk) / 2;
634
- mid_price = mid.toString();
656
+ midPrice = mid.toString();
635
657
  spread = (bestAsk - bestBid).toString();
636
- spread_bps = ((bestAsk - bestBid) / mid * 1e4).toFixed(2);
658
+ spreadBps = ((bestAsk - bestBid) / mid * 1e4).toFixed(2);
637
659
  }
638
660
  return {
639
661
  coin,
640
662
  timestamp: time ? new Date(time).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
641
663
  bids,
642
664
  asks,
643
- mid_price,
665
+ midPrice,
644
666
  spread,
645
- spread_bps
667
+ spreadBps
646
668
  };
647
669
  }
648
670
  var OxArchiveWs = class {