Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

Python binance websocket stream code for getting user data and coin price

$
0
0

I am trying to get binance futures data from a websocket stream. I've gone through all the binance documentation tried several different python approaches, but don't seem to be successfull.

I am running my code on python-anywhere servers.

I would like to also know, how do you handle reconnections to the stream and for how long do the streams stay open.

The data I need through the websocket:

  • SYMBOL TICKER
  • FUTURES ACCOUNT BALANCE
  • FUTURES OPEN POSITIONS, ORDERS

Any help and directions would be greatly appreciated.

I've tried this sample, but I don't get any response from the stream.

import asynciofrom binance import AsyncClient, BinanceSocketManager# API keysAPI_KEY = '<api_key>'API_SECRET = '<api_secret>'# Binance API endpointBASE_URL = 'https://fapi.binance.com'async def main():    client = await AsyncClient.create(api_key=API_KEY,api_secret=API_SECRET)    bm = BinanceSocketManager(client)    # start any sockets here, i.e a trade socket    ts = bm.futures_socket() # Tried also bm.futures_user_socket()    # then start receiving messages    async with ts as tscm:        while True:            res = await tscm.recv()            print(res)    await client.close_connection()loop = asyncio.get_event_loop()loop.run_until_complete(main())

Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>