问题表现:

首先是异步过程不报异常,但是会卡住,代码无法继续,跟踪代码一直停在ccxt内部的

await self.load_markets()

搞了很久没解决,尝试写个简单的写法看看:

async def judge_bill_filled(symbol):
    account = get_account()

    orders = await account.fetch_orders_by_states('filled', symbol)

asyncio.get_event_loop().run_until_complete(market.judge_bill_filled('UMA/USDT'))

依然报错:

<xxxx> requires to release all resources with an explicit call to the .close() coroutine

按照外网上方案,仍然未解决。

无意中跟踪代码到Python37\Lib\site-packages\ccxt\async_support\base\exchange.py中的fetch:

async with session_method(yarl.URL(url, encoded=True),
                          data=encoded_body,
                          headers=request_headers,
                          timeout=(self.timeout / 1000),
                          proxy=self.aiohttp_proxy) as response:

其中看到 proxy=self.aiohttp_proxy,明白了:

异步和同步时设置代理不一样,需要这样:

account.aiohttp_proxy = ‘http://ip:port'

而同步时这样设置代理: account.proxies = { 'http': 'http://ip:port' }

真坑!

Logo

加入社区!打开量化的大门,首批课程上线啦!

更多推荐