def match_shape(self): stock_percent = self.get_current_data_percent() index_percent = self.get_current_index_percent() high = Decimal(self.dataLastRow['high']) low = Decimal(self.dataLastRow['low']) open_price = float(self.dataLastRow['open']) price = Decimal(self.dataLastRow['price']) pre_close = Decimal(self.dataLastRow['pre_close']) open_percent = self.get_percent_by_price(open_price, self.dataLastRow) if(open_percent < Decimal(self.trade['params']['open_percent']['low']) or open_percent > Decimal(self.trade['params']['open_percent']['high'])): return False if(hasattr(self, 'force_stop')): return False break_top = Utils.round_dec((high - price) / (pre_close) * 100) if(break_top > Decimal(self.trade['params']['speed']['break_top'])): self.force_stop = True Ydls._logger.info(f'TradeId = {self.trade["_id"]}, Ydls break_top = {break_top}, force stop') return False upper_shadow = Utils.round_dec((high - price) / (high - low)) if(upper_shadow > Decimal(self.trade['params']['speed']['upper_shadow'])): return False flag = False if(index_percent < 0): flag = stock_percent > index_percent * Decimal(self.trade['params']['speed']['ratio_l']) else: flag = stock_percent > Decimal(self.trade['params']['speed']['ratio_r']) * index_percent if(flag): Ydls._logger.info(f'TradeId = {self.trade["_id"]}, Ydls matched shape upper_shadow = {upper_shadow}, stock_percent = {stock_percent}') return flag
def match_sell_on_zt(self): price = Decimal(self.dataLastRow['price']) pre_close = float(self.dataLastRow['pre_close']) if (abs(price - Utils.round_dec(pre_close * 1.1)) < Base.SMALL_NUMBER): if (self.trade['params']['sell_on_zt'] == '1'): return 1 return 0 return -1
def match_data(self): price = float(self.dataLastRow['price']) pre_close = float(self.dataLastRow['pre_close']) percent = Utils.round_dec((price - pre_close) / pre_close * 100) percent_low = Decimal(self.trade['params']['percent']['low']) percent_high = Decimal(self.trade['params']['percent']['high']) percent_high = 10.1 if percent_high >= 10.0 else percent_high flag = (percent >= percent_low and percent <= percent_high) if(flag): Base._logger.info('real_time = {}, tradeId = {} match data, time = {}, percent = {}, low = {}, high = {}'.format(datetime.now(), self.trade['_id'], self.dataLastRow['time'], percent, percent_low, percent_high)) return flag
def calc_soft_stop(self): percent = float(self.get_current_data_percent()) index_percent = float(self.get_current_index_percent()) max_loss = float(self.trade['params']['soft_stop']['max_loss']) max_index = float(self.trade['params']['soft_stop']['max_index']) ratio_stock = float(self.trade['params']['soft_stop']['ratio_stock']) ratio_index = float(self.trade['params']['soft_stop']['ratio_index']) pre_close = float(self.dataLastRow['pre_close']) zt_p = float( Utils.round_dec( (Utils.round_dec(pre_close * 1.1) - Decimal(pre_close)) / Decimal(pre_close) * 100)) if (index_percent > max_index): ratio_index = 0 y1 = (max_loss / 100) * math.pow(percent - zt_p, 2) if percent >= 0 else ( max_loss / 100) * math.pow(percent + zt_p, 2) y2 = (max_loss / math.pow(max_index, 2)) * math.pow( index_percent - max_index, 2) if (index_percent >= 0) else ( max_loss / math.pow(max_index, 2)) * math.pow( index_percent + max_index, 2) y = ((y1 * ratio_stock) + (y2 * ratio_index)) / (ratio_stock + ratio_index) return Utils.round_dec(percent - y)
def match_speed(self): length = self.get_data_length() if(length < Ydls._MIN_TIME_PERIOD_LENGTH): return False time = float(self.trade['params']['speed']['time_2']) index = int(20 * time) + 1 index = index * -1 if length >= index else length * -1 pre_price = Decimal(self.data[index]['price']) price = Decimal(self.dataLastRow['price']) pre_close = Decimal(self.dataLastRow['pre_close']) percent = Utils.round_dec((price - pre_price) / (pre_close) * 100) flag = percent >= Decimal(self.trade['params']['speed']['percent']) if(flag): Ydls._logger.info(f'TradeId = {self.trade["_id"]}, Ydls matched speed percnet = {percent}') return flag
def get_percent_by_price(self, price, row): pre_close = float(row['pre_close']) return Utils.round_dec((price - pre_close) / pre_close * 100)