Building a Trading Bot from Scratch

in LeoFinance6 months ago

Screenshot_20210411_200050.png

I set the Gekko trading bot up a couple of months back, it made some trades, I came out with 33% profit. But I kept tinkering with things and added a couple of other bot instances to the server. (got greedy) I waited, waited, waited, and waited with no trades happening. I thought because the price was continually on the rise, it wouldn't trade until a bigger dip.

Then I check against the back testing, and it should have done multiple trades over that period. I then took the bot of line... when the big dump happened, and missed it. I waited and put it back online... still nothing.

Then recently I had the idea, what if I reduced the instances of the bot to only one.

BINGO! The bot was trading again. Then I seemed to have remembered some discussion buried on a forum about needing multiple servers to run multiple instance of the bot.

D'oh!

Currently it's made a small profit again, I'm checking it regularly. When after say a month of trades, I'll share with you the results.

In the meantime I am looking at extra hosting options to set up more bot instances.

Programming My Own Bot

Screenshot_20210411_201105.jpg

Beyond that I am still developing my own bot. It seemed like a simple project on the surface, but it's quickly revealed itself to a complicated machine with many "moving" parts that need to mesh together. So much time has also been devoted to just thinking it through and documenting it so I have a structured plan of what parts rely on each other, thus giving me an order components to develop.

On top of that, I've had to get up to speed with programming Node.js, which I've now more or less accomplished.

There's no pretty interface yet, just text being printed to the command line to tell me what it's doing.

Currently it validates the inputs for the trading strategy, connects to the exchange and downloads the price history for a given time span and stores in the database. Now I am gong to connect it up to the live price feed and feed that to the trading strategy.

Next steps:

  • Have the strategy process the prices.
  • Decide to short, long or wait
  • Store the trades (paper only atm.) in a journal (data base)
  • Add back testing (stored prices, no live) ... (store this?)
  • Live trading (against a test net first)

This will be V 1.0 alpha

A major difference will be, unlike the Gekko trading bot, it should be able to run multiple instances on the server.

After this I will start on the graphical user interface.

It will come with a number of basic trading strategies that I will port from Gekko. If you have programming knowledge you will be able to write your own for it and back test them before running them live.

Further down the line are plans to enable more complicated trading strategies.

This will keep me busy for a while, but in the mean time, I'll still have Gekko trading for me.

Posted Using LeoFinance Beta

Sort:  

That's awesome! I've also been tinkering with building a trading bot, when I find the time to do so, but using python instead of javascript.

Posted Using LeoFinance Beta

Excellent! I was hoping that this post might entice some other programmers out of the woodwork.

Are you using the CCXT library to interface with the exchanges?

How far along is your bot?

I was using the poloniex library in python, but moving over to binance so actually shopping around for a new solution. I will have a look at CCXT.

My bot was operational last year but not very profitable, so I've taken it back to the drawing board. Struggling to find the time to put in meaningful work on it at the moment.

Posted Using LeoFinance Beta

CCXT currently supports 126 exchanges.

More importantly for you, there is Python Support.

I'm building my bot to use an arbitrary number of trading strategies. In the end it will be the strategies that determine if it is profitable or not.

Even if your bot was only turning a small profit, and not losing your money, keep it on line while you build the new one. I'm doing just this, running Gekko while I work on my own.

Posted Using LeoFinance Beta

I think it's just the idea of making the bot that's easy XD

Already up to speed on node, damn, I feel like such a noob XD

in fairness to me I'm not doing anything anywhere near that level of complexity

Yes, the idea of the bot is easy. The reality is something else. But breaking it down into smaller components and mapping out how they fit together, like the image in the article helps immensely with understanding the flow of logic necessary to make it work.

In fairness, I already had a number of years of experience with plain old Javascript. But Javascript had moved on since I last worked with it. I also had to figure out the Node.js ecosystem. There are a number of development stacks and frameworks to chooser from. Once you choose one, you are committed to it, because refactoring the code to another is a nightmare.

Posted Using LeoFinance Beta

It really has moved on quite a bit hasn't it x_x

I'm basically starting from nothing as all I ever did with js was some pretty eye candy stuff that made things look cool but wasn't necessary for page function and then eventually replaced those with css effects.

I was a web developer for many years, I've ended up having to do complicated things with Javascript. So to discover that there was something like Node.js was a gift from heaven, it meant all of that experience was still useful.

Mind you, after learning and using, PHP, Basic, 68000 Assembly and even 6502 machine code, picking up something new is not beyond me.

The fact that Node.js can even be used to create cross platform desktop and mobile apps is mind blowing.

Will it ever be as fast as C? Naaa... but you will get the job done quickly.

You can always call upon modules written in C if the needed.

Congratulations @leoplaw! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You published more than 400 posts.
Your next target is to reach 450 posts.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Support the HiveBuzz project. Vote for our proposal!