trade.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:pytrade-me 作者: arshpreetsingh 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号