Python API to get real-time commodity values

0

I need an API that can provide real-time commodity prices (more specifically, Arabica coffee prices)

I know almost nothing about the stock market, but I did a little research and found that the "symbols" used for 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 did not 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 Quandl but I could not do practically anything with it, its documentation is very weak (at least, if it is only what you have on the site, it really is weak).

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

In conclusion, I do not need to be told "this code here does what you need", just let me know the tool that the rest I'll find.

    
asked by anonymous 04.06.2017 / 02:44

1 answer

1

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

I used the API that you quoted "Quandl". In their website they have the addresses of the datasets, I chose the "Coffee C Futures, Continuous Contract # 1 (KC1) (Front Month)" to do the test, below the code. You can see it working on a notebook on 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

    
04.06.2017 / 15:14