以下是代码片段:我通过关闭 前一个。这是按顺序完成的。
from binance.client import Client
from binance.websockets import BinanceSocketManager
from binance.enums import *
import time
managerRun=False
binance_client = Client("API KEY", "SECRET KEY", {
"verify": True, "timeout": 60})
def on_message(message):
print("New Message")
print(message)
def startService(symbols):
global bm,managerRun,conkey
if(bm is None):
bm = BinanceSocketManager(binance_client)
conkey = bm.start_kline_socket(symbols, on_message, interval=binance_client.KLINE_INTERVAL_1MINUTE)
print(str(bm)+" "+conkey)
if((managerRun==False)):
bm.start()
managerRun=True
def stopService():
global bm,conkey
bm.stop_socket(conkey)
print("Socket stopped"+": "+conkey)
startService("LTCUSDT")
time.sleep(10)
stopService()
startService("BATUSDT")
time.sleep(10)
stopService()
startService("EOSUSDT")
time.sleep(10)
stopService()
startService("ZILUSDT")
time.sleep(10)
stopService()
<块引用>
控制台输出: 对于 batusdt@kline_1m 和 eosusdt@kline_1m,即使在将套接字添加到币安管理器之后, 没有收到消息。 但是收到了 ltcusdt@kline_1m 和 zilusdt@kline_1m 的消息。这种行为很不寻常。