Skip to content

Instantly share code, notes, and snippets.

@shuckc
Last active October 25, 2018 20:25
Show Gist options
  • Save shuckc/36680d311e0a59ca1185ea61fd9a087f to your computer and use it in GitHub Desktop.
Save shuckc/36680d311e0a59ca1185ea61fd9a087f to your computer and use it in GitHub Desktop.
Example order book printing
from bitmex_websocket import BitMEXWebsocket
import logging
from time import sleep
def run():
ws = BitMEXWebsocket(endpoint="https://www.bitmex.com/api/v1", symbol="XBTUSD",
api_key=None, api_secret=None)
logger = logging.getLogger()
# Run forever
while(ws.ws.sock.connected):
md = ws.market_depth()
sell = None
buy = None
if md:
for o in md:
if o['side'] == 'Sell':
if sell == None or o['price'] < sell['price']:
sell = o
if o['side'] == 'Buy':
if buy == None or o['price'] > buy['price']:
buy = o
if buy and sell:
logger.info("Market Depth: {0:14,} @ {1:10.1f} | {2:14,} @ {3:10.1f}".format(sell['size'], sell['price'], buy['size'], buy['price']))
sleep(0.5)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment