![]() |
B2BITS FIX Antenna C++
2.31.0
|
The main FIX Antenna components are:
The engine is represented by the Engine::FixEngine class. This class is responsible for:
Engine initialization is performed using the void Engine::FixEngine::init() method. This method must be called before any other FIX Antenna methods. At the end of the process void Engine::FixEngine::destroy() method must be called to deallocate the consumed resources.
For example:
The Engine::FixEngine class, as well as several other FIX Antenna C++ API classes, implements the Singleton Design Pattern. Therefore you should, first of all, get a pointer to the instance of the class, using the FixEngine* Engine::FixEngine::singleton() static method to access non-static methods of the class.
For example:
The Sessions Manager manages the creation of unregistered acceptor sessions. When CreateUnregisteredAcceptorSession is set to true, engine accepts all incoming logons and creates session acceptors. It is possible though to implement custom logic and introduce more sophisticated criteria of accepting such sessions. To do this, you need to create and register your own instance of Sessions Manager.
Create a class derived from the Engine::SessionsManager class and override the Engine::SessionsManager::onUnregisteredAcceptor() method to control acceptor session creation. Return "true" if you agree with the creation of unregistered acceptor; otherwise return "false".
Use Engine::FixEngine::registerSessionsManager() method to register custom Sessions Manager. Only one Sessions Manager can be registered to the FIX Engine.
For example:
The FIX session is represented by the Engine::Session class. This class is responsible for:
In earlier versions of FIX Antenna (2.10.14 and earlier) Session object could be uniquely identified by SenderCompId/TargetCompId pair. Starting from version 2.10.15.5 extra string identifier - SessionQualifier has been introduced in addition to SenderCompId/TargetCompId pair. The idea is to give user ability to create several sessions with the same SenderCompId and TargetCompId and to give ability to address these sessions by unique ID. See Session identifier for more details.
Each session encapsulates message storage that is used to store the sent and received messages. There are two types of storages:
When engine receives FIX logon message it extracts SenderCompID and TargetCompID fields from the message and tries to find previously created acceptor with corresponding session ID (i.e. session SenderCompID equal to TargetCompID extracted from message and session TargetCompID equal to the SenderCompID extracted from messages). Refer to the FIX Session Acceptor for more information about how to create session acceptor. If engine cannot find corresponding acceptor the incoming logon is declined and connection is not established.
Engine though can also work in "trusted mode" i.e. if corresponding session acceptor cannot be found then session is created automatically. To enable this mode set CreateUnregisteredAcceptorSession property to "true" (refer to the section Common parameters for more details about property).
The Application class is responsible for:
Create a new class derived from the Application class and override the Application::process method in this class to process incoming messages. Then pass the instance of your class to the session to start receiving incoming messages.
Engine delivers incoming messages to the Application by calling Application::process method and analyzing its return value to make sure that incoming message was processed and Application is ready to process next incoming message.
If the Engine::Application::process method does not return "true" (i.e. returns "false" or throws an exception), the engine passes the same incoming message to the Application::process again and again until either Application::process returns "true" or number of attempts is exceeded (DelayedProcessing.MaxDeliveryTries, refer to Common parameters for more information). The interval between attempts is specified by property DelayedProcessing.DeliveryTriesInterval (refer to Common parameters for more information). If the number of unsuccessful attempts exceeds the MaxDeliveryTries, a Logout message with the reason "Application is not available" is sent to the counterparty and session is closed.
Other useful methods to override are: onLogonEvent, onLogoutEvent, onSequenceGapEvent, onSessionLevelRejectEvent, etc. These are the call-back methods called to notify about the corresponding session-level events. Note that all pure virtual methods of Application must be overridden (implementation can be just empty body).
The Engine::Application::process method is called only when application-level message is received. All session-level messages (Heartbeats, Test Requests, Resend Requests, etc.) are handled by FIX Antenna. However you can modify default behavior overriding call-back methods in Application and providing your own logic.
Below is an example of custom implementation of Application interface:
The FIX message (specified by the FIX protocol) is represented by the Engine::FIXMessage class.
The Engine::FIXMessage class provides the following functionality:
Please read the FIX Protocol explanation of the Repeating group first (refer to the section About FIX messages).
The FIX message may contain repeating groups. Each group contains:
Repeating groups are usually referred by the leading tag.
To add new group to the message you simply should add leading field to the message. In the result the new group will be added with the number of entries according to the value of leading field.
To access fields inside a repeating group you should
To resize group simply modify the value of leading tag. Pay attention that this operation re-creates the group so you should populate values again.
To remove group simply remove leading tag from the message.
Engine::SessionsController class introduces interface to abstract basic session management operations like start/stop/connect/disconnect. It easies sessions management implementation and can be used as general sessions owner in application.
FixAntenna provides built-in default implementation (FixEngineSessionsController) that uses FixEngine as underlying layer to control sessions. See Scheduler for samples.
FIX Antenna-based applications are widely used to connect to venues and trading platforms. The built-in scheduling functionality is designed to deal with the periodic nature of these venues, for example, the trading day or trading week. To provide maximum flexibility for customers, the generic scheduler that is implemented in FIX Antenna (hereafter Scheduler) allows customers to use it for actions that are initiated by time-dependent events. Customers can use it together with the FIX Antenna Engine (to schedule sessions) or for other purposes.
When a user doesn't provide a Scheduler instance implementation, he/she can use the Engine's generic Scheduler by using the FixEngine::InitParams::pScheduler_
member.
To use the Scheduler, the user must create schedules (usually periodic ones, for example, every day at 9:30 AM), that define the timeline of events. The user can create schedules by defining them in the engine.properties
file or via API (refer to subsection Scheduler API examples for more details).
If the engine.properties
file is used to configure schedules, the Engine creates the schedules defined during initialization and puts them onto the Scheduler but sessions are not added to the schedules. The user must add sessions to particular schedules with her/his own code after the Engine starts, and start the Scheduler explicitly. The reason behind this is that every session requires the Engine::Application
callback sink to be defined to serve business needs that are not feasible for the Engine to have during initialization.
To see how to bind sessions to schedules using the schedule property, see the FA Scheduler documentation QuickStart Guide.
There are 5 major objects that define the Scheduler feature:
TradePeriodBegin
and TradePeriodEnd
events, and to get the execution plan.All these objects are defined as abstract interfaces. FIX Antenna C++ provides default implementation for all of these objects as follows:
One can define his/her own implementations, for example, a generator that defines timeline events that uses something other than the cron format, and use them along with those provided in FIX Antenna C++.
Engine::SessionsSchedule allows a user to set up an events callback sink (an instance derived from Engine::SessionsScheduleManager, see the API Guide for details) whose methods are invoked when TradePeriodBegin
and TradePeriodEnd
events happen or an exception was raised while events were being executed.
The user can modify an execution plan for every event to change the default Engine::SessionsSchedule behavior, see the details below.
The provided implementations define two types of time events and the session schedule's reactions to them:
onTradePeriodBegin
method of the instance derived from the corresponding Engine::SessionsScheduleManager, if so set by the user.onTradePeriodEnd
method of the instance derived from the corresponding Engine::SessionsScheduleManager, if so set by the user.After the above is complete, the System::SchedulerImpl retrieves the timeline generator instance from the schedule, asks it for the next event, and schedules the event it received. After the scheduled event time passes, everything repeats.
There are two ways to configure the session schedule: by using the engine.properties
file or by using an API.
To create a schedule from engine.properties
, the user must define the parameters as represented in the table below::
Parameter | Description | |
---|---|---|
TimezoneDB | Timeline CSV file where all valid time zones are defined. Generic name of timeline file: date_time_zonespec.csv
| No, Scheduler works in UTC only |
Schedule.<schedule_name>.TradePeriodBegin | Timetable for the beginning of the trade day. Defined in the cron format. <schedule_name> is the schedule name. | Yes |
Schedule.<schedule_name>.TradePeriodEnd | Timetable for the ending of the trade day. Defined in the cron format. <schedule_name> is the schedule name. | Yes |
Schedule.<schedule_name>.DayOffs | Defines a cron expression when events are not triggered (for example, holidays when the venue does not work). Defined in the cron format. <schedule_name> is the schedule name.
| No, no day-offs then |
Schedule.<schedule_name>.Timezone | Selects a time zone defined in the TimezoneDB property pointing file to use with the schedule. <schedule_name> is the schedule name.
| No, UTC by default |
Schedule.<schedule_name>.LateExecution | Set to 'true' to forcefully trigger the TradePeriodBegin event or to 'false' to avoid forceful triggering of the TradePeriodBegin event.When set to true, forcefully triggers the trade period begin event when the application's start occurred inside the trading period (between TradePeriodBegin and TradePeriodEnd ). | No, false by default |
Example of a schedule defined within the engine.properties
file:
Example of a timeline file with available time zones. Location:<Package>/data/date_time_zonespec.csv in the FIX Antenna package.
The user can create a schedule from the application by using an API:
To attach a schedule to the Scheduler, use:
To remove a schedule from the Scheduler, use:
To get a list of schedules, use:
Engine::SessionsScheduleManager is an interface that introduces API contract of Sessions Schedule Manager which is integrated into the schedule object.
Sessions Schedule Manager is a user-defined object which is passed to the schedule to receive notifications about TradePeriodBegin
and TradePeriodEndevent
events, and to get the execution plan.