-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticker.py
64 lines (54 loc) · 1.54 KB
/
ticker.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
import sys
import time
import types
import urllib
import json
import sl4a
import os
try:
import gdata.docs.service
except ImportError:
gdata = None
droid = sl4a.Android()
from bitbay import BitBay
from sys import argv
def event_loop():
for i in range(10):
time.sleep(1)
droid.eventClearBuffer()
time.sleep(1)
e = droid.eventPoll(1)
if e.result is not None:
return True
return False
def showCurrencies(BitBayObject):
items = BitBayObject.getPairs()
title = "Wybierz ticker"
droid.dialogCreateAlert(title)
droid.dialogSetSingleChoiceItems(items)
droid.dialogSetPositiveButtonText('Obadaj!')
droid.dialogShow()
response = droid.dialogGetResponse().result
item = droid.dialogGetSelectedItems()
return item
def showTicker(text,pair):
title = ("Ticker: %s" % (pair))
droid.dialogCreateAlert(title,text)
droid.dialogSetPositiveButtonText('OK!')
droid.dialogShow()
response = droid.dialogGetResponse().result
return response['which'] == 'positive'
if __name__ == '__main__':
os.chdir(os.path.dirname(argv[0]))
bb=BitBay()
r = showCurrencies(bb)[1][0]
pair = bb.getPairs()[r]
sys.stdout.flush()
(curr1,curr2)=pair.split('/')
ticker=bb.getTicker(curr1,curr2,False)
fields=["bid", "last", "ask", "volume", "average", "max", "min", "vwap"]
tickerText = 'Last ticker time:'+ time.ctime(bb.lastTicker(curr1,curr2))+ "\n"+ ("Pair: %s/%s" % (curr1,curr2))+ "\n"
for key in fields:
tickerText = tickerText + key + ":\t" + str(ticker[key]) + "\n"
showTicker(tickerText,pair)
sys.stdout.flush()