-
Notifications
You must be signed in to change notification settings - Fork 32
/
generatestructs.py
57 lines (47 loc) · 1.52 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
52
53
54
55
56
57
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, {})
]
"""
SRC_PATH = Path(__file__).parent / "src" / "cryptocom" / "exchange"
async def main():
exchange = cro.Exchange()
await exchange.sync_pairs()
instruments = set()
pairs = await exchange.get_pairs()
for pair in pairs:
instruments.add(pair.base_instrument)
instruments.add(pair.quote_instrument)
instruments = sorted(instruments, key=lambda c: c.exchange_name)
with (SRC_PATH / "pairs.py").open("w") as f:
f.writelines(
[
"from .structs import Pair\n\n",
]
+ [
f'{pair.name} = Pair("{pair.exchange_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("Pair")]
)
with (SRC_PATH / "instruments.py").open("w") as f:
f.writelines(
[
"from .structs import Instrument\n\n",
]
+ [
f'{instrument.name} = Instrument("{instrument.exchange_name}")\n'
for instrument in instruments
]
+ ["\n", ALL_TEMPLATE.format("Instrument")]
)
if __name__ == "__main__":
asyncio.run(main())