Create a cryptocurrency trading bot in Elixir

Hello,

I’m not sure where this should / could be posted, but I’ve put a lot of effort and just released my first video about streaming cryptocurrency prices in Elixir.

I would like to create more videos that will lead to a fully-fledged cryptocurrency trading bot in Elixir(almost like a course but in this pair programming format). On the way, people will see practical usage of OTP stuff like Supervision trees, etc.

I think that is what is missing as people get to know Elixir, but they didn’t write any “complex” systems (they didn’t get a job in Elixir yet, but they would like to be prepared)

I would love to get some comments(both here and on Youtube :wink: ), I know it’s not the greatest quality but even knowing where hurts the most could help me to iron it out the soonest :slightly_smiling_face:

Video link: https://www.youtube.com/watch?v=wVYIx7M6o28

PS. Feel free to move it to any other category on the forum.

Thanks in advance,

Kamil

12 Likes

Hello,

I just added another episode about the topic mentioned above - this time it’s about building a naive trading strategy:

Let me know what you think,

Thanks in advance,

Kamil

8 Likes

Pretty interesting! I am starting work at a financial company and this could be extremely useful. :slight_smile:

2 Likes

Thanks for the comment! I will try to push out those episodes quite frequently but I’m sure that very soon you will know much more about that stuff than me(if that isn’t the case already!) :slight_smile:
In the next episode I would like to put much more “Elixir specific” content like introducing supervision tree etc - stay tunned, like and subscribe :wink:

1 Like

Looks good! And til about that elixir socket library which looks fantastic. It’s not over engineered, I think it’s just right. I mean come on you wrote a crypto streaming app in 15 minutes… Try doing that in go! Lol

2 Likes

Hehe, I served my time in Go. From personal experience, it would be closer to a week than 15 minutes :wink:
Ignoring Go (as nobody cares) - thank you very much for your reply, I’m still testing a lot of things and comments like yours help a lot.
I was wondering did you watch both videos? I feel like the tone of them is really different and I wonder which like you like better?

Thanks in advance

1 Like

I didn’t see the second one! So a few notes, I didn’t like the music LOL, and there was about 10% of the code style that I didn’t personally like. But overall I think it’s quite good, the only truly fatal flaw is that you shouldn’t Process.exit(self(), :finished). Anything besides :normal is considered to be an error code, when you start supervising, you might not get what you expect, and if you still want the exit message you should use Logger.info or something. Also, even better than Process.exit is to emit the result {:stop, reason, state_for_terminate_2} in place of {:noreply, state}

2 Likes

Just some clarification on this one - you didn’t like the music because it wasn’t type of music you like or it was annoying / distracting you?

I think your comment regards the Process.exit is on point. I didn’t put too much effort in this part as it will be refactored in 3rd video, but indeed I’ve could return {:stop, reason, state} - that’s much less confusing for people new to Elixir processes etc.

1 Like

I think maybe it was not bad for a filler, but I dunno, i didn’t like it, though I don’t categorically hate that type of music. Pretty quickly it more or less faded away in terms of distraction, so this could have been a matter of personal taste.

1 Like

Damn, this is some good content. Watched the first video, it’s great! I wrote a trading bot in ruby couple of years ago, will be fun to compare how you implement the trading strategies.

2 Likes

Thank you very much for your comment. It will take a few good videos before I will get to stop losses, retargeting and similar - also please keep in mind that this is an “naive” strategy. My aim is not to focus on strategy itself but on laying a matrix of states that servers can be in, how they work together etc. I picked up the trading bot as it’s complex enough to get to nice web of supervision tree, updated between videos - on the other hand it’s not too geeky / abstract to keep people engaged - I think it’s cool to understand few thousands (hopefully) lines of Elixir application (not related to web - just processes and their interactions) :slight_smile:

4 Likes

I think this is fantastic, because in Elixir and Erlang you are basically off to the races and thinking about process lifetimes and failure domains extremely quickly, and what better way to highlight it than with a system where the stakes are literally money.

2 Likes

No worries. My strategy was also very simple.

https://www.quora.com/What-would-you-consider-your-overall-trading-strategy-to-be-in-the-crypto-market/answer/Shi-Ern-Lau

Very interesting, i’ve also built a tradingbot in Elixir, and are using the same simple strategy :slight_smile:

This is a very interesting strategy - thanks for sharing.
I could write it as a second example in the course - will investigate as it could have different challenges from the current one.
That would obviously be after this naive one will get a good run and build everything around it.

1 Like

Nice. Some more ideas for the future - bot should handle multiple accounts, each with own trading api key, and also each strategy can receive its own budget (imagine you run 2 strategies for 1 account, it will be difficult to trade if both of them can operate on whole available budget).

1 Like

I managed to record another video :slight_smile: This time I focused on getting the supervision tree running so you can scale the number of traders in the future (as now they would just all start at the same time and that doesn’t have too much sense).

As always enjoy, like, subscribe and leave a comment here and/or on the Youtube :wink:

6 Likes

Interesting approach. I’m building a multi-timeframe strategy for forex and took a very different approach. Perhaps it’s because I’m not building a trading bot but rather a system that generates trade signals. I keep all the data in database (obviously) and use a timer to drive the GenServer to do work when a bar ends, the time frame is configurable and it has to skip weekends, other than that my GenServer doesn’t actually do much.

2 Likes

Hmm, that’s also an interesting approach. As far as I understand that means that you were making trades yourself?
In general, this system is designed to make trades on its own - partly because crypto world never sleeps. Also, the naive strategy doesn’t utilize any signals, it’s not even based on any averages, etc (that’s why it’s a naive strategy :slight_smile: ). That shouldn’t stop anybody from developing other (more sophisticated) strategy based on this project.

Once again this is only developed/recorded for learning purposes - I don’t think you can make money reliably with this dummy strategy but you can get a gist how a little bit more “complex” systems are built in Elixir - that’s the point of the whole series at the moment.

1 Like

4th video in the series about building cryptocurrency trading bot in Elixir

We will focus on getting PubSub up and running so we will be able to scale naive strategy to multiple traders as well as other processes in the future.

6 Likes