-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathasset.py
70 lines (56 loc) · 1.81 KB
/
asset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding:utf-8 -*-
"""
Asset module.
Author: CyberQuant
Date: 2023/06/01
Email: [email protected]
"""
import json
class Asset:
""" Asset object.
Args:
platform: Exchange platform name, e.g. binance/bitmex.
account: Trade account name, e.g. [email protected].
assets: Asset information, e.g. {"BTC": {"free": "1.1", "locked": "2.2", "total": "3.3"}, ... }
timestamp: Published time, millisecond.
update: If any update? True or False.
"""
def __init__(self, platform=None, account=None, assets=None, timestamp=None, update=False):
""" Initialize. """
self.platform = platform
self.account = account
self.assets = assets
self.timestamp = timestamp
self.update = update
@property
def data(self):
d = {
"platform": self.platform,
"account_id": self.account,
"assets": self.assets,
"timestamp": self.timestamp,
"update": self.update
}
return d
def __str__(self):
info = json.dumps(self.data)
return info
def __repr__(self):
return str(self)
class AssetSubscribe:
""" Subscribe Asset.
Args:
platform: Exchange platform name, e.g. binance/bitmex.
account: Trade account name, e.g. [email protected].
callback: Asynchronous callback function for market data update.
e.g. async def on_event_account_id_update(asset: Asset):
pass
"""
def __init__(self, platform, account, callback):
""" Initialize. """
if platform == "#" or account == "#":
multi = True
else:
multi = False
from aed_quant.event import EventAsset
EventAsset(platform, account).subscribe(callback, multi)