资源加载中... loading...

紧急求助 websocket

Author: lzhqlj, Created: 2023-03-02 15:04:22, Updated:

chatgpt生成的 取得币安k线数据的代码 import websocket

url = “wss://fstream.binance.com/ws”

def on_open(ws): # 发送订阅消息,订阅BTCUSD永续合约的1分钟K线数据 sub_msg = { “method”: “SUBSCRIBE”, “params”: [ “btcusd_perpetual@kline_1m” ], “id”: 1 } ws.send(json.dumps(sub_msg))

def on_message(ws, message): # 处理接收到的K线数据 print(message)

if name == “main”: ws = websocket.WebSocketApp(url, on_open=on_open, on_message=on_message) ws.run_forever() 执行错误 Traceback (most recent call last): File “<string>”, line 1246, in init_ctx File “<string>”, line 1, in <module> ModuleNotFoundError: No module named ‘websocket’
chtgpt说这个错误是因为Python环境缺少名为websocket的模块。你需要使用pip或conda等工具安装该模块。你可以在终端或命令行中执行以下命令安装该模块:

请问是这个原因吗?如何pip呢?


More

lzhqlj 谢谢

发明者量化-小小梦 您好,pip安装包可以参考:https://blog.csdn.net/u012693479/article/details/126367014 在FMZ上创建websocket链接,可以使用:https://www.fmz.com/api#dial...