Subscriptions

One of the key algo functions is to observe the changes in the market and promptly respond to them. When the Algo is launched it uses IAlgoServices to subscribe to the events it needs to operate. Each subscribe call is paired with a matching unsubscribe call, which takes the same argument to unsubscribe.

Book

To subscribe to book updates for the specified security call, use subscribe_book and unsubscribe book.

// Subscribe to book updates for the specified security
void IAlgoServices::subscribe_book(SecurityKey);
void IAlgoServices::unsubscribe_book(SecurityKey);

// You implement
virtual void on_book(SecurityKey, Book const &) override;

Get the SecurityKey of the current security using:

services.subscribe_book(SecurityKey(algo_services().security().id()));

If your Algo needs to subscribe to other securities, their keys must be passed as parameters.

To get the details of a security, use:

api::Security const* IBeforeLaunchAlgoServices::lookup_security(SecurityKey k) const = 0;

Timer

To handle time-based logic, an Algo can subscribe to a common timer event that is invoked once every 10 milliseconds. Use the TimeStamp class from bts_chrono.h to efficiently handle time calculations.

// Subscribe to a periodic 10ms timer
void IAlgoServices::subscribe_timer();
// You implement
virtual void on_timer() override;

Ticker

The status callback is called when the market for this security opens, closes, or has some other state transition.

// Subscribe to trade ticker
void IAlgoServices::subscribe_ticker(SecurityKey);
// You implement
void on_ticker(SecurityKey, TradeVector const&) override;

Trading Status

The status callback is called when the market for this security opens, closes, or has some other state transition.

// Subscribe to security trading status
void IAlgoServices::subscribe_status(SecurityKey);
// You implement
virtual void on_status(SecurityKey, co2::TradingStatus) override;

Child Orders

When an Algo launches a child order, it is subscribed to the changes on that child order automatically. If the Algo unsubscribes from those changes, it can re-subscribe using this method.

// Subscribe to child order updates for the specified child order.
void IAlgoServices::subscribe_child_change(OrderKey);
// You implement
virtual void on_child_change(OrderKey, ChildState const &) override;

Previous   Next