1

I'm trying some basic stuff for connecting Bitmex testnet websocket. I originally wanted to close the WS connection by exit() function after receiving some data with market_depth() function. But somehow the exit() function didn't work and WS just kept pushing data to me.

But surprising when I ran on debug mode, the exit() function could actually close the WS when I ran the script line-by-line. What is the reason behind? Thanks for helping. Below is the code I use.

ps I'm new to use REST or WS api, hopefully somehow can explain it in detailed

from bitmex_websocket import BitMEXWebsocket
import logging


def run():
    logger = setup_logger()
    ws = BitMEXWebsocket(endpoint="https://testnet.bitmex.com/api/v1", symbol="XBTUSD",
                         api_key=None, api_secret=None)
    logger.info("Market depth: %s" % ws.market_depth())
    ws.exit()


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__":
    run()
JJC
  • 41
  • 1
  • Bitmex_websocket module documentation https://github.com/BitMEX/api-connectors/blob/master/official-ws/python/bitmex_websocket.py – JJC May 25 '20 at 18:06

0 Answers0