Begin a Forex project with python

Our Own Score

In the previous article I have created a Forex application with python with the help from the alpha vantage’s API and in this article, I will create another Forex application and this time I will use the FXCM API to help me to populate the currency pair combo box with majors world currency pairs. If you are new to this website then I just want to let you know that this website is about Finance and Finance software project, I like to write a python program which will help me to gather information about Forex, stock as well as digital currency and thus I am always looking for those websites that provide free financial API which I can use to gather data.

In order to use Fxcm API to create a brand new Forex project, you will need to get an api key from this site by signing up an Fxcm demo account. It is completely free to open an Fxcm demo account which you can practice trading Forex with visual money before you trade with the real money.

The next step you need to do after you have signed up an Fxcm demo account and you have gotten the API key is to install the fxcmpy module on your windows 10 pc (I am using windows 10 os but I think the process of fxcmpy module’s installation for the other os will be about the same as well) with this command on the windows command prompt.

pip install fxcmpy

Once the fxcmpy module has been installed let us create a simple tkinter program which will populate the currency pair combo box after the user has pressed the Find button. We will slowly progress by adding more features into this Forex application but for now, we will just populate the combo box with the available currency pairs from the Fxcm site.

If you run the below program and click on the Find button then a combo box which has been populated by the major currency pairs will appear on the top of the text widget.

import json
from tkinter import *
import tkinter.ttk as tk
import fxcmpy

win = Tk() # Create tk instance
win.title("Real Forex") # Add a title
win.resizable(0, 0) # Disable resizing the GUI
win.configure(background='white') # change window background color

selectorFrame = Frame(win, background="white") # create top frame to hold base and quote currency combobox
selectorFrame.pack(anchor = "nw", pady = 2, padx=10)
currency_label = Label(selectorFrame, text="Select currency pair :", background="white")
currency_label.pack(anchor="w") # the currency pair label

# Create a combo box for currency pair
base_currency = StringVar() # create a string variable
preffered_currency = tk.Combobox(selectorFrame, textvariable=base_currency)

s = StringVar() # create string variable which will be used to fill up the Forex data
# create currency frame and text widget to display the incoming currency exchange rate
currencyFrame = Frame(win)
currency = Label(currencyFrame)
text_widget = Text(currency, fg='white', background='black')
s.set("Click on the find button to get all the available currency pairs")
text_widget.insert(END, s.get())

buttonFrame = Frame(win) # create a bottom frame to hold the find button
buttonFrame.pack(side = BOTTOM, fill=X, pady = 6)

def get_major_currency(): # this method will load the incoming forex data after the api called

        con = fxcmpy.fxcmpy(config_file='fxcm.cfg')
        curr1 = tuple()  # the tuple which will be populated by currency pair
        currency_list = con.get_instruments()  # get the major world currency pairs

        # populate the combo box for all the currency pairs
        for key in currency_list:
            curr1 += (key,)
        preffered_currency['values'] = curr1
        preffered_currency.pack(side=LEFT, padx=3)

        print("An exception occurred")

action_vid = tk.Button(buttonFrame, text="Find", command=get_major_currency) # button used to get the major world currency pair


Like, share or follow me on Twitter. I have decided to continue developing this python currency exchange application and provide you all with the update of this project on this website. So if you like to create financial software and like to talk about those issues such as Stock Market, Forex and Cryptocurrency then do subscribe to this website to read a free daily article.

Hope you like this article and come back for more.


Leave a Reply

Notify of