diff --git a/generatestructs.py b/generatestructs.py new file mode 100644 index 0000000..da79d4c --- /dev/null +++ b/generatestructs.py @@ -0,0 +1,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())