-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitNotifyPy2.py
More file actions
executable file
·94 lines (77 loc) · 2.9 KB
/
Copy pathBitNotifyPy2.py
File metadata and controls
executable file
·94 lines (77 loc) · 2.9 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
import os,requests,argparse
from time import sleep
from datetime import datetime
from temboo.Library.Twitter.DirectMessages import SendDirectMessage
from temboo.core.session import TembooSession
#os.system("mode con cols=24 lines=20")
#NEED SOME TWEETING ON ERROR MESSAGES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
parser = argparse.ArgumentParser()
parser.add_argument("-%", "--threshold", help="the margin percentage to trigger a DM",
type=int, default=7)
args = parser.parse_args()
URL_bitstamp = 'https://www.bitstamp.net/api/ticker/'
URL_USDGBP = 'http://rate-exchange.appspot.com/currency?from=USD&to=GBP'
URL_Bitty = 'https://bittylicious.com/api/v1/quote/BTC/GB/GBP/BANK/1'
threshold = args.threshold
repeatFreq = 30
repeatCount = 10
def getBitstampUSD(rate):
try:
data = requests.get(URL_bitstamp, timeout = 10).json()
USD_last = data["last"]
except ValueError:
print '[Error 1001] Bitstamp is having issues, no surprise there...'
return 1
GBP_last = float(USD_last) / rate
print 'Last price = $' + USD_last
print u'And in GBP = £%.2f' % GBP_last
return GBP_last
def printUSDGBP():
data = requests.get(URL_USDGBP).json()
USDGBP = data['rate']
inv = 1/float(USDGBP)
print 'USD/GBP rate = $%.3f\n' % inv
return inv
def printBitty():
data = requests.get(URL_Bitty).json()
Bitty_last = data['totalPrice']
print u'Bittylicious = £%.2f' % Bitty_last
return Bitty_last
def bittyDelta(stamp, bitty, time):
delta = bitty - stamp
print u'Bitty_Delta = £%.2f' % delta
percent = ( bitty / stamp * 100 ) - 100
print u' = %.2f%%' % percent
return percent
def sendDM(time, text):
session = TembooSession('jgillard', 'TwitBot1', 'f7671f639f6a448d94d82950ab7f74e0')
sendDirectMessageChoreo = SendDirectMessage(session)
sendDirectMessageInputs = sendDirectMessageChoreo.new_input_set()
sendDirectMessageInputs.set_credential('JamesGYun')
sendDirectMessageInputs.set_Text(time + ' ' + text)
sendDirectMessageInputs.set_ScreenName("jamesmgillard")
sendDirectMessageChoreo.execute_with_results(sendDirectMessageInputs)
def printTime():
now = datetime.now()
time = now.strftime('%d/%m/%Y %H:%M:%S')
print time
return time
rate = printUSDGBP()
histList = [0,0,0,0,0,0,0,0,0,0]
while True:
time = printTime()
stampGBP = getBitstampUSD(rate)
bittyGBP = printBitty()
percent = bittyDelta(stampGBP, bittyGBP, time)
histList[0] = percent
if percent >= threshold:
if repeatCount > 1:
repeatCount -= 1
elif repeatCount == 1:
sendDM(time, "BL:%.2f BS:%.2f ----> %.2f%%" % (bittyGBP,stampGBP,percent) )
repeatCount = repeatFreq
if percent < threshold and repeatCount < repeatFreq:
repeatCount = 10
print '\n'
sleep(60)