def _Find(self, code_id, code_name='', code_nameEN='', exType="", nReturn=10): if (code_nameEN == ""): code_nameEN = myData_Trans.Tran_ToStr_FirstLetters(code_name, True) length = len(code_id) length_name = len(code_name) length_nameEN = len(code_nameEN) lstR = [] for x in self.lstStock: if (length > 0): if (x.code_id[0:length] == code_id): #等长匹配 if (len(lstR) < nReturn): if (exType == "" or exType == x.extype): lstR.append(x) continue if (length_name > 0): if (x.code_name[0:length_name] == code_name or x.code_name.find(code_name) >= 0): #等长、模糊匹配 if (len(lstR) < nReturn): lstR.append(x) continue if (length_nameEN > 0): if (x.code_name_En[0:length_nameEN] == code_nameEN): #等长匹配 if (len(lstR) < nReturn): lstR.append(x) continue return lstR
def _Find(self, code_id, code_name = '', code_nameEN = '', exType = "", nReturn = 10, useFuzzy = True): if(code_nameEN == ""): code_nameEN = myData_Trans.Tran_ToStr_FirstLetters(code_name, True) if(code_id.count('.') == 1): infos = code_id.split('.'); code_id = infos[1]; exType = infos[0]; length = len(code_id) length_name = len(code_name) length_nameEN = len(code_nameEN) lstR = [] for x in self.lstStock: if(length > 0): if(x.code_id[0: length] == code_id): #等长匹配 if(len(lstR) < nReturn): if(exType == "" or exType == x.extype): lstR.append(x) continue if(length_name > 0): if(x.code_name == code_name or (useFuzzy and x.code_name.find(code_name)>=0)): #等长、模糊匹配 if(len(lstR) < nReturn): lstR.append(x) continue if(length_nameEN > 0): if(x.code_name_En[0: length_nameEN] == code_nameEN): #等长匹配 if(len(lstR) < nReturn): lstR.append(x) continue return lstR
def __init__(self, extype, code, code_name, code_name_En, type="Stock", area="CN", exName="", extype2='', source_set='', source_code=''): self.extype = extype #股票交易所代码: self.extype2 = extype2 #股票交易所代码 self.exName = exName #股票交易所名称 self.code_id = code #股票代码 self.code_name = code_name #股票名称 if (code_name_En == ""): code_name_En = myData_Trans.Tran_ToStr_FirstLetters( code_name, True) self.code_name_En = code_name_En #数据名称首字母 self.source_set = source_set #数据源名称 self.source_code = source_code #数据源对应的代码 self.tradeStatus = 1 #状态(1:正常,0:停牌) self.type = type #数据类型 self.area = area #国家分类 self.isIndex = self.IsIndex() self.CheckInfo()
def _init_Updata(self): #校检最新 bExist = os.path.exists(self.Path_Stock) if (bExist): t = os.path.getmtime(self.Path_Stock) t = time.localtime(t) tNow = time.localtime() if (bExist == False or tNow.tm_year != t.tm_year or tNow.tm_mon != t.tm_mon or tNow.tm_mday != t.tm_mday): #获取标的信息 dataSecurities = self.quoteSource.getSecurities( ['index', 'stock', 'etf']) #循环所有 data_list = [] for indexs in dataSecurities.index: data = dataSecurities.loc[indexs] pDatas = data.name.split('.') pDatas.reverse() pDatas.append(data['display_name']) pDatas.append( myData_Trans.Tran_ToStr_FirstLetters( data['display_name'], True)) pDatas.append(data['type']) pDatas.append('') pDatas.append(exInfos.get(pDatas[0], '未知')) pDatas.append(pDatas[0]) if (pDatas[0] == "XSHE"): pDatas[0] = 'sz' pDatas[5] = 'CN' elif (pDatas[0] == "XSHG"): pDatas[0] = 'sh' pDatas[5] = 'CN' data_list.append(pDatas) # pDatas.append(data['name']) # pDatas.append(data['start_date']) # pDatas.append(data['end_date']) self._Init_Default(data_list) #组合输出结果 result = pd.DataFrame(data_list, columns=self.setFields) result.to_csv(self.Path_Stock, encoding="utf-8", index=False)
def _init_Updata(self): #校检最新 bExist = os.path.exists(self.Path_Stock) if(bExist): t = os.path.getmtime(self.Path_Stock) t = time.localtime(t) tNow = time.localtime() if(bExist == False or tNow.tm_year != t.tm_year or tNow.tm_mon != t.tm_mon or tNow.tm_mday != t.tm_mday): #获取标的信息 dataSecurities = self.quoteSource.getSecurities(['index', 'stock', 'etf']) #循环所有 data_list = [] for indexs in dataSecurities.index: data = dataSecurities.loc[indexs] pDatas = data.name.split('.') pDatas.reverse() pDatas.append(data['display_name']) pDatas.append(myData_Trans.Tran_ToStr_FirstLetters(data['display_name'], True)) pDatas.append(data['type']) pDatas.append('') pDatas.append(exInfos.get(pDatas[0], '未知')) pDatas.append(pDatas[0]) pDatas.append("") pDatas.append("") if(pDatas[0] == "XSHE"): pDatas[0] = 'sz' pDatas[5] = 'CN' elif(pDatas[0] == "XSHG"): pDatas[0] = 'sh' pDatas[5] = 'CN' data_list.append(pDatas) # pDatas.append(data['name']) # pDatas.append(data['start_date']) # pDatas.append(data['end_date']) ''' #期权信息 opts = [] opts_300ETF = self.quoteSource.getOptInfos("510050.XSHG", 12) opts = opts + opts_300ETF for x in opts: pDatas = [] pDatas.append(x['name'].split('.')[1]) pDatas.append(x['name'].split('.')[0]) pDatas.append(x['display_name']) pDatas.append(myData_Trans.Tran_ToStr_FirstLetters(x['display_name'], True)) pDatas.append(x['type']) pDatas.append('') pDatas.append(exInfos.get(pDatas[0], '未知')) pDatas.append(pDatas[0]) pDatas.append("JqDataAPI") pDatas.append(x['name']) if(pDatas[0] == "XSHE"): pDatas[0] = 'sz' pDatas[5] = 'CN' elif(pDatas[0] == "XSHG"): pDatas[0] = 'sh' pDatas[5] = 'CN' data_list.append(pDatas) ''' #期权信息 opts = [] opts_300ETF = self.quoteSource_2.getOptInfos("50ETF", extype = "sh") opts_300ETF = opts_300ETF + self.quoteSource_2.getOptInfos("300ETF", extype = "sh") opts = opts + opts_300ETF for x in opts: pDatas = [] pDatas.append(x['name'].split('.')[1]) pDatas.append(x['name'].split('.')[0]) pDatas.append(x['display_name']) pDatas.append(myData_Trans.Tran_ToStr_FirstLetters(x['display_name'], True)) pDatas.append(x['type']) pDatas.append('CN') pDatas.append(exInfos.get(pDatas[0], '未知')) pDatas.append(x['extype2']) pDatas.append("") pDatas.append(x['source_code']) data_list.append(pDatas) self._Init_Default(data_list) #组合输出结果 result = pd.DataFrame(data_list, columns=self.setFields) result.to_csv(self.Path_Stock, encoding="utf-8", index=False)