The first step after importing the required libraries was to authenticate using the API key (paste it instead of {key}). Then, we selected the API we wanted to use for the recipe – in the case of stock prices, it was SecurityApi.
To download the data, we used the get_security_stock_prices method of the SecurityApi class. The parameters we can specify are as follows:
- identifier: Stock ticker or another acceptable identifier.
- start_date/end_date: This is self-explanatory.
- frequency: Which data frequency is of interest to us (available choices: daily, weekly, monthly, quarterly, or yearly).
- page_size: Defines the number of observations to return on one page; we set it to a high number to collect all data in one request with no need for the next_page token.
The API returns a JSON-like object, which we then transformed into a DataFrame and set the date as an index using the set_index method of a pandas DataFrame.