我使用如下方式 安装的sdk
pip 安装后的在 ~/.local/lib/python3.10/site-packages/binance/websocket
### Python3
**SDK 1:** 可以通过以下方式获取Binance Futures Connector SDK:
* 访问 https://github.com/Binance-docs/binance-futures-connector-python
* 执行以下命令:
`pip install binance-futures-connector`
=======>
在 ~/.local/lib/python3.10/site-packages/binance/websocket/um_futures/websocket_client.py 下,__init__中没有onmessage 而是在成员函数中定义的callback。
class UMFuturesWebsocketClient(BinanceWebsocketClient):
def __init__(self, stream_url="wss://fstream.binance.com"):
super().__init__(stream_url)
def agg_trade(self, symbol: str, id: int, callback, **kwargs):
我在 binance-futures-connector-python-main/examples/websocket/um_futures例子中看到的跟packages里的不一致
def message_handler(message):
print(message)
my_client = UMFuturesWebsocketClient(on_message=message_handler)
my_client.kline(
symbol="btcusdt",
id=12,
interval="1d",```
我的问题是
1. 我用下载的最新sdk demo 和sdk,不应该出现接口不匹配的问题
2. 我这个问题该如何解决
The websocket part has been modified for the recent version 4.0.0rc2
, which has on_message
at constructor __init__
:
from binance.websocket.websocket_client import BinanceWebsocketClient
class UMFuturesWebsocketClient(BinanceWebsocketClient):
def __init__(
self,
stream_url="wss://fstream.binance.com",
on_message=None,
on_open=None,
on_close=None,
on_error=None,
on_ping=None,
on_pong=None,
is_combined=False,
):
if is_combined:
stream_url = stream_url + "/stream"
else:
stream_url = stream_url + "/ws"
super().__init__(
This file has been truncated. show original
However, 4.0.0rc2
is pre-release version, so when you do pip install binance-futures-connector
, you don’t download this version, instead you download the latest stable version at https://pypi.org/project/binance-futures-connector/#history
, which is 3.3.1
.
For you to download 4.0.0rc2
with improved WebSocket setup, you can run the following pip command:
pip install binance-futures-connector --pre
or
pip install binance-futures-connector==4.0.0rc2
pip install binance-futures-connector==4.0.0rc2
重新安装问题解决了