Currency Exchange Converter

- books

There was a talk at work on using API as the currency converter. I think it’s nice to create one.

Extracting data on currency exchange rates

base_url = "https://api.exchangeratesapi.io/latest"

Sending a GET request

import requests
response = requests.get(base_url)

Investigating the request

response.ok
True
response.status_code
200
response.text
'{"rates":{"CAD":1.5317,"HKD":8.7499,"ISK":157.0,"PHP":55.892,"DKK":7.4522,"HUF":353.62,"CZK":26.681,"AUD":1.6261,"RON":4.8393,"SEK":10.4555,"IDR":16302.76,"INR":84.4645,"BRL":6.0701,"RUB":80.8888,"HRK":7.549,"JPY":121.61,"THB":35.262,"CHF":1.0643,"SGD":1.5751,"PLN":4.4683,"BGN":1.9558,"TRY":7.7508,"CNY":7.9287,"NOK":10.6428,"NZD":1.726,"ZAR":19.2908,"USD":1.129,"MXN":25.4764,"ILS":3.895,"GBP":0.9015,"KRW":1349.06,"MYR":4.8259},"base":"EUR","date":"2020-07-07"}'
response.content
b'{"rates":{"CAD":1.5317,"HKD":8.7499,"ISK":157.0,"PHP":55.892,"DKK":7.4522,"HUF":353.62,"CZK":26.681,"AUD":1.6261,"RON":4.8393,"SEK":10.4555,"IDR":16302.76,"INR":84.4645,"BRL":6.0701,"RUB":80.8888,"HRK":7.549,"JPY":121.61,"THB":35.262,"CHF":1.0643,"SGD":1.5751,"PLN":4.4683,"BGN":1.9558,"TRY":7.7508,"CNY":7.9287,"NOK":10.6428,"NZD":1.726,"ZAR":19.2908,"USD":1.129,"MXN":25.4764,"ILS":3.895,"GBP":0.9015,"KRW":1349.06,"MYR":4.8259},"base":"EUR","date":"2020-07-07"}'

JSON

response.json()
{'rates': {'CAD': 1.5317,
  'HKD': 8.7499,
  'ISK': 157.0,
  'PHP': 55.892,
  'DKK': 7.4522,
  'HUF': 353.62,
  'CZK': 26.681,
  'AUD': 1.6261,
  'RON': 4.8393,
  'SEK': 10.4555,
  'IDR': 16302.76,
  'INR': 84.4645,
  'BRL': 6.0701,
  'RUB': 80.8888,
  'HRK': 7.549,
  'JPY': 121.61,
  'THB': 35.262,
  'CHF': 1.0643,
  'SGD': 1.5751,
  'PLN': 4.4683,
  'BGN': 1.9558,
  'TRY': 7.7508,
  'CNY': 7.9287,
  'NOK': 10.6428,
  'NZD': 1.726,
  'ZAR': 19.2908,
  'USD': 1.129,
  'MXN': 25.4764,
  'ILS': 3.895,
  'GBP': 0.9015,
  'KRW': 1349.06,
  'MYR': 4.8259},
 'base': 'EUR',
 'date': '2020-07-07'}
type(response.json())
dict
import json
json.dumps(response.json(), indent = 4)
'{\n    "rates": {\n        "CAD": 1.5317,\n        "HKD": 8.7499,\n        "ISK": 157.0,\n        "PHP": 55.892,\n        "DKK": 7.4522,\n        "HUF": 353.62,\n        "CZK": 26.681,\n        "AUD": 1.6261,\n        "RON": 4.8393,\n        "SEK": 10.4555,\n        "IDR": 16302.76,\n        "INR": 84.4645,\n        "BRL": 6.0701,\n        "RUB": 80.8888,\n        "HRK": 7.549,\n        "JPY": 121.61,\n        "THB": 35.262,\n        "CHF": 1.0643,\n        "SGD": 1.5751,\n        "PLN": 4.4683,\n        "BGN": 1.9558,\n        "TRY": 7.7508,\n        "CNY": 7.9287,\n        "NOK": 10.6428,\n        "NZD": 1.726,\n        "ZAR": 19.2908,\n        "USD": 1.129,\n        "MXN": 25.4764,\n        "ILS": 3.895,\n        "GBP": 0.9015,\n        "KRW": 1349.06,\n        "MYR": 4.8259\n    },\n    "base": "EUR",\n    "date": "2020-07-07"\n}'
print(json.dumps(response.json(), indent = 4))
{
    "rates": {
        "CAD": 1.5317,
        "HKD": 8.7499,
        "ISK": 157.0,
        "PHP": 55.892,
        "DKK": 7.4522,
        "HUF": 353.62,
        "CZK": 26.681,
        "AUD": 1.6261,
        "RON": 4.8393,
        "SEK": 10.4555,
        "IDR": 16302.76,
        "INR": 84.4645,
        "BRL": 6.0701,
        "RUB": 80.8888,
        "HRK": 7.549,
        "JPY": 121.61,
        "THB": 35.262,
        "CHF": 1.0643,
        "SGD": 1.5751,
        "PLN": 4.4683,
        "BGN": 1.9558,
        "TRY": 7.7508,
        "CNY": 7.9287,
        "NOK": 10.6428,
        "NZD": 1.726,
        "ZAR": 19.2908,
        "USD": 1.129,
        "MXN": 25.4764,
        "ILS": 3.895,
        "GBP": 0.9015,
        "KRW": 1349.06,
        "MYR": 4.8259
    },
    "base": "EUR",
    "date": "2020-07-07"
}
response.json().keys()
dict_keys(['rates', 'base', 'date'])

