forked from BitMEX/api-connectors
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
40 lines (31 loc) · 1.2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from bitmex_websocket import BitMEXWebsocket
import logging
from time import sleep
# 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://testnet.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):
logger.info("Ticker: %s" % ws.get_ticker())
if ws.api_key:
logger.info("Funds: %s" % ws.funds())
logger.info("Market Depth: %s" % ws.market_depth())
logger.info("Recent Trades: %s\n\n" % ws.recent_trades())
sleep(10)
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()