def pre_add_future(message_array): global max_instrument_id for message_info in message_array: ticker = getattr(message_info, 'InstrumentID', '') exchange_name = getattr(message_info, 'ExchangeID', '') if 'CFFEX' == exchange_name: exchange_id = 25 elif 'SHFE' == exchange_name: exchange_id = 20 elif 'DCE' == exchange_name: exchange_id = 21 elif 'CZCE' == exchange_name: exchange_id = 22 else: continue dict_key = '%s|%s' % (ticker, exchange_id) if dict_key in future_db_dict: continue future_db = Instrument() max_instrument_id += 1 future_db.id = max_instrument_id future_db.ticker = ticker future_db.exchange_id = exchange_id future_db.fut_val_pt = getattr(message_info, 'VolumeMultiple', '') future_db.max_market_order_vol = getattr(message_info, 'MaxMarketOrderVolume', '') future_db.min_market_order_vol = getattr(message_info, 'MinMarketOrderVolume', '') future_db.max_limit_order_vol = getattr(message_info, 'MaxLimitOrderVolume', '') future_db.min_limit_order_vol = getattr(message_info, 'MinLimitOrderVolume', '') future_db.longmarginratio = getattr(message_info, 'LongMarginRatio', '') future_db.shortmarginratio = getattr(message_info, 'ShortMarginRatio', '') future_db.longmarginratio_speculation = future_db.longmarginratio future_db.shortmarginratio_speculation = future_db.shortmarginratio future_db.longmarginratio_hedge = future_db.longmarginratio future_db.shortmarginratio_hedge = future_db.shortmarginratio future_db.longmarginratio_arbitrage = future_db.longmarginratio future_db.shortmarginratio_arbitrage = future_db.shortmarginratio future_db.create_date = getattr(message_info, 'CreateDate', '') future_db.expire_date = getattr(message_info, 'ExpireDate', '') future_db.ticker_exch = ticker future_db.ticker_exch_real = ticker future_db.type_id = 1 # future future_db.market_status_id = 2 future_db.multiplier = 1 future_db.crncy = 'CNY' future_db.effective_since = getattr(message_info, 'OpenDate', '') product_id = getattr(message_info, 'ProductID', '') name_message = getattr(message_info, 'InstrumentName', '') price_tick = getattr(message_info, 'PriceTick', '') if (product_id == 'TF') or (product_id == 'T'): future_db.market_sector_id = 5 future_db.round_lot_size = 1 future_db.tick_size_table = '0:%f' % (float(price_tick), ) future_db.undl_tickers = product_id future_db.name = ticker elif (product_id == 'IC') or (product_id == 'IF') or (product_id == 'IH'): future_db.market_sector_id = 6 future_db.round_lot_size = 1 future_db.tick_size_table = '0:%f' % (float(price_tick), ) future_db.longmarginratio_hedge = 0.2 future_db.shortmarginratio_hedge = 0.2 undl_ticker = '' if product_id == 'IF': undl_ticker = 'SHSZ300' elif product_id == 'IC': undl_ticker = 'SH000905' elif product_id == 'IH': undl_ticker = 'SSE50' future_db.undl_tickers = undl_ticker future_db.name = name_message.replace('中证', 'cs').replace('上证', 'SSE').replace('股指', 'IDX') \ .replace('期货', 'Future').replace('国债', 'TF').replace('指数', 'Index').strip() else: future_db.market_sector_id = 1 future_db.round_lot_size = 1 future_db.tick_size_table = '0:%f' % (float(price_tick), ) if product_id == 'cu': expire_date = getattr(message_info, 'ExpireDate', '') if now.strftime('%Y-%m') == expire_date[:7]: future_db.round_lot_size = 5 future_db.undl_tickers = product_id future_db.name = ticker future_db.is_settle_instantly = 1 future_db.is_purchase_to_redemption_instantly = 0 future_db.is_buy_to_redpur_instantly = 0 future_db.is_redpur_to_sell_instantly = 0 ticker_type = filter(lambda x: not x.isdigit(), ticker) future_db.session = __get_trading_info_list(ticker_type)[-1] future_insert_list.append(future_db) # platform_logger.info('prepare insert future:', ticker) print('prepare insert future: %s') % ticker
def pre_add_option(message_array): global max_instrument_id for messageInfo in message_array: ticker = getattr(messageInfo, 'InstrumentID', '') exchange_name = getattr(messageInfo, 'ExchangeID', '') if 'CFFEX' == exchange_name: exchange_id = 25 elif 'SHFE' == exchange_name: exchange_id = 20 elif 'DCE' == exchange_name: exchange_id = 21 elif 'CZCE' == exchange_name: exchange_id = 22 else: continue if ticker in option_db_dict: continue option_db = Instrument() max_instrument_id += 1 option_db.id = max_instrument_id option_db.ticker = ticker option_db.exchange_id = exchange_id option_db.fut_val_pt = getattr(messageInfo, 'VolumeMultiple', '') option_db.max_market_order_vol = getattr(messageInfo, 'MaxMarketOrderVolume', '') option_db.min_market_order_vol = getattr(messageInfo, 'MinMarketOrderVolume', '') option_db.max_limit_order_vol = getattr(messageInfo, 'MaxLimitOrderVolume', '') option_db.min_limit_order_vol = getattr(messageInfo, 'MinLimitOrderVolume', '') undl_tickers = getattr(messageInfo, 'UnderlyingInstrID', '') option_db.undl_tickers = undl_tickers option_db.create_date = getattr(messageInfo, 'CreateDate', '') option_db.expire_date = getattr(messageInfo, 'ExpireDate', '') instrument_name = getattr(messageInfo, 'InstrumentName', '').strip() instrument_name = instrument_name.replace('买权', 'Call').replace( '卖权', 'Put').replace('白糖', 'SR') option_db.name = ticker put_call = __get_put_call(instrument_name) option_db.put_call = put_call if put_call == 0: option_db.strike = ticker.replace('-', '').split('P')[-1] else: option_db.strike = ticker.replace('-', '').split('C')[-1] price_tick = getattr(messageInfo, 'PriceTick', '') option_db.tick_size_table = '0:%s' % (float(price_tick), ) option_db.ticker_exch = ticker option_db.ticker_exch_real = ticker option_db.market_status_id = 2 option_db.type_id = 10 # option option_db.market_sector_id = 1 option_db.round_lot_size = 1 option_db.longmarginratio = 0 option_db.shortmarginratio = 0.15 option_db.longmarginratio_speculation = option_db.longmarginratio option_db.shortmarginratio_speculation = option_db.shortmarginratio option_db.longmarginratio_hedge = option_db.longmarginratio option_db.shortmarginratio_hedge = option_db.shortmarginratio option_db.longmarginratio_arbitrage = option_db.longmarginratio option_db.shortmarginratio_arbitrage = option_db.shortmarginratio option_db.multiplier = 10 option_db.crncy = 'CNY' option_db.effective_since = filter_date_str option_db.is_settle_instantly = 1 option_db.is_purchase_to_redemption_instantly = 0 option_db.is_buy_to_redpur_instantly = 0 option_db.is_redpur_to_sell_instantly = 0 option_db.option_margin_factor1 = 0.5 option_db.option_margin_factor2 = 0.5 ticker_type = filter(lambda x: not x.isdigit(), undl_tickers) option_db.session = __get_trading_info_list(ticker_type)[-1] option_db.track_undl_tickers = __get_track_undl_tickers(ticker_type) option_insert_list.append(option_db) print 'prepare insert option:', ticker