Yahoo Finance API will need three mandatory arguments in this order:
- Tickers (1)
- Start date + End date or Period (2)
- Interval (3)
For our case, the ticker(argument 1) will be the pair BTC-USD. Furthermore, we are going to choose for this example to select the 22 last hours as a period(argument 2). And set up an interval(argument 3) of 15 minutes.
To call your data, you will have to use the following structure:
Before going further, I will bring some details on the third argument (interval).
A quick lookup on interval
I want to give you a quick shot on the different interval you can set up using yahoo finance API.
Detailed below the full list of interval possibilities which can be required:
Now that we have defined our three arguments, let’s execute the query and check the output.
Let’s pursue a live test.
When I am executing the line below, we are the 15th of January 2021, and it is 5:40 PM in London. Let’s see how the API respond and if yahoo finance can bring us the latest values.
For your information: 5:40 PM UK time correspond to 12:47 PM New York time.
Now, that we have defined our three arguments, let’s execute the line of code below:
For a recap, the line of code above is calling Yahoo finance API and requesting to get data for the last 22 hours, with an interval of 15 minutes.
And here is the output:
The price has been updated instantly; I compared the data with the current values, on official websites and we matching.
As you can see, you have an update released each second. For instance, if you look at the output above, the latest data provided are given for 5:40 PM and 03 seconds. If you re-run your kernel, the data will be updated again.
Below you can get a 10 minutes tutorial video on how to get cryptocurrency data with further explanation and test it by yourselves at home:
And here the final output using Python and Plotly:
I hope you enjoy the content and if you have any comment or want further details, feel free to let me know in the comment section.