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
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
pip install fxcmpy
Once the fxcmpy module has been installed let us create a simple
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) currencyFrame.pack(side=TOP) currency = Label(currencyFrame) currency.pack() text_widget = Text(currency, fg='white', background='black') text_widget.pack() 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 try: 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) except: print("An exception occurred") action_vid = tk.Button(buttonFrame, text="Find", command=get_major_currency) # button used to get the major world currency pair action_vid.pack() win.iconbitmap(r'ico.ico') win.mainloop()
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.