My path into crypto and algorithmic trading

Ivo Petiz
7 min readOct 27, 2020

(For legal purposes this is a fictional story)

Photo by Ilya Pavlov on Unsplash

Some background

Around 2012, online sports brokers start to become mainstream, and everyone was trying to make some extra money, with more or less success.
Online brokers tried to conquer the market by giving deposit bonuses and free bets, after the first deposit, so you could bet without risk, using your free bet or increasing your bank with bonus, up to 100% of the first deposit. To get the free bets and bonus money, some users used some archaic arbitrage, where users were betting in an event, using the free bet or the bonus money in one broker and against it another broker. Was feasible because there is an online broker, which acts likes a trade market — Betfair — where users bet against other users and not against the house, and where was possible to bet against an event. This way, users were always betting on the warranty that the money keeps in their pocket.
In almost all sports markets the trick worked, and because of that, I had more contact with some sports I didn’t know so well. Horse racing was one of those sports.

How algorithmic trading appears

Searching more about horse racing bets, I discover that horse racing had a huge market capitalization, capable of moving large amounts of money, sometimes even more than football big leagues, presenting small spreads and liquidity. During my research, I found a blog from a guy who was making lots of money in horse racing, even before the race starts. His name is Adam Heathcote, and he was making money in what’s called pre-race trading, which consists in taking advantage of the odds fluctuation, betting on a horse and against it or vice versa, before an event. For example, if the horse odd starts to decrease, you could bet on it and wait some time to catch the price lower, and then bet against that same horse. The difference between the entry and the exit odd would be your profit. The same happens during the race, but price oscillation is too big, and the prices movement is a lot faster, increasing the difficulty.
This method looked reliable, and as a programmer, it seemed simple and easy to implement, so I saw lots of potential in terms of automation.
First, I tried to use this pre-race betting method manually, but I was too green and hesitant, always looking for more confirmation signals to make my entries, which often made me lose good entry points. Another problem was the schedule, because UK horse racing, where the money is, occurs at 12 pm and 5 or 6 pm. So during these constraints, I thought I could develop a bot, that could make all this work for me.
I started with trying to anticipate the price trend, based on past prices. It was not easy because of price fluctuations, and then I tried with the price average. Later I discovered the name of what I was trying to do was simple moving average and that was when I found out algorithmic trading was the real deal. At this point, my interest in the subject grows exponentially, and my doubts about the possibility to make money, using bots, vanished.
I start reading everything I found about it, then start to apply the concepts. I gathered data, using Betfair API, which was easy to use and collect data. Meanwhile, I was developing strategies — started by trying simple and exponential moving averages and evolving to some crossing moving averages — and backtesting it, using the collected data.
(Funny story: During some government regulations forbidding online sports bets, when my backtests showed my strategies began to be profitable, Betfair closed in Portugal.
In 2015 a friend introduced me to Bitcoin, as a digital currency, which didn’t produce a lot of enthusiasm. Only a few months later, when He said Bitcoin was increasing its value, I got a little more interested and bought some at MTGox. At that time, Bitcoin was at around $200, which I hold until its price increased to almost $1000. Sold a considerable percentage and keep some, thinking about improving my knowledge in trading and restarting my journey in algorithmic trading.
MTGox had a nice API, which makes me think it would be easy to make some money trading. It was not!
Some months later MTGox enters into bankruptcy, and the dream was over.
A couple of years later, I started to use Twitter more often and realized Crypto Twitter was the thing! At that time the price of ETH was increasing, and I bought some. Meanwhile, lots of new projects were appearing, and it was almost impossible to keep an eye on every new idea and coin. Lots of scams, cloned software and failing concepts, made distinguishing between good and bad coins more complicated. So restarting once again my algorithmic trading hobby looked like the best option.

Pump & dump groups

I have discovered some Telegram pump and dump groups on Twitter. These groups consisted of a bunch of people, waiting for signals from an admin to buy a specific coin to increase its value, which would call people attention to enter the market also, and then dumping it, making a considerable profit, or at least trying.

$SLS pump and dump, from ฿0.0041 to ฿0.043. More than 10x pump.

This kind of group had one big problem, latency. First of all, the delay between Telegram groups admins, sending signals, and the different users receiving them was huge, depending on users location, Telegram was delivering messages long seconds apart among users. Sometimes before I receive the signal, the correspondent coin had already pumped and dumped, making me lose all the fun. I thought it might look for a VPN near the admin location, to get the signals faster but this was not the solution to all my problems, once I only got some advantage over the farthest groups of users and keep in disadvantage between the near users. Another problem was the time lost reading the signal and putting the buy order on the online broker. Even with the link semi-prepared, there was always some delay looking at the actual price, analyzing it and processing the buy.
Following the same path, the final approach was to automate all process, from receiving the signal/message with the coin to pump, until buying it to sell on profit. The system should use a VPS, located in a place that presented the smallest delay possible.
This approach had two considerable flaws. First, was restricted to just the groups I knew of, and secondly, even with all this optimization, I was not able to enter at the beginning and get all the price action.

A different approach
To avoid the problems with the previous solutions, I decided I should try to predict the pumped coin, instead of waiting for the signal. Once the pumps occur only with markets with a small market cap, which could pump higher than big market cap coins, the idea was to keep an eye on every pair inside these criteria.
The path started by collecting data from pumps, then analyzing it, defining possible strategies, backtesting them, creating a bot capable of detecting pumps and finally, automating entries and exits.
The first part was collecting data. It was fundamental to collect data from pumped coins but also the others, to understand the differences. In this type of analysis, speed is vital. The more reduced the period, the more definition you got. In this case, where the smallest frequency was the most crucial aspect, I tried to use the tiniest interval available, which at that time was 5sec at Poloniex and Bittrex.
From several strategies I develop and test, the best one consisted in comparing the increase in volume from all coins and the increase in the last 24h high.
The first pumps I saw were big. Something between 5 and 20 times the initial price, but after some time pumps started to reduce their strength. Mostly probably because of the disbelieve of users, who probably had negative experiences with pumps, entering late or/and making defective risk management. In terms of risk management, never risk more than a small percentage of your capital, a maximum of 10%, and place different targets, which could make you get some good profit, without risking too much. The idea was to have the first target covering the entry and have the rest of the targets designed to make a nice profit. Once the pumps tended to decrease, I used to predict the total pump as 80% of the previous pump.
My risk plan was to my first target, which was 50% of the entry, at two times my start price than a second target at four times the initial coin price, using 40%, and the third one at eight times the initial value, using the remaining 10%. The bot only enters if the price was below two times the initial cost.
As an example, if a coin pumped ten times on the previous day, I would predict a pump above eight times the initial price. For something with an initial value of ฿0.0004, the bot could only buy it when catches the price below ฿0.0008. Imagine it enters the market at 0.0005, the would sell 50% at ฿0.0010, then tries to sell 40% at ฿0.0016 and finally, the last 10% at ฿0.0032. Used the first target to cover the costs and used the rest to make some nice profit.

From simple scripts to a more composed framework

Scripts to detect pumps and dumps had around 100 lines of code and did the job. To a more generic system, it was necessary to create something more in-depth. The idea was to use something more sophisticated, capable of running different types of strategies, with a minimum number of changes. I looked for something that fits my needs and could help me build a profitable trading bot, but not find any project that fills my requirements.

I started building my trading bot project called Algotrading and hosted it on Github. Algotrading is a project that allows users to create their strategies and use them for live trade, paper trade and also for backtesting, all in one framework. I also created a database for crypto, where I store data from coins prices and volume, which I use to backtest my bots.

My project is described here.

(Can find more cool projects on my Github.)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response