Exemplo n.º 1
0
    def init(self):
        master.set_pro_name(self.PRO_CNAME)
        self.setConnect()

        while True:
            time.sleep(1)
            master.check_gid()
            for uid, rest in self.users.items():
                rest.checkRest()
Exemplo n.º 2
0
    def init(self):
        master.set_pro_name(self.PRO_CNAME)
        self.initBitmex()

        from config.user import USER_CONFIG
        for conf in USER_CONFIG:
            user = conf['user']
            name = user['name']
            symbol = conf['symbol']

            pri_redis = self.redis[name + str(conf['sandbox'])]
            pub_redis = self.redis[conf['site'] + str(user['test_net'])]

            baseBoxDate = bitmexSandbox.KLINE_LIST[0]

            # 从沙盒120根基础k线运行时间开始 当前测试k线
            s_date = self.dataframe[baseBoxDate].iloc[0:bitmexMarket.
                                                      MAX_LINE].index[-1]
            # 2019-07-03 11:00:00  5m线 第一个成交
            for index, row in self.dataframe[
                    self.BASE_DATE].loc[s_date:].iterrows():
                self.updateNowKline(index, row)

                if len(self.kline[baseBoxDate]) < bitmexMarket.MAX_LINE:
                    continue
                if len(self.kline[baseBoxDate]) > bitmexMarket.MAX_LINE:
                    self.kline[baseBoxDate] = self.kline[baseBoxDate][
                        -bitmexMarket.MAX_LINE:]

                # 获取策略
                self.strategy = conf['strategy'](user, pub_redis, pri_redis,
                                                 symbol)
                self.strategy.realMode = False
                self.strategy.backMode = True

                if self.strategy.realMode:
                    sell = row['open']
                else:
                    sell = 0
                self.setBitmexMarket(pub_redis, symbol, row['close'], sell)
                self.setBitmexKline(pub_redis, symbol)

                order = self.strategy.getOrder()
                self.strategy.runBox()

                # todo 图表观察
                # myPlot.kline(self.kline['1h'])

        master.stop()
        master.kill_me()
Exemplo n.º 3
0
    def init(self):
        master.set_pro_name(self.PRO_CNAME)

        for uid, wss in self.users.items():
            wss.link()
Exemplo n.º 4
0
    def init(self):
        master.set_pro_name(self.PRO_CNAME)

        importlib.reload(config.user)
        from config.user import USER_CONFIG

        self.initUser(USER_CONFIG)
        while True:
            try:
                time.sleep(1)
                master.check_gid()
                now_time = master.mictime()

                for conf in USER_CONFIG:
                    user = conf['user']
                    name = user['name']
                    symbol = conf['symbol']

                    pri_redis = self.redis[name + str(conf['sandbox'])]
                    pub_redis = self.redis[conf['site'] +
                                           str(user['test_net'])]

                    # 获取策略
                    strategy = conf['strategy'](user, pub_redis, pri_redis,
                                                symbol)
                    # 获取开仓订单
                    orders = strategy.getOrder()

                    # 沙盒环境
                    if conf['sandbox'] > 0:
                        strategy.runBox()
                        continue

                    status = pri_redis.get(self.IS_TRUST)

                    # 60秒仓位日志
                    if int(now_time / 1000000) % 300 == 0:
                        logging.info({
                            'title': 'strategyProcessLog',
                            'name': name,
                            'sign': strategy.sign,
                            'status': status,
                            'orders': orders,
                            'data': strategy.data
                        })

                    # 用户订单仓位未更新
                    lastInfo = pri_redis.hget(self.TRUST, 'info')

                    if not orders or 'info' not in orders or lastInfo == orders[
                            'info']:
                        continue

                    # 正在下单不处理
                    if status in ['1', '2']:
                        continue
                    # 状态为0 新下单
                    elif status == '0' and len(orders) > 2:
                        logging.info({
                            'title': 'strategyCreateOrder',
                            'name': name,
                            'sign': strategy.sign,
                            'status': status,
                            'orders': orders,
                            'data': strategy.data
                        })
                        pri_redis.hdelete(self.TRUST)
                        pri_redis.hmset(self.TRUST, orders)
                        pri_redis.set(self.IS_TRUST, 1)
            except:
                master.sysError()