Incorporating parameters in the GET request

param_url = base_url + "?symbols=USD,GBP"
param_url
'https://api.exchangeratesapi.io/latest?symbols=USD,GBP'
response = requests.get(param_url)
response
<Response [200]>
data = response.json()
data
{'rates': {'USD': 1.129, 'GBP': 0.9015}, 'base': 'EUR', 'date': '2020-07-07'}
data['base']
'EUR'
data['rates']
{'USD': 1.129, 'GBP': 0.9015}
data['date']
'2020-07-07'
param_url = base_url + "?symbols=GBP" + "&" + "base=USD"
param_url
'https://api.exchangeratesapi.io/latest?symbols=GBP&base=USD'
data = requests.get(param_url).json()
data
{'rates': {'GBP': 0.7984942427}, 'base': 'USD', 'date': '2020-07-07'}
usd_to_gbp = data['rates']['GBP']
usd_to_gbp
0.7984942427

Obtaining historical data

base_url = "https://api.exchangeratesapi.io"
historical_url = base_url + "/2016-01-26"
historical_url
'https://api.exchangeratesapi.io/2016-01-26'
response = requests.get(historical_url)
response.status_code
200
data = response.json()
print(json.dumps(data, indent=4))
{
    "rates": {
        "CAD": 1.5411,
        "HKD": 8.4498,
        "SGD": 1.5498,
        "PHP": 52.051,
        "DKK": 7.4622,
        "HUF": 312.73,
        "CZK": 27.021,
        "AUD": 1.555,
        "RON": 4.5348,
        "SEK": 9.2644,
        "IDR": 15004.76,
        "INR": 73.5797,
        "BRL": 4.4465,
        "RUB": 86.7725,
        "HRK": 7.6658,
        "JPY": 128.22,
        "THB": 38.865,
        "CHF": 1.1008,
        "PLN": 4.4942,
        "BGN": 1.9558,
        "TRY": 3.2699,
        "CNY": 7.1314,
        "NOK": 9.4858,
        "NZD": 1.6777,
        "ZAR": 17.8881,
        "USD": 1.0837,
        "MXN": 20.1259,
        "ILS": 4.3084,
        "GBP": 0.76095,
        "KRW": 1303.82,
        "MYR": 4.6335
    },
    "base": "EUR",
    "date": "2016-01-26"
}

Extracting data for a time period

