Get a price in real time in Binance Bitcoin for future transactions using Websocket
As a trader or investor, real access is very important in making reasonable decisions. In this article, we will investigate how to determine the real time market prices and Binance BTCUSDT Futures.
Conditions necessary
Before you start, make sure:
- You have a Binance API key or access marker.
- Your commercial account has been verified and linked to your Binance account.
- You installed the Pandas Library in your Python environment (install PIP Install Pandas).
True — Time link web is aimed at Spot Market
To connect to Bitcoin (BTC) points in the binance market, you need to use the final point Clines_1m and indicate the “Future” indicator. Here is an example of a code fragment:
`Python
Importing pandas as pd
Set your API key or access marker
API_KEY = ‘YOUR_API_KEY’
API_SECRET = ‘your_api_secret’
Contact Binance API
Customer = binary.client (API_ID = API_KEY, API_KEY_SECRET = API_SECRET)
Define Websocket (Spot Market) Final Point and Channel
ws_ndpoint = f “wss: //stream.binance.com: 9443/ws/dotusdt@kline_1m”
channel = “btcusdt”
Initiate an empty data frame to store data
Df = pd.dataframe ()
Although true:
Get new clines from Websocket Link
Answer = Customer.get_channel (WS_Endpoint, Channel)
Set through each clinic (1 minute interval)
For a string in response:
Get appropriate data (eg time mark, open, high, low, closed, volume)
Data = {
TIMestamp: pd.to_datetime (order [‘t’]),
‘Open’: float (line [‘o’]),
“High”: float (line [‘H’]),
‘Low’: float (line [‘l’]),
‘Close’: float (line [‘c’]),
‘Volume’: float (string [‘v’])
}
Add the data to the data frame
df = pd.concat ([df, pd.dataframe (data)], Ignore_index = TRUE)
Check for new data points
If not df.mpty:
Print prices in real time (optional)
Print (F “BTCUSDT Price Real Time: {df [‘to close’]. Max ()})
Update the logic of your trade or messaging mechanisms here
Erupted from the cycle when you are ready to stop listening
rest
Close the Websocket Link when you finish
Customer.disconnect ()
`
Get the real time price for BTCUSDT Futures
To join the Binance Futures Market (Fut), you need to use the final point “Kline_1M” and indicate the “future” of the indicator. Here is an example of a code fragment:
`Python
… the same as above
Although true:
Get new clines from Websocket Link
Answer = Customer.get_channel (WS_Endpoint, Channel)
Set through each clinic (1 minute interval)
For a string in response:
Get appropriate data (eg time mark, open, high, low, closed, volume)
Data = {
TIMestamp: pd.to_datetime (order [‘t’]),
‘Open’: float (line [‘o’]),
“High”: float (line [‘H’]),
‘Low’: float (line [‘l’]),
‘Close’: float (line [‘c’]),
‘Volume’: float (string [‘v’])
}
Add the data to the data frame
df = pd.concat ([df, pd.dataframe (data)], Ignore_index = TRUE)
Check for new data points
If not df.mpty:
Print prices in real time (optional)
Print (F “Future Future Btcusdt Price: {df [‘to close’]. Max ()})
Update your trading mechanisms or messaging mechanisms here
Erupted from the cycle when you are ready to stop listening
rest
Close the Websocket Link when you finish
Customer.