Back to Ccxt

Aiohttp Custom Session Connector

wiki/examples/py/aiohttp-custom-session-connector.md

4.5.52594 B
Original Source
python
# pip install aiohttp_socks

import asyncio
import ccxt.async_support as ccxt
import aiohttp
import aiohttp_socks

async def test():

   connector = aiohttp_socks.ProxyConnector.from_url('socks5://user:[email protected]:1080')
   session = aiohttp.ClientSession(connector=connector)

   exchange = ccxt.binance({
       'session': session,
       # ...
   })

   # ...

   await exchange.close()  # Close the exchange
   await session.close()  # don't forget to close the session

   # ...

asyncio.run(test())