Use Python to get stock specified date transaction code data

Source: Internet
Author: User

Securities Bao Www.baostock.com is a free, open-source securities data platform.

Provide a large number of accurate and complete securities historical market data, listed company financial data, real-time securities market push services.
Acquisition of securities data information through the Python API, to meet quantitative trading investors, quantitative financial enthusiasts, metering economic practitioners data needs.

        This introduction interface: Security Code query :query_all_stock ()

(The following code from the official website, invasion and deletion )

Method Description: Query the securities code and stock trading status information information, can be through the parameters ' a trading day ' access to data (including: A-share, index), providing 2014 to date data.

return type: The Dataframe type of pandas.

The sample code is as follows:

IMPORT BAOSTOCK AS BSIMPORT PANDAS AS PD ####  Landing System  ### #lg  = bs.login () #  display login return information print (' Login respond error_code: ' + Lg.error_code) Print (' login respond  error_msg: ' +lg.error_msg) ####  access to securities information  ### #rs   = bs.query_all_stock (day= "2017-06-30") print (' Query_all_stock respond error_code: ' +rs.error_code Print (' query_all_stock respond  error_msg: ' +rs.error_msg) ####  prints the result set  ### #data_list  = []while  (rs.error_code ==  ' 0 ')  & rs.next ():     #   Gets a record that merges records together     data_list.append (Rs.get_row_data ()) result = pd. DataFrame (data_list, columns=rs.fields) ####  result set Output to CSV file  ####   result.to_csv ("D : \\all_stock.csv ",  encoding=" GBK ",  index=false) print (Result) ####  logout system  ### #bs. Logout () 

Parameter meaning:
Day : The date that needs to be queried is the default current date when it is empty.

Return Data Description
parameter name parameter description
code security code
Tradestatus Trading status (1: normal trade 0: suspension)


Sample data (more data, only part of the data is posted):


Use Python to get stock specified date transaction code data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.