jeudi 24 octobre 2019

Lagging if statement on bitmex recent trade values

im trying to pull recent trades from bitmex. i can pull recent trades with no issue however when i use an if statement to filter the recent trades, the output is lagging and loads of trades are missed out. im not sure what i should do ? im new to this so bare with me loool

from bitmex_websocket import BitMEXWebsocket
import logging
from time import sleep
from pprint import pprint 


# Basic use of websocket.
def run():
    logger = setup_logger()

    # Instantiating the WS will make it connect. Be sure to add your api_key/api_secret.
    ws = BitMEXWebsocket(endpoint="https://www.bitmex.com/api/v1", symbol="XBTUSD",
                         api_key=None, api_secret=None)

    logger.info("Instrument data: %s" % ws.get_instrument())



    # Run forever
    while(ws.ws.sock.connected):

        if ws.api_key:
            logger.info("Funds: %s" % ws.funds())
        #logger.info("Market Depth: %s" % ws.market_depth())
        myValue = (ws.recent_trades()[-1]["size"])
        (logger.info("Recent Trades: %s\n\n" % myValue))

        if myValue > 9999:
            pprint(myValue)



def setup_logger():
    # Prints logger info to terminal
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)  # Change this to DEBUG if you want a lot more info
    ch = logging.StreamHandler()
    # create formatter
    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    # add formatter to ch
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    return logger


if __name__ == "__main__":
    run()

Aucun commentaire:

Enregistrer un commentaire