The story of a Serverless cryptocurrency tradingbot
Disclaimer: Statements in this article should not be considered investment advice, which is best sought directly from a qualified professional.
Why create a trading bot?
Removing the emotional part out of trading.
The downside of emotions –rushing and closing out a trade at the worst possible moment; being too greedy and taking on an unreasonable amount of risk, or just watching our overall emotional state shift with the markets.
Having someone watching over my account while I’m away or asleep.
Like any human on the planet, I need sleep. So having a bot watching over my account while I’m away/asleep sounded perfect!
Automate all the things
Typically, bots perform tasks that are both simple and structurally repetitive, at a much higher rate than would be possible for a human alone.
Getting the whole events thingy running
Since I went for a Serverless setup (no long running servers), I needed a way to trigger state changes within my system, also known as a way to trigger a function (AWS Lambda). My immediate idea was to set up an AWS DynamoDB table in order to keep track of Coinbase.com exchange rates. I quickly realized I wanted to make money, not lose money by paying for a “stale” DynamoDB table. Which led to the following architecture:
- A scheduled Lambda function which is triggered by an AWS CloudWatch Rule (every minute) in order to fetch the current exchange rates and storing them as custom AWS CloudWatch Metrics.
- A set of AWS CloudWatch Alarms which signals to a set of AWS SNS Topics.
- A Lambda function which has a subscription towards the SNS Topics and performs the actual buy/sell actions.
Currently, the CloudWatch alarm thresholds are statically defined within a CloudFormation template and is what makes the whole setup work. This, of course, makes the bot a bit of a dummy. On the other hand, it makes sure we stick with our goals to don’t trade with our emotions.
So far the bot is only buying and holding Ethereum when the“Low Buy Price Alarm” is triggered. It already proved to be useful and working since it bought ETH just before the recent Coinbase outages. In the above screenshot, it bought ETH at €200 and right after Coinbase went down around €190. Of course, this had to do with my predefined threshold of €200, if it was lower it would definitely not be able to buy due to the downtimes. In this case, I consider myself “lucky”.
For the next version of this bot, I’m planning to add a percentage threshold (5–10% up-down) which should dynamically update the CloudWatch alarm thresholds based on daily statistics.
The project can be found at https://github.com/nicka/coinboss.
One thing to keep in mind is that a bot is not a magic crystal ball that will make perfect trades every time.
Whether or not you decide to automate your trades, the basic rules apply: Don’t trade more than you can afford to lose and don’t go into any investment without at least a basic understanding of what you’re doing.