Back to Blog
by Finage at July 19, 2020 3 MIN READ
Stocks
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.
HTTPS://GITHUB.COM/FINAGELTD/FINAGE-EXAMPLE-WIDGET
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
for Windows;
\Python27\Scripts\virtualenv.exe venv
After these steps, active your environment;
$ . venv/bin/activate
for Windows;
> venv\Scripts\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.
Run,
flask run
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”.
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.
https://api.finage.co.uk/last?currencies=USDGBP&apikey=YOUR_API_KEY
Response
{"currencies":[{"name":"GBPUSD","value":1.29303,"change":0.0053,"difference":0.41}],"lastUpdate":"2020-07-28T20:31:34","lastUpdate_Timestamp":"1595968294"}
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
https://docs.finage.co.uk/#/symbols/
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.
https://github.com/FinageLTD/finage-example-widget
If you have any questions, please feel free to ask. Also, you can contact with our support team on the live chat section.
Featured Posts
How to Use WebSocket for Real-Time Financial Data: Benefits and Implementation Guide
September 16, 2024
Predicting Market Trends Using Quantum Finance
September 15, 2024
Cryptoeconomics: the Science Behind Crypto Market Trends
September 14, 2024
Building Fintech Applications with Free Financial Data APIs: What You Need to Know
September 13, 2024
Impact of Deepfake Technology on Financial Markets
September 12, 2024
Categories
Forex
Finage Updates
Stocks
Real-Time Data
Finage News
Crypto
ETFs
Indices
Technical Guides
Financial Statements
Excel Plugin
Web3
Tags
flask
phyton
Stock API
apis for stock
finage api
free stock api
Join Us
You can test all data feeds today!
Start Free Trial
If you need more information about data feeds, feel free to ask our team.
Request Consultation
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.