forked from pmaji/crypto-whale-watching-app
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathob_test.py
64 lines (49 loc) · 1.63 KB
/
ob_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from bitmex_book import BitMEXBook
import logging
from time import sleep
#import json
# Simplejson allows serialization of Decimal
import simplejson as json
import sys
import datetime as dt
DATA_DIR = 'data/'
today = dt.datetime.today().strftime('%Y-%m-%d')
import bitmex
# Basic use of websocket.
def getLastPrice():
result = bitmex.bitmex(test=False).Instrument.Instrument_get(symbol='XBTUSD', reverse=True).result()[0][0]['timestamp']
return result
def run():
logger = setup_logger()
# Instantiating the WS will make it connect.
ws = BitMEXBook()
#logger.info("Instrument data: %s" % ws.get_whole_instrument())
#ws.set_logSize()
# Run forever
while(ws.ws.sock.connected):
# sleep(2)
# try:
# with open(DATA_DIR + 'orders/orders' + '_' + today + '.json') as f:
# orders = json.load(f)
# except:
# orders = {}
logger.info(ws.init())
# logger.info(getLastPrice())
# logger.info(dt.datetime.utcnow())
# logger.info('---------------------------------')
sleep(1)
# return
def setup_logger():
# Prints logger info to terminal
logger = logging.getLogger()
# logger.setLevel(logging.DEBUG) # Change this to DEBUG if you want a lot more info
logger.setLevel(logging.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()