Пример #1
0
    def handle(self, *args, **options):
        from history.poloniex import poloniex
        from history.models import Price
        import time

        #hit API
        poo = poloniex(settings.API_KEY,settings.API_SECRET)
        balances = poo.returnBalances()

        #record balances
        deposited_amount_btc, deposited_amount_usd = get_deposit_balance()
        with transaction.atomic():
            for ticker in balances:
                val = float(balances[ticker]['available']) + float(balances[ticker]['onOrders'])
                if val > 0.0001:

                    exchange_rate_coin_to_btc = get_exchange_rate_to_btc(ticker)
                    exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
                    exchange_rate_coin_to_usd = exchange_rate_btc_to_usd * exchange_rate_coin_to_btc
                    btc_val = exchange_rate_coin_to_btc * val 
                    usd_val = exchange_rate_btc_to_usd * btc_val  
                    b = Balance(symbol=ticker,coin_balance=val,btc_balance=btc_val,exchange_to_btc_rate=exchange_rate_coin_to_btc,usd_balance=usd_val,exchange_to_usd_rate=exchange_rate_coin_to_btc,deposited_amount_btc=deposited_amount_btc if ticker =='BTC' else 0.00, deposited_amount_usd=deposited_amount_usd if ticker =='BTC' else 0.00)
                    b.save()

        for b in Balance.objects.filter(date_str='0'):
            # django timezone stuff , FML
            b.date_str = datetime.datetime.strftime(b.created_on - datetime.timedelta(hours=int(7)),'%Y-%m-%d %H:%M')
            b.save()

        #normalize trade recommendations too.  merp
        for tr in Trade.objects.filter(created_on_str=''):
            # django timezone stuff , FML
            tr.created_on_str = datetime.datetime.strftime(tr.created_on - datetime.timedelta(hours=int(7)),'%Y-%m-%d %H:%M')
            tr.save()
Пример #2
0
 def calculate_profitability_exchange_rates(self):
     from history.tools import get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd
     ticker = ''
     for this_ticker in self.symbol.split('_'):
         if this_ticker != 'BTC':
             ticker = this_ticker
     exchange_rate_coin_to_btc = get_exchange_rate_to_btc(ticker)
     exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
     self.btc_net_profit = exchange_rate_coin_to_btc * self.net_profit
     self.usd_net_profit = exchange_rate_btc_to_usd * self.btc_net_profit
Пример #3
0
 def calculate_profitability_exchange_rates(self):
     from history.tools import get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd
     ticker = ''
     for this_ticker in self.symbol.split('_'):
         if this_ticker != 'BTC':
             ticker = this_ticker
     exchange_rate_coin_to_btc = get_exchange_rate_to_btc(ticker)
     exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
     self.btc_net_profit = exchange_rate_coin_to_btc * self.net_profit
     self.usd_net_profit = exchange_rate_btc_to_usd * self.btc_net_profit
Пример #4
0
 def calculate_exchange_rates(self):
     from history.tools import get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd
     ticker = ''
     for this_ticker in self.symbol.split('_'):
         if this_ticker != 'BTC':
             ticker = this_ticker
     exchange_rate_coin_to_btc = get_exchange_rate_to_btc(ticker)
     exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
     self.btc_amount = exchange_rate_coin_to_btc * self.amount
     self.usd_amount = exchange_rate_btc_to_usd * self.btc_amount
     self.btc_fee_amount = exchange_rate_coin_to_btc * self.fee_amount
     self.usd_fee_amount = exchange_rate_btc_to_usd * self.btc_fee_amount
Пример #5
0
 def calculate_exchange_rates(self):
     from history.tools import get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd
     ticker = ''
     for this_ticker in self.symbol.split('_'):
         if this_ticker != 'BTC':
             ticker = this_ticker
     exchange_rate_coin_to_btc = get_exchange_rate_to_btc(ticker)
     exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
     self.btc_amount = exchange_rate_coin_to_btc * self.amount
     self.usd_amount = exchange_rate_btc_to_usd * self.btc_amount
     self.btc_fee_amount = exchange_rate_coin_to_btc * self.fee_amount
     self.usd_fee_amount = exchange_rate_btc_to_usd * self.btc_fee_amount
