oxarchive 0.4.4__py3-none-any.whl → 0.4.6__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
oxarchive/types.py
CHANGED
|
@@ -382,6 +382,41 @@ class WsHistoricalData(BaseModel):
|
|
|
382
382
|
data: dict[str, Any]
|
|
383
383
|
|
|
384
384
|
|
|
385
|
+
class OrderbookDelta(BaseModel):
|
|
386
|
+
"""Orderbook delta for tick-level data."""
|
|
387
|
+
|
|
388
|
+
timestamp: int
|
|
389
|
+
"""Timestamp in milliseconds."""
|
|
390
|
+
|
|
391
|
+
side: Literal["bid", "ask"]
|
|
392
|
+
"""Side: 'bid' or 'ask'."""
|
|
393
|
+
|
|
394
|
+
price: float
|
|
395
|
+
"""Price level."""
|
|
396
|
+
|
|
397
|
+
size: float
|
|
398
|
+
"""New size (0 = level removed)."""
|
|
399
|
+
|
|
400
|
+
sequence: int
|
|
401
|
+
"""Sequence number for ordering."""
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
class WsHistoricalTickData(BaseModel):
|
|
405
|
+
"""Historical tick data (granularity='tick' mode) - checkpoint + deltas.
|
|
406
|
+
|
|
407
|
+
This message type is sent when using granularity='tick' for Lighter.xyz
|
|
408
|
+
orderbook data. It provides a full checkpoint followed by incremental deltas.
|
|
409
|
+
"""
|
|
410
|
+
|
|
411
|
+
type: Literal["historical_tick_data"]
|
|
412
|
+
channel: WsChannel
|
|
413
|
+
coin: str
|
|
414
|
+
checkpoint: dict[str, Any]
|
|
415
|
+
"""Initial checkpoint (full orderbook snapshot)."""
|
|
416
|
+
deltas: list[OrderbookDelta]
|
|
417
|
+
"""Incremental deltas to apply after checkpoint."""
|
|
418
|
+
|
|
419
|
+
|
|
385
420
|
# =============================================================================
|
|
386
421
|
# WebSocket Bulk Stream Types (Bulk Download Mode)
|
|
387
422
|
# =============================================================================
|
oxarchive/websocket.py
CHANGED
|
@@ -42,6 +42,7 @@ except ImportError:
|
|
|
42
42
|
|
|
43
43
|
from .types import (
|
|
44
44
|
OrderBook,
|
|
45
|
+
OrderbookDelta,
|
|
45
46
|
PriceLevel,
|
|
46
47
|
Trade,
|
|
47
48
|
WsChannel,
|
|
@@ -57,6 +58,7 @@ from .types import (
|
|
|
57
58
|
WsReplayCompleted,
|
|
58
59
|
WsReplayStopped,
|
|
59
60
|
WsHistoricalData,
|
|
61
|
+
WsHistoricalTickData,
|
|
60
62
|
WsStreamStarted,
|
|
61
63
|
WsStreamProgress,
|
|
62
64
|
WsHistoricalBatch,
|
|
@@ -110,6 +112,7 @@ ErrorHandler = Callable[[Exception], None]
|
|
|
110
112
|
|
|
111
113
|
# Replay handlers
|
|
112
114
|
HistoricalDataHandler = Callable[[str, int, dict], None]
|
|
115
|
+
HistoricalTickDataHandler = Callable[[str, dict, list[OrderbookDelta]], None] # coin, checkpoint, deltas
|
|
113
116
|
ReplayStartHandler = Callable[[WsChannel, str, int, int, float], None] # channel, coin, start, end, speed
|
|
114
117
|
ReplayCompleteHandler = Callable[[WsChannel, str, int], None] # channel, coin, snapshots_sent
|
|
115
118
|
|
|
@@ -276,6 +279,7 @@ class OxArchiveWs:
|
|
|
276
279
|
|
|
277
280
|
# Replay handlers (Option B)
|
|
278
281
|
self._on_historical_data: Optional[HistoricalDataHandler] = None
|
|
282
|
+
self._on_historical_tick_data: Optional[HistoricalTickDataHandler] = None
|
|
279
283
|
self._on_replay_start: Optional[ReplayStartHandler] = None
|
|
280
284
|
self._on_replay_complete: Optional[ReplayCompleteHandler] = None
|
|
281
285
|
|
|
@@ -307,7 +311,9 @@ class OxArchiveWs:
|
|
|
307
311
|
url = f"{self.options.ws_url}?apiKey={self.options.api_key}"
|
|
308
312
|
|
|
309
313
|
try:
|
|
310
|
-
|
|
314
|
+
# Increase max_size to 50MB for large Lighter orderbook data with high granularity
|
|
315
|
+
# Lighter tick data with full depth (~3700 levels) can exceed 14MB per message
|
|
316
|
+
self._ws = await ws_connect(url, max_size=50 * 1024 * 1024)
|
|
311
317
|
self._reconnect_attempts = 0
|
|
312
318
|
self._set_state("connected")
|
|
313
319
|
|
|
@@ -427,6 +433,7 @@ class OxArchiveWs:
|
|
|
427
433
|
start: int,
|
|
428
434
|
end: Optional[int] = None,
|
|
429
435
|
speed: float = 1.0,
|
|
436
|
+
granularity: Optional[str] = None,
|
|
430
437
|
) -> None:
|
|
431
438
|
"""Start historical replay with timing preserved.
|
|
432
439
|
|
|
@@ -436,6 +443,7 @@ class OxArchiveWs:
|
|
|
436
443
|
start: Start timestamp (Unix ms)
|
|
437
444
|
end: End timestamp (Unix ms, defaults to now)
|
|
438
445
|
speed: Playback speed multiplier (1 = real-time, 10 = 10x faster)
|
|
446
|
+
granularity: Data resolution for Lighter orderbook ('checkpoint', '30s', '10s', '1s', 'tick')
|
|
439
447
|
|
|
440
448
|
Example:
|
|
441
449
|
>>> await ws.replay("orderbook", "BTC", start=time.time()*1000 - 86400000, speed=10)
|
|
@@ -449,6 +457,8 @@ class OxArchiveWs:
|
|
|
449
457
|
}
|
|
450
458
|
if end is not None:
|
|
451
459
|
msg["end"] = end
|
|
460
|
+
if granularity is not None:
|
|
461
|
+
msg["granularity"] = granularity
|
|
452
462
|
await self._send(msg)
|
|
453
463
|
|
|
454
464
|
async def replay_pause(self) -> None:
|
|
@@ -482,6 +492,7 @@ class OxArchiveWs:
|
|
|
482
492
|
start: int,
|
|
483
493
|
end: int,
|
|
484
494
|
batch_size: int = 1000,
|
|
495
|
+
granularity: Optional[str] = None,
|
|
485
496
|
) -> None:
|
|
486
497
|
"""Start bulk streaming for fast data download.
|
|
487
498
|
|
|
@@ -491,18 +502,22 @@ class OxArchiveWs:
|
|
|
491
502
|
start: Start timestamp (Unix ms)
|
|
492
503
|
end: End timestamp (Unix ms)
|
|
493
504
|
batch_size: Records per batch message
|
|
505
|
+
granularity: Data resolution for Lighter orderbook ('checkpoint', '30s', '10s', '1s', 'tick')
|
|
494
506
|
|
|
495
507
|
Example:
|
|
496
508
|
>>> await ws.stream("orderbook", "ETH", start=..., end=..., batch_size=1000)
|
|
497
509
|
"""
|
|
498
|
-
|
|
510
|
+
msg = {
|
|
499
511
|
"op": "stream",
|
|
500
512
|
"channel": channel,
|
|
501
513
|
"coin": coin,
|
|
502
514
|
"start": start,
|
|
503
515
|
"end": end,
|
|
504
516
|
"batch_size": batch_size,
|
|
505
|
-
}
|
|
517
|
+
}
|
|
518
|
+
if granularity is not None:
|
|
519
|
+
msg["granularity"] = granularity
|
|
520
|
+
await self._send(msg)
|
|
506
521
|
|
|
507
522
|
async def stream_stop(self) -> None:
|
|
508
523
|
"""Stop the current bulk stream."""
|
|
@@ -547,6 +562,16 @@ class OxArchiveWs:
|
|
|
547
562
|
"""
|
|
548
563
|
self._on_historical_data = handler
|
|
549
564
|
|
|
565
|
+
def on_historical_tick_data(self, handler: HistoricalTickDataHandler) -> None:
|
|
566
|
+
"""Set handler for historical tick data (granularity='tick' mode).
|
|
567
|
+
|
|
568
|
+
This is for tick-level granularity on Lighter.xyz orderbook data.
|
|
569
|
+
Receives a checkpoint (full orderbook) followed by incremental deltas.
|
|
570
|
+
|
|
571
|
+
Handler receives: (coin, checkpoint, deltas)
|
|
572
|
+
"""
|
|
573
|
+
self._on_historical_tick_data = handler
|
|
574
|
+
|
|
550
575
|
def on_replay_start(self, handler: ReplayStartHandler) -> None:
|
|
551
576
|
"""Set handler for replay started event.
|
|
552
577
|
|
|
@@ -722,6 +747,10 @@ class OxArchiveWs:
|
|
|
722
747
|
elif msg_type == "historical_data" and self._on_historical_data:
|
|
723
748
|
self._on_historical_data(data["coin"], data["timestamp"], data["data"])
|
|
724
749
|
|
|
750
|
+
elif msg_type == "historical_tick_data" and self._on_historical_tick_data:
|
|
751
|
+
msg = WsHistoricalTickData(**data)
|
|
752
|
+
self._on_historical_tick_data(msg.coin, msg.checkpoint, msg.deltas)
|
|
753
|
+
|
|
725
754
|
elif msg_type == "replay_completed" and self._on_replay_complete:
|
|
726
755
|
self._on_replay_complete(data["channel"], data["coin"], data["snapshots_sent"])
|
|
727
756
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: oxarchive
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.6
|
|
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
|
|
@@ -418,6 +418,19 @@ async def main():
|
|
|
418
418
|
speed=10 # Optional, defaults to 1x
|
|
419
419
|
)
|
|
420
420
|
|
|
421
|
+
# Lighter.xyz replay with granularity (tier restrictions apply)
|
|
422
|
+
await ws.replay(
|
|
423
|
+
"orderbook", "BTC",
|
|
424
|
+
start=int(time.time() * 1000) - 86400000,
|
|
425
|
+
speed=10,
|
|
426
|
+
granularity="10s" # Options: 'checkpoint', '30s', '10s', '1s', 'tick'
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
# Handle tick-level data (granularity='tick', Enterprise tier)
|
|
430
|
+
ws.on_historical_tick_data(lambda coin, checkpoint, deltas:
|
|
431
|
+
print(f"Checkpoint: {len(checkpoint['bids'])} bids, Deltas: {len(deltas)}")
|
|
432
|
+
)
|
|
433
|
+
|
|
421
434
|
# Control playback
|
|
422
435
|
await ws.replay_pause()
|
|
423
436
|
await ws.replay_resume()
|
|
@@ -463,6 +476,14 @@ async def main():
|
|
|
463
476
|
batch_size=1000 # Optional, defaults to 1000
|
|
464
477
|
)
|
|
465
478
|
|
|
479
|
+
# Lighter.xyz stream with granularity (tier restrictions apply)
|
|
480
|
+
await ws.stream(
|
|
481
|
+
"orderbook", "BTC",
|
|
482
|
+
start=int(time.time() * 1000) - 3600000,
|
|
483
|
+
end=int(time.time() * 1000),
|
|
484
|
+
granularity="10s" # Options: 'checkpoint', '30s', '10s', '1s', 'tick'
|
|
485
|
+
)
|
|
486
|
+
|
|
466
487
|
# Stop if needed
|
|
467
488
|
await ws.stream_stop()
|
|
468
489
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
oxarchive/__init__.py,sha256=
|
|
1
|
+
oxarchive/__init__.py,sha256=z02RMa5pktqkvB4hOuzdeASD5j-qUUYebmkHL5UHSeE,2666
|
|
2
2
|
oxarchive/client.py,sha256=XWQ_VEBQy3UIAnmZQ-Z_FyzXnvMA3FITwtinBOf3o-Y,4453
|
|
3
3
|
oxarchive/exchanges.py,sha256=kk--Uh4g1U_tPfhJhYtZD_1zR6tJS5D-iaPnOGwWa9c,2425
|
|
4
4
|
oxarchive/http.py,sha256=SY_o9Ag8ADo1HI3i3uAKW1xwkYjPE75gRAjnMsddAGs,4211
|
|
5
|
-
oxarchive/types.py,sha256=
|
|
6
|
-
oxarchive/websocket.py,sha256=
|
|
5
|
+
oxarchive/types.py,sha256=YHy04TYtuEmJSHDMRh_9D9MVnhnXVc2rGagc45LwPiQ,13380
|
|
6
|
+
oxarchive/websocket.py,sha256=sdKMJrmGeR_ApNP_c7TPJylc4DAkmrp1JXfpnRGynao,29985
|
|
7
7
|
oxarchive/resources/__init__.py,sha256=ZGS3rLOfQFD665oJYMia_MxfTWlal7MXtx874DLG5EE,448
|
|
8
8
|
oxarchive/resources/funding.py,sha256=ybMWkpoccrkdwnd6W3oHgsaor7cBcA2nkYy4CbjmHUg,4485
|
|
9
9
|
oxarchive/resources/instruments.py,sha256=6q7rMdIaixXgFVXgwQsVd-YuO7RIXr1oGPT5jBsqI9A,3733
|
|
10
10
|
oxarchive/resources/openinterest.py,sha256=whwo60KFNLGwvVrDmDYYc-rMZr35Fcizb5Iil-DSvD8,4553
|
|
11
11
|
oxarchive/resources/orderbook.py,sha256=NzgKH45MBb2oAHyPmy6BSikaYyq0nM-8GFjur9LIRN8,6661
|
|
12
12
|
oxarchive/resources/trades.py,sha256=t4iicyi1waaHzC7Q_cC-c7O4yVx1vqS4eMH8F8_5hxk,5503
|
|
13
|
-
oxarchive-0.4.
|
|
14
|
-
oxarchive-0.4.
|
|
15
|
-
oxarchive-0.4.
|
|
13
|
+
oxarchive-0.4.6.dist-info/METADATA,sha256=NUz-9REdplj8blQwCyS95rTiEaiNs6qGiJW4J6HFtWU,15945
|
|
14
|
+
oxarchive-0.4.6.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
15
|
+
oxarchive-0.4.6.dist-info/RECORD,,
|
|
File without changes
|