oxarchive 0.3.3__py3-none-any.whl → 0.3.5__py3-none-any.whl

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.
oxarchive/__init__.py CHANGED
@@ -57,7 +57,7 @@ except ImportError:
57
57
  OxArchiveWs = None # type: ignore
58
58
  WsOptions = None # type: ignore
59
59
 
60
- __version__ = "0.3.3"
60
+ __version__ = "0.3.5"
61
61
 
62
62
  __all__ = [
63
63
  # Client
oxarchive/types.py CHANGED
@@ -118,8 +118,8 @@ class Trade(BaseModel):
118
118
  closed_pnl: Optional[str] = None
119
119
  """Realized PnL if closing a position."""
120
120
 
121
- direction: Optional[Literal["Open Long", "Open Short", "Close Long", "Close Short"]] = None
122
- """Position direction."""
121
+ direction: Optional[str] = None
122
+ """Position direction (e.g., 'Open Long', 'Close Short', 'Long > Short')."""
123
123
 
124
124
  start_position: Optional[str] = None
125
125
  """Position size before this trade."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oxarchive
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Official Python SDK for 0xarchive - Hyperliquid Historical Data API
5
5
  Project-URL: Homepage, https://0xarchive.io
6
6
  Project-URL: Documentation, https://0xarchive.io/docs/sdks
@@ -45,6 +45,12 @@ Official Python SDK for [0xarchive](https://0xarchive.io) - Hyperliquid Historic
45
45
  pip install oxarchive
46
46
  ```
47
47
 
48
+ For WebSocket support:
49
+
50
+ ```bash
51
+ pip install oxarchive[websocket]
52
+ ```
53
+
48
54
  ## Quick Start
49
55
 
50
56
  ```python
@@ -97,13 +103,13 @@ async with Client(api_key="ox_your_api_key") as client:
97
103
 
98
104
  ```python
99
105
  client = Client(
100
- api_key="ox_your_api_key", # Required
101
- base_url="https://api.0xarchive.io", # Optional
102
- timeout=30.0, # Optional, request timeout in seconds
106
+ api_key="ox_your_api_key", # Required
107
+ base_url="https://api.0xarchive.io", # Optional
108
+ timeout=30.0, # Optional, request timeout in seconds (default: 30.0)
103
109
  )
104
110
  ```
105
111
 
106
- ## API Reference
112
+ ## REST API Reference
107
113
 
108
114
  ### Order Book
109
115
 
@@ -117,38 +123,63 @@ historical = client.orderbook.get("BTC", timestamp=1704067200000)
117
123
  # Get with limited depth
118
124
  shallow = client.orderbook.get("BTC", depth=10)
119
125
 
120
- # Get historical snapshots
126
+ # Get historical snapshots (start and end are required)
121
127
  history = client.orderbook.history(
122
128
  "BTC",
123
129
  start="2024-01-01",
124
130
  end="2024-01-02",
125
- limit=1000
131
+ limit=1000,
132
+ depth=20 # Price levels per side
126
133
  )
134
+
135
+ # Async versions
136
+ orderbook = await client.orderbook.aget("BTC")
137
+ history = await client.orderbook.ahistory("BTC", start=..., end=...)
127
138
  ```
128
139
 
129
140
  ### Trades
130
141
 
142
+ The trades API uses cursor-based pagination for efficient retrieval of large datasets.
143
+
131
144
  ```python
132
145
  # Get recent trades
133
146
  recent = client.trades.recent("BTC", limit=100)
134
147
 
135
- # Get trade history
136
- trades = client.trades.list(
137
- "ETH",
138
- start="2024-01-01",
139
- end="2024-01-02",
140
- side="buy" # Optional: filter by side
141
- )
148
+ # Get trade history with cursor-based pagination
149
+ result = client.trades.list("ETH", start="2024-01-01", end="2024-01-02", limit=1000)
150
+ trades = result.data
151
+
152
+ # Paginate through all results
153
+ while result.next_cursor:
154
+ result = client.trades.list(
155
+ "ETH",
156
+ start="2024-01-01",
157
+ end="2024-01-02",
158
+ cursor=result.next_cursor,
159
+ limit=1000
160
+ )
161
+ trades.extend(result.data)
162
+
163
+ # Filter by side
164
+ buys = client.trades.list("BTC", start=..., end=..., side="buy")
165
+
166
+ # Async versions
167
+ recent = await client.trades.arecent("BTC")
168
+ result = await client.trades.alist("ETH", start=..., end=...)
142
169
  ```
143
170
 
144
171
  ### Instruments
145
172
 
146
173
  ```python
147
- # List all instruments
174
+ # List all trading instruments
148
175
  instruments = client.instruments.list()
149
176
 
150
- # Get specific instrument
177
+ # Get specific instrument details
151
178
  btc = client.instruments.get("BTC")
179
+
180
+ # Async versions
181
+ instruments = await client.instruments.alist()
182
+ btc = await client.instruments.aget("BTC")
152
183
  ```
153
184
 
154
185
  ### Funding Rates
@@ -157,12 +188,16 @@ btc = client.instruments.get("BTC")
157
188
  # Get current funding rate
158
189
  current = client.funding.current("BTC")
159
190
 
160
- # Get funding rate history
191
+ # Get funding rate history (start is required)
161
192
  history = client.funding.history(
162
193
  "ETH",
163
194
  start="2024-01-01",
164
195
  end="2024-01-07"
165
196
  )
197
+
198
+ # Async versions
199
+ current = await client.funding.acurrent("BTC")
200
+ history = await client.funding.ahistory("ETH", start=..., end=...)
166
201
  ```
167
202
 
168
203
  ### Open Interest
@@ -171,40 +206,32 @@ history = client.funding.history(
171
206
  # Get current open interest
172
207
  current = client.open_interest.current("BTC")
173
208
 
174
- # Get open interest history
209
+ # Get open interest history (start is required)
175
210
  history = client.open_interest.history(
176
211
  "ETH",
177
212
  start="2024-01-01",
178
213
  end="2024-01-07"
179
214
  )
215
+
216
+ # Async versions
217
+ current = await client.open_interest.acurrent("BTC")
218
+ history = await client.open_interest.ahistory("ETH", start=..., end=...)
180
219
  ```
181
220
 
182
- ## Timestamp Formats
221
+ ## WebSocket Client
183
222
 
184
- The SDK accepts timestamps in multiple formats:
223
+ The WebSocket client supports three modes: real-time streaming, historical replay, and bulk streaming.
185
224
 
186
225
  ```python
187
- from datetime import datetime
188
-
189
- # Unix milliseconds
190
- client.orderbook.get("BTC", timestamp=1704067200000)
191
-
192
- # ISO string
193
- client.orderbook.history("BTC", start="2024-01-01", end="2024-01-02")
226
+ import asyncio
227
+ from oxarchive import OxArchiveWs, WsOptions
194
228
 
195
- # datetime object
196
- client.orderbook.history("BTC", start=datetime(2024, 1, 1), end=datetime(2024, 1, 2))
229
+ ws = OxArchiveWs(WsOptions(api_key="ox_your_api_key"))
197
230
  ```
198
231
 
199
- ## WebSocket Streaming
232
+ ### Real-time Streaming
200
233
 
201
- For real-time data, install with WebSocket support:
202
-
203
- ```bash
204
- pip install oxarchive[websocket]
205
- ```
206
-
207
- ### Basic Usage
234
+ Subscribe to live market data from Hyperliquid.
208
235
 
209
236
  ```python
210
237
  import asyncio
@@ -227,24 +254,26 @@ async def main():
227
254
  ws.subscribe_trades("BTC")
228
255
  ws.subscribe_all_tickers()
229
256
 
230
- # Handle orderbook updates
257
+ # Handle real-time data
231
258
  ws.on_orderbook(lambda coin, data: print(f"{coin}: {data.mid_price}"))
232
-
233
- # Handle trade updates
234
259
  ws.on_trades(lambda coin, trades: print(f"{coin}: {len(trades)} trades"))
235
260
 
236
261
  # Keep running
237
262
  await asyncio.sleep(60)
238
263
 
239
- # Disconnect
264
+ # Unsubscribe and disconnect
265
+ ws.unsubscribe_orderbook("ETH")
240
266
  await ws.disconnect()
241
267
 
242
268
  asyncio.run(main())
243
269
  ```
244
270
 
245
- ### Historical Replay (like Tardis.dev)
271
+ ### Historical Replay
246
272
 
247
- Replay historical data with timing preserved:
273
+ Replay historical data with timing preserved. Perfect for backtesting.
274
+
275
+ > **Important:** Replay data is delivered via `on_historical_data()`, NOT `on_trades()` or `on_orderbook()`.
276
+ > The real-time callbacks only receive live market data from subscriptions.
248
277
 
249
278
  ```python
250
279
  import asyncio
@@ -254,13 +283,14 @@ from oxarchive import OxArchiveWs, WsOptions
254
283
  async def main():
255
284
  ws = OxArchiveWs(WsOptions(api_key="ox_..."))
256
285
 
257
- # Handle replay data
286
+ # Handle replay data - this is where historical records arrive
258
287
  ws.on_historical_data(lambda coin, ts, data:
259
288
  print(f"{ts}: {data['mid_price']}")
260
289
  )
261
290
 
291
+ # Replay lifecycle events
262
292
  ws.on_replay_start(lambda ch, coin, start, end, speed:
263
- print(f"Starting replay from {start} to {end} at {speed}x")
293
+ print(f"Starting replay: {ch}/{coin} at {speed}x")
264
294
  )
265
295
 
266
296
  ws.on_replay_complete(lambda ch, coin, sent:
@@ -273,7 +303,8 @@ async def main():
273
303
  await ws.replay(
274
304
  "orderbook", "BTC",
275
305
  start=int(time.time() * 1000) - 86400000, # 24 hours ago
276
- speed=10
306
+ end=int(time.time() * 1000), # Optional
307
+ speed=10 # Optional, defaults to 1x
277
308
  )
278
309
 
279
310
  # Control playback
@@ -285,9 +316,9 @@ async def main():
285
316
  asyncio.run(main())
286
317
  ```
287
318
 
288
- ### Bulk Streaming (like Databento)
319
+ ### Bulk Streaming
289
320
 
290
- Fast bulk download for data pipelines:
321
+ Fast bulk download for data pipelines. Data arrives in batches without timing delays.
291
322
 
292
323
  ```python
293
324
  import asyncio
@@ -304,7 +335,7 @@ async def main():
304
335
  )
305
336
 
306
337
  ws.on_stream_progress(lambda snapshots_sent:
307
- print(f"Sent: {snapshots_sent} snapshots")
338
+ print(f"Progress: {snapshots_sent} snapshots")
308
339
  )
309
340
 
310
341
  ws.on_stream_complete(lambda ch, coin, sent:
@@ -318,25 +349,25 @@ async def main():
318
349
  "orderbook", "ETH",
319
350
  start=int(time.time() * 1000) - 3600000, # 1 hour ago
320
351
  end=int(time.time() * 1000),
321
- batch_size=1000
352
+ batch_size=1000 # Optional, defaults to 1000
322
353
  )
323
354
 
324
- # Stop stream if needed
355
+ # Stop if needed
325
356
  await ws.stream_stop()
326
357
 
327
358
  asyncio.run(main())
328
359
  ```
329
360
 
330
- ### Configuration
361
+ ### WebSocket Configuration
331
362
 
332
363
  ```python
333
364
  ws = OxArchiveWs(WsOptions(
334
365
  api_key="ox_your_api_key",
335
366
  ws_url="wss://api.0xarchive.io/ws", # Optional
336
- auto_reconnect=True, # Auto-reconnect on disconnect
337
- reconnect_delay=1.0, # Initial reconnect delay (seconds)
338
- max_reconnect_attempts=10, # Max reconnect attempts
339
- ping_interval=30.0, # Keep-alive ping interval (seconds)
367
+ auto_reconnect=True, # Auto-reconnect on disconnect (default: True)
368
+ reconnect_delay=1.0, # Initial reconnect delay in seconds (default: 1.0)
369
+ max_reconnect_attempts=10, # Max reconnect attempts (default: 10)
370
+ ping_interval=30.0, # Keep-alive ping interval in seconds (default: 30.0)
340
371
  ))
341
372
  ```
342
373
 
@@ -349,6 +380,27 @@ ws = OxArchiveWs(WsOptions(
349
380
  | `ticker` | Price and 24h volume | Yes |
350
381
  | `all_tickers` | All market tickers | No |
351
382
 
383
+ ## Timestamp Formats
384
+
385
+ The SDK accepts timestamps in multiple formats:
386
+
387
+ ```python
388
+ from datetime import datetime
389
+
390
+ # Unix milliseconds (int)
391
+ client.orderbook.get("BTC", timestamp=1704067200000)
392
+
393
+ # ISO string
394
+ client.orderbook.history("BTC", start="2024-01-01", end="2024-01-02")
395
+
396
+ # datetime object
397
+ client.orderbook.history(
398
+ "BTC",
399
+ start=datetime(2024, 1, 1),
400
+ end=datetime(2024, 1, 2)
401
+ )
402
+ ```
403
+
352
404
  ## Error Handling
353
405
 
354
406
  ```python
@@ -369,12 +421,15 @@ except OxArchiveError as e:
369
421
  Full type hint support with Pydantic models:
370
422
 
371
423
  ```python
372
- from oxarchive import Client, OrderBook, Trade
424
+ from oxarchive import Client
425
+ from oxarchive.types import OrderBook, Trade, Instrument, FundingRate, OpenInterest
426
+ from oxarchive.resources.trades import CursorResponse
373
427
 
374
428
  client = Client(api_key="ox_your_api_key")
375
429
 
376
430
  orderbook: OrderBook = client.orderbook.get("BTC")
377
431
  trades: list[Trade] = client.trades.recent("BTC")
432
+ result: CursorResponse = client.trades.list("BTC", start=..., end=...)
378
433
  ```
379
434
 
380
435
  ## Requirements
@@ -1,7 +1,7 @@
1
- oxarchive/__init__.py,sha256=9mUMJPsr1Yi--7G8ivg-_d8iWGmiynTNZXn3L-VgvKY,2181
1
+ oxarchive/__init__.py,sha256=0hAq5Tu5zITK8XyigM8_oYd9iAgcswqr0ozNVH2nLOM,2181
2
2
  oxarchive/client.py,sha256=3P0fvOcyM5BWppkVV4054NduDHKvRg-cWeluoGymmRk,3163
3
3
  oxarchive/http.py,sha256=SY_o9Ag8ADo1HI3i3uAKW1xwkYjPE75gRAjnMsddAGs,4211
4
- oxarchive/types.py,sha256=bd08H1oS2SNAcb1zsiw8P9qgqYa2eFdc9Ue_MUMffz8,11034
4
+ oxarchive/types.py,sha256=pQJt1ZilZaV6h4anPYHloVrB97Q9Y2v9B9iYTkMXFo0,11025
5
5
  oxarchive/websocket.py,sha256=hodeRIfY3sHrdD1DMexInnDvLXTtUzyXOrRM37Iyark,26941
6
6
  oxarchive/resources/__init__.py,sha256=WQ4GYQ8p3L0D2Isk4IV4h1DRpvyZlt6tOF1t_CJr6ls,385
7
7
  oxarchive/resources/funding.py,sha256=TXkZxodVQTVcVbzNG6SpMQAzf8AkLm2NYZJxnP4MNXw,3500
@@ -9,6 +9,6 @@ oxarchive/resources/instruments.py,sha256=flD1sH6x3P3CTqV1ZwkfwbranVacmhsHn5Dhr7
9
9
  oxarchive/resources/openinterest.py,sha256=h13yLA72LpfryUf8IqF6W7uE4ObYY2Qbc-auv4LtPqc,3552
10
10
  oxarchive/resources/orderbook.py,sha256=o_DTdpzKrZvHL9YXm8cGGUugPM8uUa6r9O_72r1ByV0,4557
11
11
  oxarchive/resources/trades.py,sha256=XCi2rXA2hxaTt0KNlWw8f7W0hzAvNWyT7DaivMz_rHw,10012
12
- oxarchive-0.3.3.dist-info/METADATA,sha256=la3_AkxO_R3b5sP9EQbgaFAt4R5vRMmV_UtkwwEXhUQ,8798
13
- oxarchive-0.3.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
- oxarchive-0.3.3.dist-info/RECORD,,
12
+ oxarchive-0.3.5.dist-info/METADATA,sha256=36bw1AAMSkGsL18Wnu4G6MdV75j7TthJJNgMg7Dqwl0,11070
13
+ oxarchive-0.3.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
+ oxarchive-0.3.5.dist-info/RECORD,,