示例#1
0
 def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast):
     print('OnRspUserLogin:'******'GetTradingDay:', self.GetTradingDay())
         print('ReqQryInstrument')
         requestid = self.get_requestid()
         self.ReqQryInstrument(ApiStruct.Instrument(''), requestid)
     else:
         print('login failed:', pRspInfo.ErrorID)
         sys.exit(-1)
    if col_name in COL_NAME_DB_TYPE_DIC:
        col_type = COL_NAME_DB_TYPE_DIC[col_name]
    else:
        val_type = type(col_value)
        if val_type == bytes:
            col_type = String(20)
        elif val_type == float:
            col_type = Float
        elif val_type == int:
            col_type = Integer
        else:
            raise TypeError('unsupported type of %s' % val_type)
    return col_type


def create_table(metadata, base_struct_obj):
    logger.debug(base_struct_obj.__class__.__name__)
    table_name = base_struct_obj.__class__.__name__
    # [print(col_name, getattr( base_struct_obj, col_name)) for col_name, col_type in base_struct_obj._fields_]
    col_attr = (Column(col_name, get_col_type(getattr(base_struct_obj, col_name), col_name)) for col_name, col_value in base_struct_obj._fields_)
    table_obj = Table(table_name, metadata, *col_attr)


if __name__ == "__main__":
    engine = Config.get_db_engine(Config.DB_SCHEMA_MD)
    metadata = MetaData()
    create_table(metadata, ApiStruct.InputOrderAction())
    create_table(metadata, ApiStruct.DepthMarketData())
    create_table(metadata, ApiStruct.Instrument())
    metadata.create_all(engine)  # 创建表结构
示例#3
0

def create_table(metadata, base_struct_obj, pk_name_set=None):
    logger.debug(base_struct_obj.__class__.__name__)
    table_name = base_struct_obj.__class__.__name__
    # [print(col_name, getattr( base_struct_obj, col_name)) for col_name, col_type in base_struct_obj._fields_]
    col_attr_list = []
    for col_name, col_value in base_struct_obj._fields_:
        col_attr = Column(
            col_name,
            get_col_type(getattr(base_struct_obj, col_name), col_name),
            primary_key=(False if (pk_name_set is None) or
                         (col_name not in pk_name_set) else True),
            autoincrement=False)
        col_attr_list.append(col_attr)
    # col_attr_list = (Column(col_name, get_col_type(getattr(base_struct_obj, col_name), col_name)) for col_name, col_value in base_struct_obj._fields_)
    table_obj = Table(table_name, metadata, *col_attr_list)


if __name__ == "__main__":
    engine = Config.get_db_engine(Config.DB_SCHEMA_MD)
    metadata = MetaData()
    create_table(metadata, ApiStruct.InputOrderAction())
    create_table(
        metadata, ApiStruct.DepthMarketData(),
        {'InstrumentID', 'TradingDay', 'UpdateTime', 'UpdateMillisec'})
    create_table(metadata, ApiStruct.Instrument(), {'InstrumentID'})
    create_table(metadata, ApiStruct.InstrumentCommissionRate(),
                 {'InstrumentID'})
    metadata.create_all(engine)  # 创建表结构