hyperquant 0.38__py3-none-any.whl → 0.41__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.
- hyperquant/broker/models/ourbit.py +12 -6
- hyperquant/broker/ourbit.py +38 -16
- hyperquant/broker/ws.py +6 -0
- {hyperquant-0.38.dist-info → hyperquant-0.41.dist-info}/METADATA +1 -1
- {hyperquant-0.38.dist-info → hyperquant-0.41.dist-info}/RECORD +6 -6
- {hyperquant-0.38.dist-info → hyperquant-0.41.dist-info}/WHEEL +0 -0
@@ -661,13 +661,13 @@ class SpotOrders(DataStore):
|
|
661
661
|
|
662
662
|
state = d.get("status")
|
663
663
|
|
664
|
-
if state ==
|
664
|
+
if state == 1:
|
665
665
|
item["state"] = "open"
|
666
666
|
self._insert([item])
|
667
667
|
|
668
|
-
elif state == 3:
|
668
|
+
elif state == 3 or state == 2:
|
669
669
|
item["state"] = "filled"
|
670
|
-
|
670
|
+
|
671
671
|
# 如果这三个字段存在追加
|
672
672
|
if d.get("singleDealId") and d.get("singleDealPrice") and d.get("singleDealQuantity"):
|
673
673
|
item.update({
|
@@ -743,7 +743,7 @@ class SpotBook(DataStore):
|
|
743
743
|
sort_data = self.sorted({'s': symbol}, self.limit)
|
744
744
|
asks = sort_data.get('a', [])
|
745
745
|
bids = sort_data.get('b', [])
|
746
|
-
self.
|
746
|
+
self._find_and_delete({'s': symbol})
|
747
747
|
self._update(asks + bids)
|
748
748
|
|
749
749
|
|
@@ -770,7 +770,7 @@ class SpotBook(DataStore):
|
|
770
770
|
sort_data = self.sorted({'s': symbol}, self.limit)
|
771
771
|
asks = sort_data.get('a', [])
|
772
772
|
bids = sort_data.get('b', [])
|
773
|
-
self.
|
773
|
+
self._find_and_delete({'s': symbol})
|
774
774
|
self._update(asks + bids)
|
775
775
|
|
776
776
|
# print(f'处理耗时: {time.time()*1000 - ts:.2f} ms')
|
@@ -1015,10 +1015,16 @@ class OurbitSpotDataStore(DataStoreCollection):
|
|
1015
1015
|
return self._get("order", SpotOrders)
|
1016
1016
|
|
1017
1017
|
def onmessage(self, msg: Item, ws: ClientWebSocketResponse | None = None) -> None:
|
1018
|
+
# print(msg, '\n')
|
1018
1019
|
channel = msg.get("c")
|
1019
|
-
|
1020
|
+
if 'msg' in msg:
|
1021
|
+
if 'invalid' in msg['msg']:
|
1022
|
+
logger.warning(f"WebSocket message invalid: {msg['msg']}")
|
1023
|
+
return
|
1024
|
+
|
1020
1025
|
if channel is None:
|
1021
1026
|
return
|
1027
|
+
|
1022
1028
|
if 'increase.aggre.depth' in channel:
|
1023
1029
|
self.book._on_message(msg)
|
1024
1030
|
|
hyperquant/broker/ourbit.py
CHANGED
@@ -65,7 +65,7 @@ class OurbitSwap:
|
|
65
65
|
hdlr_json=self.store.onmessage
|
66
66
|
)
|
67
67
|
|
68
|
-
async def
|
68
|
+
async def sub_orderbook(self, symbols: str | list[str]):
|
69
69
|
if isinstance(symbols, str):
|
70
70
|
symbols = [symbols]
|
71
71
|
|
@@ -366,7 +366,7 @@ class OurbitSpot:
|
|
366
366
|
token = res.data['data'].get("wsToken")
|
367
367
|
|
368
368
|
|
369
|
-
self.client.ws_connect(
|
369
|
+
app = self.client.ws_connect(
|
370
370
|
f"{self.ws_url}?wsToken={token}&platform=web",
|
371
371
|
send_json={
|
372
372
|
"method": "SUBSCRIPTION",
|
@@ -380,6 +380,9 @@ class OurbitSpot:
|
|
380
380
|
hdlr_json=self.store.onmessage
|
381
381
|
)
|
382
382
|
|
383
|
+
await app._event.wait()
|
384
|
+
|
385
|
+
|
383
386
|
async def sub_orderbook(self, symbols: str | list[str]):
|
384
387
|
"""订阅订单簿深度数据
|
385
388
|
|
@@ -407,16 +410,18 @@ class OurbitSpot:
|
|
407
410
|
for symbol in symbols:
|
408
411
|
subscription_params.append(f"spot@public.increase.aggre.depth@{symbol}")
|
409
412
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
413
|
+
|
414
|
+
# 一次sub20个,超过需要分开订阅
|
415
|
+
for i in range(0, len(subscription_params), 20):
|
416
|
+
self.client.ws_connect(
|
417
|
+
'wss://www.ourbit.com/ws?platform=web',
|
418
|
+
send_json={
|
419
|
+
"method": "SUBSCRIPTION",
|
420
|
+
"params": subscription_params[i:i + 20],
|
421
|
+
"id": 2
|
422
|
+
},
|
423
|
+
hdlr_json=self.store.onmessage
|
424
|
+
)
|
420
425
|
|
421
426
|
async def place_order(
|
422
427
|
self,
|
@@ -453,7 +458,8 @@ class OurbitSpot:
|
|
453
458
|
price_scale = detail.get('price_scale')
|
454
459
|
quantity_scale = detail.get('quantity_scale')
|
455
460
|
|
456
|
-
|
461
|
+
use_quantity = True if quantity is not None else False
|
462
|
+
|
457
463
|
# 如果指定了USDT金额,重新计算数量
|
458
464
|
if usdt_amount is not None:
|
459
465
|
if side == "buy":
|
@@ -482,11 +488,21 @@ class OurbitSpot:
|
|
482
488
|
data["price"] = str(price)
|
483
489
|
elif order_type == "market":
|
484
490
|
data["orderType"] = "MARKET_ORDER"
|
485
|
-
|
491
|
+
data["price"] = price
|
492
|
+
# 删除quantity, 市价只支持amount
|
493
|
+
if not use_quantity:
|
494
|
+
del data["quantity"]
|
495
|
+
data["amount"] = str(usdt_amount)
|
496
|
+
|
497
|
+
# print(data)
|
498
|
+
if order_type == 'market':
|
499
|
+
url = f'{self.api_url}/api/platform/spot/v4/order/place'
|
500
|
+
elif order_type == 'limit':
|
501
|
+
url = f'{self.api_url}/api/platform/spot/order/place'
|
486
502
|
|
487
503
|
res = await self.client.fetch(
|
488
504
|
"POST",
|
489
|
-
|
505
|
+
url,
|
490
506
|
json=data
|
491
507
|
)
|
492
508
|
|
@@ -495,4 +511,10 @@ class OurbitSpot:
|
|
495
511
|
case {"msg": 'success'}:
|
496
512
|
return res.data["data"]
|
497
513
|
case _:
|
498
|
-
raise Exception(f"Failed to place order: {res.data}")
|
514
|
+
raise Exception(f"Failed to place order: {res.data}")
|
515
|
+
|
516
|
+
async def cancel_orders(self, order_ids: list[str]):
|
517
|
+
|
518
|
+
for order_id in order_ids:
|
519
|
+
url = f'{self.api_url}/api/platform/spot/order/cancel/v2?orderId={order_id}'
|
520
|
+
await self.client.fetch("DELETE", url)
|
hyperquant/broker/ws.py
CHANGED
@@ -11,8 +11,14 @@ class Heartbeat:
|
|
11
11
|
while not ws.closed:
|
12
12
|
await ws.send_str('{"method":"ping"}')
|
13
13
|
await asyncio.sleep(10.0)
|
14
|
+
|
15
|
+
async def ourbit_spot(ws: pybotters.ws.ClientWebSocketResponse):
|
16
|
+
while not ws.closed:
|
17
|
+
await ws.send_str('{"method":"ping"}')
|
18
|
+
await asyncio.sleep(10.0)
|
14
19
|
|
15
20
|
pybotters.ws.HeartbeatHosts.items['futures.ourbit.com'] = Heartbeat.ourbit
|
21
|
+
pybotters.ws.HeartbeatHosts.items['www.ourbit.com'] = Heartbeat.ourbit_spot
|
16
22
|
|
17
23
|
class WssAuth:
|
18
24
|
@staticmethod
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hyperquant
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.41
|
4
4
|
Summary: A minimal yet hyper-efficient backtesting framework for quantitative trading
|
5
5
|
Project-URL: Homepage, https://github.com/yourusername/hyperquant
|
6
6
|
Project-URL: Issues, https://github.com/yourusername/hyperquant/issues
|
@@ -6,16 +6,16 @@ hyperquant/logkit.py,sha256=WALpXpIA3Ywr5DxKKK3k5EKubZ2h-ISGfc5dUReQUBQ,7795
|
|
6
6
|
hyperquant/notikit.py,sha256=x5yAZ_tAvLQRXcRbcg-VabCaN45LUhvlTZnUqkIqfAA,3596
|
7
7
|
hyperquant/broker/auth.py,sha256=oA9Yw1I59-u0Tnoj2e4wUup5q8V5T2qpga5RKbiAiZI,2614
|
8
8
|
hyperquant/broker/hyperliquid.py,sha256=7MxbI9OyIBcImDelPJu-8Nd53WXjxPB5TwE6gsjHbto,23252
|
9
|
-
hyperquant/broker/ourbit.py,sha256=
|
10
|
-
hyperquant/broker/ws.py,sha256=
|
9
|
+
hyperquant/broker/ourbit.py,sha256=aBRXLmUbiiMp1__xlRufTnqMajeknj_V71iCnB87u84,16641
|
10
|
+
hyperquant/broker/ws.py,sha256=umRzxwCaZaRIgIq4YY-AuA0wCXFT0uOBmQbIXFY8CK0,1555
|
11
11
|
hyperquant/broker/lib/hpstore.py,sha256=LnLK2zmnwVvhEbLzYI-jz_SfYpO1Dv2u2cJaRAb84D8,8296
|
12
12
|
hyperquant/broker/lib/hyper_types.py,sha256=HqjjzjUekldjEeVn6hxiWA8nevAViC2xHADOzDz9qyw,991
|
13
13
|
hyperquant/broker/models/hyperliquid.py,sha256=c4r5739ibZfnk69RxPjQl902AVuUOwT8RNvKsMtwXBY,9459
|
14
|
-
hyperquant/broker/models/ourbit.py,sha256=
|
14
|
+
hyperquant/broker/models/ourbit.py,sha256=8XA_VJUl7BkxvsB_Kx3Hr1xCvXIXCV8AVMZ4AX0dwuc,37569
|
15
15
|
hyperquant/datavison/_util.py,sha256=92qk4vO856RqycO0YqEIHJlEg-W9XKapDVqAMxe6rbw,533
|
16
16
|
hyperquant/datavison/binance.py,sha256=3yNKTqvt_vUQcxzeX4ocMsI5k6Q6gLZrvgXxAEad6Kc,5001
|
17
17
|
hyperquant/datavison/coinglass.py,sha256=PEjdjISP9QUKD_xzXNzhJ9WFDTlkBrRQlVL-5pxD5mo,10482
|
18
18
|
hyperquant/datavison/okx.py,sha256=yg8WrdQ7wgWHNAInIgsWPM47N3Wkfr253169IPAycAY,6898
|
19
|
-
hyperquant-0.
|
20
|
-
hyperquant-0.
|
21
|
-
hyperquant-0.
|
19
|
+
hyperquant-0.41.dist-info/METADATA,sha256=9AmgLsKlMiTMpblxz6ura21xlOuArw4gjU-dticoZGA,4317
|
20
|
+
hyperquant-0.41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
21
|
+
hyperquant-0.41.dist-info/RECORD,,
|
File without changes
|