Beispiel #1
0
def update_column_selector(schema_name):
    if schema_name:
        schema = get_schema_by_name(name=schema_name)
        cols = get_schema_columns(schema=schema)

        return [{'label': col, 'value': col} for col in cols]
    raise dash.PreventUpdate()
Beispiel #2
0
def update_code_selector(entity_type):
    if entity_type is not None:
        return [{'label': schema.__name__, 'value': schema.__name__} for schema in
                zvt_context.entity_map_schemas.get(entity_type)], \
               [{'label': code, 'value': code} for code in
                get_entities(entity_type=entity_type, columns=['code']).index]
    raise dash.PreventUpdate()
Beispiel #3
0
def update_factor_details(factor, entity_type, code, levels):
    if factor and entity_type and code and levels:
        if type(levels) is list and len(levels) >= 2:
            levels.sort()
            drawers = []
            for level in levels:
                drawers.append(zvt_context.factor_cls_registry[factor](
                    entity_schema=zvt_context.entity_schema_map[entity_type],
                    level=level,
                    codes=[code]).drawer())
            stacked = StackedDrawer(*drawers)

            return dcc.Graph(id=f'{factor}-{entity_type}-{code}',
                             figure=stacked.draw_kline(show=False, height=900))
        else:
            if type(levels) is list:
                level = levels[0]
            else:
                level = levels
            return dcc.Graph(
                id=f'{factor}-{entity_type}-{code}',
                figure=zvt_context.factor_cls_registry[factor](
                    entity_schema=zvt_context.entity_schema_map[entity_type],
                    level=level,
                    codes=[code]).draw(show=False, height=600))
    raise dash.PreventUpdate()
Beispiel #4
0
def update_target_signals(entity_id, start_date, end_date, trader_index):
    if entity_id and (trader_index is not None):
        return dcc.Graph(
            id=f'{entity_id}-signals',
            figure=get_trading_signals_figure(order_reader=order_readers[trader_index], entity_id=entity_id,
                                              start_timestamp=start_date, end_timestamp=end_date))
    raise dash.PreventUpdate()
Beispiel #5
0
def update_factor_details(region: Region, factor, entity_type, entity, levels,
                          columns, trader_index, schema_name):
    if factor and entity_type and entity and levels:
        sub_df = None
        # add sub graph
        if columns:
            if type(columns) == str:
                columns = [columns]
            columns = columns + ['entity_id', 'timestamp']
            schema: Mixin = get_schema_by_name(name=schema_name)
            sub_df = schema.query_data(region=region,
                                       entity_id=entity,
                                       columns=columns)

        # add trading signals as annotation
        annotation_df = None
        if trader_index is not None:
            order_reader = order_readers[trader_index]
            annotation_df = order_reader.data_df.copy()
            annotation_df = annotation_df[annotation_df.entity_id ==
                                          entity].copy()
            if pd_is_not_null(annotation_df):
                annotation_df['value'] = annotation_df['order_price']
                annotation_df['flag'] = annotation_df['order_type'].apply(
                    lambda x: order_type_flag(x))
                annotation_df['color'] = annotation_df['order_type'].apply(
                    lambda x: order_type_color(x))
            print(annotation_df.tail())

        if type(levels) is list and len(levels) >= 2:
            levels.sort()
            drawers = []
            for level in levels:
                drawers.append(zvt_context.factor_cls_registry[factor](
                    entity_schema=zvt_context.entity_schema_map[entity_type],
                    level=level,
                    entity_ids=[entity]).drawer())
            stacked = StackedDrawer(*drawers)

            return dcc.Graph(id=f'{factor}-{entity_type}-{entity}',
                             figure=stacked.draw_kline(show=False, height=900))
        else:
            if type(levels) is list:
                level = levels[0]
            else:
                level = levels
            drawer = zvt_context.factor_cls_registry[factor](
                entity_schema=zvt_context.entity_schema_map[entity_type],
                level=level,
                entity_ids=[entity],
                need_persist=False).drawer()
            if pd_is_not_null(sub_df):
                drawer.add_sub_df(sub_df)
            if pd_is_not_null(annotation_df):
                drawer.annotation_df = annotation_df

            return dcc.Graph(id=f'{factor}-{entity_type}-{entity}',
                             figure=drawer.draw_kline(show=False, height=800))
    raise dash.PreventUpdate()
Beispiel #6
0
def update_trader_details(interval, trader_index):
    if trader_index is not None:
        return get_account_stats_figure(account_stats_reader=account_readers[trader_index]), \
               [{'label': security_id, 'value': security_id} for security_id in
                get_order_securities(trader_name=trader_names[trader_index])], \
               traders[trader_index].start_timestamp, \
               traders[trader_index].end_timestamp
    raise dash.PreventUpdate()
Beispiel #7
0
def update_entity_selector(entity_type, related):
    if entity_type is not None:
        if related:
            schemas = zvt_context.entity_map_schemas.get(entity_type)
        else:
            schemas = zvt_context.schemas
        return [{"label": schema.__name__, "value": schema.__name__} for schema in schemas]
    raise dash.PreventUpdate()
Beispiel #8
0
def update_code_selector(entity_type):
    if entity_type is not None:
        return [{
            'label': code,
            'value': code
        }
                for code in get_entities(entity_type=entity_type,
                                         columns=['code']).index]
    raise dash.PreventUpdate()
Beispiel #9
0
def update_entity_selector(entity_type, related):
    if entity_type is not None:
        if related:
            schemas = zvt_context.entity_map_schemas.get(entity_type)
        else:
            schemas = zvt_context.schemas

        df = get_entities(entity_type=entity_type,
                          columns=['entity_id', 'code', 'name'],
                          index='entity_id')
        return [{'label': schema.__name__, 'value': schema.__name__} for schema in schemas], \
               [{'label': f'{entity_id}({entity["name"]})', 'value': entity_id} for entity_id, entity in df.iterrows()]
    raise dash.PreventUpdate()
Beispiel #10
0
def update_factor_details(factor, entity_type, code, levels, columns,
                          schema_name):
    if factor and entity_type and code and levels:
        sub_df = None
        if columns:
            if type(columns) == str:
                columns = [columns]
            columns = columns + ['entity_id', 'timestamp']
            schema: Mixin = get_schema_by_name(name=schema_name)
            sub_df = schema.query_data(code=code, columns=columns)
        if type(levels) is list and len(levels) >= 2:
            levels.sort()
            drawers = []
            for level in levels:
                drawers.append(zvt_context.factor_cls_registry[factor](
                    entity_schema=zvt_context.entity_schema_map[entity_type],
                    level=level,
                    codes=[code]).drawer())
            stacked = StackedDrawer(*drawers)

            return dcc.Graph(id=f'{factor}-{entity_type}-{code}',
                             figure=stacked.draw_kline(show=False, height=900))
        else:
            if type(levels) is list:
                level = levels[0]
            else:
                level = levels
            drawer = zvt_context.factor_cls_registry[factor](
                entity_schema=zvt_context.entity_schema_map[entity_type],
                level=level,
                codes=[code],
                need_persist=False).drawer()
            if pd_is_not_null(sub_df):
                drawer.add_sub_df(sub_df)

            return dcc.Graph(id=f'{factor}-{entity_type}-{code}',
                             figure=drawer.draw_kline(show=False, height=800))
    raise dash.PreventUpdate()