-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinanceHandler.py
More file actions
54 lines (40 loc) · 1.37 KB
/
Copy pathbinanceHandler.py
File metadata and controls
54 lines (40 loc) · 1.37 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
import datetime
import calendar
# pip install python-binance
import binance
from binance.client import Client
_now = datetime.datetime.utcnow()
_2yearAgo = calendar.timegm(_now.replace(year=_now.year-2).timetuple())
_now = calendar.timegm(_now.timetuple())
def getClient(apiKey, secret):
client = Client(apiKey, secret)
return client
def getOpenPositions(client):
openPositions = client.get_open_orders(timestamp=_2yearAgo)
return openPositions
def getBalances(client):
balances = client.get_account(timestamp=_now)["balances"]
return balances
def getWithdraws(client):
withdraws = client.get_withdraw_history(timestamp=_2yearAgo)
return withdraws["withdrawList"]
def getDeposits(client):
deposits = client.get_deposit_history(timestamp=_2yearAgo)
return deposits["depositList"]
def getAllPairs(client):
ticker = client.get_ticker()
symbols = map(lambda t: t["symbol"], ticker)
return symbols
def getTrades(client, pairSymbol, fromId = 0):
limit = 15
trades = client.get_my_trades(
symbol=pairSymbol,
timestamp=_2yearAgo,
limit=limit,
fromId = fromId)
length = len(trades)
if (length > 0):
print "========>\t\t\t\t\t" + str(pairSymbol) + " : " + str(length)
if(length == limit):
trades = trades + getTrades(client, pairSymbol, trades[limit-1]["id"]+1)
return trades