time_period = base_url + "/history" + "?start_at=2017-04-26&end_at=2018-04-26" + "&symbols=GBP"
time_period
'https://api.exchangeratesapi.io/history?start_at=2017-04-26&end_at=2018-04-26&symbols=GBP'
data = requests.get(time_period).json()
#Sort in chronological order
print(json.dumps(data, indent=4, sort_keys=True))
{
    "base": "EUR",
    "end_at": "2018-04-26",
    "rates": {
        "2017-04-26": {
            "GBP": 0.84903
        },
        "2017-04-27": {
            "GBP": 0.8442
        },
        "2017-04-28": {
            "GBP": 0.84473
        },
        "2017-05-02": {
            "GBP": 0.8452
        },
        "2017-05-03": {
            "GBP": 0.8444
        },
        "2017-05-04": {
            "GBP": 0.84765
        },
        "2017-05-05": {
            "GBP": 0.8471
        },
        "2017-05-08": {
            "GBP": 0.84465
        },
        "2017-05-09": {
            "GBP": 0.843
        },
        "2017-05-10": {
            "GBP": 0.83985
        },
        "2017-05-11": {
            "GBP": 0.84485
        },
        "2017-05-12": {
            "GBP": 0.84588
        },
        "2017-05-15": {
            "GBP": 0.84928
        },
        "2017-05-16": {
            "GBP": 0.85868
        },
        "2017-05-17": {
            "GBP": 0.85745
        },
        "2017-05-18": {
            "GBP": 0.85363
        },
        "2017-05-19": {
            "GBP": 0.85908
        },
        "2017-05-22": {
            "GBP": 0.86353
        },
        "2017-05-23": {
            "GBP": 0.86463
        },
        "2017-05-24": {
            "GBP": 0.8634
        },
        "2017-05-25": {
            "GBP": 0.86528
        },
        "2017-05-26": {
            "GBP": 0.8719
        },
        "2017-05-29": {
            "GBP": 0.87093
        },
        "2017-05-30": {
            "GBP": 0.86793
        },
        "2017-05-31": {
            "GBP": 0.87365
        },
        "2017-06-01": {
            "GBP": 0.8723
        },
        "2017-06-02": {
            "GBP": 0.87268
        },
        "2017-06-05": {
            "GBP": 0.8713
        },
        "2017-06-06": {
            "GBP": 0.8723
        },
        "2017-06-07": {
            "GBP": 0.86908
        },
        "2017-06-08": {
            "GBP": 0.86755
        },
        "2017-06-09": {
            "GBP": 0.87638
        },
        "2017-06-12": {
            "GBP": 0.88545
        },
        "2017-06-13": {
            "GBP": 0.88075
        },
        "2017-06-14": {
            "GBP": 0.8796
        },
        "2017-06-15": {
            "GBP": 0.8764
        },
        "2017-06-16": {
            "GBP": 0.87453
        },
        "2017-06-19": {
            "GBP": 0.87518
        },
        "2017-06-20": {
            "GBP": 0.88143
        },
        "2017-06-21": {
            "GBP": 0.8781
        },
        "2017-06-22": {
            "GBP": 0.88168
        },
        "2017-06-23": {
            "GBP": 0.87805
        },
        "2017-06-26": {
            "GBP": 0.8783
        },
        "2017-06-27": {
            "GBP": 0.8837
        },
        "2017-06-28": {
            "GBP": 0.88525
        },
        "2017-06-29": {
            "GBP": 0.8799
        },
        "2017-06-30": {
            "GBP": 0.87933
        },
        "2017-07-03": {
            "GBP": 0.87705
        },
        "2017-07-04": {
            "GBP": 0.87805
        },
        "2017-07-05": {
            "GBP": 0.87735
        },
        "2017-07-06": {
            "GBP": 0.88013
        },
        "2017-07-07": {
            "GBP": 0.88488
        },
        "2017-07-10": {
            "GBP": 0.88443
        },
        "2017-07-11": {
            "GBP": 0.88318
        },
        "2017-07-12": {
            "GBP": 0.88925
        },
        "2017-07-13": {
            "GBP": 0.88215
        },
        "2017-07-14": {
            "GBP": 0.87983
        },
        "2017-07-17": {
            "GBP": 0.87755
        },
        "2017-07-18": {
            "GBP": 0.8878
        },
        "2017-07-19": {
            "GBP": 0.88485
        },
        "2017-07-20": {
            "GBP": 0.88718
        },
        "2017-07-21": {
            "GBP": 0.8961
        },
        "2017-07-24": {
            "GBP": 0.8935
        },
        "2017-07-25": {
            "GBP": 0.89395
        },
        "2017-07-26": {
            "GBP": 0.89275
        },
        "2017-07-27": {
            "GBP": 0.88978
        },
        "2017-07-28": {
            "GBP": 0.89568
        },
        "2017-07-31": {
            "GBP": 0.8942
        },
        "2017-08-01": {
            "GBP": 0.8944
        },
        "2017-08-02": {
            "GBP": 0.89425
        },
        "2017-08-03": {
            "GBP": 0.90318
        },
        "2017-08-04": {
            "GBP": 0.9028
        },
        "2017-08-07": {
            "GBP": 0.90435
        },
        "2017-08-08": {
            "GBP": 0.90678
        },
        "2017-08-09": {
            "GBP": 0.90338
        },
        "2017-08-10": {
            "GBP": 0.90303
        },
        "2017-08-11": {
            "GBP": 0.90645
        },
        "2017-08-14": {
            "GBP": 0.90935
        },
        "2017-08-15": {
            "GBP": 0.91145
        },
        "2017-08-16": {
            "GBP": 0.90993
        },
        "2017-08-17": {
            "GBP": 0.90895
        },
        "2017-08-18": {
            "GBP": 0.91188
        },
        "2017-08-21": {
            "GBP": 0.91318
        },
        "2017-08-22": {
            "GBP": 0.91713
        },
        "2017-08-23": {
            "GBP": 0.92133
        },
        "2017-08-24": {
            "GBP": 0.92
        },
        "2017-08-25": {
            "GBP": 0.92083
        },
        "2017-08-28": {
            "GBP": 0.92328
        },
        "2017-08-29": {
            "GBP": 0.92965
        },
        "2017-08-30": {
            "GBP": 0.92246
        },
        "2017-08-31": {
            "GBP": 0.91973
        },
        "2017-09-01": {
            "GBP": 0.92075
        },
        "2017-09-04": {
            "GBP": 0.91855
        },
        "2017-09-05": {
            "GBP": 0.9174
        },
        "2017-09-06": {
            "GBP": 0.91428
        },
        "2017-09-07": {
            "GBP": 0.91403
        },
        "2017-09-08": {
            "GBP": 0.91268
        },
        "2017-09-11": {
            "GBP": 0.90775
        },
        "2017-09-12": {
            "GBP": 0.89878
        },
        "2017-09-13": {
            "GBP": 0.90243
        },
        "2017-09-14": {
            "GBP": 0.89123
        },
        "2017-09-15": {
            "GBP": 0.88043
        },
        "2017-09-18": {
            "GBP": 0.88253
        },
        "2017-09-19": {
            "GBP": 0.88622
        },
        "2017-09-20": {
            "GBP": 0.8868
        },
        "2017-09-21": {
            "GBP": 0.8824
        },
        "2017-09-22": {
            "GBP": 0.88155
        },
        "2017-09-25": {
            "GBP": 0.87938
        },
        "2017-09-26": {
            "GBP": 0.87775
        },
        "2017-09-27": {
            "GBP": 0.87565
        },
        "2017-09-28": {
            "GBP": 0.87635
        },
        "2017-09-29": {
            "GBP": 0.88178
        },
        "2017-10-02": {
            "GBP": 0.88418
        },
        "2017-10-03": {
            "GBP": 0.88793
        },
        "2017-10-04": {
            "GBP": 0.88768
        },
        "2017-10-05": {
            "GBP": 0.89153
        },
        "2017-10-06": {
            "GBP": 0.89535
        },
        "2017-10-09": {
            "GBP": 0.89195
        },
        "2017-10-10": {
            "GBP": 0.8941
        },
        "2017-10-11": {
            "GBP": 0.8971
        },
        "2017-10-12": {
            "GBP": 0.90235
        },
        "2017-10-13": {
            "GBP": 0.8898
        },
        "2017-10-16": {
            "GBP": 0.88753
        },
        "2017-10-17": {
            "GBP": 0.89148
        },
        "2017-10-18": {
            "GBP": 0.89283
        },
        "2017-10-19": {
            "GBP": 0.89815
        },
        "2017-10-20": {
            "GBP": 0.89623
        },
        "2017-10-23": {
            "GBP": 0.8909
        },
        "2017-10-24": {
            "GBP": 0.89303
        },
        "2017-10-25": {
            "GBP": 0.88883
        },
        "2017-10-26": {
            "GBP": 0.8901
        },
        "2017-10-27": {
            "GBP": 0.88633
        },
        "2017-10-30": {
            "GBP": 0.8798
        },
        "2017-10-31": {
            "GBP": 0.87853
        },
        "2017-11-01": {
            "GBP": 0.87385
        },
        "2017-11-02": {
            "GBP": 0.8869
        },
        "2017-11-03": {
            "GBP": 0.88923
        },
        "2017-11-06": {
            "GBP": 0.8839
        },
        "2017-11-07": {
            "GBP": 0.88038
        },
        "2017-11-08": {
            "GBP": 0.88405
        },
        "2017-11-09": {
            "GBP": 0.88633
        },
        "2017-11-10": {
            "GBP": 0.8837
        },
        "2017-11-13": {
            "GBP": 0.89018
        },
        "2017-11-14": {
            "GBP": 0.89585
        },
        "2017-11-15": {
            "GBP": 0.8991
        },
        "2017-11-16": {
            "GBP": 0.89183
        },
        "2017-11-17": {
            "GBP": 0.89385
        },
        "2017-11-20": {
            "GBP": 0.8894
        },
        "2017-11-21": {
            "GBP": 0.88498
        },
        "2017-11-22": {
            "GBP": 0.8881
        },
        "2017-11-23": {
            "GBP": 0.89005
        },
        "2017-11-24": {
            "GBP": 0.8912
        },
        "2017-11-27": {
            "GBP": 0.89375
        },
        "2017-11-28": {
            "GBP": 0.89538
        },
        "2017-11-29": {
            "GBP": 0.88293
        },
        "2017-11-30": {
            "GBP": 0.87985
        },
        "2017-12-01": {
            "GBP": 0.88115
        },
        "2017-12-04": {
            "GBP": 0.87725
        },
        "2017-12-05": {
            "GBP": 0.88183
        },
        "2017-12-06": {
            "GBP": 0.88335
        },
        "2017-12-07": {
            "GBP": 0.88068
        },
        "2017-12-08": {
            "GBP": 0.87525
        },
        "2017-12-11": {
            "GBP": 0.8825
        },
        "2017-12-12": {
            "GBP": 0.88068
        },
        "2017-12-13": {
            "GBP": 0.87905
        },
        "2017-12-14": {
            "GBP": 0.88163
        },
        "2017-12-15": {
            "GBP": 0.88253
        },
        "2017-12-18": {
            "GBP": 0.88208
        },
        "2017-12-19": {
            "GBP": 0.885
        },
        "2017-12-20": {
            "GBP": 0.8832
        },
        "2017-12-21": {
            "GBP": 0.88763
        },
        "2017-12-22": {
            "GBP": 0.88568
        },
        "2017-12-27": {
            "GBP": 0.88593
        },
        "2017-12-28": {
            "GBP": 0.88768
        },
        "2017-12-29": {
            "GBP": 0.88723
        },
        "2018-01-02": {
            "GBP": 0.88953
        },
        "2018-01-03": {
            "GBP": 0.8864
        },
        "2018-01-04": {
            "GBP": 0.89103
        },
        "2018-01-05": {
            "GBP": 0.88883
        },
        "2018-01-08": {
            "GBP": 0.88413
        },
        "2018-01-09": {
            "GBP": 0.8827
        },
        "2018-01-10": {
            "GBP": 0.8867
        },
        "2018-01-11": {
            "GBP": 0.89075
        },
        "2018-01-12": {
            "GBP": 0.88983
        },
        "2018-01-15": {
            "GBP": 0.89043
        },
        "2018-01-16": {
            "GBP": 0.8886
        },
        "2018-01-17": {
            "GBP": 0.88568
        },
        "2018-01-18": {
            "GBP": 0.88208
        },
        "2018-01-19": {
            "GBP": 0.88365
        },
        "2018-01-22": {
            "GBP": 0.88085
        },
        "2018-01-23": {
            "GBP": 0.8783
        },
        "2018-01-24": {
            "GBP": 0.87183
        },
        "2018-01-25": {
            "GBP": 0.87038
        },
        "2018-01-26": {
            "GBP": 0.87335
        },
        "2018-01-29": {
            "GBP": 0.8794
        },
        "2018-01-30": {
            "GBP": 0.8793
        },
        "2018-01-31": {
            "GBP": 0.8791
        },
        "2018-02-01": {
            "GBP": 0.8752
        },
        "2018-02-02": {
            "GBP": 0.8785
        },
        "2018-02-05": {
            "GBP": 0.88568
        },
        "2018-02-06": {
            "GBP": 0.88885
        },
        "2018-02-07": {
            "GBP": 0.88675
        },
        "2018-02-08": {
            "GBP": 0.87513
        },
        "2018-02-09": {
            "GBP": 0.8874
        },
        "2018-02-12": {
            "GBP": 0.886
        },
        "2018-02-13": {
            "GBP": 0.88935
        },
        "2018-02-14": {
            "GBP": 0.8904
        },
        "2018-02-15": {
            "GBP": 0.8866
        },
        "2018-02-16": {
            "GBP": 0.88803
        },
        "2018-02-19": {
            "GBP": 0.8859
        },
        "2018-02-20": {
            "GBP": 0.88168
        },
        "2018-02-21": {
            "GBP": 0.88463
        },
        "2018-02-22": {
            "GBP": 0.88343
        },
        "2018-02-23": {
            "GBP": 0.8794
        },
        "2018-02-26": {
            "GBP": 0.8782
        },
        "2018-02-27": {
            "GBP": 0.884
        },
        "2018-02-28": {
            "GBP": 0.88415
        },
        "2018-03-01": {
            "GBP": 0.8852
        },
        "2018-03-02": {
            "GBP": 0.8932
        },
        "2018-03-05": {
            "GBP": 0.8907
        },
        "2018-03-06": {
            "GBP": 0.89165
        },
        "2018-03-07": {
            "GBP": 0.89513
        },
        "2018-03-08": {
            "GBP": 0.89465
        },
        "2018-03-09": {
            "GBP": 0.88893
        },
        "2018-03-12": {
            "GBP": 0.8859
        },
        "2018-03-13": {
            "GBP": 0.8865
        },
        "2018-03-14": {
            "GBP": 0.8863
        },
        "2018-03-15": {
            "GBP": 0.8848
        },
        "2018-03-16": {
            "GBP": 0.88253
        },
        "2018-03-19": {
            "GBP": 0.87593
        },
        "2018-03-20": {
            "GBP": 0.87715
        },
        "2018-03-21": {
            "GBP": 0.87403
        },
        "2018-03-22": {
            "GBP": 0.872
        },
        "2018-03-23": {
            "GBP": 0.87285
        },
        "2018-03-26": {
            "GBP": 0.87248
        },
        "2018-03-27": {
            "GBP": 0.8794
        },
        "2018-03-28": {
            "GBP": 0.87605
        },
        "2018-03-29": {
            "GBP": 0.8749
        },
        "2018-04-03": {
            "GBP": 0.87523
        },
        "2018-04-04": {
            "GBP": 0.87573
        },
        "2018-04-05": {
            "GBP": 0.87395
        },
        "2018-04-06": {
            "GBP": 0.87295
        },
        "2018-04-09": {
            "GBP": 0.87088
        },
        "2018-04-10": {
            "GBP": 0.87183
        },
        "2018-04-11": {
            "GBP": 0.8736
        },
        "2018-04-12": {
            "GBP": 0.86745
        },
        "2018-04-13": {
            "GBP": 0.864
        },
        "2018-04-16": {
            "GBP": 0.86465
        },
        "2018-04-17": {
            "GBP": 0.8628
        },
        "2018-04-18": {
            "GBP": 0.87105
        },
        "2018-04-19": {
            "GBP": 0.86975
        },
        "2018-04-20": {
            "GBP": 0.87608
        },
        "2018-04-23": {
            "GBP": 0.8764
        },
        "2018-04-24": {
            "GBP": 0.87468
        },
        "2018-04-25": {
            "GBP": 0.8738
        },
        "2018-04-26": {
            "GBP": 0.871
        }
    },
    "start_at": "2017-04-26"
}

