walrasquant-lib 0.4.20__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.
- walrasquant/__init__.py +7 -0
- walrasquant/aggregation.py +449 -0
- walrasquant/backends/__init__.py +5 -0
- walrasquant/backends/db.py +109 -0
- walrasquant/backends/db_memory.py +61 -0
- walrasquant/backends/db_postgresql.py +321 -0
- walrasquant/backends/db_sqlite.py +310 -0
- walrasquant/base/__init__.py +24 -0
- walrasquant/base/api_client.py +46 -0
- walrasquant/base/connector.py +863 -0
- walrasquant/base/ems.py +794 -0
- walrasquant/base/exchange.py +213 -0
- walrasquant/base/oms.py +428 -0
- walrasquant/base/retry.py +220 -0
- walrasquant/base/sms.py +545 -0
- walrasquant/base/ws_client.py +408 -0
- walrasquant/config.py +284 -0
- walrasquant/constants.py +413 -0
- walrasquant/core/__init__.py +0 -0
- walrasquant/core/cache.py +688 -0
- walrasquant/core/clock.py +59 -0
- walrasquant/core/connection.py +41 -0
- walrasquant/core/entity.py +504 -0
- walrasquant/core/nautilius_core.py +103 -0
- walrasquant/core/registry.py +41 -0
- walrasquant/engine.py +745 -0
- walrasquant/error.py +34 -0
- walrasquant/exchange/__init__.py +13 -0
- walrasquant/exchange/base_factory.py +172 -0
- walrasquant/exchange/binance/__init__.py +30 -0
- walrasquant/exchange/binance/connector.py +1093 -0
- walrasquant/exchange/binance/constants.py +934 -0
- walrasquant/exchange/binance/ems.py +140 -0
- walrasquant/exchange/binance/error.py +48 -0
- walrasquant/exchange/binance/exchange.py +144 -0
- walrasquant/exchange/binance/factory.py +115 -0
- walrasquant/exchange/binance/oms.py +1807 -0
- walrasquant/exchange/binance/rest_api.py +1653 -0
- walrasquant/exchange/binance/schema.py +1063 -0
- walrasquant/exchange/binance/websockets.py +389 -0
- walrasquant/exchange/bitget/__init__.py +28 -0
- walrasquant/exchange/bitget/connector.py +578 -0
- walrasquant/exchange/bitget/constants.py +392 -0
- walrasquant/exchange/bitget/ems.py +202 -0
- walrasquant/exchange/bitget/error.py +36 -0
- walrasquant/exchange/bitget/exchange.py +128 -0
- walrasquant/exchange/bitget/factory.py +135 -0
- walrasquant/exchange/bitget/oms.py +1619 -0
- walrasquant/exchange/bitget/rest_api.py +610 -0
- walrasquant/exchange/bitget/schema.py +885 -0
- walrasquant/exchange/bitget/websockets.py +753 -0
- walrasquant/exchange/bybit/__init__.py +32 -0
- walrasquant/exchange/bybit/connector.py +819 -0
- walrasquant/exchange/bybit/constants.py +479 -0
- walrasquant/exchange/bybit/ems.py +93 -0
- walrasquant/exchange/bybit/error.py +36 -0
- walrasquant/exchange/bybit/exchange.py +108 -0
- walrasquant/exchange/bybit/factory.py +128 -0
- walrasquant/exchange/bybit/oms.py +1195 -0
- walrasquant/exchange/bybit/rest_api.py +570 -0
- walrasquant/exchange/bybit/schema.py +867 -0
- walrasquant/exchange/bybit/websockets.py +307 -0
- walrasquant/exchange/hyperliquid/__init__.py +28 -0
- walrasquant/exchange/hyperliquid/connector.py +370 -0
- walrasquant/exchange/hyperliquid/constants.py +371 -0
- walrasquant/exchange/hyperliquid/ems.py +156 -0
- walrasquant/exchange/hyperliquid/error.py +48 -0
- walrasquant/exchange/hyperliquid/exchange.py +120 -0
- walrasquant/exchange/hyperliquid/factory.py +135 -0
- walrasquant/exchange/hyperliquid/oms.py +1081 -0
- walrasquant/exchange/hyperliquid/rest_api.py +348 -0
- walrasquant/exchange/hyperliquid/schema.py +583 -0
- walrasquant/exchange/hyperliquid/websockets.py +592 -0
- walrasquant/exchange/okx/__init__.py +25 -0
- walrasquant/exchange/okx/connector.py +931 -0
- walrasquant/exchange/okx/constants.py +518 -0
- walrasquant/exchange/okx/ems.py +144 -0
- walrasquant/exchange/okx/error.py +66 -0
- walrasquant/exchange/okx/exchange.py +102 -0
- walrasquant/exchange/okx/factory.py +138 -0
- walrasquant/exchange/okx/oms.py +1199 -0
- walrasquant/exchange/okx/rest_api.py +799 -0
- walrasquant/exchange/okx/schema.py +1449 -0
- walrasquant/exchange/okx/websockets.py +420 -0
- walrasquant/exchange/registry.py +201 -0
- walrasquant/execution/__init__.py +24 -0
- walrasquant/execution/algorithm.py +968 -0
- walrasquant/execution/algorithms/__init__.py +3 -0
- walrasquant/execution/algorithms/twap.py +392 -0
- walrasquant/execution/config.py +34 -0
- walrasquant/execution/constants.py +27 -0
- walrasquant/execution/schema.py +62 -0
- walrasquant/indicator.py +382 -0
- walrasquant/push.py +77 -0
- walrasquant/schema.py +755 -0
- walrasquant/strategy.py +1805 -0
- walrasquant/tools/__init__.py +0 -0
- walrasquant/tools/pm2_wrapper.py +1016 -0
- walrasquant/web/__init__.py +26 -0
- walrasquant/web/app.py +157 -0
- walrasquant/web/server.py +92 -0
- walrasquant_lib-0.4.20.dist-info/METADATA +162 -0
- walrasquant_lib-0.4.20.dist-info/RECORD +105 -0
- walrasquant_lib-0.4.20.dist-info/WHEEL +4 -0
- walrasquant_lib-0.4.20.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
import msgspec
|
|
2
|
+
from decimal import Decimal
|
|
3
|
+
from walrasquant.schema import BaseMarket, Balance
|
|
4
|
+
from walrasquant.exchange.hyperliquid.constants import (
|
|
5
|
+
HyperLiquidKlineInterval,
|
|
6
|
+
HyperLiquidOrderStatusType,
|
|
7
|
+
HyperLiquidOrderSide,
|
|
8
|
+
HyperLiquidFillDirection,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class HyperLiquidMarketInfo(msgspec.Struct, kw_only=True):
|
|
13
|
+
"""Market information from HyperLiquid exchange
|
|
14
|
+
{
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
"circulatingSupply": "8888888887.9898376465",
|
|
19
|
+
"coin": "@153",
|
|
20
|
+
"totalSupply": "8888888887.9898376465",
|
|
21
|
+
"tokens": [
|
|
22
|
+
241,
|
|
23
|
+
0
|
|
24
|
+
],
|
|
25
|
+
|
|
26
|
+
"index": 153,
|
|
27
|
+
"isCanonical": false
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
"info": {
|
|
31
|
+
"szDecimals": 5,
|
|
32
|
+
|
|
33
|
+
"maxLeverage": 40,
|
|
34
|
+
"funding": "0.0000069988",
|
|
35
|
+
"openInterest": "9584.3844",
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
"premium": "-0.0004322507",
|
|
39
|
+
"oraclePx": "83285.0",
|
|
40
|
+
|
|
41
|
+
"impactPxs": [
|
|
42
|
+
"83238.0",
|
|
43
|
+
"83249.0"
|
|
44
|
+
],
|
|
45
|
+
"baseId": 0
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
# Common fields
|
|
52
|
+
name: str
|
|
53
|
+
prevDayPx: str
|
|
54
|
+
dayNtlVlm: str
|
|
55
|
+
markPx: str
|
|
56
|
+
midPx: str | None = None
|
|
57
|
+
dayBaseVlm: str
|
|
58
|
+
|
|
59
|
+
# Spot specific fields
|
|
60
|
+
circulatingSupply: str | None = None
|
|
61
|
+
coin: str | None = None
|
|
62
|
+
totalSupply: str | None = None
|
|
63
|
+
tokens: list[str] | None = None
|
|
64
|
+
index: str | None = None
|
|
65
|
+
isCanonical: bool | None = None
|
|
66
|
+
|
|
67
|
+
# Perpetual specific fields
|
|
68
|
+
szDecimals: str | None = None
|
|
69
|
+
maxLeverage: str | None = None
|
|
70
|
+
funding: str | None = None
|
|
71
|
+
openInterest: str | None = None
|
|
72
|
+
premium: str | None = None
|
|
73
|
+
oraclePx: str | None = None
|
|
74
|
+
impactPxs: list[str] | None = None
|
|
75
|
+
baseId: int | None = None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class HyperLiquidMarket(BaseMarket):
|
|
79
|
+
info: HyperLiquidMarketInfo
|
|
80
|
+
baseName: str
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class HyperLiquidOrderRestingStatus(msgspec.Struct):
|
|
84
|
+
oid: int # Order ID
|
|
85
|
+
cloid: str | None = None # Client order ID
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class HyperLiquidOrderFilledStatus(msgspec.Struct):
|
|
89
|
+
oid: int # Order ID
|
|
90
|
+
avgPx: str
|
|
91
|
+
totalSz: str
|
|
92
|
+
cloid: str | None = None # Client order ID
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class HyperLiquidOrderStatus(msgspec.Struct, kw_only=True, omit_defaults=True):
|
|
96
|
+
"""Order status information"""
|
|
97
|
+
|
|
98
|
+
error: str | None = None # Error message if any
|
|
99
|
+
resting: HyperLiquidOrderRestingStatus | None = (
|
|
100
|
+
None # Contains oid when order is resting
|
|
101
|
+
)
|
|
102
|
+
filled: HyperLiquidOrderFilledStatus | None = (
|
|
103
|
+
None # Contains oid when order is filled
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class HyperLiquidOrderData(msgspec.Struct):
|
|
108
|
+
"""Order response data"""
|
|
109
|
+
|
|
110
|
+
statuses: list[HyperLiquidOrderStatus]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class HyperLiquidOrderResponseData(msgspec.Struct):
|
|
114
|
+
"""Order response wrapper"""
|
|
115
|
+
|
|
116
|
+
type: str
|
|
117
|
+
data: HyperLiquidOrderData
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class HyperLiquidOrderResponse(msgspec.Struct):
|
|
121
|
+
"""Response from order placement"""
|
|
122
|
+
|
|
123
|
+
status: str
|
|
124
|
+
response: HyperLiquidOrderResponseData
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class HyperLiquidOrderStatusCancelStatus(msgspec.Struct):
|
|
128
|
+
error: str
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class HyperLiquidOrderDataStatuses(msgspec.Struct):
|
|
132
|
+
statuses: list[str | HyperLiquidOrderStatusCancelStatus]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class HyperLiquidCancelResponseData(msgspec.Struct):
|
|
136
|
+
type: str
|
|
137
|
+
data: HyperLiquidOrderDataStatuses
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class HyperLiquidCancelResponse(msgspec.Struct):
|
|
141
|
+
"""Response from order cancellation"""
|
|
142
|
+
|
|
143
|
+
status: str
|
|
144
|
+
response: HyperLiquidCancelResponseData
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class HyperLiquidCumFunding(msgspec.Struct):
|
|
148
|
+
"""Cumulative funding information"""
|
|
149
|
+
|
|
150
|
+
allTime: str
|
|
151
|
+
sinceChange: str
|
|
152
|
+
sinceOpen: str
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class HyperLiquidLeverage(msgspec.Struct):
|
|
156
|
+
"""Leverage information"""
|
|
157
|
+
|
|
158
|
+
type: str
|
|
159
|
+
value: int
|
|
160
|
+
rawUsd: str | None = None
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class HyperLiquidActiveAssetData(msgspec.Struct):
|
|
164
|
+
"""Active asset data for a specific coin"""
|
|
165
|
+
|
|
166
|
+
user: str # User address
|
|
167
|
+
coin: str # Coin/token symbol
|
|
168
|
+
leverage: HyperLiquidLeverage # Leverage information
|
|
169
|
+
maxTradeSzs: list[str] # Maximum trade sizes
|
|
170
|
+
availableToTrade: list[str] # Available amounts to trade
|
|
171
|
+
markPx: str # Mark price
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class HyperLiquidPosition(msgspec.Struct, kw_only=True):
|
|
175
|
+
"""Individual position data"""
|
|
176
|
+
|
|
177
|
+
coin: str
|
|
178
|
+
cumFunding: HyperLiquidCumFunding
|
|
179
|
+
entryPx: str
|
|
180
|
+
leverage: HyperLiquidLeverage
|
|
181
|
+
liquidationPx: str | None = None
|
|
182
|
+
marginUsed: str
|
|
183
|
+
maxLeverage: int
|
|
184
|
+
positionValue: str
|
|
185
|
+
returnOnEquity: str
|
|
186
|
+
szi: str
|
|
187
|
+
unrealizedPnl: str
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class HyperLiquidAssetPosition(msgspec.Struct):
|
|
191
|
+
"""Asset position wrapper"""
|
|
192
|
+
|
|
193
|
+
position: HyperLiquidPosition
|
|
194
|
+
type: str
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class HyperLiquidMarginSummary(msgspec.Struct):
|
|
198
|
+
"""Margin summary information"""
|
|
199
|
+
|
|
200
|
+
accountValue: str
|
|
201
|
+
totalMarginUsed: str
|
|
202
|
+
totalNtlPos: str
|
|
203
|
+
totalRawUsd: str
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class HyperLiquidUserPerpsSummary(msgspec.Struct):
|
|
207
|
+
"""User perpetuals summary information"""
|
|
208
|
+
|
|
209
|
+
assetPositions: list[HyperLiquidAssetPosition]
|
|
210
|
+
crossMaintenanceMarginUsed: str
|
|
211
|
+
crossMarginSummary: HyperLiquidMarginSummary
|
|
212
|
+
marginSummary: HyperLiquidMarginSummary
|
|
213
|
+
time: int
|
|
214
|
+
withdrawable: str
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class HyperLiquidMeta(msgspec.Struct):
|
|
218
|
+
"""Market metadata"""
|
|
219
|
+
|
|
220
|
+
universe: list[dict]
|
|
221
|
+
amms: list[dict]
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class HyperLiquidKline(msgspec.Struct):
|
|
225
|
+
"""
|
|
226
|
+
Kline/candlestick data from HyperLiquid API
|
|
227
|
+
[
|
|
228
|
+
{
|
|
229
|
+
"T": 1681924499999,
|
|
230
|
+
"c": "29258.0",
|
|
231
|
+
"h": "29309.0",
|
|
232
|
+
"i": "15m",
|
|
233
|
+
"l": "29250.0",
|
|
234
|
+
"n": 189,
|
|
235
|
+
"o": "29295.0",
|
|
236
|
+
"s": "BTC",
|
|
237
|
+
"t": 1681923600000,
|
|
238
|
+
"v": "0.98639"
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
T: int # Close time
|
|
244
|
+
c: str # Close price
|
|
245
|
+
h: str # High price
|
|
246
|
+
i: str # Interval
|
|
247
|
+
l: str # Low price # noqa: E741
|
|
248
|
+
n: int # Number of trades
|
|
249
|
+
o: str # Open price
|
|
250
|
+
s: str # Symbol
|
|
251
|
+
t: int # Open time
|
|
252
|
+
v: str # Volume
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class HyperLiquidTrade(msgspec.Struct):
|
|
256
|
+
"""Trade data"""
|
|
257
|
+
|
|
258
|
+
timestamp: int
|
|
259
|
+
price: str
|
|
260
|
+
size: str
|
|
261
|
+
side: str
|
|
262
|
+
hash: str
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
class HyperLiquidOrderBook(msgspec.Struct):
|
|
266
|
+
"""Order book data"""
|
|
267
|
+
|
|
268
|
+
levels: list[list[str]] # [price, size] pairs
|
|
269
|
+
timestamp: int
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
class HyperLiquidTicker(msgspec.Struct):
|
|
273
|
+
"""Ticker data"""
|
|
274
|
+
|
|
275
|
+
symbol: str
|
|
276
|
+
lastPrice: str
|
|
277
|
+
volume24h: str
|
|
278
|
+
priceChange24h: str
|
|
279
|
+
high24h: str
|
|
280
|
+
low24h: str
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class HyperLiquidUserOrder(msgspec.Struct):
|
|
284
|
+
"""
|
|
285
|
+
User order data from HyperLiquid API
|
|
286
|
+
[
|
|
287
|
+
{
|
|
288
|
+
"coin": "BTC",
|
|
289
|
+
"limitPx": "29792.0",
|
|
290
|
+
"oid": 91490942,
|
|
291
|
+
"side": "A",
|
|
292
|
+
"sz": "0.0",
|
|
293
|
+
"timestamp": 1681247412573
|
|
294
|
+
}
|
|
295
|
+
]
|
|
296
|
+
"""
|
|
297
|
+
|
|
298
|
+
coin: str # Trading pair/symbol
|
|
299
|
+
limitPx: str # Limit price
|
|
300
|
+
oid: int # Order ID
|
|
301
|
+
side: str # Side: "A" for ask/sell, "B" for bid/buy
|
|
302
|
+
sz: str # Size/quantity
|
|
303
|
+
timestamp: int # Order timestamp in milliseconds
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
class HyperLiquidSpotToken(msgspec.Struct):
|
|
307
|
+
"""
|
|
308
|
+
Spot token information from HyperLiquid API
|
|
309
|
+
{
|
|
310
|
+
"name": "USDC",
|
|
311
|
+
"szDecimals": 8,
|
|
312
|
+
"weiDecimals": 8,
|
|
313
|
+
"index": 0,
|
|
314
|
+
"tokenId": "0x6d1e7cde53ba9467b783cb7c530ce054",
|
|
315
|
+
"isCanonical": true,
|
|
316
|
+
"evmContract": null,
|
|
317
|
+
"fullName": null
|
|
318
|
+
}
|
|
319
|
+
"""
|
|
320
|
+
|
|
321
|
+
name: str # Token name/symbol
|
|
322
|
+
szDecimals: int # Size decimals
|
|
323
|
+
weiDecimals: int # Wei decimals
|
|
324
|
+
index: int # Token index
|
|
325
|
+
tokenId: str # Token ID
|
|
326
|
+
isCanonical: bool # Whether this is a canonical token
|
|
327
|
+
evmContract: dict | None = None # EVM contract address
|
|
328
|
+
fullName: str | None = None # Full token name
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
class HyperLiquidSpotUniverse(msgspec.Struct):
|
|
332
|
+
"""
|
|
333
|
+
Spot universe information from HyperLiquid API
|
|
334
|
+
{
|
|
335
|
+
"name": "PURR/USDC",
|
|
336
|
+
"tokens": [1, 0],
|
|
337
|
+
"index": 0,
|
|
338
|
+
"isCanonical": true
|
|
339
|
+
}
|
|
340
|
+
"""
|
|
341
|
+
|
|
342
|
+
name: str # Trading pair name
|
|
343
|
+
tokens: list[int] # List of token indices
|
|
344
|
+
index: int # Universe index
|
|
345
|
+
isCanonical: bool # Whether this is a canonical pair
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
class HyperLiquidSpotMeta(msgspec.Struct):
|
|
349
|
+
"""
|
|
350
|
+
Spot market metadata from HyperLiquid API
|
|
351
|
+
{
|
|
352
|
+
"tokens": [...],
|
|
353
|
+
"universe": [...]
|
|
354
|
+
}
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
tokens: list[HyperLiquidSpotToken] # List of available tokens
|
|
358
|
+
universe: list[HyperLiquidSpotUniverse] # List of trading pairs
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
class HyperLiquidSpotBalance(msgspec.Struct):
|
|
362
|
+
"""
|
|
363
|
+
Spot balance information from HyperLiquid API
|
|
364
|
+
{
|
|
365
|
+
"coin": "USDC",
|
|
366
|
+
"token": 0,
|
|
367
|
+
"hold": "0.0",
|
|
368
|
+
"total": "14.625485",
|
|
369
|
+
"entryNtl": "0.0"
|
|
370
|
+
}
|
|
371
|
+
"""
|
|
372
|
+
|
|
373
|
+
coin: str # Coin/token symbol
|
|
374
|
+
token: int # Token index
|
|
375
|
+
hold: str # Amount on hold
|
|
376
|
+
total: str # Total balance
|
|
377
|
+
entryNtl: str # Entry notional value
|
|
378
|
+
|
|
379
|
+
def parse_to_balance(self) -> Balance:
|
|
380
|
+
return Balance(
|
|
381
|
+
asset=self.coin,
|
|
382
|
+
locked=Decimal(self.hold),
|
|
383
|
+
free=Decimal(self.total) - Decimal(self.hold),
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
class HyperLiquidUserSpotSummary(msgspec.Struct):
|
|
388
|
+
"""
|
|
389
|
+
User spot summary from HyperLiquid API
|
|
390
|
+
{
|
|
391
|
+
"balances": [
|
|
392
|
+
{
|
|
393
|
+
"coin": "USDC",
|
|
394
|
+
"token": 0,
|
|
395
|
+
"hold": "0.0",
|
|
396
|
+
"total": "14.625485",
|
|
397
|
+
"entryNtl": "0.0"
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
"""
|
|
402
|
+
|
|
403
|
+
balances: list[HyperLiquidSpotBalance] # List of spot balances
|
|
404
|
+
|
|
405
|
+
def parse_to_balances(self) -> list[Balance]:
|
|
406
|
+
return [balance.parse_to_balance() for balance in self.balances]
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
class HyperLiquidWsMessageGeneral(msgspec.Struct):
|
|
410
|
+
channel: str # Channel name
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
class HyperLiquidWsBboLevelMsgData(msgspec.Struct):
|
|
414
|
+
px: str # Price
|
|
415
|
+
sz: str # Size
|
|
416
|
+
n: int # Number of orders
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class HyperLiquidWsBboMsgData(msgspec.Struct):
|
|
420
|
+
coin: str
|
|
421
|
+
time: int
|
|
422
|
+
bbo: list[HyperLiquidWsBboLevelMsgData] # Best bid/ask levels
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
class HyperLiquidWsBboMsg(msgspec.Struct):
|
|
426
|
+
"""
|
|
427
|
+
{
|
|
428
|
+
"channel": "bbo",
|
|
429
|
+
"data": {
|
|
430
|
+
"coin": "PURR/USDC",
|
|
431
|
+
"time": 1753455504649,
|
|
432
|
+
"bbo": [
|
|
433
|
+
{"px": "0.18134", "sz": "250.0", "n": 1},
|
|
434
|
+
{"px": "0.18168", "sz": "750.0", "n": 1},
|
|
435
|
+
],
|
|
436
|
+
},
|
|
437
|
+
}
|
|
438
|
+
"""
|
|
439
|
+
|
|
440
|
+
data: HyperLiquidWsBboMsgData
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
class HyperLiquidWsTradeDataMsg(msgspec.Struct):
|
|
444
|
+
coin: str
|
|
445
|
+
px: str # Price
|
|
446
|
+
side: HyperLiquidOrderSide # "A" for ask/sell, "B" for bid/buy
|
|
447
|
+
sz: str # Size
|
|
448
|
+
time: int
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
class HyperLiquidWsTradeMsg(msgspec.Struct):
|
|
452
|
+
data: list[HyperLiquidWsTradeDataMsg]
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
class HyperLiquidWsCandleDataMsg(msgspec.Struct):
|
|
456
|
+
t: int # Open time
|
|
457
|
+
T: int # Close time
|
|
458
|
+
s: str # Symbol
|
|
459
|
+
i: HyperLiquidKlineInterval # Interval
|
|
460
|
+
o: str # Open price
|
|
461
|
+
c: str # Close price
|
|
462
|
+
h: str # High price
|
|
463
|
+
l: str # Low price # noqa: E741
|
|
464
|
+
v: str # Volume
|
|
465
|
+
n: int # Number of trades
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
class HyperLiquidWsCandleMsg(msgspec.Struct):
|
|
469
|
+
data: HyperLiquidWsCandleDataMsg
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
class HyperLiquidWsBasicOrder(msgspec.Struct, kw_only=True, omit_defaults=True):
|
|
473
|
+
coin: str
|
|
474
|
+
side: HyperLiquidOrderSide # "A" for ask/sell, "B" for bid/buy
|
|
475
|
+
limitPx: str
|
|
476
|
+
sz: str
|
|
477
|
+
oid: int
|
|
478
|
+
timestamp: int
|
|
479
|
+
origSz: str
|
|
480
|
+
cloid: str | None = None # Client order ID
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
class HyperLiquidWsOrderUpdatesMsgData(msgspec.Struct):
|
|
484
|
+
order: HyperLiquidWsBasicOrder
|
|
485
|
+
status: HyperLiquidOrderStatusType # Order status
|
|
486
|
+
statusTimestamp: int # Timestamp of the status update
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
class HyperLiquidWsOrderUpdatesMsg(msgspec.Struct):
|
|
490
|
+
data: list[HyperLiquidWsOrderUpdatesMsgData]
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
class HyperLiquidWsFills(msgspec.Struct):
|
|
494
|
+
coin: str
|
|
495
|
+
px: str
|
|
496
|
+
sz: str
|
|
497
|
+
side: HyperLiquidOrderSide # "A" for ask/sell, "B" for bid/buy
|
|
498
|
+
time: int
|
|
499
|
+
startPosition: str
|
|
500
|
+
dir: HyperLiquidFillDirection # Direction of the fill
|
|
501
|
+
closedPnl: str
|
|
502
|
+
oid: int
|
|
503
|
+
crossed: bool # whether order crossed the spread (was taker)
|
|
504
|
+
fee: str
|
|
505
|
+
tid: int # Trade ID
|
|
506
|
+
feeToken: str
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
class HyperLiquidWsUserFillsMsgData(msgspec.Struct):
|
|
510
|
+
fills: list[HyperLiquidWsFills] | None = None # List of fills, if any
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
class HyperLiquidWsUserFillsMsg(msgspec.Struct):
|
|
514
|
+
data: HyperLiquidWsUserFillsMsgData
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
class HyperLiquidWsApiOrderFilledStatus(msgspec.Struct):
|
|
518
|
+
"""WebSocket API order filled status"""
|
|
519
|
+
|
|
520
|
+
totalSz: str
|
|
521
|
+
avgPx: str
|
|
522
|
+
oid: int
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
class HyperLiquidWsApiOrderStatus(msgspec.Struct, kw_only=True, omit_defaults=True):
|
|
526
|
+
"""WebSocket API order status"""
|
|
527
|
+
|
|
528
|
+
error: str | None = None
|
|
529
|
+
filled: HyperLiquidWsApiOrderFilledStatus | None = None
|
|
530
|
+
resting: HyperLiquidOrderRestingStatus | None = None
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
class HyperLiquidWsApiOrderData(msgspec.Struct):
|
|
534
|
+
"""WebSocket API order response data"""
|
|
535
|
+
|
|
536
|
+
statuses: list[HyperLiquidWsApiOrderStatus | str]
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
class HyperLiquidWsApiResponseData(msgspec.Struct):
|
|
540
|
+
"""WebSocket API response data wrapper"""
|
|
541
|
+
|
|
542
|
+
type: str # "order" or "cancel"
|
|
543
|
+
data: HyperLiquidWsApiOrderData
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
class HyperLiquidWsApiPayload(msgspec.Struct):
|
|
547
|
+
"""WebSocket API payload"""
|
|
548
|
+
|
|
549
|
+
status: str
|
|
550
|
+
response: HyperLiquidWsApiResponseData
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
class HyperLiquidWsApiResponse(msgspec.Struct):
|
|
554
|
+
"""WebSocket API response"""
|
|
555
|
+
|
|
556
|
+
type: str
|
|
557
|
+
payload: HyperLiquidWsApiPayload
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
class HyperLiquidWsApiMessageData(msgspec.Struct):
|
|
561
|
+
"""WebSocket API message data"""
|
|
562
|
+
|
|
563
|
+
id: int
|
|
564
|
+
response: HyperLiquidWsApiResponse
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
class HyperLiquidWsApiGeneralMsg(msgspec.Struct):
|
|
568
|
+
"""General WebSocket API message structure"""
|
|
569
|
+
|
|
570
|
+
channel: str
|
|
571
|
+
data: HyperLiquidWsApiMessageData | None = None
|
|
572
|
+
|
|
573
|
+
@property
|
|
574
|
+
def is_pong(self) -> bool:
|
|
575
|
+
return self.channel == "pong"
|
|
576
|
+
|
|
577
|
+
@property
|
|
578
|
+
def is_order_response(self) -> bool:
|
|
579
|
+
return self.channel == "post" and self.data is not None
|
|
580
|
+
|
|
581
|
+
@property
|
|
582
|
+
def is_ping(self) -> bool:
|
|
583
|
+
return self.channel == "ping"
|