コード例 #1
0
    def get_quote(self, symbols, dataframe=True):
        if isinstance(symbols, list) or isinstance(symbols, set) or isinstance(
                symbols, tuple):
            symbolList = list(symbols)
        elif isinstance(symbols, str):
            symbolList = symbols.split(',')
        symbols = util.symbols_to_string(symbols)
        url = URL_QUOTATION(symbols)
        retry = True
        while retry:
            try:
                quote = self.session.get(URL_QUOTATION(symbols),
                                         timeout=0.1).text
                retry = False
            except:
                pass
        quoteList = re.findall(r'\"(.*)\"', quote)
        if dataframe:
            for i in range(0, len(quoteList)):
                quoteList[i] = quoteList[i].split(',')
        else:
            for i in range(0, len(quoteList)):
                quoteList[i] = quoteList[i].split(',')
                quoteList[i].append(symbolList[i])

        if dataframe:
            df_quote = DataFrame(quoteList, columns=SINA_QUOTE_COLUMNS)
            df_quote = df_quote.drop('ms', axis=1)
            df_quote["symbol"] = symbolList
            return df_quote
        else:
            return quoteList
コード例 #2
0
    def get_quote_coroutine(self, symbols, dataframe):
        loop = asyncio.get_event_loop()
        if isinstance(symbols, list) or isinstance(symbols, set) or isinstance(
                symbols, tuple):
            symbolList = list(symbols)
        elif isinstance(symbols, str):
            symbolList = symbols.split(',')
        symbols = util.symbols_to_string(symbols)
        url = URL_QUOTATION(symbols)

        retry = True
        while retry:
            try:
                async_req = loop.run_in_executor(
                    None,
                    functools.partial(self.session.get,
                                      URL_QUOTATION(symbols),
                                      timeout=0.1))
                quote = yield from async_req
                retry = False
            except:
                pass
        quote = quote.text
        quote = re.findall(r'\"(.*)\"', quote)

        for i in range(0, len(quote)):
            quote[i] = quote[i].split(',')

        if dataframe:
            quote = DataFrame(quote, columns=SINA_QUOTE_COLUMNS)
            quote["symbol"] = symbolList
            quote["time"] = datetime.strptime(
                quote.iloc[0]["date"] + " " + quote.iloc[0]["time"],
                '%Y-%m-%d %H:%M:%S')
        return quote
コード例 #3
0
 def get_quotation_task(self, symbols):
     symbols = util.symbols_to_string(symbols)
     quotation = yield from self.fetch_quotation_coroutine(symbols=symbols)
     if 'quotation' not in self.__dict__.keys():
         self.quotation = quotation
     else:
         self.quotation.update(quotation)
コード例 #4
0
ファイル: XueqiuVendor.py プロジェクト: TanGy886/dHydra
	def get_quotation_task(self, symbols):
		symbols = util.symbols_to_string(symbols)
		quotation = yield from self.fetch_quotation_coroutine(symbols = symbols)
		if 'quotation' not in self.__dict__.keys():
			self.quotation = quotation
		else:
			self.quotation.update( quotation )
コード例 #5
0
ファイル: SinaVendor.py プロジェクト: EnjoyWall/dHydra
	def get_quote(self, symbols, dataframe = True):
		if isinstance(symbols, list) or isinstance(symbols, set) or isinstance(symbols, tuple):
			symbolList = list(symbols)
		elif isinstance(symbols, str):
			symbolList = symbols.split(',')
		symbols = util.symbols_to_string(symbols)
		url = URL_QUOTATION(symbols)
		retry = True
		while retry:
			try:
				quote  =self.session.get(
						URL_QUOTATION(symbols)
					,	timeout = 0.1
					).text
				retry = False
			except:
				pass
		quoteList = re.findall(r'\"(.*)\"', quote)
		if dataframe:
			for i in range( 0, len(quoteList) ):
				quoteList[i] = quoteList[i].split(',')
		else:
			for i in range( 0, len(quoteList) ):
				quoteList[i] = quoteList[i].split(',')
				quoteList[i].append( symbolList[i] )

		if dataframe:
			df_quote = DataFrame( quoteList, columns = SINA_QUOTE_COLUMNS )
			df_quote = df_quote.drop( 'ms', axis = 1 )
			df_quote["symbol"] = symbolList
			return df_quote
		else:
			return quoteList
コード例 #6
0
ファイル: SinaVendor.py プロジェクト: EnjoyWall/dHydra
	def get_quote_coroutine(self, symbols, dataframe):
		loop = asyncio.get_event_loop()
		if isinstance(symbols, list) or isinstance(symbols, set) or isinstance(symbols, tuple):
			symbolList = list(symbols)
		elif isinstance(symbols, str):
			symbolList = symbols.split(',')
		symbols = util.symbols_to_string(symbols)
		url = URL_QUOTATION(symbols)

		retry = True
		while retry:
			try:
				async_req = loop.run_in_executor(None, functools.partial( self.session.get
				,	URL_QUOTATION(symbols)
				,	timeout = 0.1
				) )
				quote = yield from async_req
				retry = False
			except:
				pass
		quote = quote.text
		quote = re.findall(r'\"(.*)\"', quote)

		for i in range( 0, len(quote) ):
			quote[i] = quote[i].split(',')

		if dataframe:
			quote = DataFrame( quote, columns = SINA_QUOTE_COLUMNS )
			quote["symbol"] = symbolList
			quote["time"] = datetime.strptime( quote.iloc[0]["date"] + " " + quote.iloc[0]["time"] , '%Y-%m-%d %H:%M:%S')
		return quote