Exemplo n.º 1
0
def read_position_file_lts(lts_file_path):
    print 'Start read file:' + lts_file_path
    with codecs.open(lts_file_path, 'r', 'gbk') as fr:
        sf_instrument_array = []
        of_instrument_array = []
        instrument_array = []
        market_array = []
        index_array = []
        for line in fr.xreadlines():
            base_model = BaseModel()
            for temp_str in line.split('|')[1].split(','):
                temp_array = temp_str.replace('\n', '').split(':', 1)
                setattr(base_model, temp_array[0].strip(), temp_array[1])
            if 'OnRspQrySFInstrument' in line:
                sf_instrument_array.append(base_model)
            if 'OnRspQryOFInstrument' in line:
                of_instrument_array.append(base_model)
            elif 'OnRspQryInstrument' in line:
                instrument_array.append(base_model)
            elif 'OnRtnDepthMarketData' in line:
                market_array.append(base_model)
            elif 'OnRtnL2Index' in line:
                index_array.append(base_model)

    update_fund(sf_instrument_array, of_instrument_array)  # 更新分级基金的prev_nav
    update_instrument_base_info(instrument_array)
    update_market(market_array)  # 根据md行情数据更新prev_close
    update_market_index(index_array)  # 根据md的L2行情数据更新指数的prev_close
Exemplo n.º 2
0
def read_price_file_femas(femas_file_path):
    print 'Start read file:', femas_file_path
    fr = open(femas_file_path)
    option_array = []
    future_array = []
    instrument_cff_array = []
    market_array = []
    for line in fr.readlines():
        base_model = BaseModel()
        for tempStr in line.split('|')[1].split(','):
            temp_array = tempStr.replace('\n', '').split(':', 1)
            setattr(base_model, temp_array[0].strip(), temp_array[1])
        if 'OnRspQryInstrument' in line:
            product_id = getattr(base_model, 'ProductID', '')
            options_type = getattr(base_model, 'OptionsType', '')
            if product_id in ('IC', 'IF', 'IH', 'T', 'TF', 'TS'):
                future_array.append(base_model)
                instrument_cff_array.append(base_model)
            elif (options_type == '1') or (options_type == '2'):
                option_array.append(base_model)
                instrument_cff_array.append(option_array)
        elif 'OnRtnDepthMarketData' in line:
            market_array.append(base_model)

    update_instrument_cff(future_array)
    update_market_data(market_array)
Exemplo n.º 3
0
def read_position_file_stk(stk_file_path):
    print 'Start read file:' + stk_file_path
    fr = open(stk_file_path)
    order_array = []
    trade_array = []
    expendable_fund_array = []
    expendable_shares_array = []
    for line in fr.readlines():
        if 'Account_ID' in line:
            account_id = line.replace('\n', '').split(':')[1]
        else:
            base_model = BaseModel()
            for tempStr in line.split('|')[1].split(','):
                tempArray = tempStr.replace('\n', '').split(':', 1)
                setattr(base_model, tempArray[0].strip(), tempArray[1])
            if 'OnRspQryCurrDayOrder' in line:
                order_array.append(base_model)
            elif 'OnRspQryCurrDayFill' in line:
                trade_array.append(base_model)
            elif 'OnRspQryExpendableFund' in line:
                expendable_fund_array.append(base_model)
            elif 'OnRspQryExpendableShares' in line:
                expendable_shares_array.append(base_model)

    print 'AccountID:', account_id
    # 删除该账号今日记录
    del_account_position_by_id(account_id)
    del_order_trader_by_id(account_id)
    save_order(account_id, order_array)
    save_trade(account_id, trade_array)

    save_account_cny(account_id, expendable_fund_array)
    save_account_position(account_id, expendable_shares_array)

    update_db()
