-
Notifications
You must be signed in to change notification settings - Fork 25
/
watch.py
executable file
·43 lines (30 loc) · 1008 Bytes
/
watch.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
#!/usr/bin/env python
import time
from settings import *
wait = 60
last_trades = {}
last_bids = []
last_asks = []
while True:
trades = exchange.get_trades()
now = time.time()
for tr in trades:
if not last_trades.has_key(tr["tid"]):
last_trades[tr["tid"]] = tr
# also print tid
print "%s: %s \t@ %s (%s minutes ago)" % (tr["tid"],
tr["amount"],
tr["price"],
int((now - tr["date"])/60))
time.sleep(wait)
continue
depth = exchange.get_depth()
bids = sorted(depth['bids'], key=lambda bid: bid[0])
asks = sorted(depth['asks'], key=lambda bid: bid[0])
print "*** Bids"
for price, amount in bids:
print "%s\t%s" % (price, amount)
print "\n*** Asks"
for price, amount in asks:
print "%s\t%s" % (price, amount)
time.sleep(wait)