hyperquant 0.97__tar.gz → 0.98__tar.gz
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-0.97 → hyperquant-0.98}/PKG-INFO +1 -1
- {hyperquant-0.97 → hyperquant-0.98}/apis.json +2 -2
- {hyperquant-0.97 → hyperquant-0.98}/doc/bitmart.md +3 -0
- {hyperquant-0.97 → hyperquant-0.98}/pyproject.toml +1 -1
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/bitmart.py +21 -8
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/bitmart.py +7 -7
- hyperquant-0.98/tests/test_bitmart.py +153 -0
- {hyperquant-0.97 → hyperquant-0.98}/uv.lock +1 -1
- hyperquant-0.97/tests/test_bitmart.py +0 -70
- {hyperquant-0.97 → hyperquant-0.98}/.gitignore +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/.python-version +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/README.md +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/data/alpine_smoke.log +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/data/logs/notikit.log +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/data/logs/test_order_sync.log +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/data/records_swap.csv +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/data/records_swapc.csv +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/doc/coinup.md +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/doc/lbank.md +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/pub.sh +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/requirements-dev.lock +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/requirements.lock +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/__init__.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/auth.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/bitget.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/coinup.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/coinw.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/edgex.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/hyperliquid.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/lbank.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/lib/edgex_sign.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/lib/hpstore.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/lib/hyper_types.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/lib/util.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/lighter.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/bitget.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/coinup.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/coinw.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/edgex.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/hyperliquid.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/lbank.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/lighter.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/models/ourbit.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/ourbit.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/broker/ws.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/core.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/datavison/_util.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/datavison/binance.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/datavison/coinglass.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/datavison/okx.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/db.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/draw.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/logkit.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/src/hyperquant/notikit.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_bitget.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_coinup.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_coinw.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_draw.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_edgex.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_lbank.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_lighter.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/test_ourbit.py +0 -0
- {hyperquant-0.97 → hyperquant-0.98}/tests/tmp.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hyperquant
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.98
|
|
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
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"41933ec0f5dace5eee47628ea2e2cb40a491f7fd20f983b385f8bdc5eea3d3ad4a47bd745f70fc2a"
|
|
25
25
|
],
|
|
26
26
|
"bitmart":[
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"eyJoZWFkZXIiOnsidHlwIjoiQml0TWFydCIsImFsZyI6IkJNQVBJU0lYIn0sInBheWxvYWQiOnsiamlkIjoiYTQ4YTYyODRjYzI3NDIyZTg5MzlhNmMxZDY3YWEzNWMiLCJ2ZXJzaW9uIjoiMjAyNTEwMzEiLCJleHBpcmVzQXQiOjE3NjE5NzAxNDM1NTMsImJtIjoiVXppdFJkZEdpdUNZek5KWSs5Q25xNkFjMlZWNmhiT0hhRzVwemdTSTE5cGRLS0JJN2FpUThGRXNaQkFyTDFVUkJFVGFFdFJsdlB2bE5ISU0zaktJcjF6bERSVlZNQjVlRmVySjRxZ2FaS3VxNXZveEY3NEFMRXZ3NS9mYUdZVk8xeVhzTWJEbUUvSW5sYll6ZUZ5MW5YMmxjYmM2dTd1cUVRYnQxb2ltZUNKbngrdWdEQ09ZU1hsbHNQY2dxTkJZUStVbHBTNGR1L3crejl4dGFUY2s3cjQ1UGRxTGxMODNTekRLc1FlSTdOZEtaVlZFZlIraTJFWWU3M2Zma0ZvSGlqdkJJSkdtWmZvQnAzLytVZTR6aXUrdkl5a0FFYk9rUUlJTGMxMVBqcUFQVERIS0dzNlh3d0ZhelE5S0hxQ1FoT3Zwdys1TDh2Z1BtSGJpWWNSTEtkVmlQam5vanEwZ1ZCRDdKS09rRkdyYmZpYTlqMmoweTBaeHE1cStyRWRzIn0sInNpZ25hdHVyZSI6InpWU2NKWDFLOWV5eitUaEhCNU9wOU5wZVc5OWgraWF1eXdaUlFSWjltV1I1bkwwTmozd25XZW1NSnlISkxTVkFPaVdmb1Baa3F4RVg0anAwQUtYTWNBPT0ifQ==",
|
|
28
|
+
"E3zjQwurncDtiolAiGnPU7MTOuLwgMqoS7",
|
|
29
29
|
"1UwiT974jJGn3fiqWuH2mVtrlzAwjxS8"
|
|
30
30
|
]
|
|
31
31
|
}
|
|
@@ -446,6 +446,9 @@ curl 'https://derivatives.bitmart.com/gw-api/contract-tiger/forward/v1/ifcontrac
|
|
|
446
446
|
# 订单部分
|
|
447
447
|
|
|
448
448
|
category 1 限价单 2 市价单
|
|
449
|
+
|
|
450
|
+
status 4 系统取消
|
|
451
|
+
|
|
449
452
|
## limit gtc
|
|
450
453
|
curl 'https://derivatives.bitmart.com/gw-api/contract-tiger/forward/v1/ifcontract/submitOrder' \
|
|
451
454
|
-H 'accept: application/json, text/plain, */*' \
|
|
@@ -33,10 +33,19 @@ class Bitmart:
|
|
|
33
33
|
|
|
34
34
|
self.account_index = account_index
|
|
35
35
|
self.apis = apis
|
|
36
|
+
self.symbol_to_contract_id: dict[str, str] = {}
|
|
36
37
|
|
|
37
38
|
async def __aenter__(self) -> "Bitmart":
|
|
38
39
|
await self.update("detail")
|
|
39
40
|
asyncio.create_task(self.auto_refresh())
|
|
41
|
+
|
|
42
|
+
for entry in self.store.detail.find():
|
|
43
|
+
contract_id = entry.get("contract_id")
|
|
44
|
+
symbol = entry.get("name") or entry.get("display_name")
|
|
45
|
+
if contract_id is None or symbol is None:
|
|
46
|
+
continue
|
|
47
|
+
self.symbol_to_contract_id[str(symbol)] = str(contract_id)
|
|
48
|
+
|
|
40
49
|
return self
|
|
41
50
|
|
|
42
51
|
async def auto_refresh(self, sec=3600, test=False) -> None:
|
|
@@ -325,8 +334,8 @@ class Bitmart:
|
|
|
325
334
|
*,
|
|
326
335
|
category: Literal[1,2,"limit","market"] = "limit",
|
|
327
336
|
price: float,
|
|
328
|
-
|
|
329
|
-
|
|
337
|
+
qty: float,
|
|
338
|
+
side: Literal[1, 2, 3, 4, "open_long", "close_short", "close_long", "open_short", "buy", "sell"] = "open_long",
|
|
330
339
|
mode: Literal[1, 2, 3, 4, "gtc", "ioc", "fok", "maker_only", "maker-only", "post_only"] = "gtc",
|
|
331
340
|
open_type: Literal[1, 2, "cross", "isolated"] = "isolated",
|
|
332
341
|
leverage: int | str = 10,
|
|
@@ -334,8 +343,9 @@ class Bitmart:
|
|
|
334
343
|
trigger_price: float | None = None,
|
|
335
344
|
custom_id: int | str | None = None,
|
|
336
345
|
extra_params: dict[str, Any] | None = None,
|
|
337
|
-
) ->
|
|
346
|
+
) -> int:
|
|
338
347
|
"""Submit an order via ``submitOrder``.
|
|
348
|
+
返回值: order_id (int)
|
|
339
349
|
"""
|
|
340
350
|
|
|
341
351
|
contract_id = self.get_contract_id(symbol)
|
|
@@ -359,16 +369,16 @@ class Bitmart:
|
|
|
359
369
|
if contract_size_val <= 0:
|
|
360
370
|
raise ValueError(f"Invalid contract_size for {symbol}: {contract_size_str}")
|
|
361
371
|
|
|
362
|
-
contracts_float = float(
|
|
372
|
+
contracts_float = float(qty) / contract_size_val
|
|
363
373
|
contracts_int = int(round(contracts_float))
|
|
364
374
|
if contracts_int <= 0:
|
|
365
375
|
raise ValueError(
|
|
366
|
-
f"Volume too small for contract size ({contract_size_val}): volume={
|
|
376
|
+
f"Volume too small for contract size ({contract_size_val}): volume={qty}"
|
|
367
377
|
)
|
|
368
378
|
if abs(contracts_float - contracts_int) > 1e-8:
|
|
369
379
|
raise ValueError(
|
|
370
380
|
f"Volume must be a multiple of contract_size ({contract_size_val}). "
|
|
371
|
-
f"Received volume={
|
|
381
|
+
f"Received volume={qty} -> {contracts_float} contracts."
|
|
372
382
|
)
|
|
373
383
|
|
|
374
384
|
price_unit = detail.get("price_unit") or 1
|
|
@@ -396,7 +406,7 @@ class Bitmart:
|
|
|
396
406
|
price_fmt = f"{adjusted_price:.15f}".rstrip("0").rstrip(".") or "0"
|
|
397
407
|
|
|
398
408
|
way_value = self._normalize_enum(
|
|
399
|
-
|
|
409
|
+
side,
|
|
400
410
|
{
|
|
401
411
|
"open_long": 1,
|
|
402
412
|
"close_short": 2,
|
|
@@ -460,7 +470,10 @@ class Bitmart:
|
|
|
460
470
|
|
|
461
471
|
if resp.get("success") is False or resp.get("errno") not in (None, "OK"):
|
|
462
472
|
raise ValueError(f"Bitmart submitOrder error: {resp}")
|
|
463
|
-
|
|
473
|
+
|
|
474
|
+
# {"errno":"OK","message":"Success","data":{"order_id":3000236525013551},"success":true}
|
|
475
|
+
# 直接取order_id返回
|
|
476
|
+
return resp.get("data", {}).get("order_id")
|
|
464
477
|
|
|
465
478
|
async def cancel_order(
|
|
466
479
|
self,
|
|
@@ -381,7 +381,7 @@ class BitmartDataStore(DataStoreCollection):
|
|
|
381
381
|
@property
|
|
382
382
|
def orders(self) -> Orders:
|
|
383
383
|
"""用户订单 (`userAllOrders`)。
|
|
384
|
-
|
|
384
|
+
key: order_id
|
|
385
385
|
.. code:: json
|
|
386
386
|
|
|
387
387
|
[
|
|
@@ -510,19 +510,19 @@ class BitmartDataStore(DataStoreCollection):
|
|
|
510
510
|
{
|
|
511
511
|
"account_id": 14794011,
|
|
512
512
|
"coin_code": "USDT",
|
|
513
|
-
"available_vol": "
|
|
514
|
-
"cash_vol": "
|
|
513
|
+
"available_vol": "10.970977797397999999",
|
|
514
|
+
"cash_vol": "11.000536099457999999",
|
|
515
515
|
"freeze_vol": "0",
|
|
516
|
-
"realised_vol": "0",
|
|
517
|
-
"un_realised_vol": "0",
|
|
518
|
-
"earnings_vol": "0",
|
|
516
|
+
"realised_vol": "0.000536099457999999",
|
|
517
|
+
"un_realised_vol": "-0.00001502",
|
|
518
|
+
"earnings_vol": "0.000536099457999999",
|
|
519
519
|
"total_im": "",
|
|
520
520
|
"margin_balance": "",
|
|
521
521
|
"available_balance": "",
|
|
522
522
|
"trans_out_balance": "",
|
|
523
523
|
"status": 0,
|
|
524
524
|
"total_balance": "",
|
|
525
|
-
"account_rights": "
|
|
525
|
+
"account_rights": "11.000521079457999999",
|
|
526
526
|
"bonus_voucher_vol": "",
|
|
527
527
|
"freeze_bonus_voucher_vol": ""
|
|
528
528
|
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import pybotters
|
|
2
|
+
|
|
3
|
+
from hyperquant.broker.lighter import Lighter
|
|
4
|
+
import asyncio
|
|
5
|
+
from logging import Logger
|
|
6
|
+
import time
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Any, Awaitable, Literal
|
|
9
|
+
from hyperquant.logkit import get_logger
|
|
10
|
+
from hyperquant.broker.bitmart import Bitmart
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def test_update():
|
|
15
|
+
async with pybotters.Client(apis='./apis.json') as client:
|
|
16
|
+
async with Bitmart(client=client) as broker:
|
|
17
|
+
# print(broker.store.detail.find()[0])
|
|
18
|
+
# await broker.update('balances')
|
|
19
|
+
# print(broker.store.balances.find())
|
|
20
|
+
# await broker.update('ticker')
|
|
21
|
+
# print(broker.store.ticker.find())
|
|
22
|
+
|
|
23
|
+
await broker.update('history_orders')
|
|
24
|
+
print(broker.store.orders.find())
|
|
25
|
+
print(broker.store.orders.get({'order_id':3000237069605967}))
|
|
26
|
+
|
|
27
|
+
async def test_place():
|
|
28
|
+
async with pybotters.Client(apis='./apis.json') as client:
|
|
29
|
+
async with Bitmart(client=client) as broker:
|
|
30
|
+
|
|
31
|
+
oid = await broker.place_order(
|
|
32
|
+
symbol='ONDOUSDT',
|
|
33
|
+
side='sell',
|
|
34
|
+
category='limit',
|
|
35
|
+
price=0.7,
|
|
36
|
+
qty=0.2,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
print(f"Placed order ID: {oid}")
|
|
40
|
+
|
|
41
|
+
resp = await broker.cancel_order(
|
|
42
|
+
symbol='ONDOUSDT',
|
|
43
|
+
order_ids=[oid],
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
print(f"Cancel response: {resp}")
|
|
47
|
+
|
|
48
|
+
@dataclass
|
|
49
|
+
class OrderSyncResult:
|
|
50
|
+
position: dict[str, Any]
|
|
51
|
+
order: dict[str, Any]
|
|
52
|
+
|
|
53
|
+
async def order_sync_polling(
|
|
54
|
+
broker: Bitmart,
|
|
55
|
+
place_task: Awaitable,
|
|
56
|
+
is_ioc: bool = True,
|
|
57
|
+
cancel_retry: int = 3,
|
|
58
|
+
logger: Logger | None = None,
|
|
59
|
+
) -> OrderSyncResult:
|
|
60
|
+
try:
|
|
61
|
+
oid = await place_task
|
|
62
|
+
except Exception as e:
|
|
63
|
+
if logger:
|
|
64
|
+
logger.warning(f"Order placement failed: {e}")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async def sync():
|
|
68
|
+
await broker.update('history_orders')
|
|
69
|
+
await broker.update('positions')
|
|
70
|
+
order = broker.store.orders.get({'order_id': oid})
|
|
71
|
+
if order:
|
|
72
|
+
contract_id = order.get('contract_id')
|
|
73
|
+
positions = broker.store.positions.find({'contract_id': contract_id})
|
|
74
|
+
position = positions[0] if positions else {}
|
|
75
|
+
return OrderSyncResult(position=position, order=order)
|
|
76
|
+
|
|
77
|
+
if is_ioc:
|
|
78
|
+
return await sync()
|
|
79
|
+
else:
|
|
80
|
+
for attempt in range(cancel_retry):
|
|
81
|
+
await asyncio.sleep(1)
|
|
82
|
+
await broker.update('history_orders')
|
|
83
|
+
order = broker.store.orders.get({'order_id': oid})
|
|
84
|
+
# 说明订单已经置入历史委托
|
|
85
|
+
if order:
|
|
86
|
+
return await sync()
|
|
87
|
+
else:
|
|
88
|
+
try:
|
|
89
|
+
await broker.cancel_order(
|
|
90
|
+
symbol=order.get('symbol'),
|
|
91
|
+
order_ids=[oid],
|
|
92
|
+
)
|
|
93
|
+
except Exception as e:
|
|
94
|
+
if logger:
|
|
95
|
+
logger.warning(f"Order cancellation attempt {attempt + 1} failed: {e}")
|
|
96
|
+
|
|
97
|
+
return OrderSyncResult(position={}, order={})
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
async def test_sub_book():
|
|
101
|
+
async with pybotters.Client() as client:
|
|
102
|
+
async with Bitmart(client=client) as broker:
|
|
103
|
+
broker.store.book.limit = 1
|
|
104
|
+
await broker.sub_orderbook(["TRXUSDT", 'XRPUSDT', 'DOTUSDT'])
|
|
105
|
+
while True:
|
|
106
|
+
# await broker.store.book.wait()
|
|
107
|
+
# print(broker.store.book.find())
|
|
108
|
+
asks = broker.store.book.find({"S": "a", 's': 'TRXUSDT'})
|
|
109
|
+
bids = broker.store.book.find({"S": "b", 's': 'TRXUSDT'})
|
|
110
|
+
# 订单薄format化输出
|
|
111
|
+
print("Asks:")
|
|
112
|
+
for ask in asks:
|
|
113
|
+
print(f"Price: {ask['p']}, Quantity: {ask['q']}")
|
|
114
|
+
print("Bids:")
|
|
115
|
+
for bid in bids:
|
|
116
|
+
print(f"Price: {bid['p']}, Quantity: {bid['q']}")
|
|
117
|
+
print("-" * 30)
|
|
118
|
+
await asyncio.sleep(1)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# with broker.store.book.watch() as stream:
|
|
122
|
+
# async for change in stream:
|
|
123
|
+
# print(change)
|
|
124
|
+
|
|
125
|
+
async def test_auto_refresh():
|
|
126
|
+
async with pybotters.Client(apis='./apis.json') as client:
|
|
127
|
+
async with Bitmart(client=client, apis='./apis.json') as broker:
|
|
128
|
+
await broker.auto_refresh(0, test=True)
|
|
129
|
+
await asyncio.sleep(2)
|
|
130
|
+
|
|
131
|
+
async def test_sync_place():
|
|
132
|
+
logger = get_logger("test_sync_place")
|
|
133
|
+
async with pybotters.Client(apis='./apis.json') as client:
|
|
134
|
+
async with Bitmart(client=client) as broker:
|
|
135
|
+
place_task = broker.place_order(
|
|
136
|
+
symbol='ONDOUSDT',
|
|
137
|
+
side='sell',
|
|
138
|
+
category='market',
|
|
139
|
+
mode='ioc',
|
|
140
|
+
price=0.71,
|
|
141
|
+
qty=0.2,
|
|
142
|
+
)
|
|
143
|
+
result = await order_sync_polling(
|
|
144
|
+
broker,
|
|
145
|
+
place_task,
|
|
146
|
+
is_ioc=False,
|
|
147
|
+
cancel_retry=2,
|
|
148
|
+
logger=logger,
|
|
149
|
+
)
|
|
150
|
+
logger.info(f"Order Sync Result: {result}")
|
|
151
|
+
|
|
152
|
+
if __name__ == "__main__":
|
|
153
|
+
asyncio.run(test_sync_place())
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import pybotters
|
|
2
|
-
|
|
3
|
-
from hyperquant.broker.lighter import Lighter
|
|
4
|
-
import asyncio
|
|
5
|
-
from logging import Logger
|
|
6
|
-
import time
|
|
7
|
-
from dataclasses import dataclass
|
|
8
|
-
from typing import Any, Literal
|
|
9
|
-
from hyperquant.logkit import get_logger
|
|
10
|
-
from hyperquant.broker.bitmart import Bitmart
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
async def test_update():
|
|
15
|
-
async with pybotters.Client(apis='./apis.json') as client:
|
|
16
|
-
async with Bitmart(client=client) as broker:
|
|
17
|
-
# print(broker.store.detail.find()[0])
|
|
18
|
-
# await broker.update('balances')
|
|
19
|
-
# print(broker.store.balances.find())
|
|
20
|
-
await broker.update('ticker')
|
|
21
|
-
print(broker.store.ticker.find())
|
|
22
|
-
|
|
23
|
-
# await broker.update('history_orders')
|
|
24
|
-
# print(broker.store.orders.find())
|
|
25
|
-
|
|
26
|
-
async def test_place():
|
|
27
|
-
async with pybotters.Client(apis='./apis.json') as client:
|
|
28
|
-
async with Bitmart(client=client) as broker:
|
|
29
|
-
order = await broker.place_order(
|
|
30
|
-
symbol='TRXUSDT',
|
|
31
|
-
way='buy',
|
|
32
|
-
category='market',
|
|
33
|
-
price=0.0296,
|
|
34
|
-
qty=1,
|
|
35
|
-
)
|
|
36
|
-
print(order)
|
|
37
|
-
|
|
38
|
-
async def test_sub_book():
|
|
39
|
-
async with pybotters.Client() as client:
|
|
40
|
-
async with Bitmart(client=client) as broker:
|
|
41
|
-
broker.store.book.limit = 1
|
|
42
|
-
await broker.sub_orderbook(["TRXUSDT", 'XRPUSDT', 'DOTUSDT'])
|
|
43
|
-
while True:
|
|
44
|
-
# await broker.store.book.wait()
|
|
45
|
-
# print(broker.store.book.find())
|
|
46
|
-
asks = broker.store.book.find({"S": "a", 's': 'TRXUSDT'})
|
|
47
|
-
bids = broker.store.book.find({"S": "b", 's': 'TRXUSDT'})
|
|
48
|
-
# 订单薄format化输出
|
|
49
|
-
print("Asks:")
|
|
50
|
-
for ask in asks:
|
|
51
|
-
print(f"Price: {ask['p']}, Quantity: {ask['q']}")
|
|
52
|
-
print("Bids:")
|
|
53
|
-
for bid in bids:
|
|
54
|
-
print(f"Price: {bid['p']}, Quantity: {bid['q']}")
|
|
55
|
-
print("-" * 30)
|
|
56
|
-
await asyncio.sleep(1)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# with broker.store.book.watch() as stream:
|
|
60
|
-
# async for change in stream:
|
|
61
|
-
# print(change)
|
|
62
|
-
|
|
63
|
-
async def test_auto_refresh():
|
|
64
|
-
async with pybotters.Client(apis='./apis.json') as client:
|
|
65
|
-
async with Bitmart(client=client, apis='./apis.json') as broker:
|
|
66
|
-
await broker.auto_refresh(0, test=True)
|
|
67
|
-
await asyncio.sleep(2)
|
|
68
|
-
|
|
69
|
-
if __name__ == "__main__":
|
|
70
|
-
asyncio.run(test_update())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|