#!/usr/bin/env python3.5#-*-Coding:utf8-*-ImportTime,osImportAsyncioImportaiohttp#10-File quotesclassLeverfun:stock_api='Https://app.leverfun.com/timelyInfo/timelyOrderForm' def __init__(self): self.stocks_dict=dict ()defstocks (self, stock_codes):ifType (stock_codes) is notList:stock_codes=[Stock_codes] Threads= [] forStockinchstock_codes:threads.append (Self.get_stock_detail (stock))Try: Loop=Asyncio.get_event_loop ()exceptRuntimeerror:loop=Asyncio.new_event_loop () Asyncio.set_event_loop (loop) Loop.run_until_complete (asyncio.wait (Threads )) returnself.stocks_dict AsyncdefGet_stock_detail (Self, stock_code): params= Dict (stockcode=stock_code) Async with Aiohttp.get (LEVERFUN.STOCK_API, params=params) as R:r_json=await R.json () Self.stocks_dict[stock_code]=Leverfun.format_response_data (R_json) @classmethoddefFormat_response_data (CLS, Response_data, * *Kwargs): Data= response_data['Data'] Buys= data['Buypankou'] Sells= data['Sellpankou'] Stock_dict=Dict (Close=round (data['Preclose'], 3), now=data['Match'], buy=buys[0][' Price'], sell=sells[0][' Price'], ) forTrade_info_li, NameinchZip ([sells, buys], ['Ask','Bid']): forI, Trade_infoinchEnumerate (trade_info_li): stock_dict['{Name}{index}'. Format (Name=name, index=i + 1)] = trade_info[' Price'] stock_dict['{Name}{index}_volume'. Format (Name=name, index=i + 1)] = trade_info['Volume'] * 100returnstock_dictif __name__=="__main__": Code="" ifCode = ="": Code= Input ("Please enter the code:") ifCode:#instantiation of 10-file quotesQ =Leverfun () whileTrue:#D_sina = Quotaion_sina (code)D_LF =q.stocks (Code) Os.system ("CLS") MyData="""Pay:%s $10 Price:%s Sell 10:%s Buy 10 Price:%s Buy 10 Volume:%s Sell nine price:%s sell nine:%s buy nine price:%s buy Nine Volume:%s sell eight Price:%s Eight:%s lot Buy eight price:%s buy Eight:%s sell seven price:%s sell seven:%s buy seven price:%s sell seven:%s sell six the price:%s sold at six: the%s buy six price:%s buy six volume:%s sell five: The number of five of the price:%s Buy five price:%s buy five:%s sell four price:%s sell four:%s buy four price:%s buy four volume:%s sell three price:%s sold Three: the%s buy three price:%s buy three:%s Sell Price:%s two Volume:%s Buy two price:%s buy two: %s sell a price:%s sell a quantity:%s buy a price:%s buy a quantity:%s hand"""% (d_lf[code][' Now'],d_lf[code]['Ask10'],d_lf[code]['Ask10_volume']/100,d_lf[code]['BID10'],d_lf[code]['Bid10_volume']/100, d_lf[code]['ASK9'],d_lf[code]['Ask9_volume']/100,d_lf[code]['bid9'],d_lf[code]['Bid9_volume']/100, d_lf[code]['Ask8'],d_lf[code]['Ask8_volume']/100,d_lf[code]['Bid8'],d_lf[code]['Bid8_volume']/100, d_lf[code]['Ask7'],d_lf[code]['Ask7_volume']/100,d_lf[code]['Bid7'],d_lf[code]['Bid7_volume']/100, d_lf[code]['ask6'],d_lf[code]['Ask6_volume']/100,d_lf[code]['Bid6'],d_lf[code]['Bid6_volume']/100, d_lf[code]['Ask5'],d_lf[code]['Ask5_volume']/100,d_lf[code]['BID5'],d_lf[code]['Bid5_volume']/100, d_lf[code]['Ask4'],d_lf[code]['Ask4_volume']/100,d_lf[code]['Bid4'],d_lf[code]['Bid4_volume']/100, d_lf[code]['Ask3'],d_lf[code]['Ask3_volume']/100,d_lf[code]['BID3'],d_lf[code]['Bid3_volume']/100, d_lf[code]['Ask2'],d_lf[code]['Ask2_volume']/100,d_lf[code]['Bid2'],d_lf[code]['Bid2_volume']/100, d_lf[code]['Ask1'],d_lf[code]['Ask1_volume']/100,d_lf[code]['Bid1'],d_lf[code]['Bid1_volume']/100,) Print(MyData) time.sleep (3)
How to query the relevant stock ten-file market