Integrating a Currency Exchange API into your Cloud Native Application

An Overview into Stock Trader’s optional microservice: Cash Account

Celina Chen
4 min readMay 19, 2023

Introduction

Hello! I am Celina Chen, an intern for CJOT (Cloud Journey Optimization Team) at Kyndryl from January 2023 to May 2023. During my internship, I created the microservice Cash Account for the Stock Trader application. Throughout the implementation of Cash Account, I worked on various frameworks and software that were new and unfamiliar to me. I learned quite a lot throughout this journey working with Spring, Redis, and PostgresSQL, none of which I had prior experience in.

Overview

IBM Stock Trader is an application that allows a user to manage portfolios and charge a commission fee for buying/selling stocks. It is made and managed by CJOT. A more in-depth overview can be found here. Cash Account is a new optional microservice that can be enabled via a boolean value in the CR YAML under its stanza.

Cash Account manages the cash account balance for each portfolio and is made entirely in Spring. When creating a portfolio, one can set the initial balance and the currency that the cash account uses (with USD being the default).

In order for Cash Account to work properly with Stock Trader, we also had to make minor changes to Trader, Broker, and Portfolio so that it would be able to interact with the initial portfolio feature and show in the user interface.

Debit & Credit

Alongside the basic CRUD operations, one of Cash Account’s main features is the ability to debit and credit to the cash account from USD to a variety of currencies.

When the cash account has been created, then one can begin to manage stocks with their balance. The stock prices are grabbed from a separate API that returns the stock price in USD, which wouldn’t apply to cash accounts with different currencies. When the transactions debit /credit the balance, then they will both call the same method to grab currency exchange rates. Afterwards, these rates will be utilized to convert the stock price into the corresponding amount in the currency that the cash account uses. We use a currency exchange API that’s updated daily and does not have rate limits.

Alongside the API, Cash Account also uses a Redis cache that stores the exchange rates for a duration of twenty four hours. This helps prevent the service from constantly pinging the API every time we want to convert stock prices for a transaction. This also improves the time it takes the service to debit and credit the cash accounts.

To keep track of cash accounts, the service uses it’s own table named cashaccount . The table stores the account’s owner name, balance amount, and the balance currency. When a portfolio is deleted, broker will also delete the associated cash account row as well.

Future Work

  • JWT Integration— Currently, Cash Account allows all traffic to call it’s REST methods. We plan to integrate JWT to restrict calls to authenticated users.
  • Database Flexibility — Cash Account should be able to work with different kinds of databases. However, it’s currently hardcoded to Postgres in it’s application properties because other microservices, mainly those written in Liberty uses the prefix psql while Spring uses postgresql . The yaml used to deploy Stock Trader’s services uses psql which wouldn’t work with Cash Account.
  • Mainframe Modernization — This microservice was created to be a precursor to an “intregrate with” scenario for mainframe modernization. We also would like to implement a CICS/COBOL version of the same service using MicroFocus in the cloud. Once we can call it in place of the Java iteration, the team will then use BluAge to convert the COBOL to Java. Finally, we will evaluate the differences between the converted Java for Cash Account to the handwritten version.

Summary

While Cash Account was only a part of my internship, I gained invaluable experience by implementing this microservice. Given my lack of professional experience and technical skills, I didn’t expect to achieve much in my role. However, with the help of my coworkers, John and Ryan, I was able to overcome challenges and successfully develop Cash Account. Although there is still work to be done, particularly in the Future Work section, I take pride of what I was able to accomplish. Prior to the internship, I would’ve been hesitant to work with the software mentioned in this article. Now I can confidently integrate relational databases like PostgresSQL and caches like Redis into applications. Furthermore, I can also implement services using the Spring framwork. Lastly, Cash Account’s source code can be found on Github. Feel free to check it out and thanks for reading!

Thank you to John Alcorn for editing this article!

--

--