May 2, 2020

Creating A Live Email Alert Bot For Foreign Exchange Rates

By chandan

Real-Life Problem Statement

I have to send money to my parents in India every month since I am living and working here in Indonesia. So I receive my salary in IDR currency and then I had to send it in INR through exchange services in Indonesia such as Topremit.

Now, Before this COVID situation, currency fluctuation was not that volatile so It was not a problem for me to send money anytime I want. But with the COVID situation, the entire market was crashed and IDR-INR rates went up like crazy around 20-30% more than the average rates. I kept looking at the exchange rates daily on google but the problem was when sometimes rate went low I did not notice the rate and missed out on opportunities and when I use to notice again the rate was up again.

Solution

Then, one particular day, I thought let’s automate this problem and get currency rate alerts on email on the particular condition so that I can send my money to India whenever I get an alert on email.

Requirements for achieving this-

1.One Currency Converter API which can tell me rates in INR and IDR.
2.One server or online/cloud service(like Jenkins) which can run our corn in every 30 minutes or so and send an email to the particular email address
3. For easier maintenance, I didn’t want to create any git-repo or code management activity for this, Everything should happen through service used in step 2.

How did I achieve this?

I start looking for an API that can give me results in from IDR to INR and should be free of cost (at least 100 API calls should be free based on my requirement).

I looked at the number of APIs but all of them were either paid or did not have INR as Base Currency. Most of the API were giving results with a base currency like USD or GBP.

Finally, I found one API- https://free.currconv.com/api/v7/ which was giving me results in INR to IDR, All I had to do is generate my access token and then hit their API with to and from currency as params.

Now, I created a Jenkins job with an email ext plugin to send an email to me and in a build step, I used a shell command where I supplied a simple curl command with required details. To receive the only price-related stuff from the API response, I added start and end condition in Jenkins build log by using “${BUILD_LOG_EXCERPT, start=”\b(start-here)\b”, end=”\b(end-here)\b”}” and added this code in email ext body content.

--curl command 
response=$(curl -sb -H "Accept: application/json" "https://free.currconv.com/api/v7/convert?q=INR_IDR&compact=ultra&apiKey=yourkey")
echo "${response}"

And Boom I started receiving email alerts of pricing and sent money to India when I saw the price was right, Having price history in emails, also helped me to see the trend where I can notice at what time of the day. price seems to be the lowest.
Build Trigger Handling-In the cron expression of the build trigger section, I mentioned it to run on every 30 minutes.

That’s how you can create a simple currency exchange alert bot for your money transfer problem and can save 5-10% money every month.

User Question: Why Storing data in emails and not in some excel file or in DB tables.

Answer: Problem with Excel and DB would have been viewing it in iPad or mobile by using email I am seeing alerts when I want to and dumping it also for analysis. Once I have enough data to do analysis, I can easily extract it from emails to CSV using UIpath or java /python mail programs.

User Question: Why not restrict emails by applying some conditions so that server does not send emails every 30 mins.

Answer:48 emails a day is not much load on the server and all these emails go to a very new email account which I created for this purpose only, Filters and conditions will be applied when I have enough data to visualize. Once I see the pattern for 2 months then I can say send alerts when the rate is <195. There is no point in applying filers right now as it may not reach that amount but based on data I can see the lowest rate amount and frequency of this amount between let’s say date 20th-30th. Now I can select a reasonable amount to send email alerts.