Python API for real-time commodity values

Asked

Viewed 1,831 times

1

I need an API that can provide me with real-time commodity prices (more specifically, Arabica Coffee price)

I know practically nothing about the stock market, but I did some research and found that the "symbols" used for the Arabica Coffee are something like NYCC, KC, KCXXX, where 'XXX' would be the month and year of the contract.

I tried to use yahoo-Finance to extract coffee prices but it didn’t work, follow the code below:

from yahoo_finance import Share
coffe = Share('KC')  # I've tried KC, KCN17, NYCC, KFE.
print(coffe.get_price())

The code below was found in the yahoo_finance documentation and works for YHOO, which shows the current Yahoo share price.

I also tried to use the Quandl but I could do practically nothing with it, its documentation is very weak (at least, if it is only what has on the site, really is weak).

What I need is an API that can provide me with real-time data (prices) of the Arabica Coffee quotation (or any commodity, if it works for one, it should work for coffee as well).

To conclude, I don’t need to be told "this code here does what you need," just tell me the tool that the rest I fix.

1 answer

2

Although you asked not to post the code, I did not find a way to explain only verbatim, so I decided to post, even to know if it really works, beyond the fact that it can help other people in other contexts.

I used the API you quoted "Quandl". On their website have the addresses of the datasets, I chose "Coffee C Futures, Continuous Contract #1 (KC1) (Front Month)" to test, below the code. You can see it running in one notebook in anaconda cloud.

import requests
import json

url_coffe_futures = 'https://www.quandl.com/api/v3/datasets/CHRIS/ICE_KC1'
rjson = requests.get(url_coffe_futures).json()

print (rjson['dataset']['name'])
Coffee C Futures, Continuous Contract #1 (KC1) (Front Month)

print (rjson['dataset']['description'])
Historical Futures Prices: Coffee C Futures, Continuous Contract #1. Non-adjusted price based on spot-month continuous contract calculations. Raw data from ICE.

print (rjson['dataset']['column_names'])
['Date', 'Open', 'High', 'Low', 'Settle', 'Change', 'Wave', 'Volume', 'Prev. Day Open Interest', 'EFP Volume', 'EFS Volume', 'Block Volume']

print (rjson['dataset']['data'][0])
['2017-06-02', 128.0, 128.15, 125.25, 125.55, -2.15, 126.78, 22408.0, 96836.0, 455.0, 52.0, None]

DEMO

  • Thank you for the excellent reply, congratulations.

  • Unfortunately the answer above does not offer what I need, I just checked to see if it is working (the bag is open already) but the prices are outdated, so I read about this json it is updated only daily and this is not good for me, would have to be an instant thing, I appreciate the reply and kept the upvote, but I cleared as answered.

  • 1

    @gabrielbelini Ai the "fault" is not of the json itself but of the api (Quandl) what you have to do is discover another api (probably paid) and apply the same solution with the new url.

  • 1

    It seems to me that Quandl itself has a subscription mode (Premium), which may suit what you are looking for. [Search their website. ] (https://www.quandl.com/)

  • Unfortunately Quandl does not offer this service, I emailed them and I’ve been told that they do not do this

  • See the text of these guys, If I don’t see you, it’s gonna be hard. : -) This API offers real time commodity Futures price Quotes from major global commodity Exchanges such as CME, NYMEX, COMEX, CBOT, Euronext Liffe, Eurex and others. In addition to commodity Futures price Quotes, the API also provides options, spot prices, and Contract termination Schedules.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.