我试着在这里简单地开始,这样我就能掌握这些东西的窍门了。我理解异步的前提,但是试图与ccxt一起使用它是如此的令人费解。除了可以转发我的异步文档之外,还有推荐的资源吗?
import time
import ccxt.async_support as ccxt
import configpro
exchange = ccxt.coinbasepro({
'apiKey': configpro.apiKey,
'secret':configpro.secret,
'password': configpro.password,
'enableRateLimit': True})
async def test():
async with exchange as session:
print(await session.fetch_ticker('BTC/USD'))
async def main():
print(f"started at {time.strftime('%X')}")
await test()
print(f"finished at {time.strftime('%X')}")
asyncio.run(main())
我的错误是:
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001ED6BE8EDC0>
Traceback (most recent call last):
File "C:\Users\micha\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\micha\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\micha\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
self._check_closed()
File "C:\Users\micha\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
发布于 2022-03-06 11:34:08
这应该是可行的:
import time
import asyncio
import ccxt.async_support as ccxt
import configpro
print('CCXT Version:', ccxt.__version__)
async def test(exchange):
ticker = await exchange.fetch_ticker('BTC/USD')
pprint(ticker)
async def main():
exchange = ccxt.coinbasepro({
'apiKey': configpro.apiKey,
'secret':configpro.secret,
'password': configpro.password,
})
print(f"started at {time.strftime('%X')}")
await test(exchange)
print(f"finished at {time.strftime('%X')}")
await exchange.close()
asyncio.run(main())
请查看这里的示例:
https://stackoverflow.com/questions/71330370
复制相似问题