<s> from django . core . management . base import BaseCommand <EOL> from django . conf import settings <EOL> from history . tools import get_exchange_rate_to_btc , get_exchange_rate_btc_to_usd , get_deposit_balance <EOL> from history . models import Balance , Trade <EOL> import datetime <EOL> from django . db import transaction <EOL> import warnings <EOL> warnings . filterwarnings ( "<STR_LIT:ignore>" , category = DeprecationWarning ) <EOL> warnings . filterwarnings ( "<STR_LIT:ignore>" , category = RuntimeWarning ) <EOL> class Command ( BaseCommand ) : <EOL> help = '<STR_LIT>' <EOL> def handle ( self , * args , ** options ) : <EOL> from history . poloniex import poloniex <EOL> poo = poloniex ( settings . API_KEY , settings . API_SECRET ) <EOL> balances = poo . returnBalances ( ) <EOL> deposited_amount_btc , deposited_amount_usd = get_deposit_balance ( ) <EOL> with transaction . atomic ( ) : <EOL> for ticker in balances : <EOL> val = float ( balances [ ticker ] [ '<STR_LIT>' ] ) + float ( balances [ ticker ] [ '<STR_LIT>' ] ) <EOL> if val > <NUM_LIT> : <EOL> exchange_rate_coin_to_btc = get_exchange_rate_to_btc ( ticker ) <EOL> exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd ( ) <EOL> btc_val = exchange_rate_coin_to_btc * val <EOL> usd_val = exchange_rate_btc_to_usd * btc_val <EOL> b = Balance ( symbol = ticker , coin_balance = val , btc_balance = btc_val , <EOL> exchange_to_btc_rate = exchange_rate_coin_to_btc , usd_balance = usd_val , <EOL> exchange_to_usd_rate = exchange_rate_coin_to_btc , <EOL> deposited_amount_btc = deposited_amount_btc if ticker == '<STR_LIT>' else <NUM_LIT> , <EOL> deposited_amount_usd = deposited_amount_usd if ticker == '<STR_LIT>' else <NUM_LIT> ) <EOL> b . save ( ) <EOL> for b in Balance . objects . filter ( date_str = '<STR_LIT:0>' ) : <EOL> b . date_str = datetime . datetime . strftime ( b . created_on - datetime . timedelta ( hours = int ( <NUM_LIT:7> ) ) , '<STR_LIT>' ) <EOL> b . save ( ) <EOL> for tr in Trade . objects . filter ( created_on_str = '<STR_LIT>' ) : <EOL> tr . created_on_str = datetime . datetime . strftime ( <EOL> tr . created_on - datetime . timedelta ( hours = int ( <NUM_LIT:7> ) ) , '<STR_LIT>' ) <EOL> tr . save ( ) </s>
