예제 #1
0
def calc_d_base(date):
    # 计算并保存d_base
    r = []
    symbol_list = get_symbols_quote()
    for symbol in symbol_list:
        if symbol[:2] != 'IO':
            continue

        try:
            basic = symbol[:6]
            strike = get_contract(symbol).strike

            symbol_c = basic + '-C-' + str(strike)
            symbol_p = basic + '-P-' + str(strike)

            fn = get_dss() + 'fut/bar/day_' + symbol_c + '.csv'
            df_c = pd.read_csv(fn)
            fn = get_dss() + 'fut/bar/day_' + symbol_p + '.csv'
            df_p = pd.read_csv(fn)

            d_base = df_c.iat[-1, 5] + df_p.iat[-1, 5]
            r.append([date, basic, strike, d_base])
        except Exception as e:
            # s = traceback.format_exc()
            # to_log(s)
            pass

    df = pd.DataFrame(r, columns=['date', 'basic', 'strike', 'd_base'])
    fn = get_dss() + 'opt/sdiffer_d_base.csv'
    if os.path.exists(fn):
        df.to_csv(fn, index=False, mode='a', header=False)
    else:
        df.to_csv(fn, index=False)
예제 #2
0
def examine():
    dss = get_dss()

    # setting_pz中的品种已在trade_time中维护
    #读取交易时段文件
    fn = dss + 'fut/cfg/trade_time.csv'
    df = pd.read_csv(fn)
    tm_pz_set = set(df.symbol)
    #print(tm_pz_set)

    fn = dss + 'fut/cfg/setting_pz.csv'
    df = pd.read_csv(fn)
    setting_pz_list = list(df.pz)
    #print(setting_pz_list)

    for pz in setting_pz_list:
        if pz not in tm_pz_set:
            to_log('examine: ' + pz +
                   ' of setting_pz.csv not in trade_time.csv')

    # 加载配置,目前盯市的品种已在setting_pz中维护
    symbols_quote_list = get_symbols_quote()
    for symbol in symbols_quote_list:
        c = get_contract(symbol)
        #print( c.pz )
        if c is None:
            to_log('examine: ' + symbol +
                   ' of config.json not in setting_pz.csv')

    # symbols_quote涵盖symbols_trade
    symbols_trade_list = get_symbols_trade()
    for symbol in symbols_trade_list:
        if symbol not in symbols_quote_list:
            to_log('examine: ' + symbol +
                   ' of symbols_trade not in symbols_quote')

    # 行情接收器是否存在超时情况
    config = open(dss + 'fut/cfg/config.json')
    setting = json.load(config)
    symbol = setting['symbols_quote_canary']
    # symbols_quote_list = symbols.split(',')
    now = datetime.now()
    today = now.strftime('%Y-%m-%d')
    # today = '20200515'
    fn = get_dss() + 'fut/tick/tick_' + today + '_' + symbol + '.csv'
    if os.path.exists(fn):
        df = pd.read_csv(fn)
        df = df[(df.UpdateTime >= '14:50:59') & (df.UpdateTime <= '14:59:59')]
        df = df.sample(3)
        for i, row in df.iterrows():
            u = datetime.strptime(row.UpdateDate + ' ' + row.UpdateTime,
                                  '%Y-%m-%d %H:%M:%S')
            u += timedelta(seconds=3)
            u = datetime.strftime(u, '%Y-%m-%d %H:%M:%S')
            # print(row.Localtime, u)
            if row.Localtime > u:
                to_log('examine: over time! ' + row.Localtime + ' > ' + u)
예제 #3
0
    def __init__(self):
        """Constructor"""
        CtpQuote.__init__(self)

        # 加载配置
        # config = open(get_dss()+'fut/cfg/config.json')
        # setting = json.load(config)
        # symbols = setting['symbols_quote']
        # self.id_list = symbols.split(',')
        self.id_list = get_symbols_quote()

        self.dss = get_dss()
        self.tradeDay = ''
        self.night_day = ''
        self.temp_tradeDay = ''
        self.bar_min1_dict = {}
예제 #4
0
def tick2bar(tradeDay):
    #读取交易时段文件
    fn = get_dss() + 'fut/cfg/trade_time.csv'
    df_tm = pd.read_csv(fn)

    symbol_list = get_symbols_quote()
    # symbol_list = ['ag1912']

    # 逐个处理每个合约
    for symbol in symbol_list:
        try:
            # 读取品种的tick文件
            fn = get_dss() + 'fut/tick/tick_' + tradeDay + '_' + symbol + '.csv'
            if os.path.exists(fn) == False:
                # print(fn+' not exists')
                continue

            # print(fn+' begin ... ')
            df = pd.read_csv(fn)

            # 获取品种交易时段
            pz = get_contract(symbol).pz
            df2 = df_tm[df_tm.symbol==pz].sort_values(by='seq')
            r1 = []
            # 逐个时段遍历处理
            for i,row in df2.iterrows():
                # 组装该时段数据,进行数据清洗
                if row.end > row.begin:
                    # 非夜盘跨零点交易时段
                    df1 = df[(df.UpdateTime>=row.begin) & (df.UpdateTime<=row.end)]
                    if len(df1) > 0:
                        # 处理tick异常数据,删除盘后非交易时段推送的数据
                        df1 = df1.sort_values(by=['UpdateDate','UpdateTime'])
                        df1 = df1.reset_index()
                        dt = df1.at[0,'UpdateDate']
                        df1 = df1[df1.UpdateDate == dt]
                else:
                    # 夜盘跨零点交易时段,作特殊拼接处理
                    df11 = df[(df.UpdateTime>=row.begin) & (df.UpdateTime<='23:59:59')]
                    df12 = df[(df.UpdateTime>='00:00:00') & (df.UpdateTime<=row.end)]
                    df1 = pd.concat([df11, df12])

                # 加工生成该时段的 bar_min1 数据,至少有2根tick才能加工成bar
                if len(df1) > 3:
                    # 排序很重要,因为tick送过来的顺序可能是乱的
                    df1 = df1.sort_values(by=['UpdateDate','UpdateTime'])
                    df1 = df1.reset_index()
                    # 处理该时段的tick,加工返回bar数据集
                    r1 += proc_segment(df1, row.begin, row.end, row.num, symbol)
                else:
                    if len(symbol) < 9:
                        to_log( symbol + ' 时段数据缺失:'+ tradeDay + ' ' + str(row.seq) )

            # 该合约处理完毕,保存各周期bar到文件
            if len(r1) > 0:
                save_bar(r1, symbol)

        except Exception as e:
            s = traceback.format_exc()
            to_log(s)
            to_log('error: ' + symbol)
            continue