First of all, I'm not a programmer, but a trader. Years ago I had some java training at school, so I understand the code and can build some little thing by copy&paste.
I managed to get data from the websocket in a Python script.
I need a small favour. My question: How can I put two values (price and symbol) out of the websocket data in variabel price and variable symbol?
example: variable price: 30000 variable symbol: BTCUSDT
#####################################################
from BybitWebsocket import BybitWebsocket
import logging
from time import sleep
def setup_logger():
logger = logging.getLogger()
logger.setLevel(logging.DEBUG) # Change this to DEBUG if you want a lot more info
ch = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger
if __name__ == "__main__":
logger = setup_logger()
ws_public = BybitWebsocket(wsURL="wss://stream-testnet.bybit.com/realtime",
api_key="apikey", api_secret="apisecret"
)
ws_public.subscribe_orderBookL2("BTCUSD")
while(1):
logger.info(ws_public.get_data("orderBookL2_25.BTCUSD"))
sleep(1)
#####################################################
As @Alex B pointed out, you can implement this using the Pybit library:
Conclusion:
Let's slightly transform the previous code by adding code to the handle_message() function to display the information we need in real time
Conclusion:
Thanks to this code, you get real-time information