def history(stock_code, market=None, bundle_path='~/.rqalpha/bundle'): d = BaseDataSource(os.path.expanduser(bundle_path)) instruments = d._instruments.get_all_instruments() stock_map = {i.order_book_id: i for i in instruments} if not market: market = easyutils.get_stock_type(stock_code) if market == 'sh': stock_code += '.XSHG' else: stock_code += '.XSHE' raw = d._all_day_bars_of(stock_map[stock_code]) df = pd.DataFrame.from_dict(raw) df.set_index('datetime', inplace=True) return df
if not os.path.exists(path_market): os.makedirs(path_market) scu = SCU(path=path) stocks = scu.stock_codes_remove_no_stock_basic() stocks = scu.add_allstock_xshg_xshe(stocks) #rqa.update_bundle() rqalpha_path = "~/.rqalpha" data_bundle_path = os.path.join(os.path.expanduser(rqalpha_path), "bundle") data = BaseDataSource(data_bundle_path) Instru = InstrumentMixin(data._instruments._instruments) for stock_code in stocks: print('procesing...', stock_code) stock_data = pd.DataFrame( data._all_day_bars_of(Instru.instruments(stock_code))) stock_data.datetime = stock_data.datetime.apply( lambda x: datetime.strptime(str(x)[:-6], '%Y%m%d')) stock_data.to_csv(os.path.join(path_market, stock_code[:-5] + '.csv'), index=False) sec_name = [] sec_index = [] for k, v in Instru._sym_id_map.items(): sec_name.append(k) sec_index.append(v) Instru.all_instruments('CS') Instru.instruments('603032.XSHG') Instru.instruments('德新交运')