oxarchive 0.3.1__py3-none-any.whl → 0.3.2__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/websocket.py CHANGED
@@ -120,6 +120,40 @@ StreamProgressHandler = Callable[[int], None] # snapshots_sent
120
120
  StreamCompleteHandler = Callable[[WsChannel, str, int], None] # channel, coin, snapshots_sent
121
121
 
122
122
 
123
+ def _transform_trade(coin: str, raw: dict) -> Trade:
124
+ """Transform raw Hyperliquid trade format to SDK Trade type.
125
+
126
+ Raw format: { coin, side, px, sz, time, hash, tid }
127
+ SDK format: { coin, side, price, size, timestamp, tx_hash, trade_id }
128
+ """
129
+ from datetime import datetime
130
+
131
+ # Check if already in SDK format (from REST API or historical replay)
132
+ if "price" in raw and "size" in raw:
133
+ return Trade(**raw)
134
+
135
+ # Transform from Hyperliquid raw format
136
+ time_ms = raw.get("time")
137
+ timestamp = datetime.utcfromtimestamp(time_ms / 1000).isoformat() + "Z" if time_ms else None
138
+
139
+ return Trade(
140
+ coin=raw.get("coin", coin),
141
+ side=raw.get("side", "B"),
142
+ price=str(raw.get("px", "0")),
143
+ size=str(raw.get("sz", "0")),
144
+ timestamp=timestamp,
145
+ tx_hash=raw.get("hash"),
146
+ trade_id=raw.get("tid"),
147
+ )
148
+
149
+
150
+ def _transform_trades(coin: str, raw_data: list) -> list[Trade]:
151
+ """Transform a list of raw trades to SDK Trade types."""
152
+ if not isinstance(raw_data, list):
153
+ return [_transform_trade(coin, raw_data)]
154
+ return [_transform_trade(coin, t) for t in raw_data]
155
+
156
+
123
157
  def _transform_orderbook(coin: str, raw: dict) -> OrderBook:
124
158
  """Transform raw Hyperliquid orderbook format to SDK OrderBook type.
125
159
 
@@ -642,7 +676,8 @@ class OxArchiveWs:
642
676
  self._on_orderbook(coin, orderbook)
643
677
 
644
678
  elif channel == "trades" and self._on_trades:
645
- trades = [Trade(**t) for t in raw_data]
679
+ # Transform raw Hyperliquid format to SDK Trade type
680
+ trades = _transform_trades(coin, raw_data)
646
681
  self._on_trades(coin, trades)
647
682
 
648
683
  # Replay messages (Option B)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oxarchive
3
- Version: 0.3.1
3
+ Version: 0.3.2
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
@@ -2,13 +2,13 @@ oxarchive/__init__.py,sha256=QqBnxRIGEBXE2wHdmynznUEBoJsePN_xObo_v79lPZI,2181
2
2
  oxarchive/client.py,sha256=3P0fvOcyM5BWppkVV4054NduDHKvRg-cWeluoGymmRk,3163
3
3
  oxarchive/http.py,sha256=LJgw488_nNb14ixRoDv5ChuhUvyzTGtQ4aTSdEEwXww,3577
4
4
  oxarchive/types.py,sha256=8PD5LV5YSx-FdrPehvqALCLykfjdDmxNfqo_vPB3JkY,10686
5
- oxarchive/websocket.py,sha256=BM6CmUbRdYptNnlicmAVPKBdqlyZBSI1l5iUt_OzWwo,25126
5
+ oxarchive/websocket.py,sha256=rhxpPh-t5j92H4zAiX1KJUjt0gHS4Zzc1CzI81QDE0w,26388
6
6
  oxarchive/resources/__init__.py,sha256=WQ4GYQ8p3L0D2Isk4IV4h1DRpvyZlt6tOF1t_CJr6ls,385
7
7
  oxarchive/resources/funding.py,sha256=TXkZxodVQTVcVbzNG6SpMQAzf8AkLm2NYZJxnP4MNXw,3500
8
8
  oxarchive/resources/instruments.py,sha256=flD1sH6x3P3CTqV1ZwkfwbranVacmhsHn5Dhr7lGQhM,1606
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.1.dist-info/METADATA,sha256=rMdddr7UhWAF5XjykaItJ7o9KG2-Hh9lADtMtqepBFM,8749
13
- oxarchive-0.3.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
- oxarchive-0.3.1.dist-info/RECORD,,
12
+ oxarchive-0.3.2.dist-info/METADATA,sha256=EBUhCI5oyLh-LqZeaXMNzASYJmAj0bQp3rmA0lNokig,8749
13
+ oxarchive-0.3.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
+ oxarchive-0.3.2.dist-info/RECORD,,