forked from ericjang/cryptocurrency_arbitrage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broker_utils.py
36 lines (31 loc) · 1.13 KB
/
broker_utils.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
import config
from Broker import Broker
from CryptoExchange import CryptoExchange
def create_brokers(mode, pairs, exchangeNames):
# returns an array of Broker objects
brokers = []
for name in exchangeNames:
if (name == 'binance'):
xchg = CryptoExchange('binance', config.BINANCE_KEY, config.BINANCE_SECRET)
else:
print('Exchange ' + name + ' not supported!')
continue
print('%s initialized' % (xchg.name))
broker = Broker(mode, xchg)
if mode == 'BACKTEST':
# broker.balances = config.PAPER_BALANCE
broker.balances = broker.xchg.get_all_balances() # use real starting balances.
brokers.append(broker)
return brokers
def get_assets(brokers):
# prints out total assets held across all brokers
assets = {}
for broker in brokers:
for currency, balance in broker.balances.items():
if currency in assets:
assets[currency] += balance
elif balance > 0.0:
assets[currency] = balance
return assets
def print_assets(brokers):
print(get_assets(brokers))