Get exchange rates from open exchange rates in Python

open exchange rates is a web service that provides an API to get exchange rates. There is a limit of hourly renewal & 1000 cases / month, but we offer a free plan (this limit may be difficult depending on the purpose, but in that case you can use a paid plan or other similar services Let's consider).

Below, I will write how to sign up for a free plan for open exchange rates and call the API from Python to get the rate.

Sign up

Click here for the free plan sign-up page.

https://openexchangerates.org/signup/free

Enter your e-mail address, password, name, and Catpcha numbers, check "Aggreement" and press the "Continue" button. The APP ID will be sent by email.

Get the latest rate

With open exchange rates, you can get the latest rate and the historical rate by specifying the date.

As a test, write a script that displays the latest rate against JPY when you specify the currency.

If you don't have httplib2, put it in with pip install httplib2.

forex.rb


#!/usr/bin/env python`
# -*- coding: utf-8 -*-

import sys
import httplib2
import json

app_id='Put your APP ID here'
api_url='http://openexchangerates.org/api/latest.json?app_id=' + app_id

if __name__ == '__main__':
        client = httplib2.Http()
        response, context = client.request(api_url, "GET")
        rates = json.loads(context)['rates']

        target_currency = sys.argv[1]
        rate = rates['JPY'] * (1.0 / rates[target_currency])
        print target_currency + '/JPY rate is ' + "{0:.2f}".format(rate) + ' now.'

This is all you need to get the minimum rate. It works like this.

[shin@tk2-235-27441 sandbox]$ python forex.py EUR
EUR/JPY rate is 140.02 now.
[shin@tk2-235-27441 sandbox]$ python forex.py AUD
AUD/JPY rate is 96.83 now.
[shin@tk2-235-27441 sandbox]$ python forex.py JPY
JPY/JPY rate is 1.00 now.

Appendix.

What about other services?

There are a number of services that take exchange rates from REST APIs on the Web in the same way. Famous ... or rather, as a provider that seems to be highly reliable

There is a hit. However, the service of a proper provider costs a reasonable usage fee, so it is difficult for individuals to use it.

As a service that I do not know the reliability well but can use for free

There seems to be. I'm not sure where the rate is coming from, and I can't say anything about the continuity of the service, but if you use it for fun, this is fine.

How is the API used?

With the free plan, there is a limit to the number of API calls, but you can see how much you have used from the following page. You can also change your password here.

https://openexchangerates.org/account/usage

Recommended Posts

Get exchange rates from open exchange rates in Python
Get data from Quandl in Python
Get battery level from SwitchBot in Python
Get Precipitation Probability from XML in Python
Get metric history from MLflow in Python
Get date in Python
Get time series data from k-db.com in Python
Get only articles from web pages in Python
Get YouTube Comments in Python
Get last month in python
OCR from PDF in Python
Get data from GPS module at 10Hz in Python
Get Terminal size in Python
Explicitly get EOF in python
Get Evernote notes in Python
Get Japanese synonyms in Python
Get your heart rate from the fitbit API in Python!
Get the value while specifying the default value from dict in Python
Hit REST in Python to get data from New Relic
Get macro constants from C (++) header file (.h) in Python
Get message from first offset with kafka consumer in python
Get Leap Motion data in Python.
Get the desktop path in Python
Open UTF-8 with BOM in Python
Get the script path in Python
Extract text from images in Python
Get, post communication memo in Python
Hash method (open address method) in Python
Get upcoming weather from python weather api
Get the desktop path in Python
Get the host name in Python
Get started with Python in Blender
Extract strings from files in Python
Get the Ticker Symbol for US exchange listed stocks in Python
How to get a string from a command line argument in python
Get additional data in LDAP with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Get Suica balance in Python (using libpafe)
Get keystrokes from / dev / input (python evdev)
Revived from "no internet access" in Python
Prevent double boot from cron in Python
Get Google Fit API data in Python
How to get a stacktrace in python
Get Youtube data in Python using Youtube Data API
Download images from URL list in Python
Get a token for conoha in python
Get Started with TopCoder in Python (2020 Edition)
Generate a class from a string in Python
Generate C language from S-expressions in Python
Get the EDINET code list in Python
Convert from Markdown to HTML in Python
Get Cloud Logging available in Python in 10 minutes
[Python] Get the main color from the screenshot
Get rid of DICOM images in Python
Get your own IP address in Python
How to get a value from a parameter store in lambda (using python)
Get options in Python from both JSON files and command line arguments
Quadtree in Python --2
Python in optimization
Get the contents of git diff from python