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.
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.
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.
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.
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