Back to Blog
by Finage at July 19, 2020 3 MIN READ
Today, we will create a simple currency converter widget for our website. We will use Python and Flask together to build this simple widget. Let’s start.
Firstly, you need to create a folder and a venv folder inside this folder:
$ mkdir currencyconverter $ cd currencyconverter $ python3 -m venv venv
If you are using Windows, then you should use this command
$ py -3 -m venv venv
We will use Python3 for this project but if you want to continue with Python2, you need to use these commands;
$ python2 -m virtualenv venv
After these steps, active your environment;
$ . venv/bin/activate
At least, install the Flask.
$ pip install Flask
I’ll continue with MacOS, if you do not know how to use Flask on Windows. Please visit https://flask.palletsprojects.com/en/1.1.x/quickstart/
I’ll create an app.py and export it;
$ export FLASK_APP=app.py
Then, you should create a folder that named templates. Your architecture will look like this;
/app.py /templates /index.html
app.py and the index.html files will look like this.
and open the browser and go to http://127.0.0.1:5000/convert/gbp/usd/1 , you will see your index.html file here.
If you can see “gbpusd” in the output of this URL, then everything is okay.
Let’s continue. We will use the “Requests” library to make API requests. You can install “requests” with the given command below.
pip install requests
Also, we need to parse the requested JSON data. So, we need to import “json”.
We are ready to make an API request to get latest currency value.
r = req.get('https://api.finage.co.uk/last?currencies='+currency+'&apikey=YOUR_API_KEY')
This line will make an API request. We will get “currency” from the URL and calculate the amount. URL will fill the link that given above and it will look like this.
In this project, we will get the base currency and the second currency from the URL. After that, our application will make an API request to get the latest values from the Finage. Also, we get the amount from the URL. Check the last status of the index.html and app.py below;
If you make a request like http://localhost:5000/convert/usd/gbp/100
You’ll see something like this;
You can check the available currency list from here
If you want to try Finage’s API, you can get your FREE API with the link given below.
Visit Github to access this project.
If you have any questions, please feel free to ask. Also, you can contact with our support team on the live chat section.
The Evolution of High-Frequency Trading Technologies
August 21, 2023
The Role of APIs in Financial Innovation
August 20, 2023
Smart Contracts: Transforming Financial Agreements
August 19, 2023
NFTs and the Art Market: A Financial Perspective
August 18, 2023
The Role of Cryptocurrencies in Global Economics
August 17, 2023
apis for stock
free stock api
Back to Blog
Please note that all data provided under Finage and on this website, including the prices displayed on the ticker and charts pages, are not necessarily real-time or accurate. They are strictly intended for informational purposes and should not be relied upon for investing or trading decisions. Redistribution of the information displayed on or provided by Finage is strictly prohibited. Please be aware that the data types offered are not sourced directly or indirectly from any exchanges, but rather from over-the-counter, peer-to-peer, and market makers. Therefore, the prices may not be accurate and could differ from the actual market prices. We want to emphasize that we are not liable for any trading or investing losses that you may incur. By using the data, charts, or any related information, you accept all responsibility for any risks involved. Finage will not accept any liability for losses or damages arising from the use of our data or related services. By accessing our website or using our services, all users/visitors are deemed to have accepted these conditions.