[英]Binance Websocket for futures
I can't make the websocket for COIN-M on Binance returns any data.我无法让 Binance 上的 COIN-M 的 websocket 返回任何数据。 I managed to get it to work with the SPOT endpoint, but in the Futures it is a null response.我设法让它与 SPOT 端点一起工作,但在 Futures 中它是一个 null 响应。
import websocket
import _thread
import time
import json
WEBSOCKET_URL_FUTURES = "wss://dstream.binance.com/ws"
WEBSOCKET_URL_SPOT = "wss://stream.binance.com:9443/ws"
def on_message(ws, message):
print(f'ONMESSAGE######: {message}')
with open ('./data.json', 'a') as f:
f.write(f'{message}\n')
def on_error(ws, error):
print(f'ONERROR####: {error}')
def on_close(ws, close_status_code, close_msg):
print("### closed ###")
def on_open(ws):
print("### opened ###")
subscribe_message = {
"method": "SUBSCRIBE",
"params":
[
"ethusd_perpetual@aggTrade"
],
"id": 1
}
list_message = {
"method": "LIST_SUBSCRIPTIONS",
"id": 3
}
ws.send(json.dumps(subscribe_message))
ws.send(json.dumps(list_message))
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp(WEBSOCKET_URL_SPOT,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever()
I'm trying differents parameters in the SUSBCRIBE method but neither of them returns anything.我正在 SUSBCRIBE 方法中尝试不同的参数,但它们都不返回任何内容。 Also, I can't find any list with all the possible symbol pairs that could be used.此外,我找不到包含所有可能使用的符号对的列表。 Any ideas?有任何想法吗?
There might be a typo in your stream URL.您的 stream URL 可能有错别字。
The code uses wss://dstream...
, while this should be wss://fstream...
该代码使用wss://dstream...
,而这应该是wss://fstream...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.