def get_index_stock(index_symbol, return_list=True): # 连接本地终端时,td_addr为localhost:8001, if (td.init('*****@*****.**', 'zyj2590@1109', 'strategy_1') == 0): try: stock_list = "" css = md.get_constituents(index_symbol) if return_list: stock_list = [cs.symbol for cs in css] else: for cs in css: stock_list += "," + cs.symbol return stock_list[1:] except: pass
print('get_last_dailybars: ', len(r)) #提取最新N笔dailybar数据 r = md.get_last_n_dailybars('SHSE.600000', 10) print('get_last_n_dailybars(10): ', len(r)) #提取交易代码 r = md.get_instruments('SHSE', 1, 1) print('get_instruments: ', len(r)) #根据期货品种提取交易代码 r = md.get_instruments_by_name('ag') print('get_instruments_by_name', len(r)) #提取指数的成分股代码 r = md.get_constituents('SHSE.000001') print('get_constituents', len(r)) #按时间周期提取FinancialIndex r = md.get_financial_index('SHSE.600000', '2010-12-01 09:30:00', '2016-01-08 12:00:00') print('get_financial_index', len(r)) #提取快照, 即最新的FinancialIndex r = md.get_last_financial_index('SHSE.600000,SZSE.000001') print('get_last_financial_index', len(r)) #提取最近n条FinancialIndex r = md.get_last_n_financial_index('SHSE.600000', 5) print('get_last_n_financial_index', len(r)) #按时间周期提取ShareIndex
def get_constituents(index_symbol):#指数权重 var = md.get_constituents(index_symbol) return to_pd(var,'symbol')
def get_constituents(index_symbol): # 指数权重 var = md.get_constituents(index_symbol) return to_pd(var, 'symbol')