RobotHood: A Crypto Trading Bot for the Greater Good

Caïtucoli Maxime
5 min readJan 31, 2023

--

At least now you are sure that I am not a graphic designer

The first thing that may strike your mind after reading this should be something like: “How the hell a Crypto Trading Bot can do any good?”.

I have long held skepticism towards the neo-liberal system and its tendency to prioritize the interests of the wealthy at the expense of democracy, the environment and the poorest. High-frequency trading bots are a perfect example of the new technical tools supporting the shortcomings and the vacuity of this harmful economic system.

The idea behind this project is to make a profitable trading bot using Python on the Binance cryptocurrency exchange and to give the generated profits to non-governmental organisations. RobotHood will not change the face of the world but it will constitute a humble attempt to redistribute wealth at my scale.

1. When to buy, when to sell?

That is THE question. And let’s face it once for all: finding this answer remains a pipe dream, especially on the crypto market which is highly volatile. When I started this project a year ago I quickly realized that I couldn't generate the trading signals myself. Plus I didn't want to spend time on learning trading for some reasons.

Hopefully, a good friend of mine which trades crypto on his free time introduced me to a private discord channel in which the community pushes great quality trading signals. Here are the reasons why their work is perfect for what I am trying to achieve:

  • Their results are published for years and are fairly good (~97% of the signals reached the first selling target).
  • Their trading signals are formatted which makes them easy to scrap with some regex.
  • Discord is quite easy to monitor with python.
  • The community provides around 50 signals per month.

We will therefore not create a high frequency market killing machine but a low risk slow profit making bot. Let’s see how.

2. From Discord Messages to executable Trading Signals

As is often the case with data-oriented problems, the first challenge was to extract data and make them usable. Moreover, as we never know when a message will pop, we have to use a bot that live scans the trading signal’s discord channel.

To do so I use the discord.py-self library, which allows for the execution of my code when triggered by specific events within my Discord account, such as when a message is sent on a designated channel 😏

Once received, a discord message will then be treated and transformed into a TradingSignal python object. Here is a transformation example with an old signal:

3. Executing Trading Signals

Now we have a proper TradingSignal object we can use the TradingSignalManager. This object will use python-binance to interact with Binance API and:

  • Calculate buying quantities according to the free founds I have on my Binance account.
  • Make a buying order on the market.
  • Calculate selling quantities according to our trading strategy (in which proportions we use each price target).
  • Make one or several OCO selling orders with the corresponding parameters.

The OCO selling orders sell your crypto at the target price if the currencies price reaches it and at the stop loss price otherwise: once we execute them we have nothing left to do.

RobotHood simplified process

4. Cover your back

As we are dealing with money here we have to take some measure to avoid losing everything we’ve got. Here is what I did to cover my back:

  • Using my Discord Token as an environment variable (never hard code it anywhere).
  • Protecting my Binance API keys, and use them as environment variable (never hard code them anywhere).
  • Protecting my Binance account.
  • Testing every function I made like a maniac (you can find them in the test folder of the git repository).
  • Using GitHub actions CI/CD to ensure code quality.
  • Containerizing the bot in a secured Docker image.
  • Generating logs all along the process to allow efficient troubleshooting.
  • Investing only money I can afford to lose.

I also deployed the bot on a RaspberryPi I already use for other purposes to lower its energy consumption.

Last but not least

You may want to ask me how do I know if this will work? I don’t really. Let me explain: I have been back testing this bot for the last three months and generated something like 100€ with a initial investment of 2000€. However cryptos are highly volatile and we can not know or even make suppositions about what will happen next.

The main motivation that drives me along the development of this bot is showing that we can hack what was originally designed to generate personal profit to make the world a better place. As a developer I hate the way technology is usually being used, this project is an attempt to spark a glimmer of hope for those who feel the same.

It was also the occasion to learn new skills solving complex problems by working on a meaningful project.

/!\ DISCLAIMER: I only published a dummy and harmless version of RobotHood on GitHub so that nobody can use it for their own profit or loss. It does not contain the TradingSignalManager which is the core feature.

Indeed RobotHood would not be RobotHood if I published the full source code on the web. Plus I will not reveal which discord group I use to get the trading signals.

Conclusion

I am very proud to finally write about this piece of work, you will find the GitHub link here. This was a quick overview of RobotHood’s main features, more articles are to come, now in the pipe:

  • How to track the profits generated by RobotHood.
  • A data science approach on the investment strategy optimization.
  • A presentation of the NGOs supported and the donating system of RobotHood.
  • And some more about other projects and developers tricks!

Follow me if you don’t want to miss any of them!

PS: I am now a freelance Data Scientist, if you like my work and need (or know somebody that needs) some help with a data project don’t hesitate to contact me. For more information, check my Malt profile here or my website there.

--

--