Testing the API response to incorrect input

invalid_url = base_url + "/2019-13-01" + "?base=USB"
response = requests.get(invalid_url)
response.status_code
400
response.json()
{'error': "time data '2019-13-01' does not match format '%Y-%m-%d'"}
response.json()
{'error': "time data '2019-13-01' does not match format '%Y-%m-%d'"}

Creating a simple currency convertor

  1. Gather the parameters of interest
  2. Construct the URL and send a GET request to it
  3. For unsuccesful requests: print the error message
  4. For successful requests: extract the relevant data and calculate the result
  5. Display the result to the user
date = input("Please enter the date (in the format 'yyyy-mm-dd' or 'latest'): ")
base = input("Convert from (currency): ")
curr = input("Convert to (currency): ")
quan = float(input("How much {} do you want to convert: ".format(base)))

url = base_url + "/" + date + "?base=" + base + "&symbols=" + curr
response = requests.get(url)

if(response.ok is False):
    print("\nError {}:".format(response.status_code))
    print(response.json()['error'])
    
else:
    data = response.json()
    rate = data['rates'][curr]
    
    result = quan*rate
    
    print("\n{0} {1} is equal to {2} {3}, based upon exchange rates on {4}".format(quan,base,result,curr,data['date']))
Please enter the date (in the format 'yyyy-mm-dd' or 'latest'): latest
Convert from (currency): USD
Convert to (currency): IDR
How much USD do you want to convert: 21000

21000.0 USD is equal to 303240000.0 IDR, based upon exchange rates on 2020-07-07