Vote up!

3

Building an Agentic Trading Platform

The trading platform, currently code named Irowor, makes decisions and takes action automatically. It's not AI-enabled, it's pretty straightforward with hard-coded rules. As I finish writing that system, the structure of the trading bot will be reused for agentic AI. Because an agentic system has to make observations, decisions, and then take actions. This is like watching the market, following a strategy, and placing trades.

Let's get started. We'll go from simple to complex to save ourselves time and headache. Let's review the trading platform architecture since it's already pretty much done. Also, we will be doing this in ruby on rails mostly, as a matter of personal preference. If you are starting from scratch I probably have to recommend python, since so much AI code is python. And I definitely recommend against typescript, I suggest you use pure javascript because it is so much clearer and lighter.

Let's say the setup has been done already. We'll go back to re-doing the setup once we establish the common time step. For now, assume everything is already working.

The fundamental action that the agent takes is placing a trade. The trade is usually a roll of a position: close two legs, open two legs. The trade is a call to the broker-dealer's API. Placing the trade is an Action, so we have actions:

 class Tda::Order.place_order
   include Wco::Action
   ## ...
 end

Right now everything is wired to be actuated through clicking buttons in the UI. But actions can be called from cron (or something that looks like cron).

Actions look like they can be sidekiq background jobs. It's a job that executes - sounds very reasonable to me. No need to even define a separate interface, since we're just assuming it's a background job. (Note: no need for AI here. Background jobs have existed forever.)

The loop that runs in the cron is also nothing special, and has been done already. There is an operating system-level execution task that calls something and sleeps eg 15 seconds:

 while true do
   SomeStrategy.new({ ...with_params }).evaluate
   sleep 15 # seconds
 end

Again, as far as the architecture goes, the trading bot runs the following loop continuously:

 For each position,
   Evaluate the position according to some strategy.
   If it says to place an order,
     Place the order.
 Sleep 15 seconds and repeat.

Is this agentic? It may or may not be, but also it's already implemented, it's been done. So let's move on to semantically describing how an email agent would work, since that hasn't quite been done yet, and may prove more challenging.

Related Articles
Please log in to post comments:  
Login with Google