cryptocom-exchange
cryptocom-exchange copied to clipboard
TypeError when using exchange.listen_orderbook
Hi,
I would like to use the websocket option to retrieve orderbook data. However, I'm facing a type error when running the following code block:
import asyncio
import cryptocom.exchange as cro
async def main():
exchange = cro.Exchange()
price = await exchange.listen_orderbook([cro.pairs.CRO_USDT])
print(f'CRO price {price}')
asyncio.run(main())
Traceback:
Traceback (most recent call last):
File "/Users/xxxxx/projects/crypto-board/src/data/test.py", line 10, in <module>
asyncio.run(main())
File "/usr/local/Cellar/[email protected]/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/Cellar/[email protected]/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/xxxxx/projects/crypto-board/src/data/test.py", line 6, in main
price = await exchange.listen_orderbook([cro.pairs.CRO_USDT])
TypeError: object async_generator can't be used in 'await' expression
I'm using: Python 3.9.7 cryptocom-exchange: 0.9.2
My mistake, works perfectly fine using the following code snippet:
import asyncio
import cryptocom.exchange as cro
async def main():
exchange = cro.Exchange()
cro_usdt = cro.Pair(exchange_name="CRO_USDT", price_precision=4, quantity_precision=6)
async for orderbook in exchange.listen_orderbook(cro_usdt):
print(f"Buy in orderbook: {orderbook.buys[0]}")
asyncio.run(main())
I'll add the code snippet to the useful examples in the documentation, might be helpful for someone else.
will add but need a timeout because it will run tests forever)