1 year ago

#311864

test-img

Cassano

Async Client Binance

I'm trying Async Client, and also, I'm not really familiar with async programming, so I'm trying to grasp it.

I'm confused about what the "await client.close_connection()" part does. Is it necessary to have that? Because the code just works fine without that.

Code:

async def main():
    client = await AsyncClient.create(config.API_KEY, config.API_SECRET_KEY, tld='com')
    bm = BinanceSocketManager(client)
    # start any sockets here, i.e a trade socket
    ts = bm.trade_socket('BTCUSDT')
    # then start receiving messages
    async with ts as tscm:
        while True:
            res = await tscm.recv()
            print(res)

    await client.close_connection()

if __name__ == "__main__":

    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

python

binance

binance-api-client

0 Answers

Your Answer

Accepted video resources