Exemple #1
0
    def handle(self, *args, **options):
        from history.poloniex import poloniex
        from history.models import Price
        import time

        poo = poloniex(settings.API_KEY,settings.API_SECRET)
        now = get_utc_unixtime()
        r = poo.returnDepositHistory(0,now)
        deposits = r['deposits'] + r['withdrawals']
        for d in deposits:
            print(d)
            currency = d['currency']
            amount = float(d['amount']) * ( -1  if 'withdrawalNumber' in d.keys() else 1 )
            timestamp = d['timestamp']
            txid = d['withdrawalNumber'] if 'withdrawalNumber' in d.keys() else d['txid']
            status = d['status']
            created_on = datetime.datetime.fromtimestamp(timestamp)
            try:
                d = Deposit.objects.get(txid=txid)
            except:
                d = Deposit()
            d.symbol=currency
            d.amount = amount
            d.txid = txid
            d.type = 'deposit' if amount > 0 else 'withdrawal'
            d.status = status
            d.created_on = created_on
            d.modified_on = created_on
            d.created_on_str = datetime.datetime.strftime(created_on - datetime.timedelta(hours=int(7)),'%Y-%m-%d %H:%M')
            d.save()
Exemple #2
0
    def handle(self, *args, **options):
        # setup
        self.poo = poloniex(settings.API_KEY, settings.API_SECRET)
        self.setup()
        print_and_log("(t){} ---- ****** STARTING TRAINERS  ******* ".format(str(datetime.datetime.now())))
        self.get_traders()
        print_and_log("(t){} ---- ****** DONE TRAINING ALL TRAINERS  ******* ".format(str(datetime.datetime.now())))

        while True:

            # TLDR -- which NNs should run at this granularity?
            should_run = []
            recommendations = dict.fromkeys(range(0, len(self.predictors)))

            for i in range(0, len(self.predictor_configs)):
                config = self.predictor_configs[i]
                if (int(get_utc_unixtime() / 60) % config['granularity'] == 0 and datetime.datetime.now().second < 1):
                    should_run.append(i)

            # TLDR -- update open orders bfore placing new ones
            if len(should_run) > 0:
                self.handle_open_orders()

            # TLDR -- run the NNs specified at this granularity
            for i in should_run:
                config = self.predictor_configs[i]
                recommend = self.run_predictor(i)
                recommendations[i] = recommend
                time.sleep(1)

            # TLDR - act upon recommendations
            for i in range(0, len(recommendations)):
                recommendation = recommendations[i]
                config = self.predictor_configs[i]
                if recommendation is not None:
                    print_and_log("(t)recommendation {} - {} : {}".format(i, str(config['name']), recommendation))
                    self.act_upon_recommendation(i, recommendation)

            # TLDR - cleanup and stats
            if len(should_run) > 0:
                pct_buy = round(100.0 * sum(recommendations[i] == 'BUY' for
                                            i in recommendations) / len(recommendations))
                pct_sell = round(100.0 * sum(recommendations[i] == 'SELL' for
                                             i in recommendations) / len(recommendations))
                print_and_log("(t)TLDR - {}% buy & {}% sell: {}".format(pct_buy, pct_sell, recommendations))
                print_and_log("(t) ******************************************************************************* ")
                print_and_log("(t) portfolio is {}".format(self.get_portfolio_breakdown_pct()))
                print_and_log("(t) ******************************************************************************* ")
                print_and_log("(t) {} ..... waiting again ..... ".format(str(datetime.datetime.now())))
                print_and_log("(t) ******************************************************************************* ")

            time.sleep(1)
Exemple #3
0
    def handle(self, *args, **options):
        # setup
        self.poo = poloniex(settings.API_KEY, settings.API_SECRET)
        self.setup()
        print_and_log("(t){} ---- ****** STARTING TRAINERS  ******* ".format(
            str(datetime.datetime.now())))
        self.get_traders()
        print_and_log(
            "(t){} ---- ****** DONE TRAINING ALL TRAINERS  ******* ".format(
                str(datetime.datetime.now())))

        while True:

            # TLDR -- which NNs should run at this granularity?
            should_run = []
            recommendations = dict.fromkeys(range(0, len(self.predictors)))

            for i in range(0, len(self.predictor_configs)):
                config = self.predictor_configs[i]
                if (int(get_utc_unixtime() / 60) % config['granularity'] == 0
                        and datetime.datetime.now().second < 1):
                    should_run.append(i)

            # TLDR -- update open orders bfore placing new ones
            if len(should_run) > 0:
                self.handle_open_orders()

            # TLDR -- run the NNs specified at this granularity
            for i in should_run:
                config = self.predictor_configs[i]
                recommend = self.run_predictor(i)
                recommendations[i] = recommend
                time.sleep(1)

            # TLDR - act upon recommendations
            for i in range(0, len(recommendations)):
                recommendation = recommendations[i]
                config = self.predictor_configs[i]
                if recommendation is not None:
                    print_and_log("(t)recommendation {} - {} : {}".format(
                        i, str(config['name']), recommendation))
                    self.act_upon_recommendation(i, recommendation)

            # TLDR - cleanup and stats
            if len(should_run) > 0:
                pct_buy = round(100.0 * sum(recommendations[i] == 'BUY'
                                            for i in recommendations) /
                                len(recommendations))
                pct_sell = round(100.0 * sum(recommendations[i] == 'SELL'
                                             for i in recommendations) /
                                 len(recommendations))
                print_and_log("(t)TLDR - {}% buy & {}% sell: {}".format(
                    pct_buy, pct_sell, recommendations))
                print_and_log(
                    "(t) ******************************************************************************* "
                )
                print_and_log("(t) portfolio is {}".format(
                    self.get_portfolio_breakdown_pct()))
                print_and_log(
                    "(t) ******************************************************************************* "
                )
                print_and_log("(t) {} ..... waiting again ..... ".format(
                    str(datetime.datetime.now())))
                print_and_log(
                    "(t) ******************************************************************************* "
                )

            time.sleep(1)