Monday, February 8, 2016

Algo interface

Hello, welcome back to my blog about automated trading. Last week I have covered the topic about real time quotes. This week I will introduce the interface which allows to plug in various trading strategies into the system.

For the source code example, please download repository and update to branch 5-algo, changeset 61bfc9e57423.

Background

In the chapter Daily cycle I have split the day into 2 parts - overnight and trading session. For better imagination, please see the image below.



As it was stated there is planty of computing time available over night and there is a need to make processing very fast during the trading session. This gives need for interface to have 2 different methods. Let's call them doTraining and processEvent. Both of them need to have access to the data sources and both of them have to tell to platform what to do. However their needs and responses are different. So let's go through it.

Method doTraining is used for crwaling through stocks, finding the best deals and so on. This method needs to have access to the stock screener, currently open positions and historical data. Result of the call tells to the platform what to prepare for the trading session. Currently the supported command is  subscription request for real time quotes during next trading session.

Method processEvent is used for processing event which happenes during the trading session (e.g. price change). Anytime this happens the method is called. Therefore this method is called many times per trading session. Input to the metod contains the event which triggered the call. Available data sources are all the one which works in real time during trading session (e.g. real time quotes). Result of the call tells to the platform what to do. Currently strategy can ask platform to send orders for buy or sell.

What about sharing data between calls? Each method has another parameter called variables of the type VariableContext. This is interface used exactly for this. Client can persists variables in one call and use them in another call. Please note that another call might happen on the different computer so using of this interface is the only guaranteed way to keep everything consistent.

Coding

As for coding, please refer to the interface called Algo. This is the entry point to everything. There is a different data provider for each of the method and each of the method returns different result. Finally both methods have variables which are used as a point for data sharing between the calls (trading cloud persist this into the database).

That's it for today. Next week I will show how to make backtesting. Thank you for reading!

No comments:

Post a Comment