Building a Crypto Trading Bot
auto-manage your portfolio with RESTful APIs
--
Last week I built a simple trading algorithm that buys or sells based on temporal AI-generated Bitcoin price predictions. It delivered 9% average returns in 90 days, which was quite fun to see.
However, it was a dreadfully basic implementation, for several reasons:
It didn’t simulate “noise” such as slippage or various exchange fees that a portfolio will face in the real world.
It also, quite importantly, wasn’t the present real world. I’m happy to boast of great success on historical data, but if the bot hasn’t made any real cash as of yet, many would understandably restrain their enthusiasm.
Past behavior is the best predictor of future behavior — right up until it isn’t. That moment can be quite painful for investors who inadvertently run into it, so let’s set about rebuilding a backtesting algorithm into a true trading bot.
There’s two things to take care of before that cute little bot is ready to sail:
- Connect it to an API for output + websocket for input
- Built a more nuanced algorithm
The latter part is quite interesting, and will delve somewhat into economic theory and risk management. But we won’t get anywhere without understanding the data engineering framework, so let’s unpack that here.
Automating your Trading
If you’ve ever invested in a mutual fund, you delegated the process of trading your portfolio to a fund manager who’ll make decisions for you as new data streams in. I would argue that this is a form of automation, not in the least because many of them won’t get you the results you desire.
Most of us would like more control over our portfolios; we’re engaging in carefully-analyzed gambling, after all. But people don’t just guess: they take well-considered risks based on diverse streams of information.
Veteran traders speak in hushed tones of “price signs” and “market crosses”, like weathered sailors discussing patterns in waves, clouds and seagulls that indicate storms ahead.
Most adherents of technical analysis wouldn’t automatically trade simply on such signals…