【发布时间】:2020-12-03 19:35:04
【问题描述】:
我正在尝试使用 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)
【问题讨论】: