In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how Python configures the flush Shunquan data interface, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
Go to: http://quantapi.10jqka.com.cn/?page=home
If it is windows, you can choose different downloads according to different users.
1. IFinDPy module
When the download is complete, a DataInterface_free_Windows_20210812.7z file appears and unzipped to any folder. Open this folder and enter the Bin folder, then open the Tool folder, double-click to run SuperCommand.exe, and log in for free using your iFinD account.
Select python and make sure. Add a path at the same time.
Elected. Then restart the computer, and the relevant environment variable settings take effect.
You can now call iFinDPy in the python environment.
II. Related codes
After you install iFinDPy, you can. For more information, please refer to http://quantapi.10jqka.com.cn/?page=sample.
#-*-coding: utf-8-*-from iFinDPy import * from datetimeimport datetimeimport pandas as pdimport time as _ timeimport jsonfrom threading import Thread,Lock,Semaphoreimport requestssem = Semaphore (5) # this variable is used to control the maximum number of concurrency dllock = Lock () # this variable is used to control the lock # login function def thslogindemo (): # enter the user's account number and password thsLogin = THS_iFinDLogin ("data interface _ account") "data interface _ password") print (thsLogin) if thsLogin! = 0: print ('login failed') else: print ('login successful') def datepool_basicdata_demo (): # through the block component function and basic data function of the datapool Data_hs300 = THS_DP ('block',' 2020-11-16) closing price of all stocks withdrew from Shanghai and Shenzhen during 2020-11-16. 001005290, 'date:Y,thscode:Y,security_name:Y') if data_hs300.errorcode! = 0: print (' error: {} '.format (data_hs300.errmsg)) else: seccode_hs300_list = data_hs300.data [' THSCODE'] .tolist () data_result = THS_BD (seccode_hs300_list, 'ths_close_price_stock' '2020-11-16100') if data_result.errorcode! = 0: print (' error: {} '.format (data_result.errmsg)) else: data_df = data_result.data print (data_df) def datapool_realtime_demo (): # through the block component function and real-time quotation function of the data pool Extract the latest price data of all stocks of SSE 50 and export it to the csv file today_str = datetime.today (). Strftime ('% Ymuri% mmurf% d') print ('today: {}' .format (today_str)) data_sz50 = THS_DP ('block',' {}) 001005260'.format (today_str), 'date:Y,thscode:Y,security_name:Y') if data_sz50.errorcode! = 0: print (' error: {} '.format (data_sz50.errmsg)) else: seccode_sz50_list = data_sz50.data [' THSCODE'] .tolist () data_result = THS_RQ (seccode_sz50_list) 'latest') if data_result.errorcode! = 0: print (' error: {} '.format (data_result.errmsg)) else: data_df = data_result.data print (data_df) data_df.to_csv (' realtimedata_ {} .csv '.format (today_str)) def iwencai_demo (): # demonstrate how to communicate Call common data print ('output capital flow data') data_wencai_zjlx = THS_WC ('main capital flow') through natural language statements that do not consume traffic 'stock') if data_wencai_zjlx.errorcode! = 0: print (' error: {} '.format (data_wencai_zjlx.errmsg)) else: print (data_wencai_zjlx.data) print (' output stock score data') data_wencai_xny = THS_WC ('stock score' 'stock') if data_wencai_xny.errorcode! = 0: print (' error: {} '.format (data_wencai_xny.errmsg)) else: print (data_wencai_xny.data) def dlwork (tick_data): # this function subscribes to the task function dllock.acquire () with open (' dlwork.txt') of the newly started thread for real-time subscription 'a') as f: for stock_data in tick_data ['tables']: if' time' in stock_data: timestr = _ time.strftime ('% Y-%m-%d% HV% MV% S') _ time.localtime (stock_data ['time'] [0]) print (timestr) f.write (timestr + str (stock_data) +'\ n') else: pass dllock.release () def work (codestr,lock,indilist): sem.acquire () stockdata = THS_HF (codestr,' '.join (indilist),'', '2020-08-11 09Groupe 1500Gao,' 2020-08-11 1515Groupe 30min Die format JSON') if stockdata.errorcode! = 0: print ('error: {}' .format (stockdata.errmsg)) sem.release () else: print (stockdata.data) lock.acquire () with open ('test1.txt') 'a') as f: f.write (str (stockdata.data) +'\ n') lock.release () sem.release () def multiThread_demo (): # this function is an example of how to use multithreading to accelerate data extraction through high-frequency sequence functions. In this case, all A shares are divided into 100 groups. Maximum number of threads sem for extraction # users can modify today_str = datetime.today (). Strftime ('% Ymuri% MMI% d') print ('today: {}' .format (today_str)) data_alla = THS_DP ('block',' {}) 001005010'.format (today_str), 'date:Y,thscode:Y,security_name:Y') if data_alla.errorcode! = 0: print (' error: {} '.format (data_alla.errmsg)) else: stock_list = data_alla.data [' THSCODE'] .tolist () indi_list = ['close',' high', 'low' 'volume'] lock = Lock () btime = datetime.now () l = [] for eachlist in [stock_ list [I: I + int (len (stock_list) / 10)] for i in range (0, len (stock_list), int (len (stock_list) / 10)]: nowstr =', '.join (eachlist) p = Thread (target=work, args= (nowstr, lock) Indi_list) l.append (p) for p in l: p.start () for p in l: p.join () etime = datetime.now () print (etime-btime) pd.options.display.width = 320pd.options.display.max_columns = Nonedef reportDownload (): df = THS_ReportQuery EndrDate:2021-08-31 ReportType:901','reportDate:Y,thscode:Y,secName:Y,ctime:Y,reportTitle:Y,pdfURL:Y,seq:Y') .data print (df) for i in range (len (df)): pdfName = df.iloc [iMed 4] + str (df.iloc [iMed 6]) + '.pdf' pdfURL = df.iloc [iMed 5] r = requests.get (pdfURL) with open (pdfName) 'wb+') as f: f.write (r.content) def main (): # this script is an example of a common data interface scenario. You can observe the effect by uncommenting the following example function # login function thslogindemo () # through the block component function and basic data function of the datapool Extract the daily closing price of all stocks in Shanghai and Shenzhen from 2020 to 11-16 # datepool_basicdata_demo () # through the plate component function and real-time market function of the data pool Extract the latest price data of all stocks of SSE 50 and export it to csv file # datapool_realtime_demo () # demonstrate how to call common data # iwencai_demo () # through natural language statements that do not consume traffic. This function is an example of how to use high-frequency sequence functions to demonstrate how to use multithreading to accelerate data extraction. Maximum number of threads sem to extract # multiThread_demo () # this function demonstrates how to use the announcement function to extract announcements that meet the conditions And download its pdf # reportDownload () if _ _ name__ ='_ _ main__': main () Thank you for reading this article carefully. I hope the article "how to configure Python with flush data interface" shared by the editor will be helpful to everyone. At the same time, I also hope you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.