forked from goincrypto/cryptocom-exchange
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneratestructs.py
51 lines (40 loc) · 1.3 KB
/
generatestructs.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
import asyncio
from pathlib import Path
from cryptocom import exchange as cro
ALL_TEMPLATE = """
def all():
return [
value for name, value in globals().items()
if isinstance(value, {class_name})
]
"""
SRC_PATH = Path(__file__).parent / 'src' / 'cryptocom' / 'exchange'
async def main():
exchange = cro.Exchange()
account = cro.Account(from_env=True)
coins = (await account.get_balance()).keys()
pairs = await exchange.get_pairs()
with (SRC_PATH / 'pairs.py').open('w') as f:
f.writelines([
"from .structs import Pair\n\n",
] + [
f'{pair.name} = Pair("{pair.name}", '
f'price_precision={pair.price_precision}, '
f'quantity_precision={pair.quantity_precision})\n'
for pair in sorted(pairs, key=lambda p: p.name)
] + [
"\n",
ALL_TEMPLATE.format(class_name='Pair')
])
with (SRC_PATH / 'coins.py').open('w') as f:
f.writelines([
"from .structs import Coin\n\n",
] + [
f'{coin.name} = Coin("{coin.name}")\n'
for coin in sorted(coins, key=lambda c: c.name)
] + [
"\n",
ALL_TEMPLATE.format(class_name='Coin')
])
if __name__ == '__main__':
asyncio.run(main())