Пример #1
0
    def get_realtime_quotes(self,
                            symbols=None,
                            dataframe=True,
                            loop=None,
                            split=False):
        self.quote = None
        if symbols is None:
            symbols = self.get_symbols()
        if loop is None:
            loop = asyncio.get_event_loop()
        else:
            asyncio.set_event_loop(loop)

        if isinstance(symbols, str):
            symbolList = symbols.split(',')
        else:
            symbolList = list(symbols)
        [symbols_sz, symbols_sh] = util.split_symbols(symbolList)
        symbolListSlice = util.slice_list(step=800, dataList=symbols_sz)
        symbolListSlice.extend(util.slice_list(step=800, dataList=symbols_sh))
        loop.run_until_complete(
            self.get_quote_task(symbolListSlice=symbolListSlice,
                                dataframe=dataframe))
        if dataframe:
            self.quote = self.quote.drop('ms', axis=1)
            self.quote.convert_objects(convert_dates=False,
                                       convert_numeric=True,
                                       convert_timedeltas=False)
        if split:
            quote_sz = self.quote[self.quote.symbol > 'sz']
            quote_sh = self.quote[self.quote.symbol < 'sz']
            return [quote_sz, quote_sh]
        return self.quote
Пример #2
0
    def get_quotation(self,
                      symbol=None,
                      symbolSet=None,
                      dataframe=True,
                      threadNum=3):
        if 'quotation' in self.__dict__.keys():
            del (self.quotation)
            # Cut symbolList
        symbolList = list(symbolSet)
        threads = []
        symbolListSlice = util.slice_list(num=threadNum, dataList=symbolList)
        for symbolList in symbolListSlice:
            loop = asyncio.new_event_loop()
            symbolsList = util.slice_list(step=50, dataList=symbolList)
            tasks = [
                self.get_quotation_task(symbols=symbols)
                for symbols in symbolsList
            ]
            t = threading.Thread(target=util.thread_loop, args=(loop, tasks))
            threads.append(t)
        for t in threads:
            t.start()
        for t in threads:
            t.join()

        if dataframe:
            self.quotation = DataFrame.from_records(self.quotation).T
        return (self.quotation)
Пример #3
0
	def get_realtime_quotes(self, symbols = None, dataframe = True, loop = None, split = False):
		self.quote = None
		if symbols is None:
			symbols = self.symbols
		if loop is None:
			loop = asyncio.get_event_loop()
		else:
			asyncio.set_event_loop(loop)

		if isinstance(symbols, str):
			symbolList = symbols.split(',')
		else:
			symbolList = list(symbols)
		[ symbols_sz, symbols_sh ] = util.split_symbols(symbolList)
		symbolListSlice = util.slice_list(step = 800, data_list = symbols_sz)
		symbolListSlice.extend( util.slice_list(step = 800, data_list = symbols_sh) )
		loop.run_until_complete( self.get_quote_task(symbolListSlice=symbolListSlice, dataframe = dataframe) )
		if dataframe:
			self.quote = self.quote.drop( 'ms', axis = 1 )
			self.quote.convert_objects(convert_dates=False,convert_numeric=True,convert_timedeltas=False)
		if split:
			quote_sz = self.quote[ self.quote.symbol > 'sz' ]
			quote_sh = self.quote[ self.quote.symbol < 'sz' ]
			return [ quote_sz, quote_sh ]
		return self.quote
Пример #4
0
 def get_history_data(self, code, year, season):
     """
     新浪历史复权数据接口
     """
     res = self.session.get(url=URL_HISTORY_DATA(code, year, season))
     if res.status_code == 200:
         pattern_data = r'<div align="center">([\d\.]+)</div>'
         data = re.findall(pattern_data, res.text)
         records = util.slice_list(step=7, data_list=data)
         print(records)
         df = DataFrame.from_records(
             records,
             columns=[
                 'open',
                 'high',
                 'close',
                 'low',
                 'volume',
                 'amount',
                 'restoration_factor'
             ]
         )
         pattern_date = r'date=([\d]{4}-[\d]{2}-[\d]{2})'
         date = re.findall(pattern_date, res.text)
         df["date"] = date
         return df
     else:
         self.logger.debug("Status Code: {}".format(res.status_code))
         return False
Пример #5
0
 def get_history_data(self, code, year, season):
     """
     新浪历史复权数据接口
     """
     res = self.session.get(url=URL_HISTORY_DATA(code, year, season))
     if res.status_code == 200:
         pattern_data = r'<div align="center">([\d\.]+)</div>'
         data = re.findall(pattern_data, res.text)
         records = util.slice_list(step=7, data_list=data)
         print(records)
         df = DataFrame.from_records(
             records,
             columns=[
                 'open',
                 'high',
                 'close',
                 'low',
                 'volume',
                 'amount',
                 'restoration_factor'
             ]
         )
         pattern_date = r'date=([\d]{4}-[\d]{2}-[\d]{2})'
         date = re.findall(pattern_date, res.text)
         df["date"] = date
         return df
     else:
         self.logger.debug("Status Code: {}".format(res.status_code))
         return False
Пример #6
0
	def get_quotation(self, symbol=None, symbolSet=None, dataframe = True, threadNum = 3):
		if 'quotation' in self.__dict__.keys():
			del(self.quotation)
			# Cut symbolList
		symbolList = list(symbolSet)
		threads = []
		symbolListSlice = util.slice_list(num = threadNum,data_list = symbolList)
		for symbolList in symbolListSlice:
			loop = asyncio.new_event_loop()
			symbolsList = util.slice_list(step=50, data_list = symbolList)
			tasks = [self.get_quotation_task(symbols=symbols) for symbols in symbolsList]
			t = threading.Thread(target = util.thread_loop,args=(loop,tasks) )
			threads.append(t)
		for t in threads:
			t.start()
		for t in threads:
			t.join()

		if dataframe:
			self.quotation = DataFrame.from_records( self.quotation ).T
		return(self.quotation)