-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCurrencyWrapper.py
42 lines (34 loc) · 1.54 KB
/
CurrencyWrapper.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
import ccxt
import botutils
import botconfig
class Currency:
def __init__(self, name, key=None, secret=None):
self.Name = name
self.id = name
self.Key = key
self.Secret = secret
self.Exchanges = {}
self.Precisions = {}
self.Balance = 0
self.Available = 0
if key != None:
self.Balance = botutils.balance(name, key)
self.Available = self.Balance
def add_exchange(self, exchange, balancesheet):
if id in exchange.currencies:
self.Exchanges[exchange.id] = {'total':balancesheet[self.id]['total'],'available':balancesheet[self.id]['free']}
self.Precisions[exchange.id] = exchange.currencies[id]['precision']
self.Balance += balancesheet[self.id]['total']
self.Available += balancesheet[self.id]['free']
def update_exchange(self, exchange, balancesheet):
if exchange.id in self.Exchanges:
self.Balance -= self.Exchanges[exchange.id]['total']
self.Available -= self.Exchanges[exchange.id]['available']
self.Exchanges[exchange.id] = {'total': balancesheet[self.id]['total'],
'available': balancesheet[self.id]['free']}
self.Balance += balancesheet[self.id]['total']
self.Available += balancesheet[self.id]['free']
def check_balance(self):
return {"id":self.id, "total":self.Balance, "available":self.Available, "used":self.Balance-self.Available}
def __str__(self):
return self.Name