forked from OmniLayer/omniEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cacheOrderBook.py
38 lines (30 loc) · 1.08 KB
/
cacheOrderBook.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
from omnidex import getOrderbook
from sqltools import *
from cacher import *
import json, time, datetime, 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 == None:
lasttrade=0
lastpending = rGet("omniwallet:omnidex:lastpending")
if lastpending == 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']))
dbCommit()
except Exception as e:
printmsg("Error updating orderbook cache "+str(e))
def main():
updateOrderbookCache()
if __name__ == "__main__":main() ## with if