MCPcopy
hub / github.com/owocki/pytrader / handle

Method handle

history/management/commands/pull_balance.py:17–52  ·  view source on GitHub ↗
(self, *args, **options)

Source from the content-addressed store, hash-verified

15 help = 'pulls balances and stores them in a DB'
16
17 def handle(self, *args, **options):
18 from history.poloniex import poloniex
19
20 # hit API
21 poo = poloniex(settings.API_KEY, settings.API_SECRET)
22 balances = poo.returnBalances()
23
24 # record balances
25 deposited_amount_btc, deposited_amount_usd = get_deposit_balance()
26 with transaction.atomic():
27 for ticker in balances:
28 val = float(balances[ticker]['available']) + float(balances[ticker]['onOrders'])
29 if val > 0.0001:
30
31 exchange_rate_coin_to_btc = get_exchange_rate_to_btc(ticker)
32 exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
33 btc_val = exchange_rate_coin_to_btc * val
34 usd_val = exchange_rate_btc_to_usd * btc_val
35 b = Balance(symbol=ticker, coin_balance=val, btc_balance=btc_val,
36 exchange_to_btc_rate=exchange_rate_coin_to_btc, usd_balance=usd_val,
37 exchange_to_usd_rate=exchange_rate_coin_to_btc,
38 deposited_amount_btc=deposited_amount_btc if ticker == 'BTC' else 0.00,
39 deposited_amount_usd=deposited_amount_usd if ticker == 'BTC' else 0.00)
40 b.save()
41
42 for b in Balance.objects.filter(date_str='0'):
43 # django timezone stuff , FML
44 b.date_str = datetime.datetime.strftime(b.created_on - datetime.timedelta(hours=int(7)), '%Y-%m-%d %H:%M')
45 b.save()
46
47 # normalize trade recommendations too. merp
48 for tr in Trade.objects.filter(created_on_str=''):
49 # django timezone stuff , FML
50 tr.created_on_str = datetime.datetime.strftime(
51 tr.created_on - datetime.timedelta(hours=int(7)), '%Y-%m-%d %H:%M')
52 tr.save()

Callers

nothing calls this directly

Calls 7

poloniexClass · 0.90
get_deposit_balanceFunction · 0.90
get_exchange_rate_to_btcFunction · 0.90
BalanceClass · 0.90
returnBalancesMethod · 0.80
saveMethod · 0.45

Tested by

no test coverage detected