Python Websocket 未收到消息

问题描述

我正在尝试创建一个线程 websocket 系统来从 binance 流式传输数据。我创建了一个名为“crypto”的类,它代表将基于币安流进行交易的特定货币。这是主线程。它实例化一个加密货币和一个客户端。它还维护一个共享的数据字典。这个想法是,当 websocket 获取新数据时,它会将其存储在主字典中并更新添加时间。然后,主线程将处理数据。我的目标是能够在各自的线程中创建多个加密流。我的流正在连接到币安,但我没有收到来自流的任何消息。

location /api/ {
   proxy_pass http://127.0.0.1:5000/api/
}

这是 websocket 类:

#main thread
from client import Client
from crypto import Crypto
import constants as c
import threading
from datetime import datetime
import time

def run(orderbook,lock):
    current_time = datetime.Now()
    while True:
        try:
            #check for new update
            if orderbooks['last_update'] != current_time:
                print("I need to process new data")
                with lock:
                    print("Main has the lock\n")
                    for crypto in orderbooks:
                        if crypto != 'last_update':
                            print("Processing {}.".format(crypto.symbol))
                            #Do stuff here
                    current_time = orderbook['last_update']
                    print("\nI am done updating data")
                print("Main released the lock\n")
            time.sleep(1)
            #I am doing this so I can verify this function is getting called
            print(datetime.Now())
        except Exception:
            pass

#Instantiate the crpto currencies
DOGE = Crypto(
    symbol=c.DOGE_SYMBOL,Trade_quantity=c.DOGE_TradE_QUANTITY,buy_price=c.BUY_PRICE,sell_price=c.SELL_PRICE,position_status=c.POSITION_STATUS
)

lock = threading.Lock()

orderbooks = {
    DOGE: {},"last_update": None,}

#instantiate the websockets for each crypto
#these connect to binance and use 1 minute klines
doge_client = Client(
    orderbook=orderbooks,socket=c.DOGE_SOCKET,symbol=c.DOGE_SYMBOL,lock=lock,crypto=DOGE
    )

#Start the stream
doge_client.run()

#start checking for new data to process
run(orderbooks,lock)

我认为我在客户端类中犯了一个错误,但我一直盯着这个太久没有弄清楚。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...