You are not defining nor using a Python class
properly.
I think you need to do it like this (untested). I’ve added an __init__()
method to initialize the class when an instance of it is created. In particular note how I added self.
prefix to the self.process_message
argument being passed to bm.start_trade_socket()
since it’s a method of the class
.
You may need to make bm
an instance attribute, too. (i.e. self.bm
everywhere it’s referenced.)
import websockets
from binance.client import Client
from binance.websockets import BinanceSocketManager
class BinanceFutures:
def __init__(self):
print("binance futures class")
# websocket start
futures_api_key = "oooo"
futures_secret_key = "ppppp"
client = Client(futures_api_key, futures_secret_key)
bm = BinanceSocketManager(client)
conn_key = bm.start_trade_socket('BNBBTC', self.process_message)
bm.start()
def process_message(self, msg):
print("message type: {}".format(msg['e']))
print(msg)
# do something
if __name__ == "__main__":
print("binance main")
CLICK HERE to find out more related problems solutions.