-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.py
48 lines (36 loc) · 1.24 KB
/
listener.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
import schedule
import time
import json
import datetime
import ccxt
keyFile = open(".keys","r")
binanceKey = keyFile.readline().rstrip("\n")
binanceSecret = keyFile.readline().rstrip("\n")
binanceUSKey = keyFile.readline().rstrip("\n")
binanceUSSecret = keyFile.readline().rstrip("\n")
#Binance.us exchange instantiation - uses BINANCE.US keys
exchange_class = getattr(ccxt, "binanceus")
binanceUS = exchange_class({
"apiKey" : binanceUSKey,
"secret": binanceUSSecret,
"timeout": 30000,
"enableRateLimit": True,
})
print "*** Starting" + binanceUS.id + "Listener ***"
#Connect to Databases
savedDeposits = open("deposit-database.txt", "r")
outDeposits = open("deposit-database.txt", "a")
def job():
BTCUSD = ( binanceUS.fetch_ticker("BTC/USD")["bid"] + binanceUS.fetch_ticker("BTC/USD")["ask"] ) / 2
print "BTCUSD Price :" + str(BTCUSD)
deposits = binanceUS.fetch_deposits()
for i in deposits:
savedDeposit = savedDeposits.readline().rstrip("\n")
# print "Deposit from API:" + str(i)
# print "Saved Deposit:" + savedDeposit
if str(i) != savedDeposit:
outDeposits.write(str(i) + "\n")
schedule.every(1).seconds.do(job)
while 1:
schedule.run_pending()
time.sleep(.1)