目前,我正试图从Binance那里获得实时价格,但是在运行代码之后,即使程序正在运行,我也会看到一个空白的屏幕。
以下是代码:
import os
from binance.client import Client
import time
from binance import ThreadedWebsocketManager
from binance import ThreadedDepthCacheManager
api_key = os.environ.get('api_key')
api_secret = os.environ.get('api_secret')
client = Client(api_key, api_secret)
def main():
symbol = 'BTCUSDT'
twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret)
#Start is required to initialise its internal loop
twm.start()
def handle_socket_message(msg):
print(f"message type: {msg['e']}")
print(msg)
twm.start_kline_socket(callback=handle_socket_message, symbol=symbol)
twm.join()
if __name__ == "__main__":
main()发布于 2022-07-11 21:42:11
我最近也遇到了同样的问题。
由于某种原因,我无法从ThreadedWebSocketManager那里得到任何回应。
在寻找答案时,我遇到了你的问题,经过进一步的研究,我发现这是一个已知问题。似乎ThreadedWebSocketManager在Python3.10上工作得不太好。我降级为Python3.9,它运行得很好:)
https://stackoverflow.com/questions/72604518
复制相似问题