Exemplo n.º 4
0
def read_position_file_ctp(ctp_file_path):
    print 'Start read file:' + ctp_file_path
    fr = open(ctp_file_path)
    order_array = []
    trade_array = []
    trading_account_array = []
    investor_position_array = []
    commission_rate_array = []
    for line in fr.readlines():
        if 'Account_ID' in line:
            account_id = line.replace('\n', '').split(':')[1]
        else:
            base_model = BaseModel()
            for tempStr in line.split('|')[1].split(','):
                temp_array = tempStr.replace('\n', '').split(':', 1)
                setattr(base_model, temp_array[0].strip(),
                        temp_array[1].strip())
            if 'OnRspQryOrder' in line:
                order_array.append(base_model)
            elif 'OnRspQryTrade' in line:
                trade_array.append(base_model)
            elif 'OnRspQryTradingAccount' in line:
                trading_account_array.append(base_model)
            elif 'OnRspQryInvestorPosition' in line:
                investor_position_array.append(base_model)
            elif 'OnRspQryInstrumentCommissionRate' in line:
                commission_rate_array.append(base_model)

    print 'AccountID:', account_id
    if not trading_account_array:
        print 'Account Info Missing!'
        return
    # 删除该账号今日记录
    del_account_position_by_id(account_id)
    del_order_trader_by_id(account_id)

    account_name, cny_position_db = __get_account_cny(account_id,
                                                      trading_account_array)

    # 需特殊处理账号标志位
    # special_account_flag = __query_special_account_flag(account_id)

    commission_rate_list = __get_commission_rate_list(commission_rate_array)
    (order_list, order_dict) = __get_order_list(account_id, account_name,
                                                order_array)
    trade_list = __get__trade_list(account_id, account_name, trade_array,
                                   order_dict)

    (position_dict,
     position_db_list) = __build_account_position(account_id, account_name,
                                                  investor_position_array)
    position_db_list.append(cny_position_db)

    update_db(commission_rate_list, order_list, trade_list, position_db_list)
    update_account_trade_restrictions(account_id)
def read_position_file_guosen(guosen_file_path):
    print 'Start read file:' + guosen_file_path
    fr = open(guosen_file_path)
    trading_account_array = []
    investor_position_array = []
    for line in fr.readlines():
        if 'Account_ID' in line:
            account_id = line.replace('\n', '').split(':')[1]
        else:
            base_model = BaseModel()
            item_array = line.split('|')[1].split('')
            for i in range(0, len(item_array)):
                if i == len(item_array) - 1:
                    continue
                item = item_array[i].split('=', 1)
                if item[0] == '702':
                    group = []
                    cross_size = int(item[1])
                    for j in range(0, cross_size):
                        group.append('%s|%s' % (item_array[i + 1 + 2 * j],
                                                item_array[i + 2 + 2 * j]))
                    setattr(base_model, 'GroupA', group)
                    i += cross_size
                elif item[0] == '753':
                    group = []
                    cross_size = int(item[1])
                    for j in range(0, cross_size):
                        group.append('%s|%s' % (item_array[i + 1 + 2 * j],
                                                item_array[i + 2 + 2 * j]))
                    setattr(base_model, 'GroupB', group)
                    i += cross_size
                else:
                    setattr(base_model, item[0].strip(), item[1])

            msg_type = getattr(base_model, '35', '0')
            if msg_type == 'UAP':
                posreq_type = getattr(base_model, '724', '0')
                posreq_result = getattr(base_model, '728', '0')
                if posreq_result != '0':
                    print 'The returned message is wrong:', line
                    continue

                if posreq_type == '9':
                    trading_account_array.append(base_model)  # 资金
                elif posreq_type == '0':
                    investor_position_array.append(base_model)  # 股份

    # 删除该账号今日记录
    del_account_position_by_id(account_id)
    del_order_trader_by_id(account_id)
    save_account_cny(account_id, trading_account_array)
    save_account_position(account_id, investor_position_array)
    update_db()
Exemplo n.º 6
0
def read_ctp_file(file_path):
    market_array = []
    fr = open(file_path)
    for line in fr.readlines():
        baseModel = BaseModel()
        if len(line.strip()) == 0:
            continue
        for tempStr in line.split('|')[1].split(','):
            temp_array = tempStr.replace('\n', '').split(':', 1)
            setattr(baseModel, temp_array[0].strip(), temp_array[1])
        if 'OnRspQryDepthMarketData' in line:
            market_array.append(baseModel)
    return market_array
