示例#1
0
    def try_pass(self, symbol, period) -> bool:
        kline = get_present_period(symbol=symbol, period=period)

        self.msg_args = (kline.close, kline.open)
        if kline.close < kline.open:
            return True
        return False
示例#2
0
    def try_pass(self, symbol, period, amount: int) -> bool:
        now = get_present_period(symbol=symbol).close
        lb = get_LB(symbol=symbol, period=period)

        if now >= lb:
            self.msg_args = (now, lb, None, None, None, None, None, None)
            return False
        ###############################################
        self.create_condition()
        if not self.is_second_pass():
            self.msg_args = (now, lb, False, None, None, None, None, None)
            return False

        ###############################################
        vol, vol3 = get_vol_vol3(symbol=symbol, period=period)

        # self.msg_args = (vol, vol3)
        if vol <= vol3:
            self.msg_args = (now, lb, True, vol, vol3, None, None, None)
            return False
        ###############################################
        try:
            order_id = market_buy(amount=amount, symbol=symbol)
            self.order_id = order_id
            self.msg_args = (now, lb, True, vol, vol3, amount, symbol,
                             order_id)
            logger_buy.info('buy successfully, info: {}'.format(
                self.MSG_FORMAT.format(*self.msg_args)))
            return True
        except Exception as e:
            logger_buy.error('somethings wrong, detail: {}'.format(e.args))
            self.msg_args = (now, lb, True, vol, vol3, None, None, None)
            return False
示例#3
0
    def try_pass(self, mission_id: int, amount: int, symbol: str) -> bool:
        last_trade = Trade.get_last(mission_id=mission_id)
        if last_trade is None or last_trade.type != 'buy-market':
            logger_buy.info(f'last trade: {last_trade}, return here')
            self.msg_arg = (0, 0, 0, 0, 0, 0, 0, 0)
            self.need_record = False
            return False

        buy_price = float(last_trade.price)
        kline = get_present_period(symbol=last_trade.symbol, period='60min')
        now_price = kline.close
        last_hour_price = kline.open
        diff = buy_price - now_price
        p = diff / last_hour_price
        self.msg_args = (buy_price, now_price, diff, last_hour_price, p * 100,
                         0, 0, 0)
        if not (diff > 0 and p > 0.03):
            return False
        else:
            condition = get_or_create_condition('%stop lose%')
            if not condition.valid:
                condition.valid = True
                condition.save()

        try:
            order_id = market_sell(amount=amount, symbol=symbol)
            self.order_id = order_id
            self.msg_args = (buy_price, now_price, diff, last_hour_price,
                             p * 100, amount, symbol, order_id)
            logger_buy.info('buy successfully, info: {}'.format(
                self.MSG_FORMAT.format(*self.msg_args)))
            return True
        except Exception as e:
            logger_buy.error('somethings wrong, detail: {}'.format(e.args))
            return False
示例#4
0
    def try_pass(self, symbol, period) -> bool:
        now = get_present_period(symbol=symbol).close
        ub = get_UB(symbol=symbol, period=period)

        self.msg_args = (now, ub)
        if now > ub:
            return True
        return False
示例#5
0
    def try_pass(self, symbol, period) -> bool:
        ma20 = get_ma20(symbol=symbol, period=period)
        now_price = get_present_period(symbol=symbol).close

        self.msg_args = (now_price, ma20)
        if now_price < ma20:
            return True
        return False
示例#6
0
    def try_pass(self, symbol, period) -> bool:
        ma20 = get_ma20(symbol=symbol, period=period)
        open_price = get_present_period(symbol=symbol, period=period).open
        open_min = ma20 * 0.90
        open_max = ma20 * 1.10

        self.msg_args = (ma20, open_min, open_max, open_price)
        if open_min <= open_price <= open_max:
            return True
        return False
示例#7
0
    def try_pass(self, symbol, period, amount) -> bool:
        now = get_present_period(symbol=symbol).close
        ub = get_UB(symbol=symbol, period=period)

        self.msg_args = (now, ub, None, None, None)
        if now <= ub:
            return False
        #############################################################################
        try:
            order_id = market_sell(amount=amount, symbol=symbol)
            self.order_id = order_id
            self.msg_args = (now, ub, amount, symbol, order_id)
            logger_buy.info('buy successfully, info: {}'.format(
                self.MSG_FORMAT.format(*self.msg_args)))
            return True
        except Exception as e:
            logger_buy.error('somethings wrong, detail: {}'.format(e.args))
            return False
示例#8
0
    def try_pass(self, mission_id) -> bool:
        last_trade = Trade.get_last(mission_id=mission_id, type='buy-market')
        if last_trade is None:
            self.msg_arg = (0, 0, 0, 0, 0)
            return False

        buy_price = float(last_trade.price)
        kline = get_present_period(symbol=last_trade.symbol, period='60min')
        now_price = kline.close
        last_hour_price = kline.open
        diff = buy_price - now_price
        p = diff/last_hour_price
        self.msg_args = (buy_price, now_price, diff, last_hour_price, p*100)
        if diff > 0 and p > 0.03:
            # TODO: move to others
            condition = Conditions.query.filter(Conditions.name.like('%stop lose%')).first()
            if condition:
                condition.valid = True
                condition.save()
            else:
                Conditions.create(name='stop lose', valid=True)
            return True

        return False