How do I download a specific date range using Python?
Note that each data feed on Nasdaq Data Link is delivered through one of the following Nasdaq Data Link APIs:
- Streaming API for real-time data
- REST API for real-time or delayed data
- REST API for time-series
- REST API for tables
You can learn more about these APIs and data formats here.
For the Streaming API for real-time data, note that we only store real-time data from up to 24 hours ago. If you are using the Java SDK and want to download data from a given timestamp, see example 9 here. If you are using the Python SDK and want to download data from a given timestamp, see example 8 here.
For data delivered through the REST API for time-series or tables, there is the Nasdaq Data Link Python package – see details below:
To download data using Python, you first have to download and install the Python package as per the instructions here.
Time-series
To download a specific date range for an individual time-series, use the start_date and end_date parameters, like this:
data = nasdaqdatalink.get("XNAS/ACIW", start_date="2016-01-01", end_date="2016-01-31")
The above command will return data from 2016-01-01 to 2016-01-31 from the XNAS/ACIW time-series because start_date="2016-01-01" and end_date="2016-01-31".
Please note that it is only possible to get data for a specific date range for an individual time-series. The above example returns data for the XNAS/ACIW time-series which is part of the NASDAQ Stock Market Prices data feed. If you wanted to get data for a specific date range for the entire End of Day US Stock Prices data feed (i.e. all tickers), this is not currently possible with our Python package. In this case, we would recommend bulk downloading the entire End of Day US Stock Prices data feed and then filtering by date locally. Instructions for how to do a bulk download are explained in our Python documentation under the section called Download an entire time-series dataset.
To see other parameters for individual time-series, please see the documentation here. To see other examples of Python commands for time-series data, please see here.
Tables
To download a specific date range from a table, you first have to identify which columns you can use as filters for that particular table and if any of those filters are date-related. This is because each table on Nasdaq Data Link uses different filters.You can identify filters for a particular table by reading the Documentation for that table or by making a metadata API call for that table.
Once you've identified which date-related columns you can use as filters, you can download a specific date range by using the .gte and .lte operators with those filters in your Python command. You can learn more about operators here.
For example:
- The Mergent Global Fundamentals (MF1) data feed is in tables format. You can see the product page for this data feed here. As you'll see, there is one data table called Mergent Global Fundamentals with table code MER/F1.
- To identify which columns can be used as filters for the Mergent Global Fundamentals table, go to the product page, click on Documentation at the top. Then, click Column Definitions at the left. That will lead you to this page. From the chart, you'll see that the "reportdate" column is a date filter.
- You can also use a metadata API call like this to identify which columns may be used as filters:
https://data.nasdaq.com/api/v3/datatables/MER/F1/metadata.json?api_key=YOURAPIKEY<br>
data = nasdaqdatalink.get_table('MER/F1', reportdate = { 'gte': '2010-12-31', 'lte': '2015-12-31' })<br>