我正在尝试使用python-binance运行binance WebSocket API的示例代码,并遵循此教程:https://livedataframe.com/live-cryptocurrency-data-python-tutorial/
不幸的是,我不能让它工作。WebSocket只是不响应什么结果在空终端没有任何打印出来。
我用的是python 3.7.8,PyCharm IDE,Windows 10
请帮帮忙,谢谢!
import time
from binance.client import Client # Import the Binance Client
from binance.websockets import BinanceSocketManager # Import the Binance Socket Manager
_API_KEY = "mykey"
_API_SECRET = "mykey"
client = Client(_API_KEY, _API_SECRET)
# Instantiate a BinanceSocketManager, passing in the client that you instantiated
bm = BinanceSocketManager(client)
# This is our callback function. For now, it just prints messages as they come.
def handle_message(msg):
print(msg)
# Start trade socket with 'ETHBTC' and use handle_message to.. handle the message.
conn_key = bm.start_trade_socket('ETHBTC', handle_message)
# then start the socket manager
bm.start()
# let some data flow..
time.sleep(10)
# stop the socket manager
bm.stop_socket(conn_key)
另外,我可以运行这段代码,但WebSocket API似乎不适合我。
from binance.client import Client
_API_KEY = "key"
_API_SECRET = "key"
client = Client(_API_KEY, _API_SECRET)
btc_price = client.get_symbol_ticker(symbol="BTCUSDT")
# print full output (dictionary)
print(btc_price)
3条答案
按热度按时间tyky79it1#
我已经删除了我无意中发布在这里的错误信息。不幸的是,这篇文章的其余部分不再像以前那样有意义:/
其余的文章没有错误的信息:
要做到这一点,你可以使用unicorn-binance-websocket-api:
创建到Binance的WebSocket连接:
和另外4行来打印接收到的数据记录:
试试这个例子:https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/blob/master/example_userdata_stream.py
f3temu5u2#
最新版本如
python-binance
v1.0.15用途:或
查看:https://python-binance.readthedocs.io/en/latest/#
b5lpy0ml3#
@丹尼尔Droguett Quezada,应该是这个代替