Exemplo n.º 7
0
def read_position_file_hs(hs_file_path, add_flag):
    print 'Start read file:' + hs_file_path
    fr = open(hs_file_path)
    order_array = []
    trade_array = []
    trading_account_array = []
    investor_position_array = []
    for line in fr.readlines():
        if line.strip() == '':
            continue

        if 'Account_ID' in line:
            account_id = line.replace('\n', '').split(':')[1]
        else:
            base_model = BaseModel()
            for tempStr in line.split('|')[1].split(','):
                temp_array = tempStr.replace('\n', '').split(':', 1)
                if len(temp_array) != 2:
                    continue
                setattr(base_model, temp_array[0].strip(),
                        temp_array[1].strip())
            if 'QryOrder' in line:
                order_array.append(base_model)
            elif 'QryTrade' in line:
                trade_array.append(base_model)
            elif 'QryCash' in line:
                trading_account_array.append(base_model)
            elif 'QryPosition' in line:
                investor_position_array.append(base_model)

    print 'AccountID:', account_id

    # 删除该账号今日记录
    del_account_position_by_id(account_id)

    (order_list, order_dict) = __get_order_list(account_id, order_array)
    trade_list = __get__trade_list(account_id, trade_array, order_dict)

    (position_dict,
     position_db_list) = __build_account_position(account_id,
                                                  investor_position_array)

    cny_position_db = __get_account_cny(account_id, trading_account_array)
    position_db_list.append(cny_position_db)
    update_db(order_list, trade_list, position_db_list)
Exemplo n.º 8
0
def read_position_file_lts(lts_file_path, filter_date_str):
    print 'Start Read File:' + lts_file_path
    fr = open(lts_file_path)
    order_array = []
    trade_array = []
    trading_account_array = []
    investor_position_array = []

    for line in fr.readlines():
        if 'Account_ID' in line:
            account_id = line.replace('\n', '').split(':')[1]
        else:
            base_model = BaseModel()
            for tempStr in line.split('|')[1].split(','):
                temp_array = tempStr.replace('\n', '').split(':', 1)
                setattr(base_model, temp_array[0].strip(), temp_array[1])
            if 'OnRspQryOrder' in line:
                order_array.append(base_model)
            elif 'OnRspQryTrade' in line:
                trade_array.append(base_model)
            elif 'OnRspQryTradingAccount' in line:
                trading_account_array.append(base_model)
            elif 'OnRspQryInvestorPosition' in line:
                investor_position_array.append(base_model)

    print 'AccountID:', account_id
    account_info = get_account_info(account_id)
    # 删除该账号今日记录
    del_account_position_by_id(account_id, filter_date_str)
    del_order_trader_by_id(account_id, filter_date_str)

    order_list = save_order(account_id, order_array, filter_date_str)
    trade_list = save_trade(account_info, trade_array, filter_date_str)

    position_list = []
    account_position_list = save_account_cny(account_info, trading_account_array, filter_date_str)
    ticker_position_list = save_account_position(account_info, investor_position_array, filter_date_str)
    position_list.extend(account_position_list)
    position_list.extend(ticker_position_list)

    update_db(order_list, trade_list, position_list)
    __update_account_trade_restrictions(account_id, order_list)
Exemplo n.º 9
0
def read_position_file(xtp_file_path, add_flag):
    print 'Start read file:' + xtp_file_path

    order_array = []
    trade_array = []
    trading_account_array = []
    investor_position_array = []
    with open(xtp_file_path) as fr:
        for line in fr.readlines():
            if 'Account_ID' in line:
                account_id = line.replace('\n', '').split(':')[1]
            else:
                base_model = BaseModel()
                for tempStr in line.split('|')[1].split(','):
                    temp_array = tempStr.replace('\n', '').split(':', 1)
                    setattr(base_model, temp_array[0].strip(),
                            temp_array[1].strip())
                if 'OnQryOrder' in line:
                    order_array.append(base_model)
                elif 'OnQryTrade' in line:
                    trade_array.append(base_model)
                elif 'OnQryAsset' in line:
                    trading_account_array.append(base_model)
                elif 'OnQryPosition' in line:
                    investor_position_array.append(base_model)

    print 'AccountID:', account_id

    if add_flag:
        # 删除该账号今日记录
        del_account_position_by_id(account_id)

    order_list = __get_order_list(account_id, order_array)
    trade_list = __get__trade_list(account_id, trade_array)

    (position_dict,
     position_db_list) = __build_account_position(account_id,
                                                  investor_position_array)

    cny_position_db = __get_account_cny(account_id, trading_account_array)
    position_db_list.append(cny_position_db)
    update_db(order_list, trade_list, position_db_list)
