-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.py
38 lines (28 loc) · 1022 Bytes
/
wallet.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
import logging
from decimal import Decimal
from enum import Enum
logger = logging.getLogger(__name__)
class Coin(Enum):
USDT = 'USDT'
BTC = 'BTC'
class Wallet:
def __init__(self, usdt=0.0, btc=0.0):
self.balance = {
Coin.USDT: usdt,
Coin.BTC: btc
}
def get(self, coin): return self.balance.get(coin, 0.0)
def set(self, coin, value): self.balance[coin] = value
def add(self, coin, value):
if coin not in self.balance:
self.balance[coin] = 0
self.balance[coin] += value
def subtract(self, coin, value):
self.add(coin, -value)
def __repr__(self):
return f'({self.balance[Coin.USDT].normalize()} USDT - {self.balance[Coin.BTC].normalize()} BTC)'
def update_balances(self, binance_manager):
for coin in Coin:
data = binance_manager.client.get_asset_balance(asset=coin.value)
self.set(coin, Decimal(data['free']))
# logger.info(f'Updated balances - {self}')