In part 1 of this tutorial series we built a trading bot using an Azure Function. In this 2nd part we will create a simple mobile app to keep track of what our bot is doing. Since it’s still a robot we also want to control it a bit simply to prevent our robot overlords from taking over.
This post will cover a few different topics:
- Adding an iOS mobile app
- Adding HTTP endpoints for our mobile app to gather trade data from
- Adding push notifications to the mobile app
The topic of creating a mobile app is not within the scope of this post although I reference it shortly. The main focus of this post is hooking it up to our bot through Azure Functions.
Creating a mobile app
To create the mobile companion app to the bot I use Xamarin Forms. This is a really simple framework to create cross-platform native apps and suits this project quite well. It’s also what I’m used to using for my app development and if you expected anything else you haven’t been reading this blog ;) This is the mobile app I came up with for this post:
Like I said before I will not be going over how to create a Xamarin app in detail in this post. There are more than enough resources on that available on the web. You’re free to create the mobile app as you see fit. The interesting part here is how we can leverage Azure Functions to retrieve data from our bot and send commands to it.
Getting the data from the bot
The mobile app needs to be able to pull in the trade data of our bot. In the previous post I stored this data in Azure Table Storage so querying it isn’t too complicated. The only thing we need to do is create a few new Azure Functions that use an
HttpTrigger. These Azure Functions basically act as web API endpoints in the cloud that spit out our trade data for the app to use. These functions are only started when people use them so you only pay for the actual usage. This is a great technique for performing simple API-like tasks in the cloud.
We need a few of these for different functionalities in the app that we’re creating:
GETRetrieve our current active trades
GETRetrieve our trade history
GETRetrieve the settings our bot is currently using
POSTDirect sell a trade
POSTRegister our device for push notifications
Source code for all of these is available on the Github page for this bot.
We want to be able to be notified of a trade. This sample will implement push notifications but by abstracting the notification manager into an interface we can plugin different types of notifications. If you want to receive an e-mail or a message in a Telegram chat you can simply implement the
INotificationManager interface and plug it into the trade manager upon initialization :)
By registering our device for push notifications we can receive a notification when we enter or exit a trade and in the case of an exit we can also notify the user of the amount of profit of that trade. To easily implement push notifications we can make use of an Azure component called Notification Hubs. Registering our device becomes as simple as calling an Azure Function:
We have created a companion app for our trade bot. This is our main interface to see what is going on with our trades and it enables us to exercise some form of control over it. Now lets hope our bot gets us some nice profits :) Need more information? You can always leave a comment or ask me on Twitter. As usual the code can be found on Github.