OnixS Eurex ETI Handler C++ library 9.29.0
Users' manual and API documentation
Loading...
Searching...
No Matches
Timestamps

The Handler represents points in time with HighResolutionTime, with microsecond resolution.

HighResolutionTime

A HighResolutionTime is one of the following:

The two kinds of valid times behave the same way:

The difference between two local clock readings is taken on the monotonic clock directly, so it is not affected when the system clock is adjusted in between, manually or by NTP.

using namespace OnixS::Eurex::Trading;
now.getFields(&fields);
// For example, "20261018-16:51:38.996195".
std::cout << now.toString() << std::endl;
// The current date in UTC, as YYYYMMDD.
const unsigned utcDate = fields.year * 10000u + fields.month * 100u
+ fields.day;
using namespace OnixS::Eurex::Trading;
"20261231-16:00:00.000000"
);
// Positive while the deadline is still ahead.
const HighResolutionTimeSpan remaining = deadline

Where the API uses it

MessageInfo accompanies every message passed to a listener, and carries three times:

Time Meaning Source
MessageInfo::requestTime The gateway read the request this message answers from its TCP socket, RequestTime (5979). Gateway, UTC.
MessageInfo::sendingTime The gateway sent this message, SendingTime (52). Gateway, UTC.
MessageInfo::receivingTime The Handler started processing the data that contained this message. Local monotonic clock.

Responses carry both gateway times, notifications and broadcasts carry only the sending time, and other messages carry neither. A gateway time the message does not carry is UInt64NoValue in MessageInfo::rawRequestTime or MessageInfo::rawSendingTime. Check the raw field before calling MessageInfo::requestTime or [MessageInfo::sendingTime]: they do not recognize that value and return a meaningless time for it.

The Handler takes MessageInfo::receivingTime once for each block of data it reads from the socket, after the received-bytes listener has been invoked, and all messages decoded from that block share it.

The raw fields hold the values as received or measured: MessageInfo::rawRequestTime and MessageInfo::rawSendingTime are nanoseconds since the UNIX epoch, and MessageInfo::rawReceivingTime is a reading of the local clock in the platform's own units, described below.

Measuring latency

Subtracting MessageInfo::receivingTime from HighResolutionTime::now gives the time a message spent in the Handler before reaching the listener. Both are local clock readings, so the result is exact to the clock's resolution. When several messages arrive in one block of data, the time of a later message also includes the processing of the earlier ones, their listener callbacks among them.

Subtracting MessageInfo::sendingTime from MessageInfo::receivingTime gives the time from the gateway to the Handler. The two times come from different clocks, so the result also includes the offset between the gateway's clock and the local system clock, and is only as accurate as the local clock's synchronization.

using namespace OnixS::Eurex::Trading;
class LatencyListener : public OrderHandlingListener
{
public:
void onNewOrderResponse(
const NewOrderResponse& /*msg*/,
const MessageInfo& msgInfo
) override
{
// Time spent inside the Handler between reading the message from the
// socket and invoking this callback, in microseconds.
const HighResolutionTimeSpan inHandler = HighResolutionTime::now()
- msgInfo.receivingTime();
// From the gateway sending the response to the Handler receiving it, in
// microseconds. Includes the offset between the gateway's clock and the
// local system clock.
const HighResolutionTimeSpan fromGateway = msgInfo.receivingTime()
- msgInfo.sendingTime();
std::cout << "Received at " << msgInfo.receivingTime() << " (UTC), "
<< inHandler << " us in the Handler, " << fromGateway
<< " us from the gateway." << std::endl;
}
};

Platform specifics

Linux

  • The local clock is CLOCK_MONOTONIC, read with microsecond resolution.
  • MessageInfo::rawReceivingTime is a timeval holding a CLOCK_MONOTONIC reading, so it can be compared directly with the application's own clock_gettime(CLOCK_MONOTONIC, ...) readings.
  • A local clock reading is converted to UTC using the offset between CLOCK_REALTIME and CLOCK_MONOTONIC at the moment of conversion. The UTC time therefore follows adjustments of the system clock, and the same reading may convert to a slightly different UTC time after the system clock has been adjusted.

Windows