hyperquant 0.39__py3-none-any.whl → 0.42__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.
@@ -661,13 +661,13 @@ class SpotOrders(DataStore):
661
661
 
662
662
  state = d.get("status")
663
663
 
664
- if state == 2 or state == 1:
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._clear()
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._clear()
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,6 +1015,7 @@ 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:
1020
1021
  if 'invalid' in msg['msg']:
@@ -65,7 +65,7 @@ class OurbitSwap:
65
65
  hdlr_json=self.store.onmessage
66
66
  )
67
67
 
68
- async def sub_order_book(self, symbols: str | list[str]):
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
- # 订阅WebSocket深度数据
411
- self.client.ws_connect(
412
- 'wss://www.ourbit.com/ws?platform=web',
413
- send_json={
414
- "method": "SUBSCRIPTION",
415
- "params": subscription_params,
416
- "id": 2
417
- },
418
- hdlr_json=self.store.onmessage
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
- f"{self.api_url}/api/platform/spot/order/place",
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/core.py CHANGED
@@ -343,6 +343,7 @@ class Exchange(ExchangeBase):
343
343
 
344
344
  if kwargs:
345
345
  self.opt.update(kwargs)
346
+ self.account[symbol].update(kwargs)
346
347
 
347
348
  # 记录账户总资产到 history
348
349
  if self.recorded:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperquant
3
- Version: 0.39
3
+ Version: 0.42
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
@@ -1,21 +1,21 @@
1
1
  hyperquant/__init__.py,sha256=UpjiX4LS5jmrBc2kE8RiLR02eCfD8JDQrR1q8zkLNcQ,161
2
- hyperquant/core.py,sha256=7XrpuHvccWl9lNyVihqaptupqUMsG3xYmQr8eEDrwS4,20610
2
+ hyperquant/core.py,sha256=O0NEvv4CcMxP-2Zy7TKeCsHehoxEh8p9NMsTwuUonFo,20658
3
3
  hyperquant/db.py,sha256=i2TjkCbmH4Uxo7UTDvOYBfy973gLcGexdzuT_YcSeIE,6678
4
4
  hyperquant/draw.py,sha256=up_lQ3pHeVLoNOyh9vPjgNwjD0M-6_IetSGviQUgjhY,54624
5
5
  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=zXPJmdxQV7PyJIG_eX5dd6MBKy1xcUUggB7rZIAFouY,15835
9
+ hyperquant/broker/ourbit.py,sha256=aBRXLmUbiiMp1__xlRufTnqMajeknj_V71iCnB87u84,16641
10
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=fC0yDPyWb1kAfLRmFh4bOnHga72l4mMoM-CyjKYyFtw,37492
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.39.dist-info/METADATA,sha256=HC7jvAznxXIr341r7P2eEe8qqsoaZAq-TeRGFDoyN4Q,4317
20
- hyperquant-0.39.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
- hyperquant-0.39.dist-info/RECORD,,
19
+ hyperquant-0.42.dist-info/METADATA,sha256=yd_IdWhrCMj_VbMpG53xXe7NBPt-JV1R5SR0hkFA3hI,4317
20
+ hyperquant-0.42.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
+ hyperquant-0.42.dist-info/RECORD,,