Exemplo n.º 10
0
def read_lts_file(filePath):
    email_list.append('Start read file:' + filePath)
    fr = codecs.open(filePath, 'r', 'gbk')
    for line in fr.xreadlines():
        baseModel = BaseModel()
        for tempStr in line.split('|')[1].split(','):
            tempArray = tempStr.replace('\n', '').split(':', 1)
            setattr(baseModel, tempArray[0].strip(), tempArray[1])
        if 'OnRspQryInstrument' in line:
            product_id = getattr(baseModel, 'ProductID', '')
            product_class = getattr(baseModel, 'ProductClass', '')
            if (product_class == '6') and ((product_id == 'SZA') or
                                           (product_id == 'SHA') or
                                           (product_id == 'CY')):
                instrument_id = getattr(baseModel, 'InstrumentID', '')
                instrument_name = getattr(baseModel, 'InstrumentName', '')
                if instrument_name.startswith('S') or \
                        instrument_name.startswith('ST') or \
                        instrument_name.startswith('*ST'):
                    st_stock_list.append(instrument_id)
Exemplo n.º 11
0
def read_price_file_femas(femas_file_path):
    print 'Start read file:', femas_file_path
    fr = open(femas_file_path)
    option_array = []
    future_array = []
    for line in fr.readlines():
        base_model = BaseModel()
        for tempStr in line.split('|')[1].split(','):
            temp_array = tempStr.replace('\n', '').split(':', 1)
            setattr(base_model, temp_array[0].strip(), temp_array[1])
        if 'OnRspQryInstrument' in line:
            product_id = getattr(base_model, 'ProductID', '')
            options_type = getattr(base_model, 'OptionsType', '')
            if (product_id == 'IC') or (product_id == 'IF') or (product_id == 'IH') or (product_id == 'TF') or \
                    (product_id == 'T'):
                future_array.append(base_model)
            elif (options_type == '1') or (options_type == '2'):
                option_array.append(base_model)

    add_future(future_array)  # 新增期货
    add_option(option_array)  # 新增期货期权等
Exemplo n.º 12
0
def read_price_file_ctp(ctp_file_path):
    print 'Start read file:', ctp_file_path

    future_list = []
    option_list = []
    with open(ctp_file_path) as fr:
        for line in fr.readlines():
            base_model = BaseModel()
            if len(line.strip()) == 0:
                continue
            for tempStr in line.split('|')[1].split(','):
                temp_array = tempStr.replace('\n', '').split(':', 1)
                setattr(base_model, temp_array[0].strip(), temp_array[1])

            if 'OnRspQryInstrument' in line:
                product_class = getattr(base_model, 'ProductClass', '')
                if product_class == '1':
                    future_list.append(base_model)
                if product_class == '2':
                    option_list.append(base_model)
    pre_add_future(future_list)  # 新增期货
    pre_add_option(option_list)  # 新增期权
Exemplo n.º 13
0
def read_price_file_ctp(ctp_file_path):
    print 'Start read file:', ctp_file_path

    instrument_array = []
    market_array = []
    with open(ctp_file_path) as fr:
        for line in fr.readlines():
            base_model = BaseModel()
            if len(line.strip()) == 0:
                continue
            for tempStr in line.split('|')[1].split(','):
                temp_array = tempStr.replace('\n', '').split(':', 1)
                setattr(base_model, temp_array[0].strip(), temp_array[1])

            if 'OnRspQryInstrument' in line:
                # exchange_id = getattr(base_model, 'ExchangeID', '')
                # product_id = getattr(base_model, 'ProductID', '')
                instrument_array.append(base_model)
            elif 'OnRspQryDepthMarketData' in line:
                market_array.append(base_model)

    update_instrument_info(instrument_array)
    update_market_info(market_array)  # 根据md行情数据更新prev_close
