def get_trading_signals_figure(order_reader: OrderReader, entity_id: str, start_timestamp=None, end_timestamp=None): entity_type, _, _ = decode_entity_id(entity_id) data_schema = get_kdata_schema(entity_type=entity_type, level=order_reader.level) if not start_timestamp: start_timestamp = order_reader.start_timestamp if not end_timestamp: end_timestamp = order_reader.end_timestamp kdata_reader = DataReader(entity_ids=[entity_id], data_schema=data_schema, entity_schema=entity_schema_map.get(entity_type), start_timestamp=start_timestamp, end_timestamp=end_timestamp, level=order_reader.level) # generate the annotation df order_reader.move_on(timeout=0) df = order_reader.data_df.copy() df = df[df.entity_id == entity_id].copy() if pd_is_not_null(df): df['value'] = df['order_price'] df['flag'] = df['order_type'].apply(lambda x: order_type_flag(x)) df['color'] = df['order_type'].apply(lambda x: order_type_color(x)) print(df.tail()) drawer = Drawer(main_df=kdata_reader.data_df, annotation_df=df) return drawer.draw_kline(show=False)
entity_ids: List[str] = None, exchanges: List[str] = None, codes: List[str] = None, the_timestamp: Union[str, pd.Timestamp] = None, start_timestamp: Union[str, pd.Timestamp] = None, end_timestamp: Union[str, pd.Timestamp] = None, columns: List = ['id', 'entity_id', 'timestamp', 'level', 'open', 'close', 'high', 'low'], filters: List = None, order: object = None, limit: int = None, level: Union[str, IntervalLevel] = IntervalLevel.LEVEL_1DAY, category_field: str = 'entity_id', time_field: str = 'timestamp', computing_window: int = None, keep_all_timestamp: bool = False, fill_method: str = 'ffill', effective_number: int = None, accumulator: Accumulator = None, need_persist: bool = False, dry_run: bool = False, adjust_type: Union[AdjustType, str] = None, window=30) -> None: self.adjust_type = adjust_type transformer = TopBottomTransformer(window=window) super().__init__(entity_schema, provider, entity_provider, entity_ids, exchanges, codes, the_timestamp, start_timestamp, end_timestamp, columns, filters, order, limit, level, category_field, time_field, computing_window, keep_all_timestamp, fill_method, effective_number, transformer, accumulator, need_persist, dry_run, adjust_type) if __name__ == '__main__': factor = TopBottomFactor(codes=['601318'], start_timestamp='2005-01-01', end_timestamp=now_pd_timestamp(), level=IntervalLevel.LEVEL_1DAY, window=120) print(factor.factor_df) data_reader1 = DataReader(codes=['601318'], data_schema=Stock1dKdata, entity_schema=Stock) drawer = Drawer(main_df=data_reader1.data_df, factor_df=factor.factor_df[['top', 'bottom']]) drawer.draw_kline()
duans = [] for index, item in duan_df.iterrows(): if len(duans) == 4: x = duans[0][0] x1 = duans[3][0] if duans[0][1] < duans[1][1]: y, y1 = intersect((duans[0][1], duans[1][1]), (duans[2][1], duans[3][1])) else: y, y1 = intersect((duans[1][1], duans[0][1]), (duans[3][1], duans[2][1])) rects.append(((x, y), (x1, y1))) duans = [] else: duans.append((index[1], item.value)) drawer = Drawer(main_df=df, factor_df_list=[flag_df[['value']], duan_df], annotation_df=flag_df) fig = drawer.draw_kline(show=False) for rect in rects: fig.add_shape(type="rect", x0=rect[0][0], y0=rect[0][1], x1=rect[1][0], y1=rect[1][1], line=dict( color="RoyalBlue", width=2, ), fillcolor="LightSkyBlue", ) fig.update_shapes(dict(xref='x', yref='y')) fig.show() # the __all__ is generated __all__ = ['Direction', 'Fenxing', 'KState', 'DuanState', 'a_include_b', 'is_including', 'get_direction', 'is_up', 'is_down', 'handle_first_fenxing', 'handle_duan', 'handle_including', 'ZenTransformer', 'ZenFactor']