我试着在一些行上做一个简单的流,但是我得到了一个错误消息。我可以注意到,根据版本的不同,websocket调用是不同的。我在1.0.15版本
你能帮我一下吗?
# Importing libraries
from binance.client import Client
import configparser
from binance.streams import ThreadedWebsocketManager
# Loading keys from config file
config = configparser.ConfigParser()
config.read_file(open('secret.cfg'))
actual_api_key = config.get('BINANCE', 'ACTUAL_API_KEY')
actual_secret_key = config.get('BINANCE', 'ACTUAL_SECRET_KEY')
client = Client(actual_api_key, actual_secret_key, tld="com")
def stream_data(msg):
"""
Function to process the received messages
param msg: input message
"""
print(f"message type: {msg['e']}")
print(f"close price: {msg['c']}")
print(f"best ask price: {msg['a']}")
print(f"best bid price: {msg['b']}")
print("---------------------------")
# Starting the WebSocket
twm = ThreadedWebsocketManager()
twm.start()
#Subscribe to the stream
twm.start_symbol_miniticker_socket(callback=stream_data, symbol="BTCUSDT")
# Stopping websocket
twm.stop()在这里,错误消息:
取消read_loop
进程已完成,退出代码为0
发布于 2022-01-20 02:24:09
应处理下列各部分:
在这个场景中,
的情况下加入twm。
# Importing libraries
from binance.client import Client
import configparser
from binance.streams import ThreadedWebsocketManager
# Loading keys from config file
config = configparser.ConfigParser()
config.read_file(open('secret.cfg'))
actual_api_key = config.get('BINANCE', 'ACTUAL_API_KEY')
actual_secret_key = config.get('BINANCE', 'ACTUAL_SECRET_KEY')
# This is not REQUIRED
# client = Client(actual_api_key, actual_secret_key, tld="com")
def stream_data(msg):
"""
Function to process the received messages
param msg: input message
"""
print(f"message type: {msg['e']}")
print(f"close price: {msg['c']}")
print(f"best ask price: {msg['a']}")
print(f"best bid price: {msg['b']}")
print("---------------------------")
# Starting the WebSocket
twm = ThreadedWebsocketManager(api_key=actual_api_key, api_secret=actual_secret_key)
twm.start()
# Define a stream or two
streams = ['ethusdt@kline_1m', 'btcusdt@kline_1m']
# Starting Binance multiplex_socket on ThreadedWebsocketManager
twm.start_multiplex_socket(callback=stream_data, streams=streams)
timeout = 0.1 # seconds
while True and twm.is_alive():
twm.join(timeout=timeout) # Give twm a call to process the streaming
# Do other stuff here
# Stopping websocket
twm.stop()https://stackoverflow.com/questions/70474836
复制相似问题