Exemplo n.º 1
0
def _wrap_kline(f, measurement, code, reset_flag=False):
    """
    推送缠论kline
    """
    for ktype in conf.HDF5_SHARE_WRAP_KTYPE:
        ctags = {"kcode": code, "ktype": ktype}
        wrap_ds_name = conf.HDF5_INDEX_WRAP + "_" + ktype
        if f.get(wrap_ds_name) is None:
            console.write_msg(code + "缠论数据不存在")
            continue

        wrap_df = tool.df_from_dataset(f, wrap_ds_name, None)
        wrap_df = _datetime_index(wrap_df)
        last_datetime = influx.get_last_datetime(measurement, ctags)
        if last_datetime is not None and reset_flag is False:
            wrap_df = wrap_df.loc[wrap_df.index > last_datetime]
        else:
            wrap_df = wrap_df.tail(DF_INIT_LIMIT)
        if len(wrap_df) > 0:
            try:
                influx.reset_df(wrap_df, measurement, ctags)
                console.write_exec()
            except Exception as er:
                print(str(er))
        else:
            console.write_pass()
    return
Exemplo n.º 2
0
def filter_share(code_list, start_date):
    """
    整理筛选的股票缠论k线
    """
    f = h5py.File(conf.HDF5_FILE_SHARE, 'a')
    console.write_head(conf.HDF5_OPERATE_WRAP, conf.HDF5_RESOURCE_TUSHARE,
                       conf.HDF5_INDEX_WRAP)
    for code in code_list:
        code_prefix = code[0:3]
        code_group_path = '/' + code_prefix + '/' + code
        if f.get(code_group_path) is None:
            continue
        # 忽略停牌、退市、无法获取的情况
        if f[code_prefix][code].attrs.get(
                conf.HDF5_BASIC_QUIT
        ) is not None or f[code_prefix][code].attrs.get(
                conf.HDF5_BASIC_ST) is not None:
            continue

        for ktype in conf.HDF5_SHARE_WRAP_KTYPE:
            ds_name = ktype
            if f[code_prefix][code].get(ds_name) is None:
                continue
            share_df = tool.df_from_dataset(f[code_prefix][code], ds_name,
                                            None)
            wrap_df = one_df(share_df)
            if wrap_df is not None:
                ds_name = conf.HDF5_INDEX_WRAP + "_" + ktype
                if f[code_prefix][code].get(ds_name) is not None:
                    tool.delete_dataset(f[code_prefix][code], ds_name)
                tool.create_df_dataset(f[code_prefix][code], ds_name, wrap_df)
                console.write_exec()
            else:
                console.write_pass()
    console.write_blank()
    console.write_tail()
    f.close()
    return
Exemplo n.º 3
0
def _basic_info(f, measurement, code, reset_flag):
    ctags = {"kcode": code}
    basic_ds_name = conf.HDF5_BASIC_DETAIL
    if f.get(basic_ds_name) is None:
        console.write_msg(code + "基本面数据不存在")
        return

    basic_df = tool.df_from_dataset(f, basic_ds_name, None)
    basic_df = _datetime_index(basic_df)
    last_datetime = influx.get_last_datetime(measurement, ctags)
    if last_datetime is not None and reset_flag is False:
        basic_df = basic_df.loc[basic_df.index > last_datetime]
    else:
        basic_df = basic_df.tail(DF_INIT_LIMIT)
    if len(basic_df) > 0:
        try:
            influx.reset_df(basic_df, measurement, ctags)
            console.write_exec()
        except Exception as er:
            print(str(er))
    else:
        console.write_pass()
    return
