コード例 #1
0
def add_stock(message_array):
    # print 'hello'
    # print message_array
    global max_instrument_id
    for messageInfo in message_array:
        ticker = getattr(messageInfo, 'InstrumentID', '')
        # print ticker
        exchange_name = getattr(messageInfo, 'ExchangeID', '')
        if exchange_name == 'SSE':
            exchange_id = 18
        elif exchange_name == 'SZE':
            exchange_id = 19
        elif exchange_name == 'HGE':
            exchange_id = 13
        dict_key = '%s|%s' % (ticker, exchange_id)
        # # print instrument_db_dict
        if dict_key in instrument_db_dict:
            continue
        # instrument_name = getattr(messageInfo, 'InstrumentName', '')

        # print "bye"
        stock_db = Instrument()
        max_instrument_id += 1
        stock_db.id = max_instrument_id
        stock_db.ticker = ticker
        stock_db.exchange_id = exchange_id
        stock_db.name = ''

        stock_db.ticker_exch = ticker
        stock_db.ticker_exch_real = ticker
        stock_db.market_status_id = 2
        stock_db.market_sector_id = 4
        stock_db.type_id = 4
        stock_db.crncy = 'CNY'
        stock_db.round_lot_size = 100
        stock_db.tick_size_table = '0:0.01'
        stock_db.fut_val_pt = 1
        stock_db.max_market_order_vol = 0
        stock_db.min_market_order_vol = 0
        stock_db.max_limit_order_vol = 1000000
        stock_db.min_limit_order_vol = 100
        stock_db.longmarginratio = 0
        stock_db.shortmarginratio = 999
        stock_db.longmarginratio_speculation = stock_db.longmarginratio
        stock_db.shortmarginratio_speculation = stock_db.shortmarginratio
        stock_db.longmarginratio_hedge = stock_db.longmarginratio
        stock_db.shortmarginratio_hedge = stock_db.shortmarginratio
        stock_db.longmarginratio_arbitrage = stock_db.longmarginratio
        stock_db.shortmarginratio_arbitrage = stock_db.shortmarginratio
        stock_db.multiplier = 1
        stock_db.strike = 0
        stock_db.is_settle_instantly = 0
        stock_db.is_purchase_to_redemption_instantly = 0
        stock_db.is_buy_to_redpur_instantly = 1
        stock_db.is_redpur_to_sell_instantly = 1
        # print 'hi'
        instrument_insert_list.append(stock_db)
        print 'prepare insert stock:', ticker
コード例 #2
0
def add_mmf_fund(message_array):
    global max_instrument_id
    for messageInfo in message_array:
        # print "good"
        ticker = getattr(messageInfo, 'InstrumentID', '')
        exchange_name = getattr(messageInfo, 'ExchangeID', '')
        if exchange_name == 'SSE':
            exchange_id = 18
        elif exchange_name == 'SZE':
            exchange_id = 19

        dict_key = '%s|%s' % (ticker, exchange_id)
        if dict_key in instrument_db_dict:
            continue

        mmf_fund_db = Instrument()
        max_instrument_id += 1
        mmf_fund_db.id = max_instrument_id
        mmf_fund_db.ticker = ticker
        mmf_fund_db.exchange_id = exchange_id
        mmf_fund_db.name = ''

        mmf_fund_db.fut_val_pt = getattr(messageInfo, 'VolumeMultiple', '')
        mmf_fund_db.multiplier = mmf_fund_db.fut_val_pt
        mmf_fund_db.max_market_order_vol = getattr(messageInfo,
                                                   'MaxMarketOrderVolume', '')
        mmf_fund_db.min_market_order_vol = getattr(messageInfo,
                                                   'MinMarketOrderVolume', '')
        mmf_fund_db.max_limit_order_vol = getattr(messageInfo,
                                                  'MaxLimitOrderVolume', '')
        mmf_fund_db.min_limit_order_vol = getattr(messageInfo,
                                                  'MinLimitOrderVolume', '')

        mmf_fund_db.ticker_exch = ticker
        mmf_fund_db.ticker_exch_real = ticker
        mmf_fund_db.market_status_id = 2
        mmf_fund_db.type_id = 15
        mmf_fund_db.market_sector_id = 4
        mmf_fund_db.round_lot_size = 100
        # price_tick = getattr(messageInfo, 'PriceTick', '')
        mmf_fund_db.tick_size_table = '0:0.001'
        mmf_fund_db.crncy = 'CNY'
        mmf_fund_db.longmarginratio = 0
        mmf_fund_db.shortmarginratio = 999
        mmf_fund_db.longmarginratio_speculation = mmf_fund_db.longmarginratio
        mmf_fund_db.shortmarginratio_speculation = mmf_fund_db.shortmarginratio
        mmf_fund_db.longmarginratio_hedge = mmf_fund_db.longmarginratio
        mmf_fund_db.shortmarginratio_hedge = mmf_fund_db.shortmarginratio
        mmf_fund_db.longmarginratio_arbitrage = mmf_fund_db.longmarginratio
        mmf_fund_db.shortmarginratio_arbitrage = mmf_fund_db.shortmarginratio

        if exchange_name == 'SSE':
            mmf_fund_db.is_settle_instantly = 1
            mmf_fund_db.is_purchase_to_redemption_instantly = 0
            mmf_fund_db.is_buy_to_redpur_instantly = 0
            mmf_fund_db.is_redpur_to_sell_instantly = 0
        elif exchange_name == 'SZE':
            mmf_fund_db.is_settle_instantly = 1
            mmf_fund_db.is_purchase_to_redemption_instantly = 1
            mmf_fund_db.is_buy_to_redpur_instantly = 1
            mmf_fund_db.is_redpur_to_sell_instantly = 1

        instrument_insert_list.append(mmf_fund_db)
        # print instrument_insert_list
        print 'prepare insert etf:', ticker
