If you’re looking forward to using an API to get WTI and Brent crude oil real-time rates, then here we explain to you which is the best way to do it.
Crude oil is and has always been one of the most important commodities in the world. This is because it is a limited resource, which means that it can’t be regenerated naturally, which makes it expensive and high demanded. Since it’s a fossil fuel, it is used for products like gasoline, diesel, and other petrochemicals.
To find out the price of this item, it can be really helpful to use an API, which is an interface that links two websites, computers, or programs, among other things, and allows them to speak with each other. When you submit a request to an API, you get an immediate response in a programming language.
So, if you’re looking for real-time WTI and Brent crude oil rates, here we explain to you how it works.
Where To Get An API
APIs are really easy to find online since there are tons of them. However, not everyone works the same way, which makes the decision of choosing one for your investments really hard. For this example, we will use Commodities-API, since we believe it’s the most complete one and it’s perfect for oil rates.
To use this API you need to:
1. Enter www.commodities-API.com and sign in to get your own API key.
2. Search for the symbols of oil and the currency of your preference. Have in mind that WTI oil and Brent crude oil employ different symbols, so you’ll need to make two API calls to obtain both results.
3. Use these symbols to find the commodity and currency in the list. Once you choose them, make the API call.
4. Search for the spot rates. The website will return you an API in various programming languages that you can adapt and use however you like.
The API answer will look something like this:
{ "success": true, "timestamp": 1519296206, "base": "EUR", "date": "2018-09-10", "rates": { "AUD": 1.566015, "CAD": 1.560132, "CHF": 1.154727, "CNY": 7.827874, "GBP": 0.882047, "JPY": 132.360679, "USD": 1.23396, [...] } }
Is This Information Reliable?
It is! Commodities-API gathers data from banks and stock exchanges and uses it to provide you with the most current and secure data. Furthermore, it employs bank-grade 256-bit SSL encryption to safeguard your connection’s security at all times. Only midpoint data for commodities and currency rates is provided via the API. The midpoint is calculated by calculating the average median rate of Bid and Ask over a certain time period.
Also published on Medium.