Exemplo n.º 4
0
def _raw_kline(f, measurement, code, reset_flag=False):
    """
    推送原始kline
    """
    for ktype in conf.HDF5_SHARE_KTYPE:
        ctags = {"kcode": code, "ktype": ktype}
        detail_ds_name = ktype
        index_ds_name = conf.HDF5_INDEX_DETAIL + "_" + ktype

        if f.get(detail_ds_name) is None:
            console.write_msg(code + "的detail数据不存在")
            continue
        if f.get(index_ds_name) is None:
            console.write_msg(code + "的index数据不存在")
            continue
        detail_df = tool.df_from_dataset(f, detail_ds_name, None)
        index_df = tool.df_from_dataset(f, index_ds_name, None)
        detail_df = detail_df.merge(index_df,
                                    left_on=conf.HDF5_SHARE_DATE_INDEX,
                                    right_on=conf.HDF5_SHARE_DATE_INDEX,
                                    how='left')
        detail_df = _datetime_index(detail_df)
        last_datetime = influx.get_last_datetime(measurement, ctags)
        if last_datetime is not None and reset_flag is False:
            detail_df = detail_df.loc[detail_df.index > last_datetime]
        else:
            detail_df = detail_df.tail(DF_INIT_LIMIT)
        detail_df = detail_df.drop("ma_border", axis=1)
        if len(detail_df) > 0:
            try:
                influx.reset_df(detail_df, measurement, ctags)
                console.write_exec()
            except Exception as er:
                print(str(er))
        else:
            console.write_pass()
    return
Exemplo n.º 5
0
def all_exec(omit_list):
    """
    筛选出存在背离的股票
    """
    # 筛选记录内容如下:
    # 1. 月线macd趋势
    # 2. 周线macd趋势
    # 3. 日线macd趋势,是否背离,数值差距
    # 4. 30min的macd趋势,是否背离,数值差距,震荡中枢数量
    # 5. 5min的macd趋势,是否背离,数值差距,震荡中枢数量
    console.write_head(conf.HDF5_OPERATE_SCREEN, conf.HDF5_RESOURCE_TUSHARE,
                       conf.STRATEGY_TREND_AND_REVERSE)
    f = h5py.File(conf.HDF5_FILE_SHARE, 'a')
    filter_df = tool.init_empty_df(_ini_filter_columns())
    for code_prefix in f:
        if code_prefix in omit_list:
            continue
        for code in f[code_prefix]:
            code_group_path = '/' + code_prefix + '/' + code
            if f.get(code_group_path) is None:
                console.write_blank()
                console.write_msg(code + "的tushare数据不存在")
                continue

            # 忽略停牌、退市、无法获取的情况
            if f[code_prefix][code].attrs.get(
                    conf.HDF5_BASIC_QUIT
            ) is not None or f[code_prefix][code].attrs.get(
                    conf.HDF5_BASIC_ST) is not None:
                console.write_blank()
                console.write_msg(code + "已退市或停牌")
                continue

            try:
                code_dict = code_exec(f, code)
                if code_dict is None:
                    console.write_pass()
                    continue
                else:
                    console.write_exec()
                    filter_df = filter_df.append(code_dict, ignore_index=True)
            except Exception as er:
                console.write_msg("[" + code + "]" + str(er))
    f.close()
    f_screen = h5py.File(conf.HDF5_FILE_SCREEN, 'a')
    if f_screen.get(conf.STRATEGY_TREND_AND_REVERSE) is None:
        f_screen.create_group(conf.STRATEGY_TREND_AND_REVERSE)
    if f_screen[conf.STRATEGY_TREND_AND_REVERSE].get(
            conf.SCREEN_SHARE_FILTER) is None:
        f_screen[conf.STRATEGY_TREND_AND_REVERSE].create_group(
            conf.SCREEN_SHARE_FILTER)
    today_str = tradetime.get_today()
    tool.delete_dataset(
        f_screen[conf.STRATEGY_TREND_AND_REVERSE][conf.SCREEN_SHARE_FILTER],
        today_str)
    tool.merge_df_dataset(
        f_screen[conf.STRATEGY_TREND_AND_REVERSE][conf.SCREEN_SHARE_FILTER],
        today_str, filter_df)
    f_screen.close()
    console.write_blank()
    console.write_tail()
    return