我怎样才能获得到Kucoin Exchange的WebSocket连接?我正在尝试该代码:
import os
import time, hashlib, requests, base64, hmac, json, websocket, uuid
now = str(int(time.time() * 1000))
token = "my token"
SOCKET = f'wss://push1-v2.kucoin.net/endpoint?token={token}&connectId={now}'
params = {"type": "subscribe", "topic": "/market/ticker:BTC-USDT", "response": True}
def on_open(ws):
print('Opened Connection')
ws.send(json.dumps(params))
def on_close(ws):
print('Closed Connection')
def on_ping(ws, message):
pass
def on_pong(ws, message):
pass
def on_message(ws, message):
print(message)
def on_error(ws, err):
print("Got a an error: ", err)
if __name__ == "__main__":
ws = websocket.WebSocketApp(SOCKET, on_open = on_open, on_close = on_close, on_message = on_message,on_error=on_error, on_ping=on_ping, on_pong=on_pong)
ws.run_forever(ping_interval=10, ping_timeout=5)
但我得到的信息是:[Errno 11001] getaddrinfo失败可能我使用了错误的端点?我必须使用哪个端点?
2条答案
按热度按时间laik7k3q1#
我希望这有帮助-它的格式奇怪,因为我用它的规模,但它应该做你想要的。
yc0p9oo02#
只需将此项目(push1-v2.kucoin.net)更改为(ws-api.kucoin.com)即可