How I Spent a Month Building a Cryptocurrency Trading Platform
Tags: programming
Published: 2023-06-12 15:10:23

---
title: How I Spent a Month Building a Cryptocurrency Trading Platform
published: true
date: 2023-06-11 19:05:00 UTC
tags: programming
canonical_url: https://www.stephanmiller.com/i-built-a-cryptocurrency-trading-bot/
---
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6u26x38a3flh958nc8c7.png)

I have always been interested in statistics and machine learning. Boring, you say. Yeah, I like it when that is most peoples’ opinion. It leaves more for me.

These tools give me an edge at predicting things. What things? I always think of things like the stock market, NFL games, and horse races. Things you can bet on. If software can do it for me and do it smarter than I am all about it.

## How I won a bunch of cryptocurrency

When I first heard of cryptocurrency, I thought it was a neat idea, but I would not put my money in it. Then I entered a stock trading contest and won some. I didn’t check the wallet for 6 months because I didn’t even know how to use it.

But when I did, it was worth five figures in US dollars. So I opened a Coinbase account and tested cashing some out. It worked! It was real. The cryptocurrency bug bit me, but manual trading was too slow. I wanted to find a trading bot to trade for me.

## Open source cryptocurrency trading bots were lacking

This was at the end of 2017, when Bitcoin had just hit 20k for the first time. I had done some investigation and knew some features I wanted.

- I wanted to do back-testing, so I could test a trading strategy on historical cryptocurrency prices.
- I wanted it to use the [ccxt](https://github.com/ccxt/ccxt) library, because it covered the most exchanges. If a bot didn’t use this, chances are the developer spent a lot of time writing this functionality instead of other necessary features. I also wanted to try arbitrage and the more exchanges I could connect to, the more arbitrage I could do.
- I wanted it to be in a programming language I knew.

There were a few other things I was looking for, but after looking through Github repos for hours, I settled for the list above.

## I forked the best cryptocurrency trading bot I could find

A trading bot is usually a full application, not a library you can add to a project. I knew I would end up forking and modifying a project at some point. The Github project that fit the bill at the time was [Titan](https://github.com/exdx/Titan). It checked all the marks on my list, plus it used [threads in Python](https://github.com/exdx/Titan/wiki), so I saw that I could probably break apart parts of the application to make it quicker and handle a bigger load.

## The next month went by in a blur

The cryptocurrency market was going strong, and I wanted to get this running. So I worked on it with every spare minute I had and my list of features to add to my fork, which I called [KryptoBot](https://github.com/eristoddle/KryptoBot), grew. It looked something like this:

- Simpler configuration so I could deploy to multiple servers
- SQL Alchemy so I could use models and interchangeable data sources
- Arbitrage ability
- [Engima catalyst](https://www.enigma.co/catalyst/) models (my second choice to fork)
- Bot integration (I thought I could have a Telegram bot to give me signals and I could reply with a trade.)
- Add (TA-lib)[https://mrjbq7.github.io/ta-lib/] to the project so I could have access to just about every indicator known to man
- Distribute the application somehow

I did all of this in a month while working a full-time job. One of the first things I did was add Jupyter to the project so I could test things quickly and [print charts of my strategies](https://github.com/eristoddle/KryptoBot/blob/master/notebooks/t2_strategies.ipynb).

I learned how threading in Python worked for the first time, even though I had written code in the language for about a decade. I also broke the application up into workers using Docker and [Celery](https://docs.celeryproject.org/en/stable/getting-started/introduction.html).

I pushed it a little too far at the end, when I had the application launch over 100 back-tests at the same time with slightly different parameters and then tried to compare the results to find the best strategy. I somehow had met my match and lost track of the threads.

But everything else went smoothly other than that. It surprised me. I had a working, if somewhat cranky, application. It did everything I had put on my requirements lists and I actually was testing some strategies that looked promising and I had made a few live trades using it.

## And I made a million dollars

Not. In the end, I realized that the issue I had with my back-test launcher was something I wanted to work out. I needed it to work to use genetic algorithms to find the best strategy, and I needed to use a faster language where threads were easier to handle like Golang.

But it was definitely worth it. I would do it over even if it ended up here. I haven’t started on the Golang version yet, but now I know what I need to do. And it was the first time I wrote my own Python package, used Python threads, or used Celery.

Someday I may get back to it. It currently looks like a good time to do it. But first, I might look around again, see what’s out there, fork another project that is close to what I want, and learn some more things.