Exemplo n.º 14
0
def read_position_file_lts(lts_file_path):
    print 'Start read file:' + lts_file_path
    with codecs.open(lts_file_path, 'r', 'gbk') as fr:
        sf_instrument_array = []
        option_array = []
        stock_array = []
        structured_fund_array = []
        mmf_fund_array = []  # 货币基金
        convertible_bond_array = []  # 可转债
        for line in fr.xreadlines():
            base_model = BaseModel()
            for tempStr in line.split('|')[1].split(','):
                temp_array = tempStr.replace('\n', '').split(':', 1)
                setattr(base_model, temp_array[0].strip(), temp_array[1])

            if 'OnRspQryInstrument' in line:
                product_id = getattr(base_model, 'ProductID', '')
                if product_id in ('SHEOP', 'SHAOP'):
                    option_array.append(base_model)
                elif product_id in ('SZA', 'SHA', 'HKA', 'CY'):
                    stock_array.append(base_model)
                elif product_id in ('SZOF', 'SHOF'):
                    structured_fund_array.append(base_model)
                elif product_id in ('SHCB', 'SZCB'):
                    convertible_bond_array.append(base_model)
                elif product_id == 'SHFUNDETF':
                    mmf_fund_array.append(base_model)
            elif 'OnRspQrySFInstrument' in line:
                sf_instrument_array.append(base_model)
    print len(option_array)
    # structured_fund_undl_ticker(sf_instrument_array)
    # add_structured_fund(structured_fund_array)
    add_convertible_bond(convertible_bond_array)  # 新增可转债
    add_option(option_array)  # 新增期权
    add_stock(stock_array)  # 更新股票停牌日期数据和新增股票
    add_mmf_fund(mmf_fund_array)  # 新增货币基金
Exemplo n.º 15
0
def read_position_file_femas(femas_file_path):
    print 'Start read file:' + femas_file_path
    fr = open(femas_file_path)
    order_array = []
    trade_array = []
    trading_account_array = []
    investor_position_array = []
    for line in fr.readlines():
        if 'Account_ID' in line:
            account_id = line.replace('\n', '').split(':')[1]
        else:
            base_model = BaseModel()
            for temp_str in line.split('|')[1].split(','):
                temp_array = temp_str.replace('\n', '').split(':', 1)
                setattr(base_model, temp_array[0].strip(), temp_array[1])
            if 'OnRspQryOrder' in line:
                order_array.append(base_model)
            elif 'OnRspQryTrade' in line:
                trade_array.append(base_model)
            elif 'OnRspQryInvestorAccount' in line:
                trading_account_array.append(base_model)
            elif 'OnRspQryInvestorPosition' in line:
                investor_position_array.append(base_model)

    print 'AccountID:', account_id
    # 删除该账号今日记录
    del_account_position_by_id(account_id)
    del_order_trader_by_id(account_id)

    save_order(account_id, order_array)
    save_trade(account_id, trade_array)
    save_account_cny(account_id, trading_account_array)
    save_account_position(account_id, investor_position_array)

    update_db()
    update_position_prev_net(account_id)
Exemplo n.º 16
0
def read_position_file_ts(ts_file_path):
    print 'Start read file:' + ts_file_path
    fr = open(ts_file_path)
    account_dict = dict()
    position_dict = dict()
    order_dict = dict()

    for line in fr.readlines():
        base_model = BaseModel()
        for tempStr in line.split(','):
            temp_array = tempStr.replace('\n', '').split(':', 1)
            setattr(base_model, temp_array[0].strip(), temp_array[1].strip())
        msg_type = getattr(base_model, 'MSG_TYPE', '')
        account_name = getattr(base_model, 'ACCOUNT_ID', '')

        if msg_type == 'ACCOUNT':
            account_dict[account_name] = base_model
        elif msg_type == 'ORDER':
            if account_name in order_dict:
                order_dict[account_name].append(base_model)
            else:
                order_dict[account_name] = [base_model]
        elif msg_type == 'POSITION':
            if account_name in position_dict:
                position_dict[account_name].append(base_model)
            else:
                position_dict[account_name] = [base_model]

    for account_name in account_dict.keys():
        account_info_db = __get_account_info(account_name)
        account_id = account_info_db.accountid
        print 'AccountID:', account_id

        __del_order_trader_by_id(account_id)

        order_list = []
        trade_list = []
        if account_name in order_dict:
            order_list, trade_list = __build_order_trade(
                account_id, order_dict[account_name])

        # position_info_list = []
        # if len(trade_list) > 0:
        #     position_info_list = __get_position_info_list(account_id)
        #     position_db_list = __calculation_position(account_id, position_info_list, trade_list)
        # else:
        #     __del_account_position_by_id(account_id)
        #     if account_name in position_dict:
        #         position_list = position_dict[account_name]
        #     else:
        #         position_list = []
        #     position_db_list = __build_account_position(account_id, position_list)
        position_info_list = []

        __del_account_position_by_id(account_id)
        if account_name in position_dict:
            position_list = position_dict[account_name]
        else:
            position_list = []
        position_db_list = __build_account_position(account_id, position_list)

        cny_position_db = __get_account_cny(account_id,
                                            account_dict[account_name],
                                            position_info_list)
        position_db_list.append(cny_position_db)

        update_db(order_list, trade_list, position_db_list)
        update_account_trade_restrictions(account_id)
