Hi, I have two questions:
- when I run the code below, the exception below arises
- when calling asyncio.gather, if I put _listen_orders_updates(exchange, [c]) at the beginning of the list, everything works (and the exception of point 1) comes up), if I put it at the end, this function is never called and the orders are never watched. It does not make sense to me, am I doing anything wrong with asyncio or there is a problem with watch_orders?
Thanks
import asyncio
from typing import List
import ccxtpro
class Consumer:
def __init__(self):
pass
async def order_update(self, order):
print(order)
async def orderbook_update(self, orderbook):
print(orderbook)
async def _listen_orderbook(exchange: ccxtpro.Exchange, symbol: str, queue: asyncio.Queue):
while True:
orderbook = await exchange.watch_order_book(symbol)
await queue.put(orderbook['bids'][0])
async def _listen_orders_updates(exchange: ccxtpro.Exchange, orders_consumers: List[Consumer]):
while True:
orders = await exchange.watch_orders()
for order in orders:
for order_consumer in orders_consumers:
await order_consumer.order_update(order)
async def _read_queue(queue: asyncio.Queue, consumer: Consumer):
while True:
orderbook = await queue.get()
await consumer.orderbook_update(orderbook)
await asyncio.sleep(2)
async def main():
exchange = ccxtpro.poloniex({
'apiKey': 'MY API KEY',
'secret': 'MY SECRET',
})
q = asyncio.Queue()
c = Consumer()
tasks = [
_listen_orders_updates(exchange, [c]),
_listen_orderbook(exchange, 'BTC/USDT', q),
_read_queue(q, c),
]
await asyncio.gather(*tasks)
asyncio.run(main())
Exception in callback FastClient.receive_loop.<locals>.handler() at /Users/ema/Documents/AvcCryptoTrading/venv/lib/python3.8/site-packages/ccxtpro/base/fast_client.py:20
handle: <Handle FastClient.receive_loop.<locals>.handler() at /Users/ema/Documents/AvcCryptoTrading/venv/lib/python3.8/site-packages/ccxtpro/base/fast_client.py:20>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "/Users/Documents/venv/lib/python3.8/site-packages/ccxtpro/base/fast_client.py", line 25, in handler
self.handle_message(message)
File "/Users/Documents/venv/lib/python3.8/site-packages/ccxtpro/base/aiohttp_client.py", line 32, in handle_message
self.handle_text_or_binary_message(message.data)
File "/Users/Documents/venv/lib/python3.8/site-packages/ccxtpro/base/aiohttp_client.py", line 27, in handle_text_or_binary_message
self.on_message_callback(self, decoded)
File "/Users/Documents/venv/lib/python3.8/site-packages/ccxtpro/poloniex.py", line 776, in handle_message
method(client, message)
File "/Users/Documents/venv/lib/python3.8/site-packages/ccxtpro/poloniex.py", line 437, in handle_account_notifications
callback(client, entry)
File "/Users/Documents/venv/lib/python3.8/site-packages/ccxtpro/poloniex.py", line 689, in handle_order
symbolSpecificMessageHash = messageHash + ':' + symbol
TypeError: can only concatenate str (not "NoneType") to str
Hi, I have two questions:
Thanks