OSE Library Interface and Usage Guidelines
OSE2 Access Library is a set of C++ components and interfaces designed to
provide high-level access to Osaka Securities Exchange electronic Trading
System (OSE-TS). Library components manage physical and logical connections
with OSE-TS, allowing client to concentrate more on financial data
manipulations. Library also provides representation of OSE-TS protocol messages
and Data Items as a set of C++ classes with access methods for message fields
specified by OSE-TS protocol.
NOTE: In this document OSE2 Access Library refers to a set of components
for managing trading session with OSE Trading System Auction Trading.
NOTE: Access Library name prefix “OSE2” has been
chosen because of internal naming conventions of JASMIN Exchange Access Library
package designed and developed by Orchid Technolody K.K.
-
Session control. Library should provide efficient means to control connection sessions with
OSE-TS, which includes "Application Link", "Order
Link" and "Notification Link".
-
Financial data representation. Design should simplify manipulations with financial data.
-
Integration with client system. Library should set up minimum requirements for client systems.
OSE Trading System consists of AP/DP server, which processes trading transactions, Communication Server, which acts as a front end for OSE system, handles connections with Transaction Participant System (TPS), which provides access to OSE-TS for Virtual Clients (Users).
In common case Transaction Participant System (TPS) consists of several Virtual Clients (Users) logged in to Logical Terminal.
A number of Communication and AP/DB servers exist in the OSE-TS system. Communication Server assigned to Transaction Participant System receives Order and other messages from TPS and delivers them to appropriate AP/DB server; it also collects Notification messages from AP/DB server and delivers them to Transaction Participant System.
For TPS ßà OSE-TS data
exchange “Application Link” should be set up with Communication Server by
establishing of TCP/IP connection using specified IP addresses, Port
numbers, Communication Server ID, Logical Terminal ID, Transaction Participant
Code and other identification data provided by OSE-TS.
“Notification Link” should be established to receive Notification messages from OSE-TS.
OSE-TS session
begins with establishment of so called “Application Link”. It could be done
after successfult TCP/IP connection by sending an “Application Start” request
message with identification data required by OSE-TS. If authentification has
completed normally, OSE-TS answers with “Application Start Response” message
with Response Result Code “Normal”(0000) and most recent Receipt/Execute
Notification Sequence numbers transmitted by OSE-TS. After that, OSE-TS sends
information about current status of system and Products. This information is
delivered by OSE-TS “Application Status” messages. “Application Link” is established
after receiving “Application Start Response” and “Application Status”
message(s). “Application Status” messages may be received from OSE-TS in
batches of up to 20 Data Items if Logical Terminal has been prescribed by OSE
advance application form.
Successfully
established “Application Link” may be used to establish “Order Link” for user
with User ID to allow sending “Order” messages to OSE-TS. To provide this
additional Login procedure must be performed by sending “Login Request” message
with specified User ID and Password to OSE-TS. After receiving “Login Response”
message with “Normal” Response Result Code “Order Link” is established, and
“Order” messages may be send for this user from Client Application to OSE-TS.
Multiple “Login Request” messages for on Logical Terminal with different User
IDs are supported by OSE-TS.
If Client
Application needs to receive OSE-TS “Notification” Messages then “Notification
Link” should be established after “Application Link” established successfully.
It may be done by sending “Notification Start Request” message to OSE-TS.
Notification Link is established if “Notification Start Response” with “Normal”
Response Result Code received from OSE-TS.
OSE-TS
specifies several types of messages used in data exchange between Transaction
Participant System and OSE-TS Communication Server. Those are
“One-query-one-response” messages and “Broadcast” messages. These two types of
messages are independent and can be sent in parallel.
By OSE-TS protocol
requirements for every sent “One-query-one-response” message correspondent
Response message must be sent back. Next “One-query-one-response” message may
be sent only after Response message received.“Broadcast” messages do not
require any Responses to be sent back.
For example,
“Notification Start Request”, “Order” – are “One-query-one-response” messages
and “System Error”, “Keep Alive” – are “Broadcast” messages.
Order Data
Items can be blocked into batches of up to 20 Data Items into one OSE-TS “Order”
message for transmission from one Logical Terminal and different Virtual
Clients (Users). All types of Order Data Items (such as New, Correction,
Cancellation) are allowed in one batch. Once put together, batch is send as a
single upstream “Order” message to OSE-TS. Number and sequence of Data Items in
correspondent “Order Response” message received by TPS is the same as in
correspondent “Order” message.
Specific
messages which may be received by TPS are “Notification” messages.
“Notification” messages are “One-query-one-response” messages. For every
“Notification” message received by TPS, the correspondent Response message must
be sent back to OSE-TS. “Notification” messages may be sent OSE-TS in batches
of up to 20 Data Items, only if Logical Terminal has been declared in advance
for blocking.
3.4 Sequence numbers and recovery mechanisms on OSE-TS
All messages sent/received to/from OSE-TS
have special field in message header called “Message Sequence Number”. This
field may be filled by TPS Client Application for some messages and for some
messages it should be filled with spaces.
According to OSE-TS Specification contents
of this field is never checked by OSE-TS. OSE-TS just copies the contents of
this field when sending the response message to the TPS Client.
OSE-TS system introduces several types of
Notifications. These Notification types are Receipt Notifications and Execute
(Result) Notifications.
Each type of Notification is assigned its own
Sequence Numbers. Notification Sequence Numbers are calculated and assigned by
OSE-TS and should be returned with no changes by TPS in correspondent fields of
Response messages. Notification Sequence Numbers are managed by OSE-TS and TPS
and used to prevent duplicatied or missing notification messages.
OSE-TS system provides its clients with
recovery mechanisms. Clients can request notifications to be retransmitted or
to be re-routed from one of its Logical Terminals to another. These facilities
are provided by OSE-TS via mechanism of Operating Messages such as “Retransmit
Request” and “Proxy Request”.
4. Library Interface
4.1 Introduction to library
interface
When client application code uses OSE2
Access Library, it operates with abstract entities called “Session”. In terms
of C++, a single session with OSE-TS is represented by an object, which exposes
a set of methods to control session state, sends commands(requests) to OSE-TS
using Control Messages, Operating Messages and post financial transactions(also
called Order(Application) Messages). As OSE-TS provides responses to posted
commands(requests) and transactions, session object delivers those via a set of
event notification callbacks.
An important notice is to be made: no
interface method invocation results in a synchronous callback! Result of an
operation is always provided as an interface method return value.Thus, client
application code is protected from re-entries. On the contrary, a callback
handler can safely invoke library interface methods.
Both exposed methods and delivered events form OSE2 Access Library interface,
are described in more details in this section.
4.2 Session control and
session state
Communication between TPS client and OSE-TS
system can be thought of as two-layer. Lower level has little idea about
financial information flow, its duties include:
- Establishing and supporting TCP
connection with OSE-TS system(socket I/O operations)
- Establishing of “Application Link” with
OSE-TS.
- Establishing of “Notification Link” with
OSE-TS(if necessary).
- Performing Login/Logout procedures to
establish/terminate “Order Link” with OSE-TS.
- Managing logical connection with OSE-TS
including message Responses.
- Formatting and posting OSE-TS Operation
Messages. A term "Operation Message" implies one of the
following: a “Final Order Inquiry Request”, “Retransmit Request”,
“Retransmit Cancellation Request”, “Proxy Request”, “Proxy Cancellation
Request”.
- Packing transaction Data Items provided
by client into transaction messages and posting them to OSE-TS in
accordance with OSE-TS protocol.
- Notifying client of any session-related
events: connection/disconnection, session establishment and termination,
transaction message acknowledgements, operation instruction
acknowledgements and market state changes.
Low level operations are represented by IOSE2_SessionControl
interface. It is an abstract C++ structure, which contains two data types and
several methods. The data types are:
- EOSE2_SessionControlReturnType - data type represents a set of possible return values for IOSE2_SessionControl
interface methods. OSE2 Access Library uses non-blocking approach to all
socket operations, which has proved more efficient. As a result, some
operations may return before actual completion. Return value eOSE2_SessionControl_OK
indicates successful completion, whileas eOSE2_SessionControl_InProgress
means rather that operation has not failed immediately. Other return
values indicate errors:
eOSE2_SessionControl_OperationNotAllowed - requested operation is
not allowed in current library session object state; eOSE2_SessionControl_DuplicateConnection
- duplicate connection attempt for a session object, e.g. sending of
“Application Start Request” Message requested after “Application Link” was
established already;
eOSE2_SessionControl_DuplicateNotificationStart - duplicate
Notification Link establishment attempt for a session object, e.g. sending
of “Notifcation Start Request” Message requested after “Notification Link”
was established already;
eOSE2_SessionControl_InvalidParameter - an invalid parameter was
passed in invocation;
eOSE2_SessionControl_QueueOverflow - a maximum of 20 transactions
already wait for posting/acknowledgement. eOSE2_SessionControl_QueueInsertFailed
- a transaction Data Item insertion into the Transaction Queue failed most
probably because of duplicated sequence number provided as a parameter for
one of OSE2_AUC_Post… method.
eOSE2_SessionControl_CommObjectError - indicates that operation has
failed.
- EOSE2_SessionState - data type represents a set of possible session states:
eOSE2_Disconnected is initial state for a session object;
eOSE2_Connecting indicates that TCP connect is in progress;
eOSE2_Disconnecting indicates that TCP disconnection is in
progress;
eOSE2_ApplicationStartRequestSent indicates that “Application
Start” message sent to OSE-TS and session object is waiting for a
“Application Start Response” from OSE-TS;
eOSE2_Online state is set first time for the session object after
successful receiving "Application Start Response" message with
“Normal” Result Code. Also, it is set every time after successful send of
one-query-one-response message and receiving of correspondent Response
message. Posting of any Control, Operation Request messages to OSE-TS which
requires Response message to be received is allowed only when session
object is in eOSE2_Online state;
eOSE2_NotificationStartRequestSent state indicates that
“Notification Start” message sent to OSE-TS and session object is waiting
of “Notification Start Response” message;
eOSE2_LoginRequestSent state indicates that “Login Request” message
sent to OSE-TS and session object is waiting of “Login Response” message;
eOSE2_LogoutRequestSent state indicates that “Logout Request”
message sent to OSE-TS and session object is waiting of “Logout Response”
message;
eOSE2_OrderSent state indicates that “Order” message sent to OSE-TS
and session object is waiting of “Order Response” message;
eOSE2_FinalOrderInquirySent state indicates that “Final Order
Inquiry” message sent to OSE-TS and session object is waiting of “Final
Order Inquiry Response” message;
eOSE2_RetransmitRequestSent state indicates that “Retransmit
Request” message sent to OSE-TS and session object is waiting of
“Retransmit Request Response” message;
eOSE2_RetransmitCancellationSent state indicates that “Retransmit
Cancellation” message sent to OSE-TS and session object is waiting of
“Retransmit Cancellation Response” message;
eOSE2_ProxyRequestSent state indicates that “Proxy Request” message
sent to OSE-TS and session object is waiting of “Proxy Request Response”
message;
eOSE2_ProxyCancellationSent state indicates that “Proxy
Cancellation” message sent to OSE-TS and session object is waiting of
“Proxy Cancellation Response” message;
After receiving
"Application Start Response" message with Response Result Code
“Normal”(0000), session object enters eOSE2_Online state, otherwise eOSE2_Disconnecting
state and then after drop-off procedure to eOSE2_Disconnected state.
Session control methods are:
- EOSE2_SessionState
OSE2_SessionStateGet() const throw()
Method returns current session state.
- EOSE2_SessionControlReturnType OSE2_ApplicationStartRequest()
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method initiates session establishment procedure by establishing TCP
connection and then formatting and sending “Application Start Request”
message to OSE-TS. If TCP connect succeeds rightaway, method
returns eOSE2_SessionControl_OK otherwise
eOSE2_SessionControl_InProgress.
In case of failure one of possible error codes is returned; if error is
not caused by duplicate connection attempt, session state is reset to eOSE2_Disconnected.
After receiving of “Application Start Response” message with Response
Result Code “Normal”(0000) session object state will be set to eOSE2_Online.
OSE-TS “Application Start Response” message is delivered as an asynchronous callback.
- EOSE2_SessionControlReturnType OSE2_ApplicationEndRequest()
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts “Application End
Request” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Application End Response” message is delivered as an
asynchronous callback.
- EOSE2_SessionControlReturnType
OSE2_ApplicationLinkTerminate()
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method initiates disconnection procedure.
“Application End Request” message is not sent.
- EOSE2_SessionControlReturnType
OSE2_NotificationStartRequest(unsigned long _ulReceiptSequenceNumber,
unsigned long_ulExecuteSequenceNumber)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Notification Start Request” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Notification Start Response” message is delivered as an
asynchronous callback.
- EOSE2_SessionControlReturnType
OSE2_LoginRequest(const char* _cszUser_ID,
const char* _cszUserPassword)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Login Request” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Login Response” message is delivered as an asynchronous
callback.
- EOSE2_SessionControlReturnType
OSE2_LogoutRequest(const char* _cszUser_ID)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Logout Request” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Logout Response” message is delivered as an asynchronous
callback.
- EOSE2_SessionControlReturnType
OSE2_SystemErrorMessage(const char * _cszCommunicationResultCode,
const char * _cszAdditionalInfo)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “System Error” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is in one of the following states: eOSE2_Disconnected,
eOSE2_Connecting, eOSE2_Disconnecting, eOSE2_ApplicationStartRequestSent.
- EOSE2_SessionControlReturnType OSE2_FinalOrderInquiry(const char* _cszUser_ID
,const char* _cszInquiryTerminal_ID
,const char* _cszInquiryUser_ID)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Final Order Inquiry” message to OSE-TS. One
of the parameters _cszInquiryTerminal_ID or _cszInquiryUser_ID
must be NULL but not both of them.
Return value indicates whether local operation has succeeded or failed.
Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Final Order Inquiry Response” message is delivered as an
asynchronous callback.
- EOSE2_SessionControlReturnType
OSE2_RetransmitRequest(const char* _cszUser_ID,
const char* _cszSourceTerminal_ID,
char_cNotificationType,
char _cNotificationTypeCode,
unsigned long _ulStartNotificationSequenceNo,
unsigned long _ulEndNotificationSequenceNo)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Retransmit Request” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Retransmit Request Response” message is delivered as an
asynchronous callback.
- EOSE2_SessionControlReturnType
OSE2_RetransmitCancellation(const char* _cszUser_ID)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Retransmit Cancellation” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Retransmit Cancellation Response” message is delivered as
an asynchronous callback.
- EOSE2_SessionControlReturnType
OSE2_ProxyRequest(const char* _cszUser_ID,
const char* _cszProxySourceTerminal_ID)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Proxy Request” message to reroute all
Notifications designated for Logical Terminal with ID _cszProxySourceTerminal_ID
to Logical Terminal which posts “Proxy Request”.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Proxy Request Response” message is delivered as an
asynchronous callback.
- EOSE2_SessionControlReturnType
OSE2_ProxyCancellation(const char* _cszUser_ID,
const char* _cszProxySourceTerminal_ID)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method formats and posts the “Proxy Cancellation” message to OSE-TS.
Return value indicates whether local operation has succeeded or
failed. Return values of successful completion are eOSE2_SessionControl_OK
or eOSE2_SessionControl_InProgress. Method returns eOSE2_SessionControl_OperationNotAllowed
value if session object is not in eOSE2_Online state.
OSE-TS “Proxy Cancellation Response” message is delivered as an
asynchronous callback.
- const
SOSE2SessionStatistics& OSE2_GetSessionStatistics() const throw()
This method returns session object statistics. Return type is a const
reference to a structure that contain information about current session,
such as flag if some transaction is pending, size of space available in
internal Order Transaction Queue etc. This method has no error return
value. When state of session object is eOSE2_Disconnected contents
of returned structure is undefined.
Invocations of methods listed above generally may result in
response actions from OSE-TS side. All OSE-TS response messages are translated
by session object into C++ callbacks, which are brought together by
notification interface IOSE2_SessionNotification. This interface is also
represented by a C++ structure that contains one data type and several event
callback prototypes. Client code willing to receive session level notifications
needs to derive from IOSE2_SessionNotification, implement its methods
and provide session object with implementation. Data type
enclosed in IOSE2_SessionNotification is described below:
- EOSE2DisconnectionReason - data type represents a set of possible reasons for session
disconnection. Except for user-requested disconnection, which may complete
synchronously, any session disconnection is reported as an asynchronous
callback. Following reason codes may be encountered in disconnection
callback:
eOSE2DisconnectionReason_NoDisconnection
Special code, indicates that no disconnection is in progress;
eOSE2DisconnectionReason_ConnectionFailed
OSE-TS connection failure. Additional information is reported to the log;
eOSE2DisconnectionReason_DataParseError
Failed to parse incoming OSE-TS data;
eOSE2DisconnectionReason_DialogError
OSE-TS logical protocol failure detected;
eOSE2DisconnectionReason_EndOfDay
OSE-TS was disconnected due to the end of trading day;
eOSE2DisconnectionReason_UpperLevelRequest
OSE-TS was disconnected due to to a request from upper Client Application
level. This value is kept for special purposes; see Connection
implementation;
eOSE2DisconnectionReason_ErrorOperationOnHoldReceived
OSE-TS responded with message with Comunication Result Code set to
“Operation On Hold” ("09") value in state when no “Order”
messages sent to the OSE-TS;
eOSE2DisconnectionReason_ErrorOperationCancelledReceived
OSE-TS responded with Error message with Comunication Result Code set to
“Operation Operation Cancelled” ("99") value;
eOSE2DisconnectionReason_ErrorMaximumNumberOfOrdersExceededLimitReceived
OSE-TS responded with Error message with Comunication Result Code set to
“Over Capacity” ("0A") value in state when no “Order” messages
sent to the OSE-TS;
An application that makes use of OSE2
Access Library can potentially have more than one session established with
OSE-TS system, hence, it needs to differentiate between session objects.
OSE2 Access Library provides an additional
property for session object, called "session ID" - an integer number
assigned by client during session object construction. Sesison ID is of type TOSE2SessionID,
which is a typedef for C++ unsigned long. OSE2 Access Library makes no
use of this identifier, only provides it as the first parameter with every
event callback for corresponding session.
Event callbacks notify clients about
library session object events (such as OSE-TS disconnection) and about protocol
messages received from OSE-TS.
Not all received messages cause callback
invocation. For example, “Heartbeat” messages received from OSE-TS are
processed automatically by the library object and there is no callback
invocation in this case.
Callback parameter values provide all
necessary data about correspondent event.
Pointers (e.g. const char*)
and Data Iterators (e.g. CASDIIterator) with received data
provided as callback parameters remain valid only inside callback invocation. Data
contents should be copied by client application code to use them outside of the
scope of callback invocation.
Event callback prototypes are described
below:
- void OSE2_NotifyApplicationStartResponse(const TOSE2SessionID&_refSessionID
,unsigned long _ulResponseResultCode
,unsigned long _ulReceiptSequenceNumber
,unsigned long _ulExecuteSequenceNumber)
Callback notifies user that “Application Start Response” message received from OSE-TS.
If Response Result Code is “Normal” “Application Link” is established.
Parameter _ulResponseResultCode is received
Response Result Code extracted from received message and converted to unsigned
long.
Parameters _ulReceiptSequenceNumber and
_ulExecuteSequenceNumber are most recent Notification Sequence
numbers transmitted by OSE-TS extracted from received message and
converted to unsigned long.
If received Response Result Code value is “End_Of_Online_Session”
or “Operation_On_Hold” then session object will be set to eOSE2_Disconnecting state. In this case just after client application code returns from
callback invocation “Application Link” will be closed: TCP/IP connection
will be released and OSE2_NotifyApplicationLinkClosed callback
will be invoked. Otherwise, session object will be set to eOSE2_Online
state.
- void OSE2_NotifyApplicationStatus(const TOSE2SessionID& _refSessionID
,CASDIIterator _iFirst
,CASDIIterator _iLast)
Callback notifies user that “Application Status” message received.
It passes client a range of iterators [_iFirst, _iLast)
that can be used to traverse group of Application Status Data Items.
CASDIIterator is an iterator type declared in OSE2ConnectionInterface.hh,
which can be dereferenced to obtain a CASDIWrapper object.
- void OSE2_NotifyNotificationStartResponse(const TOSE2SessionID&_refSessionID
,unsigned long _ulResponseResultCode)
Callback notifies user that “Notification
Start Response” message received from OSE-TS.
If Response Result Code is “Normal” “Notification Link” is
established.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void OSE2_NotifyLoginResponse(const
TOSE2SessionID& _refSessionID
,const char * _cszUser_ID
,unsigned long _ulResponseResultCode)
Callback notifies user that “Login Response”
message received from OSE-TS.
If Response Result Code is “Normal” “Order Link” is established.
In this case it is possible to post transactions
(Order Messages) to OSE-TS for user with _cszUser_ID using
session object classes and methods.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
Parameter _cszUser_ID is pointer to zero terminated
string with User ID extracted from received message.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void
OSE2_NotifyApplicationLinkClosed(const TOSE2SessionID& _refSessionID,
EOSE2DisconnectionReason _eReason)
Callback notifies user that “Application
Link” (Session) with OSE-TS closed by OSE2 Access Library. TCP/IP
Connection physically disconnected with OSE-TS. Additional information is
written by library code to log file (if provided). _eReason contains reason code of disconnection.
- void
OSE2_NotifyApplicationEndResponse(const TOSE2SessionID& _refSessionID
,unsigned long _ulResponseResultCode)
Callback notifies user that “Application
End Response” message received from OSE-TS.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
Session object will be set to eOSE2_Disconnecting state.
Just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked.
- void
OSE2_NotifyLogoutResponse(const TOSE2SessionID& _refSessionID
,const char * _cszUser_ID
,unsigned long _ulResponseResultCode)
Callback notifies user that “Logout
Response” message received from OSE-TS.
Parameter _cszUser_ID is pointer to zero terminated
string with User ID extracted from received message.
Parameter _ulResponseResultCode is received Response
Result Code extracted from message and converted to unsigned long.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void
OSE2_NotifyApplicationEndInstruction(const TOSE2SessionID&
_refSessionID)
Callback notifies user that “Application
End Instruction” message received from OSE-TS.
Session object will be set to eOSE2_Disconnecting state. In
this case just after client application code returns from callback
invocation “Application Link” will be closed: TCP/IP connection will be
released and OSE2_NotifyApplicationLinkClosed callback will
be invoked.
- void OSE2_NotifyError(const TOSE2SessionID& _refSessionID
,const char * _cszCommunicationResultCode
,const
char * _cszHeaderOfMessageError)
Callback notifies user that “Error”
message received from OSE-TS.
Parameter _cszCommunicationResultCode is pointer to
zero terminated string with Communication Result Code extracted from
received message.
Parameter _cszHeaderOfMessageError is pointer to
zero terminated string with first 256 bytes of message which cause an
“Error” extracted from received message.
Session object will be set to eOSE2_Disconnecting state. In
this case just after client application code returns from callback
invocation “Application Link” will be closed: TCP/IP connection will be
released and OSE2_NotifyApplicationLinkClosed callback will
be invoked.
- void
OSE2_NotifyFinalOrderInquiryResponse(const TOSE2SessionID&_refSessionID
,const char * _cszUser_ID
,unsigned long _ulResponseResultCode
,OSE2::CFinal_Order_Inquiry_Response_Data_Item& _refResponse)
Callback notifies user that “Final Order
Inquiry Response” message received from OSE-TS.
Parameter _cszUser_ID is pointer to zero terminated string
with User ID extracted from received message.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
NOTE: _cszUser_ID and _ulResponseResultCode values are extracted
copies of values stored in OSE2::CFinal_Order_Inquiry_Response_Data_Item.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void
OSE2_NotifyRetransmitRequestResponse(const TOSE2SessionID&_refSessionID
,const char * _cszUser_ID
,unsigned long _ulResponseResultCode
,const char* _cszSourceTerminal_ID
,char _cNotificationType
,char _cNotificationTypeCode
,unsigned long _ulStartNotificationSequenceNo
,unsigned long _ulEndNotificationSequenceNo)
Callback notifies user that “Retransmit
Request Response” Message received from OSE-TS.
Parameter _cszUser_ID is pointer to zero terminated
string with User ID extracted from received message.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
All other parameters contain contents of fields extracted from
received message and converted if necessary to appropriate data type.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void
OSE2_NotifyRetransmitCancellationResponse(const TOSE2SessionID&_refSessionID
,const char * _cszUser_ID
,unsigned long _ulResponseResultCode)
Callback notifies user that “Retransmit
Cancellation Response” Message received from OSE-TS.
Parameter _cszUser_ID is pointer to zero terminated
string with User ID extracted from received message.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void
OSE2_NotifyProxyRequestResponse(const TOSE2SessionID& _refSessionID
,const char * _cszUser_ID
,unsigned
long _ulResponseResultCode
,const char* _cszProxySourceTerminal_ID)
Callback notifies user that “Proxy Request
Response” Message received from OSE-TS.
Parameter _cszUser_ID is pointer to zero terminated
string with User ID extracted from received message.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
Parameter _cszProxySourceTerminal_ID is pointer to
zero terminated string with Proxy Source Terminal ID extracted from
received message.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void
OSE2_NotifyProxyCancellationResponse(const TOSE2SessionID&_refSessionID
,const char * _cszUser_ID
,unsigned long _ulResponseResultCode
,const char* _cszProxySourceTerminal_ID)
Callback notifies user that “Proxy
Cancellation Response” Message received from OSE-TS.
Parameter _cszUser_ID is pointer to zero terminated
string with User ID extracted from received message.
Parameter _ulResponseResultCode is received
Response Result Code extracted from message and converted to unsigned
long.
Parameter _cszProxySourceTerminal_ID is pointer to
zero terminated string with Proxy Source Terminal ID extracted from
received message.
If received Response Result Code value is “Operation_On_Hold” then
session object will be set to eOSE2_Disconnecting state. In this
case just after client application code returns from callback invocation
“Application Link” will be closed: TCP/IP connection will be released and OSE2_NotifyApplicationLinkClosed
callback will be invoked. Otherwise, session object will be set to
eOSE2_Online state.
- void OSE2_NotifyOrderResponse(const TOSE2SessionID& _refSessionID
,COrderResponseIterator _iFirst
,COrderResponseIterator _iLast)
Callback notifies user that “Order
Response” Message received.
Range of iterators [_iFirst, _iLast)
can be
used to traverse all accepted/rejected Order Data Items.
COrderResponseIterator is an iterator type declared in OSE2ConnectionInterface.hh,
which can be dereferenced to obtain a COrderResponseWrapper object.
Session object will be set to eOSE2_Online state.
- void
OSE2_NotifyOrderResponseError(const TOSE2SessionID& _refSessionID
,const char * _cszCommunicationResultCode
,const char * _cszHeaderOfMessageError
,COrderResponseErrorIterator _iFirst
,COrderResponseErrorIterator _iLast)
Callback notifies user that “Error”
Message received from OSE-TS message with Communication Result Code set to
“09” or “0A” in special case when “Order Response” message is expected by
the library after sending “Order” message to OSE-TS.
Callback provides client with the “Error” message data and Data Items of
rejected Orders extracted from library internal Transaction Queue.
Parameter _cszCommunicationResultCode is pointer to zero
terminated string with Communication Result Code extracted from received
message.
Parameter _cszHeaderOfMessageError is pointer to
zero terminated string with first 256 bytes of message which cause an
“Error” extracted from received message.
Range of iterators [_iFirst, _iLast) can be
used to traverse rejected Order Data Items.
COrderResponseErrorIterator is an iterator type declared in OSE2ConnectionInterface.hh,
which can be dereferenced to obtain a COrderResponseErrorWrapper
object.
NOTE: Rejected order Data Items are deleted from internal Transaction
Queue after this callback invoked and need to be posted again if
necessary.
No OSE2_NotifyError invocation performed if this
callback was invoked.
Session object will be set to eOSE2_Online state.
4.3 Posting Orders and
receiving Notifications
Two interfaces described above give user
means to control a single OSE-TS session and receive information about session
state transitions and session-level events. Rest of functionality, which
includes formatting and posting financial transactions and receiving OSE-TS Notifications,
is provided by the other two interfaces that represent the upper level of OSE2
Access Library. Unlike previously described session-related interfaces, these
two are unaware of any session level details. Upper level interfaces handle the following tasks:
- Providing means that allow easy access
and formatting of OSE-TS Order Data Items and Notification Data Items.
Upper level includes a set of classes that wrap all OSE-TS protocol Data
Items and provide easy way to access and check consistency of Data Item
fields.
- Delivering all Notifications received
from OSE-TS to client in the form of C++ classes. Delivery as a raw buffer
is also possible.
Transaction posting functionality is
represented by IOSE2_AUCTradeControl interface. It is an abstract C++
structure, which has two data types and several methods. Data types are:
- EOSE2_AUCTradeControlStatus - data type represents a set of return values for IOSE2_AUCTradeControl
interface methods: eOSE2_AUCTradeControl_OK indicates that a
transaction was successfully accepted by session object;
eOSE2_AUCTradeControl_PostFailed indicates a general failure;
eOSE2_AUCTradeControl_OutOfSequence means that an operation that
was attempted, was out of sequence;
eOSE2_AUCTradeControl_SessionDown indicates that an operation has
failed due to session object was not initialized properly;
eOSE2_AUCTradeControl_SystemError is returned in case of a system
error inside the library and is normally accompanied by an extended log
message.
- EOSE2_AUCTradeState - data type represents a set of possible states of transaction
input:
eOSE2_AUCTrade_NoSession;
eOSE2_AUCTrade_TransactionsDisabled;
eOSE2_AUCTrade_TransactionsEnabled.
NOTE: This data type is not used in current implementation of OSE2 Access
Library and reserved for future use.
OSE2 Access Library's trading interface
covers two different strategies of posting transactions.
First one implements a
"query-one-post-one" algorithm, where user first requests an instance
of desired input transaction Data Item, then either fills it with data and
posts it, or drops it, releasing resources. A subsequent input transaction Data
Item instance cannot be requested from the library without previous one being
either posted or dropped. Attempt to do so will cause an error return value of eOSE2_AUCTradeControl_OutOfSequence.
Types that represent transaction input Data Items are part of library
interface:
- OSE2AUC::COrder_New_Data_Item
- OSE2AUC::COrder_Cancellation_Data_Item
- OSE2AUC::COrder_Correction_Data_Item
Second strategy implies that client code
does all routine concerning transaction Data Item formatting and provides
library method with a ready buffer. This strategy imposes no extra limitations
on how many posts are done in a row.
Taking the above into account, IOSE2_AUCTradeControl
interface methods looks like the following:
- OSE2AUC::COrder_New_Data_Item&
OSE2_AUC_Request_Order_New()
throw(EOSE2_AUCTradeControlStatus,
IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method returns a reference to the object created in internal Transaction
Queue of type OSE2AUC::COrder_New_Data_Item, which is a C++ wrapper
class for OSE-TS Order New Data Item.
Returned reference should be used by client code to fill Order New Data
Item with data, then either a post or a drop method must be called before OSE2_AUC_Request_Order_*
can be called again.
- OSE2AUC::COrder_Cancellation_Data_Item&
OSE2_AUC_Request_Order_Cancellation()
throw(EOSE2_AUCTradeControlStatus,
IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method returns a reference to the object created in internal Transaction
Queue of type OSE2AUC::COrder_Cancellation_Data_Item,
which is a C++ wrapper class for OSE-TS Order Cancellation Data Item.
Semantics is same as for New Order.
- OSE2AUC::COrder_Correction_Data_Item&
OSE2_AUC_Request_Order_Correction()erface::EEvtManagerStatus,std::bad_alloc)
Method returns a reference to the object created in internal Transaction
Queue of type OSE2AUC::COrder_Correction_Data_Item,
which is a C++ wrapper class for OSE-TS Order Correction Data Item.
Semantics is same as for New Order.
- EOSE2_AUCTradeControlStatus
OSE2_AUC_PostTransaction(unsigned long _ulTransactionSequenceNumber)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method posts a transaction Data Item that was previously created in a call
to one of OSE2_AUC_Request_Order_* methods. In case of
success return value will be eOSE2_AUCTradeControl_OK.
If no Order Data Item was created prior to calling OSE2_AUC_PostTransaction,
return value will be eOSE2_AUCTradeControl_OutOfSequence.
In case if posting failed because of some other reason return value will
be eOSE2_AUCTradeControl_PostFailed or eOSE2_AUCTradeControl_SystemError
and transaction Data Item will be dropped.
If size of internal Transaction Queue reaches its maximum capacity (20)
after OSE2_AUC_PostTransaction method call, then library
object delivers all queued transaction Data Items (including just posted
one) immediately by call of OSE2_AUC_DeliverCollectedTransactions method
internally. Otherwise, posted transaction Data Items wait in internal
Transaction Queue for OSE2_AUC_DeliverCollectedTransactions
call or delay timeout expiration. Also, receiving of “Heartbeat” Message
may cause library session object to start delivery process of queued
transaction Data Items to OSE-TS (instead of sending “KeepAlive” message)
in case if there are no any other messages requested to be sent to OSE-TS.
- EOSE2_AUCTradeControlStatus
OSE2_AUC_DropTransaction()
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method is used to discasrd a previously requested Order Data Item. After
calling this method another Order Data Item can be requested from the
library. In case of success return value will be eOSE2_AUCTradeControl_OK.
If no message was created prior to calling OSE2_AUC_DropTransaction,
return value will be eOSE2_AUCTradeControl_OutOfSequence. In this
case such a return value is not considered as an error.
- EOSE2_AUCTradeControlStatus
OSE2_AUC_PostForeignTransaction(unsigned long
_ulTransactionSequenceNumber, const char* _cszTXBuffer, int _iTXLength)
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method posts preformatted Order Data Item. In case of success return value
will be eOSE2_AUCTradeControl_OK.
In case of failure return value will be eOSE2_AUCTradeControl_PostFailed
or eOSE2_AUCTradeControl_SystemError.
Calling this method does not affect the state of Order Data Item requested
from the library via OSE2_AUC_Request_Order_* methods.
If size of internal Transaction Queue reaches its maximum capacity (20)
after OSE2_AUC_PostForeignTransaction method call, then
library object delivers all queued transaction Data Items (including just
posted one) immediately by call of OSE2_AUC_DeliverCollectedTransactions
method internally. Otherwise, posted transaction Data Items wait
in internal Transaction Queue for OSE2_AUC_DeliverCollectedTransactions
call or delay timeout expiration. Also, receiving of “Heartbeat” Message
may cause library session object to start delivery process of queued
transaction Data Items to OSE-TS (instead of sending “KeepAlive” message)
in case if there are no any other messages requested to be sent to OSE-TS.
- EOSE2_AUCTradeControlStatus
OSE2_AUC_DeliverCollectedTransactions()
throw(IEventLogInterface::ELogStatus,IEventManagerInterface::EEvtManagerStatus,std::bad_alloc)
Method is used to deliver transaction Data Items queued in internal
Transaction Queue immediately. In case of success return
value will be eOSE2_AUCTradeControl_OK.
Method will fail with return value eOSE2_AUCTradeControl_OutOfSequence
if some transaction Data Items are on the way to OSE-TS but not yet
acknowledged by “Order Response” Message from OSE-TS.
In case if delivering failed because of some other reason return
value will be eOSE2_AUCTradeControl_SystemError.
OSE2 Access Library delivers OSE-TS
Notifications to its client via IOSE2_AUCTradeNotification interface.
Client code derives from an abstract C++ structure, implements its methods and
registers implementation in session object in order to receive Notifications.
Basically, all callbacks are similar in that they accept a session identifier,
a reference to an object of a special type that represents OSE-TS message
header and a reference to a particular Notification Data Item object. Classes
representing OSE-TS Notification Data Items provide access and validation
methods for all Data Item fields. Notification interface is outlined below:
bool OSE2_AUC_NotifyOSE2Notification(const TOSE2SessionID& _refSessionID,
const OSE2::CHEADER& _refHeader,
const char* _cszFrameStart, int _iFrameLength);
bool OSE2_AUC_NotifyReceiptNotification(const TOSE2SessionID& _refSessionID,
const OSE2::CHEADER& _refHeader,
const OSE2AUC::CReceipt_Notification_Data_Item& _refNotification);
bool OSE2_AUC_NotifyReceiptNotificationError(const TOSE2SessionID&_refSessionID,
const OSE2::CHEADER& _refHeader,
const OSE2AUC::CReceipt_Notification_Error_Data_Item& _refNotification);
bool OSE2_AUC_NotifyExecuteNotificationContractExecution(const TOSE2SessionID&_refSessionID,
const OSE2::CHEADER& _refHeader,
const OSE2AUC::CExecute_Notification_Contract_Execution_Data_Item&_refNotification);
bool OSE2_AUC_NotifyExecuteNotificationExpiredInvalid(const TOSE2SessionID& _refSessionID,
const OSE2::CHEADER& _refHeader,
const OSE2AUC::CExecute_Notification_ExpiredInvalid_Data_Item& _refNotification);
bool OSE2_AUC_NotifyResultNotificationCorrection(const TOSE2SessionID&_refSessionID,
const OSE2::CHEADER& _refHeader,
const OSE2AUC::CResult_Notification_Correction_Data_Item&_refNotification);
bool OSE2_AUC_NotifyResultNotificationCancellation(const TOSE2SessionID& _refSessionID,
const OSE2::CHEADER& _refHeader,
const OSE2AUC::CResult_Notification_Cancellation_Data_Item&_refNotification);
bool OSE2_AUC_NotifyExecuteNotificationEndOfOutput(const TOSE2SessionID&_refSessionID, const OSE2::CHEADER& _refHeader,
const OSE2::CHEADER& _refHeader,
const OSE2AUC::CExecute_Notification_End_Of_Output_Data_Item& _refNotification);
The only
callback that deserves special attention is OSE2_AUC_NotifyOSE2Notification.
It is always invoked first, when a Notification message arrives from OSE-TS and
it delivers to the client raw Notification buffer which may consist of multiple
Notification Data Items blocked by OSE-TS specification rules. If return value
is false then session object stops Notification processing and doesn’t
invoke separate callbacks for particular Notification Data Items.
4.4 Administrative interface
Aside of the interfaces described above,
session object provides initialization methods for user to register callback
interfaces and to query control and trade interfaces. Prototypes
for those methods are given below:
- IOSE2_SessionControl*
OSE2_AUC_GetControlInterface() throw()
- IOSE2_AUCTradeControl*
OSE2_AUC_GetTradeInterface() throw()
- void
OSE2_AUC_RegisterSessionClient(IOSE2_SessionNotification* _pSNI) throw()
- void OSE2_AUC_RegisterTradeClient(IOSE2_AUCTradeNotification*
_pTNI) throw()
4.5 Financial data
representation
OSE-TS system receives and transmits data
over communication media using proprietary ASCII subset character format. OSE2
Access Library provides a convenient system of frame access classes
capable of frame parsing and composition. For each data entity, such as an
Order Data Item defined in OSE-TS data specification, a corresponding C++ class
is defined. All data access classes have similar structure; their code has been
automatically generated, based on formal data specification.
Data Item formats utilized by OSE-TS differ for different system types.
OSE2 Access Library data framework follows this separation defining
every system types data access classes in corresponding separate namespaces.
However, since certain session-level messages, such as message header are
common for all system types, those are defined in common OSE2::
namespace.
NOTE: Currently OSE2 Access Library defines separate
namespaces for data access: OSE2AUC::, covering OSE Auction
Trading System only.
Raw frame manipulation
Class CFrameWrapper represents a raw memory buffer
allocated somewhere. It does not control buffer's allocation and release,
instead it stores buffer pointer and length and provides a set of methods for
accessing underlying buffer memory. CFrameWrapper's interface is divided
into two parts:
- Frame Access Classes interface.
A frame access class like COrder_New_Data_Item has an
associated CFrameWrapper class instance. Frame parsing and composition
methods access frame's data via this instance. Basically all methods of
the frame access class like set_Field() or get_Field() are
just thin inline functions, responsible for field's type and position
within frame. And all the complexity of data manipulation is concentrated
in CFrameWrapper's format access interface.
It’s primary aim is to provide sophisticated routines for raw frame access
to be called from particular fields code.
- User side interface.
CFrameWrapper instances are normally created by user code and are
used to attach Frame Access class instances for subsequent field
access. User side interface is thus comprised of Frame Access class
attach/detach functionality. Frame access objects can be attached to the
beginning or to the end of a CFrameWrapper object. The second
parameter of Attach() method provides this option. Attach operation
results in cutting a part from either the beginning or the end of the
controlled buffer and assigning just cut part to the instance of frame
access class. As soon as an instance of frame access class is attached, it
can check underlying frame's consistency, extract or store field values.
Allocation of CFrameWrapper-controlled buffers is left to user: it
can be dynamic or automatic memory.
As explained above, all the complexity of data formats used
in data specification is concentrated in CFrameWrapper class.
OSE-TS system protocol has specific data formats such as
prices and quantities that may require specific alignment and filling. For instance,
price can be either 'Market price', 'Limit price', or 'Empty'.
On user side such field's value is represented by an instance of CFrameWrapper::SOSE2Price
structure.
Integer value fields which may be set to ‘Empty’
value are represented by CFrameWrapper::SUINTWithStatus or CFrameWrapper::SUINT64WithStatus
data type.
To summarize, CFrameWrapper class has very simple
contents - a pointer to raw buffer and its length. However, it contains
sophisticated functionality for manipulating frame's content. CFrameWrapper
objects can be instantiated on arbitrary buffers and can be used as a base for
frame access classes, which can be attached to and detached from the designated
frame.
Frame access classes
Frame access classes represent most valuable part of OSE2
Access library data access framework. Their objective is to simplify procedure
of manipulating the content of raw character frames, understood by OSE-TS
trading system. Any data block is naturally represented as sequence of fields,
frame access classes contain access methods for every individual field.
All Frame Access classes have common functionality,
concentrated in the base class - CGenericBlock. As explained in previous
section all access classes can be attached to CFrameWrapper instance.
This functionality is implemented by CGenericBlock::Attach(), CGenericBlock::Detach()
methods. Also, every frame access class has a designated frame, assigned
during attach operation. This frame is stored in CGenericBlock::m_Frame
member and is accessed by implementations of all field access methods. CGenericBlock
class also contains DynamicClone() method for polymorphic creation of
frame access instances on the heap. This functionality is useful when instances
are stored in heterogeneous containers forming queues or more sophisticated
data structures.
Similar to DynamicClone() method of CGenericBlock,
all frame access classes have Clone() method, which is not polymorphic
and returns created instance to the caller on the stack.
Every field of a data block has special check_Field()
method, that should be executed to check whether underlying data is properly
formatted. However, individual check_Field() methods are not normally
called by library users. Instead there is single check() method that
invokes specific check_Field() method for every field in the message.
set_Field() methods are used
to assign new values to corresponding fields. There can be several set_Field()
for a single field. Different methods accept different parameters. If the
parameter of the set_Field() method cannot be converted to valid value
for the field, an exception is thrown.
get_Field() method is used
to retrieve field's value. It does not accept any parameters and returns
converted value via stack. get_Field() should always be applied to properly
formatted field, i.e. underlying code assumes that corresponding field has been
checked with individual or generic check() method. This assumption
allows simpler get_Field() method implementation, that should provide
better performance. If prior check() operation has not been performed
debug version of the library triggers runtime assertion to signal improper
usage on early stage of the software development. There can be several get_Field()
methods with different names to return different representations of the field's
value.
As mentioned above, set_Field() and check_Field()
methods can throw exceptions to signal improper parameter or field's value.
Thrown exception has type CBlockException, defined inside frame access
class. This class in inherited from global CFrameException class. CFrameException
has single member - m_eReason, identifying error code, describing
exceptional condition. By itself CBlockException class can be thrown
from Attach() and Detach() methods to signal operation error. For
example frame access object cannot be properly attached, because supplied frame
is too small. In all other cases derived instance is thrown. All CBlockException
classes have a single member, identifying the field that caused the exception,
so that exception handler can report invalid field and reason for exception.
5. Configuration
When a session object is instantiated, it requires that the
following configuration parameters are provided in constructor:
- const TOSE2SessionID&
_crefSessionID - an integer assigned by user
to identify this session object within application. Session object makes
no use of this parameter - only returns it with every event callback.
- const char* _cszLogicalTerminalID –Logical Terminal ID provided by OSE-TS. Must
be 5 characters.
- const char* _cszCommunication_ServerID – Communication Server ID provided by OSE-TS, must be 5
characters.
- const char*
_cszTransactionParticipantCode – Transaction
Participant Code, Provided by OSE-TS. Must be 5 characters.
- const char* _cszReceiptNotificationDestinationPrimary – Logical Terminal ID that will receive primary receipt
notifications. Must be an existing Logical Terminal ID or set to 5 spaces.
- const char*
_cszExecuteNotificationDestinationPrimary -
Logical Terminal ID that will receive primary contract notifications. Must
be an existing Logical Terminal ID or set to 5 spaces.
- const char*
_cszReceiptNotificationDestinationBackup -
Logical Terminal ID of virtual server that will receive backup receipt
notifications. Must be an existing Logical Terminal ID or set to 5 spaces.
- const char*
_cszExecuteNotificationDestinationBackup -
Logical Terminal ID that will receive backup contract notifications. Must
be an existing Logical Terminal ID or set to 5 spaces.
- unsigned int _uiOrderCollectionTimeoutMS – OSE2 Access Library provides a configurable timeout, during
which it will collect orders before sending them to OSE-TS. Send operation
will be performed when either timeout expires or there are 20 orders
waiting to be sent to OSE-TS. This parameter sets the timeout in
milliseconds. Setting this parameter to 0 value forces sending to be
performed immediately after OSE2_AUC_Post* method call. In
this case there is no possibility to create OSE-TS Order message with
multiple Order Data Items in one OSE-TS message.
- unsigned int
_uiOrderCollectionQueueSize –OSE2 Access
Library maximum number of Order Data Items allowed to be collected before
sending them to OSE-TS. Must be set to value 20.
- const char*
_cszOutgoingInterfaceIPAddress - local IP
address to which connecting socket is bound. Assigned by OSE-TS. Must be a
valid IP address in "xxx.xxx.xxx.xxx" representation.
- unsigned short
_uiOutgoingInterfaceTCPPort - local TCP port
to which connecting socket is bound. Assigned by OSE-TS. Must be a valid
TCP port number.
- const char*
_cszCommunicationServerIPAddress –
Communication Server IP address, provided by OSE-TS. Must be a valid IP
address in "xxx.xxx.xxx.xxx" representation.
- unsigned short
_uiCommunicationServerTCPPort - Communication server
listening TCP port, provided by OSE-TS. Must be a
valid TCP port number.
- IEventManagerInterface&
_refEventManager - a reference to event
manager interface.
- IEventLogInterface* _pEventLog - a pointer to event logger interface. Optional
parameter, default value is NULL.
6. Usage guidelines
This section provides guidelines for efficient using OSE2
Access Library in client code. It consists of several points that should be
kept in mind when using library.
Session object construction
Single session object is represented by an instance of COSE2AUCImpl
class. Session object allows copy construction and assignment to enable its
insertion into STL containers. Note that in case of copying, a newly created
copy gains control over session lifetime. In case of assignment the object in
the left side of the assignment operator gains control over session lifetime.
Invoking session control interface methods
User should always examine session state after a session control interface
method failure. Some methods, being improperly invoked, can cause session
termination, it is user's responsibility to handle such situations. When
session is terminated, session object performs its total state reset. Session
statistics returned by interface method is not guaranteed to be any real for a
disconnected session object.
Posting transactions
OSE2 Access Library provides two ways to prepare Order Data Items and send it
to OSE-TS:
- On-the-Fly method. This one is normally
used when message is being composed just before being sent to OSE-TS. In
this case message is being composed directly inside library's outgoing
buffer. This should provide the best performance. Here's the sequence of
steps to be taken:
- Acquire order data access object from
the library, attached to the outgoing buffer using trade control
interface:
OSE2AUC::COrder_New_Data_Item& l_refNewOrder =
IOSE2_AUCTradeControl::OSE2_AUC_Request_Order_New();
- Fill acquired transaction Data Item
using proper set_Field() methods for all fields of Data Item
(including Reserved Fields). Use composite check(); method to see
if accidentally some field is forgotten to be filled. If all fields are
successfully filled, call method IOSE2_AUCTradeControl::OSE2_AUC_PostTransaction()
to commit this order for transmission. If frame composition exception has
been detected, method IOSE2_AUCTradeControl::OSE2_AUC_DropTransaction()
must be used to cancel transaction request and release relevant library
resources.
- Delayed method. All frames are prepared
on buffers allocated by user and are provided to the library in raw form.
This approach is suitable for applications keeping queues of Orders Data
Items or for those receiving preformatted OSE-TS Data Items or messages
from other applications. This way requires following steps:
- Decide where raw frames are allocated.
Data access headers have special global constants for every defined data
block. These can be used for frame allocation just in automatic memory.
For example, for New Order Data Item frame access block OSE2AUC::COrder_New_Data_Item
and length constant OSE2AUC::g_culOrder_New_Data_Item_Length are
defined.
- Instantiate CFrameWrapper class
using allocated buffer and its length as constructor parameters.
- Instantiate frame access object (for our
example it is OSE2AUC::COrder_New_Data_Item) and link it to just
allocated buffer using CFrameWrapper::Attach() method.
- Now frame access object is ready to
render outgoing buffer. Use corresponding set_Field() methods for
all fields (including Reserved Fields) to fill Data Item. Optional
check() method may be used to check whether there are fields forgotten to
be filled.
- When the frame is ready to be sent to
OSE-TS, use method IOSE2_AUCTradeControl::OSE2_AUC_PostForeignTransaction()
to pass ready order data to the library for subsequent transmission.
Note that once OSE2_AUC_PostTransaction()
or OSE2_AUC_PostForeignTransaction() has succeeded, transaction Data
Item is stored within internal Transaction Queue waiting to be posted to
OSE-TS. Depending on library configuration _uiOrderCollectionTimeoutMS parameter
value, posting may happen immediately or may take some time. If during this
time a disconnection from OSE-TS occurs, all Order Data Items stored by library
in internal Transaction Queue, but not posted yet, are discarded.
OSE-TS “Final Order Inquiry” Request must
be used after session recovery to determine the latest Order Data Item actually
received by OSE-TS system.
Notification processing
When library receives a Notification message from OSE-TS, it first invokes OSE2_AUC_NotifyOSE2Notification
callback to deliver the whole buffer to client. This callback has default
implementation that just returns true. After that, Notification Data
Items are extracted one by one and Notification-specific callbacks of IOSE2_AUCTradeNotification
interface are invoked. If user only wants to receive the raw buffer, the first
callback should be overridden and its implementation should return false.
Generally, once a notification callback has returned false, subsequent
notification extraction is not performed and notifications remaining in the
buffer are discarded. This scenario may be used by applications which don't
need to deal with separate notifications and only have to pass the whole buffer
further on.
7. Dependencies
Current release of OSE2 Access Library has no specific
software or hardware dependencies. Ordinary TCP/IP stack is used for
communications and is accessed via sockets interface. OSE2 Access Library can
be built on any system that has a standard-compliant C++ compiler and supports
major POSIX system calls and Berkeley Sockets interface to TCP protocol.
OSE2 Access Library requires that application's
implementation of main loop supports a predefined interface. Library is
accompanied with an example of UNIX version of event manager that implements
application's main loop. Description of required interface can be found in
this document.
OSE2 Access Library's objects will make use of an event
logging component if one is provided during construction. Event logging
interface supported by library is described in this document. Event logging
categories supported by session objects are: all predefined categories,
"OSE2.raw.data" (controls dumping of data being passed in hexadecimal
format) and "OSE2.comm.debug" (additional debugging information for
communication level)
- Library was initially developed for Linux
platform. Various gcc versions starting from 3.2.3 were used for source
code conformance testing and cross-compilation. Generally a release can be
provided for any C++ standard compliant compiler, for any platform that
supports Sockets and a major subset of POSIX system calls, however, it may
require additional testing and possibly source code tweaking. OSE2 Access
Library is initially provided as a per-compiler static library.
- _UNIX_APP_
preprocessor symbol should be defined before including library headers
when using the library under UNIX, since some of the accompanying headers
use it to identify UNIX builds.
- Library uses NDEBUG preprocessor symbol
to differentiate between debug and release compilation modes.
9. Library usage example code
Library is shipped with a sample application that
highlights library features described in this document and can be used as a
test console for OSE-TS Trading System. Application reads a configuration file
on startup and displays command prompt. User can create OSE2 sessions according
to configuration file entries, perform establishing of “Application Link”,
“Notification Link”, “Order Link”, load contents of transaction Data Items from
text files, send multiple transactions and review state of existing session.
Additional commands are implemented to provide examples of
using set_(), get_() check_() methods for OSE2 Access Library
implementation of OSE-TS Price format.
Sample application includes implementations of event
manager and event logger, which conform to library's requirements.
(C) Orchid Technology K.K. 2005-2008. All
rights reserved.