Exemplo n.º 17
0
def file_check(file_path):
    mkt_num = 0
    found_mkt_num = 0
    rebuild_mkt_num = 0
    soft_found_mkt_num = 0
    bid_price1_last = 0
    bid_volume1_last = 0
    offer_price1_last = 0
    offer_volume1_last = 0
    check_date = ''
    order_list = []
    trade_list = []
    unfound_mkt_list = []
    trade_delayed_message_list = []
    rebuild_mkt_dict = dict()

    fr = open(file_path)

    last_found = False
    interval_list = []
    unfound_time_list = []

    for line in fr.readlines():
        if ('CSecurityFtdcL2MarketDataField' in line) or ('Security_Mktdt_L10T' in line):
            item_array = line.split(',')
            mkt_model_content = BaseModel()
            for item in item_array:
                if '=' not in item:
                    if ':' in item:
                        setattr(mkt_model_content, 'Mkt_Time', item)
                    continue
                (key, value) = item.split('=')
                setattr(mkt_model_content, key.strip(), value.strip())

            if 'CSecurityFtdcL2MarketDataField' in line:
                ticker_snapshot = getattr(mkt_model_content, 'InstrumentID')
                mkt_time_snapshot = getattr(mkt_model_content, 'Mkt_Time', '')
                #                 timeStamp_snapshot = getattr(mkt_model_content, 'TimeStamp', '')
                bid_price1_snapshot = getattr(mkt_model_content, 'BidPrice1', '')
                bid_volume1_snapshot = '%.0f' % (float(getattr(mkt_model_content, 'BidVolume1', '')),)
                offer_price1_snapshot = getattr(mkt_model_content, 'OfferPrice1', '')
                offer_volume1_snapshot = '%.0f' % (float(getattr(mkt_model_content, 'OfferVolume1', '')),)

                snapshot_datetime = datetime.datetime.strptime(mkt_time_snapshot, "%Y-%m-%d %H:%M:%S.%f")
                if check_date == '':
                    check_date = snapshot_datetime.strftime('%Y-%m-%d')
                # d2 = datetime.datetime.strptime(check_date + ' 09:30:00.000001', "%Y-%m-%d %H:%M:%S.%f")
                d3 = datetime.datetime.strptime(check_date + ' 14:57:00.000001', "%Y-%m-%d %H:%M:%S.%f")
                # 晚于14:57的不处理
                if compare_date_time(d3, snapshot_datetime):
                    break

                if ticker_snapshot not in rebuild_mkt_dict:
                    continue
                else:
                    dict_value_list = rebuild_mkt_dict.get(ticker_snapshot)
                mkt_num += 1

                fund_flag = False
                bid_found = False
                ask_found = False
                if (last_found and bid_price1_last == bid_price1_snapshot and bid_volume1_last == bid_volume1_snapshot
                        and offer_price1_last == offer_price1_snapshot and offer_volume1_last == offer_volume1_snapshot):
                    fund_flag = True
                else:
                    times = len(dict_value_list)
                    while times > 0:
                        rebuild_mkt_model = dict_value_list[times - 1]
                        mkt_time_rebuild = getattr(rebuild_mkt_model, 'Mkt_Time', '')
                        rebuild_datetime = datetime.datetime.strptime(mkt_time_rebuild, "%Y-%m-%d %H:%M:%S.%f")

                        # ticker = getattr(rebuild_mkt_model, 'InstrumentID', '')
                        # timeStamp = getattr(rebuild_mkt_model, 'TimeStamp', '')
                        bid_price1 = getattr(rebuild_mkt_model, 'BidPrice1', '')
                        bid_volume1 = '%.0f' % (float(getattr(rebuild_mkt_model, 'BidVolume1', '')),)
                        offer_price1 = getattr(rebuild_mkt_model, 'OfferPrice1', '')
                        offer_volume1 = '%.0f' % (float(getattr(rebuild_mkt_model, 'OfferVolume1', '')),)

                        temp_bid_dict = dict()
                        temp_offer_dict = dict()
                        for a in ('1', '2', '3', '4', '5', '6', '7', '8', '9', 'A'):
                            temp_bid_price = getattr(rebuild_mkt_model, 'BidPrice' + a, '')
                            temp_bid_volume = '%.0f' % (float(getattr(rebuild_mkt_model, 'BidVolume' + a, '')),)
                            temp_bid_dict[temp_bid_price] = temp_bid_volume
                            temp_offer_price = getattr(rebuild_mkt_model, 'OfferPrice' + a, '')
                            temp_offer_volume = '%.0f' % (float(getattr(rebuild_mkt_model, 'OfferVolume' + a, '')),)
                            temp_offer_dict[temp_offer_price] = temp_offer_volume

                        if (bid_price1 == bid_price1_snapshot) and (bid_volume1 == bid_volume1_snapshot) \
                                and (offer_price1 == offer_price1_snapshot) and (
                                offer_volume1 == offer_volume1_snapshot):
                            [bid_price1_last, bid_volume1_last, offer_price1_last, offer_volume1_last] = [
                                bid_price1_snapshot, bid_volume1_snapshot, offer_price1_snapshot,
                                offer_volume1_snapshot]
                            last_found = True
                            fund_flag = True
                            interval_list.append((mkt_time_snapshot, mkt_time_rebuild))
                            break
                        elif (bid_price1_snapshot in temp_bid_dict) and (
                                bid_volume1_snapshot == temp_bid_dict[bid_price1_snapshot]):
                            bid_found = True
                        elif (offer_price1_snapshot in temp_offer_dict) and (
                                offer_volume1_snapshot == temp_offer_dict[offer_price1_snapshot]):
                            ask_found = True
                        times -= 1

                        if (snapshot_datetime - rebuild_datetime).seconds > 20:
                            break

                if fund_flag:
                    found_mkt_num += 1
                elif ask_found and bid_found:
                    soft_found_mkt_num += 1
                    unfound_time_list.append('soft found:\n' + line)
                else:
                    last_found = False
                    unfound_time_list.append(line)
                    unfound_mkt_list.append(mkt_model_content)

            elif 'Security_Mktdt_L10T' in line:
                rebuild_mkt_num += 1
                ticker = getattr(mkt_model_content, 'InstrumentID', '')
                if ticker in rebuild_mkt_dict:
                    rebuild_mkt_dict[ticker].append(mkt_model_content)
                else:
                    mkt_model_list = [mkt_model_content]
                    rebuild_mkt_dict[ticker] = mkt_model_list
        elif 'CSecurityFtdcL2OrderField' in line:
            item_array = line.split(',')
            mkt_model_content = BaseModel()
            for item in item_array:
                if '=' not in item:
                    if ':' in item:
                        setattr(mkt_model_content, 'Mkt_Time', item)
                    continue
                (key, value) = item.split('=')
                setattr(mkt_model_content, key.strip(), value.strip())
            order_list.append(mkt_model_content)
        elif 'CSecurityFtdcL2TradeField' in line:
            item_array = line.split(',')
            mkt_model_content = BaseModel()
            for item in item_array:
                if '=' not in item:
                    if ':' in item:
                        setattr(mkt_model_content, 'Mkt_Time', item)
                    continue
                (key, value) = item.split('=')
                setattr(mkt_model_content, key.strip(), value.strip())
            trade_list.append(mkt_model_content)
        elif 'Trade Delayed' in line:
            trade_delayed_message_list.append(line)

    # 未匹配的快照,查询是否有TimeStamp在其之前,但接收时间在其之后的order或trade
    receive_time_error_num = 0
    # 快照往后查找3秒内重建,可匹配的数目
    rebuild_later_num = 0
    delay_matching_list = []

    (rebuild_start_time1, rebuild_start_time2) = get_rebuild_start_time(trade_delayed_message_list)

    # for unfound_mkt_model in unfound_mkt_list:
    #     receive_time_error_flag = False
    #
    #     mkt_time_unfound = datetime.datetime.strptime(getattr(unfound_mkt_model, 'Mkt_Time', ''),
    #                                                   "%Y-%m-%d %H:%M:%S.%f")
    #     check_time_unfound = mkt_time_unfound + datetime.timedelta(seconds=20)
    #     timestamp_unfound = getattr(unfound_mkt_model, 'TimeStamp', '')
    #     # unfound_snapshot_datetime = datetime.datetime.strptime('%s %s' % (check_date, timestamp_unfound),
    #     #                                                        '%Y-%m-%d %H:%M:%S')
    #     ticker = getattr(unfound_mkt_model, 'InstrumentID', '')
    #     bid_price1_snapshot = getattr(unfound_mkt_model, 'BidPrice1', '')
    #     bid_volume1_snapshot = '%.0f' % (float(getattr(unfound_mkt_model, 'BidVolume1', '')),)
    #     offer_price1_snapshot = getattr(unfound_mkt_model, 'OfferPrice1', '')
    #     offer_volume1_snapshot = '%.0f' % (float(getattr(unfound_mkt_model, 'OfferVolume1', '')),)
    #
    #     rebuild_mkt_list = rebuild_mkt_dict.get(ticker)
    #     for rebuild_mkt in rebuild_mkt_list:
    #         rebuild_datetime = datetime.datetime.strptime(getattr(rebuild_mkt, 'Mkt_Time', ''),
    #                                                       "%Y-%m-%d %H:%M:%S.%f")
    #         if (compare_date_time(mkt_time_unfound, rebuild_datetime) == True) and (
    #                     (rebuild_datetime - mkt_time_unfound).seconds > 4):
    #             break
    #         elif compare_date_time(mkt_time_unfound, rebuild_datetime):
    #             # ticker = getattr(rebuild_mkt, 'InstrumentID', '')
    #             # timeStamp = getattr(rebuild_mkt, 'TimeStamp', '')
    #             bid_price1 = getattr(rebuild_mkt, 'BidPrice1', '')
    #             bid_volume1 = '%.0f' % (float(getattr(rebuild_mkt, 'BidVolume1', '')),)
    #             offer_price1 = getattr(rebuild_mkt, 'OfferPrice1', '')
    #             offer_volume1 = '%.0f' % (float(getattr(rebuild_mkt, 'OfferVolume1', '')),)
    #             if (bid_price1 == bid_price1_snapshot) and (bid_volume1 == bid_volume1_snapshot) and (
    #                         offer_price1 == offer_price1_snapshot) and (offer_volume1 == offer_volume1_snapshot):
    #                 delay_matching_message = 'found delay matching---snapshot_datetime:%s rebuild_datetime:%s' % (
    #                     mkt_time_unfound, rebuild_datetime)
    #                 print delay_matching_message
    #                 delay_matching_list.append(delay_matching_message)
    #                 rebuild_later_num += 1
    #                 break
    #
    #     for order_content in order_list:
    #         mkt_time = datetime.datetime.strptime(getattr(order_content, 'Mkt_Time', ''), "%Y-%m-%d %H:%M:%S.%f")
    #         if compare_date_time(mkt_time, mkt_time_unfound):
    #             continue
    #         elif compare_date_time(check_time_unfound, mkt_time):
    #             break
    #
    #         timestamp = getattr(order_content, 'OrderTime', '')
    #         if (timestamp < timestamp_unfound) and (compare_date_time(mkt_time_unfound, mkt_time) == True):
    #             receive_time_error_num += 1
    #             receive_time_error_flag = True
    #             break
    #
    #     if receive_time_error_flag:
    #         continue
    #
    #     for trade_content in trade_list:
    #         mkt_time = datetime.datetime.strptime(getattr(trade_content, 'Mkt_Time', ''), "%Y-%m-%d %H:%M:%S.%f")
    #         if compare_date_time(mkt_time, mkt_time_unfound):
    #             continue
    #         elif compare_date_time(check_time_unfound, mkt_time):
    #             break
    #
    #         timestamp = getattr(trade_content, 'TradeTime', '')
    #         if (timestamp < timestamp_unfound) and compare_date_time(mkt_time_unfound, mkt_time):
    #             receive_time_error_num += 1
    #             break
    return (mkt_num - rebuild_later_num, found_mkt_num, soft_found_mkt_num, receive_time_error_num, rebuild_mkt_num,
            interval_list, unfound_time_list, delay_matching_list, rebuild_start_time1, rebuild_start_time2)