What I've learned from building a crypto trading bot

What I've learned from building a crypto trading bot

To the moon! 🚀

Context

Huge Disclaimer: The information in this post is not intended to be and do not constitute financial advice.

Recently, I gave a lot of thought to how to maximise my savings yield after being inspired by FIRE movement (not to be confuse with Fyre Festival) advocates.

I was contemplating on staking a portion of my income in the lottery, in the hopes that it will turn me into a millionaire.

Other alternatives would be robo-advisors or a token sum every month into stocks and shares.

The severity of my headache went up exponentially as I researched about investment options.

It was too much effort for my lazy ass.

By sheer coincidence, I chanced upon Gemini (founded by the famous/infamous Winklevoss twins) and their REST API reference documents.

I connected the dots and had a eureka moment.

REST API + Automated Trading + My Lazy Ass

I had officially embarked on the Bitcoin #FOMO rocketship.

Trading for dummies

Since I had zero to zilch experience in investment strategies and technical analysis, I decided to go with the most idiot-proof approach.

Mean Reversion. What's that?

Basically what mean reversion means (heh) is that asset prices will tend to average out over a time period.

By this technical assumption, if I create a buy order when the price dips past 0.8% and sell when it increases by 0.81% (minus the fees), I would be making a profit! Ka Ching!!

Example scenarios

Scenario 1

Base (USD) Current (USD) Total (USD) Executed (USD) Fees (0.35%) P & L (USD) Side Trades
58,578.20 58,578.20 10.00 10.00 -0.035 0 Buy 1
58,578.20 59,046.83 0 NA -0.035 +0.01 Sell 0

Scenario 2

Base (USD) Current (USD) Total (USD) Executed (USD) Fees (0.35%) P & L (USD) Side Trades
58,578.20 58,578.20 10.00 10.00 -0.035 0 Buy 1
58,343.89 58,109.57 20.00 10.00 -0.035 0 Buy 2
58,109.57 58,810.64 0 NA -0.07 +0.04 Sell 3

Scenario 3

Base (USD) Current (USD) Total (USD) Executed (USD) Fees (0.35%) P & L (USD) Side Trades
58,578.20 58,578.20 10.00 10.00 -0.035 0 Buy 1
58,578.20 59,046.83 0 NA -0.035 +0.01 Sell 2
59,043.05 59,043.05 10.00 10.00 -0.035 0 Buy 3
59,043.05 59,515.39 0 NA -0.035 +0.01 Sell 4

Of course, life is never that straightforward.

Throwing a wrench

There were several factors to consider namely:

  • Initial Capital
    Based on pure speculation and to test my strategy, I started with an initial outlay of USD200. Each market order would be USD10.

  • Slippage
    Due to the volatility of crypto trading, the asset price would have differed by quite a fair bit when the trade is executed. Thankfully Gemini provides a fill-or-kill executing option that fills the entire order immediately or cancels if it doesn't.

  • Trading Fees
    Gemini charges a 0.35% taker fee using the fill-or-kill executing option for orders less than one million. I had to calibrate my selling price threshold to ensure my investments turn into tiny realised profits. Essentially trade_cost(qty) = (2 * qty * taker fee (0.35%)).

  • AWS Fees
    Since I am leveraging AWS services to automate the entire process, my profits would need to cover the running costs.

  • Backtesting Strategy
    What? LOL #YOLO

The setup

Challenge No. 1

Because Lambda functions are stateless, a storage solution was required to record the current price of my crypto assets.

AWS Database services like RDS or Dynamo DB felt like overkill.

I ended up going with Amazon ElastiCache for Redis for its simplicity and ease of use.

Challenge No. 2

Up till this point, the only way to receive updates and monitor my bot's performance was through the Gemini console or via Amazon CloudWatch logs.

Too much effort!

With a little elbow grease, I integrated a simple Telegram bot to receive notifications via Amazon SNS.

Good bot.

How did we fare?

The adage rings true. If it sounds too good to be true, it probably is.

As it turns out, trying to generate a profit using this strategy is harder than it looks.

Firstly, a minimum of one hundred dollars is required for each trade to even move the needle slightly.

I would go broke in a constant downward trend.

Secondly, given the volatility of crypto trading, I was expecting to hit the desired buy/sell target at a faster pace, which is clearly not the case.

Conclusion

At the end of 3 days, I racked up $12.35 for my AWS costs.

This was the profit generated by the bot.

{
    'btc_balance': '0',
    'cash_balance': '200.0129643600000007',
    'buy': '20',
    'sell': '1',
    'profit': '0.0129643600000007'
}
I'm 1 cent richer!

A colleague mentioned recently that the best investment is one that allows you to sleep soundly at night and have time for families and love ones. (paraphrase)

Would I sleep soundly if every order was a hundred beans? Probably not.

Would I be mentally present when I am with my family and loved ones? Probably not.

What would be a good investment then? The old cliché. Invest in yourself.

As for myself, I'll be sticking with Dollar Cost Averaging (DCA) for now.

Apparently, Even God Couldn’t Beat Dollar-Cost Averaging.

Resources

Latest Posts

What I've learned from building a crypto trading botWhat I've learned from building a crypto trading bot
How to set up a basic AWS Virtual Private CloudHow to set up a basic AWS Virtual Private Cloud
Why you should use strict equality 99% of the timeWhy you should use strict equality 99% of the time

Copyright © Terence Lucas Yap

Powered by Gatsby JS