How would you architecture a trading phoenix application?


I’m learning Phoenix and as a learning project for me - I’d like to build a simple bitcoin trading app. I’ve built something similar in Ruby before, and want to reimplement and improve it in Elixir.

Here is a plan how I would build it, please add your thoughts what you would do differently.

General idea what I want:
I’m thinking the system will have user registration where you can add your Bitstamp API key. Then you can pick different trading strategies and select how much funds you dedicate to each strategy. Then the system would execute the strategy when the conditions are met. Strategies will be fixed, and not some kind of user input with some DSL.


Use postgres to store users, funds for each strategy.

  1. Build user registration and settings for strategies.
  2. Get live price data with a Genserver process, use WebSockex for it.
  3. One trader Genserver process with multiple workers (1 worker per user - strategy?). It receives price data from the WebSockex process, and sends it to the worker.
  4. Worker executes the strategy with the current price, available funds, etc. Then either the order on the exchange is created or not.
  5. Make some email notifications that a trade happened.

What do you guys think? Does it sound like a good architecture for my idea?

1 Like

Seems good, although do you need multiple workers to receive and process price data, is it that common of a task? A pool of workers is always the safer bet though so it’s good. :slight_smile:

Have a queue for your emails (probably persistent, likely in PG, to survive restarts), because delivering email is prone to much flakiness from email servers.

My reason behind it was that it guarantees that only 1 strategy for each user will be running at 1 point in time and at the same time, it doesn’t block other users.

Thanks. I would use something like Mailgun and they’ll take care that it’s delivered. I’m more worried about processing orders on the exchange. This should definitely survive restarts.

Yes, using a 3rd-party service for email is a good idea. Might still want a queue, just in case it’s down, but probably much less worry about error handling…

Howdy @egze,

I’ve been working on an Elixir trading toolkit that you could build on top of Tai - A composable, real time, market data and trade execution toolkit.

Lmk if you need any help getting up and running.

@rupurt Do you personally think it’s possible to make money out of automatic trading (I have more in mind Forex trading actually)? Because I guess you at least tried. Or is it just a myth? Creating a lot of parameters in the app; launching hundreds of thousands of different workers in parallel with different parameters; workers simulating orders; pick the one with a higher success ratio; make them trade live. Profit? Elixir/BEAM is the perfect candidate for this. I am currently building an API to a Forex broker and plan to code a simple algo I have in mind.

It’s possible, but not easy

It was not too hard 30 years ago. Current days, it generally takes a lot of compute power because of all the trading firms doing it.

Not saying you can’t find something nobody else has, just the general rule that it takes a lot of capital…