コード例 #3
0
def add_option(message_array):
    global max_instrument_id
    for messageInfo in message_array:
        ticker = getattr(messageInfo, 'InstrumentID', '')
        exchange_name = getattr(messageInfo, 'ExchangeID', '')
        if exchange_name == 'SSE':
            exchange_id = 18
        elif exchange_name == 'SZE':
            exchange_id = 19

        dict_key = '%s|%s' % (ticker, exchange_id)
        if dict_key in instrument_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', '')
        option_db.strike = getattr(messageInfo, 'ExecPrice', '')

        exchange_inst_id = getattr(messageInfo, 'ExchangeInstID', '')
        undl_tickers = exchange_inst_id[0:6]
        option_db.undl_tickers = undl_tickers
        option_db.track_undl_tickers = undl_tickers
        if 'M' in exchange_inst_id:
            option_db.contract_adjustment = 0
        elif 'A' in exchange_inst_id:
            option_db.contract_adjustment = 1
        elif 'B' in exchange_inst_id:
            option_db.contract_adjustment = 2
        elif 'C' in exchange_inst_id:
            option_db.contract_adjustment = 3

        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('月', 'month') \
            .replace('中国平安', undl_tickers).replace('上汽集团', undl_tickers)
        if 'Call' in instrument_name:
            put_call = 1
        else:
            put_call = 0
        option_db.name = instrument_name
        option_db.put_call = put_call

        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 = 4
        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 = 10000
        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.15
        option_db.option_margin_factor2 = 0.07
        instrument_insert_list.append(option_db)
        # print instrument_insert_list
        print 'prepare insert option:', ticker
コード例 #4
0
def add_structured_fund(message_array):
    global max_instrument_id
    for messageInfo in message_array:
        ticker = getattr(messageInfo, 'InstrumentID', '')

        if ticker not in structured_fund_dict:
            continue
        # print ticker
        exchange_name = getattr(messageInfo, 'ExchangeID', '')

        if exchange_name == 'SSE':
            exchange_id = 18
        elif exchange_name == 'SZE':
            exchange_id = 19
        else:
            print '-------------------', exchange_id
        dict_key = '%s|%s' % (ticker, exchange_id)
        if dict_key in instrument_db_dict:
            continue

        structured_fund_db = Instrument()
        max_instrument_id += 1
        structured_fund_db.id = max_instrument_id
        structured_fund_db.ticker = ticker
        structured_fund_db.exchange_id = exchange_id
        structured_fund_db.name = ''

        undl_ticker_str = ''
        if ticker in undl_ticker_dict:
            undl_ticker_list = undl_ticker_dict[ticker]
            undl_ticker_str = ';'.join(undl_ticker_list)
        structured_fund_db.undl_tickers = undl_ticker_str

        if exchange_id == 18:
            structured_fund_db.is_settle_instantly = 0
            structured_fund_db.is_purchase_to_redemption_instantly = 0
            structured_fund_db.is_buy_to_redpur_instantly = 1
            structured_fund_db.is_redpur_to_sell_instantly = 1
        elif exchange_id == 19:
            structured_fund_db.is_settle_instantly = 0
            structured_fund_db.is_purchase_to_redemption_instantly = 0
            structured_fund_db.is_buy_to_redpur_instantly = 0
            structured_fund_db.is_redpur_to_sell_instantly = 0

        structured_fund_db.ticker_exch = ticker
        structured_fund_db.ticker_exch_real = ticker
        structured_fund_db.market_sector_id = 4
        structured_fund_db.type_id = 16
        structured_fund_db.crncy = 'CNY'
        structured_fund_db.round_lot_size = 100
        structured_fund_db.tick_size_table = '0:0.001'
        structured_fund_db.market_status_id = 2
        structured_fund_db.fut_val_pt = 1
        structured_fund_db.max_limit_order_vol = 1000000
        structured_fund_db.min_limit_order_vol = 100
        structured_fund_db.max_market_order_vol = 0
        structured_fund_db.min_market_order_vol = 0
        structured_fund_db.longmarginratio = 0
        structured_fund_db.shortmarginratio = 999
        structured_fund_db.longmarginratio_speculation = structured_fund_db.longmarginratio
        structured_fund_db.shortmarginratio_speculation = structured_fund_db.shortmarginratio
        structured_fund_db.longmarginratio_hedge = structured_fund_db.longmarginratio
        structured_fund_db.shortmarginratio_hedge = structured_fund_db.shortmarginratio
        structured_fund_db.longmarginratio_arbitrage = structured_fund_db.longmarginratio
        structured_fund_db.shortmarginratio_arbitrage = structured_fund_db.shortmarginratio
        structured_fund_db.multiplier = 1
        instrument_insert_list.append(structured_fund_db)
        # print instrument_insert_list
        print 'prepare insert structured fund:', ticker
コード例 #5
0
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
コード例 #6
0
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