Пример #6
0
    def handle(self, *args, **options):
        from history.poloniex import poloniex
        from history.models import Price
        import time

        #hit API
        poo = poloniex(settings.API_KEY, settings.API_SECRET)
        balances = poo.returnBalances()

        #record balances
        deposited_amount_btc, deposited_amount_usd = get_deposit_balance()
        with transaction.atomic():
            for ticker in balances:
                val = float(balances[ticker]['available']) + float(
                    balances[ticker]['onOrders'])
                if val > 0.0001:

                    exchange_rate_coin_to_btc = get_exchange_rate_to_btc(
                        ticker)
                    exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
                    exchange_rate_coin_to_usd = exchange_rate_btc_to_usd * exchange_rate_coin_to_btc
                    btc_val = exchange_rate_coin_to_btc * val
                    usd_val = exchange_rate_btc_to_usd * btc_val
                    b = Balance(symbol=ticker,
                                coin_balance=val,
                                btc_balance=btc_val,
                                exchange_to_btc_rate=exchange_rate_coin_to_btc,
                                usd_balance=usd_val,
                                exchange_to_usd_rate=exchange_rate_coin_to_btc,
                                deposited_amount_btc=deposited_amount_btc
                                if ticker == 'BTC' else 0.00,
                                deposited_amount_usd=deposited_amount_usd
                                if ticker == 'BTC' else 0.00)
                    b.save()

        for b in Balance.objects.filter(date_str='0'):
            # django timezone stuff , FML
            b.date_str = datetime.datetime.strftime(
                b.created_on - datetime.timedelta(hours=int(7)),
                '%Y-%m-%d %H:%M')
            b.save()

        #normalize trade recommendations too.  merp
        for tr in Trade.objects.filter(created_on_str=''):
            # django timezone stuff , FML
            tr.created_on_str = datetime.datetime.strftime(
                tr.created_on - datetime.timedelta(hours=int(7)),
                '%Y-%m-%d %H:%M')
            tr.save()
Пример #7
0
    def handle(self, *args, **options):
        from history.poloniex import poloniex

        # hit API
        poo = poloniex(settings.API_KEY, settings.API_SECRET)
        balances = poo.returnBalances()
        balances = json.dumps(balances)
        balances = json.loads(balances)
        # record balances
        deposited_amount_btc, deposited_amount_usd = get_deposit_balance()
        with transaction.atomic():
            try: 
                for ticker2 in balances['info']:
                    print(ticker2)
                    val = float(ticker2['balance'])
                    print(val)
                    if val > 0.0001:
                        ticker = ticker2  ['currency']
                        exchange_rate_coin_to_btc = get_exchange_rate_to_btc(ticker)
                        exchange_rate_btc_to_usd = get_exchange_rate_btc_to_usd()
                        btc_val = val / exchange_rate_coin_to_btc
                        usd_val = btc_val / exchange_rate_btc_to_usd
                        b = Balance(symbol=ticker, coin_balance=val, btc_balance=btc_val,
                                    exchange_to_btc_rate=exchange_rate_coin_to_btc, usd_balance=usd_val,
                                    exchange_to_usd_rate=exchange_rate_coin_to_btc,
                                    deposited_amount_btc=deposited_amount_btc if ticker == 'BTC' else 0.00,
                                    deposited_amount_usd=deposited_amount_usd if ticker == 'BTC' else 0.00)
                        b.save()
            except Exception as e:
                print(e)
        for b in Balance.objects.filter(date_str='0'):
            # django timezone stuff , FML
            b.date_str = datetime.datetime.strftime(b.created_on - datetime.timedelta(hours=int(7)), '%Y-%m-%d %H:%M')
            b.save()

        # normalize trade recommendations too.  merp
        for tr in Trade.objects.filter(created_on_str=''):
            # django timezone stuff , FML
            tr.created_on_str = datetime.datetime.strftime(
                tr.created_on - datetime.timedelta(hours=int(7)), '%Y-%m-%d %H:%M')
            tr.save()