-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcacheOrderBook.py
More file actions
43 lines (33 loc) · 1.23 KB
/
cacheOrderBook.py
File metadata and controls
43 lines (33 loc) · 1.23 KB
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
from omnidex import getOrderbook
from sqltools import *
from cacher import *
import json
import time
import datetime
import sys
def printmsg(msg):
print str(datetime.datetime.now()) + str(" ") + str(msg)
sys.stdout.flush()
def updateOrderbookCache():
while True:
time.sleep(20)
printmsg("Checking for orderbook updates")
try:
lasttrade = rGet("omniwallet:omnidex:lasttrade")
if lasttrade is None:
lasttrade = 0
lastpending = rGet("omniwallet:omnidex:lastpending")
if lastpending is None:
lastpending = 0
ret = getOrderbook(lasttrade, lastpending)
if ret['updated']:
printmsg("Orderbook cache updated. Lasttrade: " + str(lasttrade) + " Lastpending: " + str(lastpending))
rSet("omniwallet:omnidex:lasttrade", ret['lasttrade'])
rSet("omniwallet:omnidex:lastpending", ret['lastpending'])
rSet("omniwallet:omnidex:book", json.dumps(ret['book']))
except Exception as e:
printmsg("Error updating orderbook cache " + str(e))
dbCommit()
def main():
updateOrderbookCache()
if __name__ == "__main__": main() ## with if