High Frequency FIX Parser
C++ library for high frequency messaging with the Financial Information Exchange (FIX) protocol.
|
One FIX message for writing. More...
#include <hffix.hpp>
Public Member Functions | |
message_writer (char *buffer, size_t size) | |
Construct by buffer size. | |
message_writer (char *begin, char *end) | |
Construct by buffer begin and end. | |
template<size_t N> | |
message_writer (char(&buffer)[N]) | |
Construct on an array reference to a buffer. | |
~message_writer () | |
Owns no resources, so destruction is no-op. | |
Buffer Access | |
size_t | message_size () const |
Size of the message in bytes. | |
char * | message_begin () const |
Pointer to beginning of the message. | |
char * | message_end () const |
Pointer to past-the-end of the message. | |
size_t | buffer_size () const |
Total available buffer size, including buffer already written to by this message. | |
size_t | buffer_size_remaining () const |
Remaining available buffer size. Excludes buffer already written to by this message. | |
Transport Fields | |
void | push_back_header (char const *begin_string_version) |
Write the BeginString and BodyLength fields to the buffer. | |
void | push_back_header (std::string_view begin_string_version) |
Write the BeginString and BodyLength fields to the buffer. | |
void | push_back_trailer (bool calculate_checksum=true) |
Write the CheckSum field to the buffer. | |
String Fields | |
void | push_back_string (int tag, char const *begin, char const *end) |
Append a string field to the message. | |
void | push_back_string (int tag, char const *cstring) |
Append a string field to the message. | |
void | push_back_string (int tag, std::string const &s) |
Append a string field to the message. | |
void | push_back_string (int tag, std::string_view s) |
Append a string field to the message. | |
void | push_back_char (int tag, char character) |
Append a char field to the message. | |
Integer Fields | |
template<typename Int_type > | |
void | push_back_int (int tag, Int_type number) |
Append an integer field to the message. | |
Decimal Float Fields | |
template<typename Int_type > | |
void | push_back_decimal (int tag, Int_type mantissa, Int_type exponent) |
Append a decimal float field to the message. | |
Date and Time Fields | |
void | push_back_date (int tag, int year, int month, int day) |
Append a LocalMktDate or UTCDate field to the message. | |
void | push_back_monthyear (int tag, int year, int month) |
Append a month-year field to the message. | |
void | push_back_timeonly (int tag, int hour, int minute, int second) |
Append a UTCTimeOnly field to the message. | |
void | push_back_timeonly (int tag, int hour, int minute, int second, int millisecond) |
Append a UTCTimeOnly field to the message with millisecond precision. | |
void | push_back_timeonly_nano (int tag, int hour, int minute, int second, int nanosecond) |
Append a UTCTimeOnly field to the message with up to nanosecond precision. | |
void | push_back_timestamp (int tag, int year, int month, int day, int hour, int minute, int second) |
Append a UTCTimestamp field to the message. | |
void | push_back_timestamp (int tag, int year, int month, int day, int hour, int minute, int second, int millisecond) |
Append a UTCTimestamp field to the message with millisecond precision. | |
void | push_back_timestamp_nano (int tag, int year, int month, int day, int hour, int minute, int second, int nanosecond) |
Append a UTCTimestamp field to the message with nanosecond precision. | |
Boost Date and Time Fields | |
void | push_back_date (int tag, boost::gregorian::date date) |
Append a LocalMktDate or UTCDate field to the message. | |
void | push_back_timeonly (int tag, boost::posix_time::time_duration timeonly) |
Append a UTCTimeOnly field to the message with millisecond precision. | |
void | push_back_timeonly_nano (int tag, boost::posix_time::time_duration timeonly) |
Append a UTCTimeOnly field to the message with nanosecond precision. | |
void | push_back_timestamp (int tag, boost::posix_time::ptime timestamp) |
Append a UTCTimestamp field to the message with millisecond precision. | |
void | push_back_timestamp_nano (int tag, boost::posix_time::ptime timestamp) |
Append a UTCTimestamp field to the message with nanosecond precision. | |
std::chrono Date and Time Fields | |
template<typename Clock , typename Duration > | |
void | push_back_timestamp (int tag, std::chrono::time_point< Clock, Duration > tp) |
Append a std::chrono::time_point field to the message with millisecond precision. | |
template<typename Clock , typename Duration > | |
void | push_back_timestamp_nano (int tag, std::chrono::time_point< Clock, Duration > tp) |
Append a std::chrono::time_point field to the message with nanosecond precision. | |
template<typename Rep , typename Period > | |
void | push_back_timeonly (int tag, std::chrono::duration< Rep, Period > timeonly) |
Append a UTCTimeOnly field to the message with millisecond precision. | |
template<typename Rep , typename Period > | |
void | push_back_timeonly_nano (int tag, std::chrono::duration< Rep, Period > timeonly) |
Append a UTCTimeOnly field to the message with nanosecond precision. | |
Data Fields | |
void | push_back_data (int tag_data_length, int tag_data, char const *begin, char const *end) |
Append a data length field and a data field to the message. | |
One FIX message for writing.
Given a buffer, the message_writer will write a FIX message to the buffer. message_writer does not take ownership of the buffer.
The message_writer interface is patterned after Back Insertion Sequence Containers, with overloads of push_back
for different FIX field data types.
The push_back_header()
method will write the BeginString and BodyLength fields to the message, and the FIX Standard Message Header requires also MsgType, SenderCompID, TargetCompID, MsgSeqNum and SendingTime. You must write those fields yourself, starting with MsgType.
After calling all other push_back
methods and before sending the message, you must call push_back_trailer(), which will write the CheckSum field for you.
Keep in mind that if you don't like the way any of these push_back
methods perform serialization, then you can always do your own serialization for any data type, and then append it to the message by push_back_string()
.
For example, these two statements are equivalent for hffix::message_writer w
.
For another example, if a trading peer has extended FIX for femtosecond timestamp precision, then a custom timestamp can be serialized to a string and then written to a field.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Pointer to past-the-end of the message.
|
inline |
Size of the message in bytes.
|
inline |
|
inline |
Append a data length field and a data field to the message.
Note that this method will append two fields to the message. The first field is an integer equal to the content length of the second field. FIX does this so that the content of the second field may contain Ascii NULL or SOH or other control characters.
High Frequency FIX Parser calculates the content length for you and writes out both fields, you just have to provide both tags and pointers to the data. For most of the data fields in FIX, it is true that tag_data = tag_data_length + 1, but we daren't assume that.
Example:
tag_data_length | FIX tag for the data length field. |
tag_data | FIX tag for the data field. |
begin | Pointer to the beginning of the data. |
end | Pointer to after-the-end of the data. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
|
inline |
|
inline |
Append a decimal float field to the message.
The decimal float is of the form mantissa×10exponent.
Non-normalized. The exponent parameter must be less than or equal to zero. If the exponent parameter is zero, no decimal point will be written to the ascii field.
Int_type | Integer type for the mantissa and exponent. |
tag | FIX tag. |
mantissa | The mantissa of the decimal float. |
exponent | The exponent of the decimal float. Must be less than or equal to zero. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Write the BeginString and BodyLength fields to the buffer.
This method must be called before any other push_back
method. It may only be called once for each message_writer.
push_back
method has yet been called. begin_string_version | The value for the BeginString FIX field. Should probably be "FIX.4.2" or "FIX.4.3" or "FIX.4.4" or "FIXT.1.1" (for FIX 5.0). |
std::out_of_range | When the remaining buffer size is too small. |
std::logic_error | When called more than once for a single message. |
|
inline |
Write the BeginString and BodyLength fields to the buffer.
This method must be called before any other push_back
method. It may only be called once for each message_writer.
push_back
method has yet been called. begin_string_version | The value for the BeginString FIX field. Should probably be "FIX.4.2" or "FIX.4.3" or "FIX.4.4" or "FIXT.1.1" (for FIX 5.0). |
std::out_of_range | When the remaining buffer size is too small. |
std::logic_error | When called more than once for a single message. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Append a string field to the message.
The entire, literal contents of s will be copied to the output buffer, so if you are using std::wstring you may need to first convert from UTF-32 to UTF-8, or do some other encoding transformation.
tag | FIX tag. |
s | String. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
|
inline |
Append a UTCTimeOnly field to the message with millisecond precision.
No time zone or daylight savings time transformations are done to the time.
Fractional seconds will be written to the field, rounded to the millisecond.
tag | FIX tag. |
timeonly | Time. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimeOnly field to the message.
No time zone or daylight savings time transformations are done to the time.
No fractional seconds are written to the field.
tag | FIX tag. |
hour | Hour. |
minute | Minute. |
second | Second. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimeOnly field to the message with millisecond precision.
No time zone or daylight savings time transformations are done to the time.
tag | FIX tag. |
hour | Hour. |
minute | Minute. |
second | Second. |
millisecond | Millisecond. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimeOnly field to the message with millisecond precision.
No time zone or daylight savings time transformations are done to the time.
Fractional seconds will be written to the field, rounded to the millisecond.
tag | FIX tag. |
timeonly | Time. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimeOnly field to the message with nanosecond precision.
No time zone or daylight savings time transformations are done to the time.
Fractional seconds will be written to the field, rounded to the nanosecond.
tag | FIX tag. |
timeonly | Time. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimeOnly field to the message with up to nanosecond precision.
No time zone or daylight savings time transformations are done to the time.
tag | FIX tag. |
hour | Hour. |
minute | Minute. |
second | Second. |
nanosecond | Nanosecond. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimeOnly field to the message with nanosecond precision.
No time zone or daylight savings time transformations are done to the time.
Fractional seconds will be written to the field, rounded to the nanosecond.
tag | FIX tag. |
timeonly | Time. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimestamp field to the message with millisecond precision.
No time zone or daylight savings time transformations are done to the timestamp.
Fractional seconds will be written to the field, rounded to the millisecond.
tag | FIX tag. |
timestamp | Date and time. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimestamp field to the message.
No time zone or daylight savings time transformations are done to the timestamp.
No fractional seconds are written to the field.
tag | FIX tag. |
year | Year. |
month | Month. |
day | Day. |
hour | Hour. |
minute | Minute. |
second | Second. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimestamp field to the message with millisecond precision.
No time zone or daylight savings time transformations are done to the timestamp.
tag | FIX tag. |
year | Year. |
month | Month. |
day | Day. |
hour | Hour. |
minute | Minute. |
second | Second. |
millisecond | Millisecond. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a std::chrono::time_point
field to the message with millisecond precision.
Fractional seconds will be written to the field, rounded to the millisecond.
Uses algorithms from http://howardhinnant.github.io/date_algorithms.html , which implement a proleptic Gregorian calendar. This will probably be superseded by C++20.
tag | FIX tag. |
tp | std::chrono::time_point . |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimestamp field to the message with nanosecond precision.
No time zone or daylight savings time transformations are done to the timestamp.
Fractional seconds will be written to the field, rounded to the nanosecond.
tag | FIX tag. |
timestamp | Date and time. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a UTCTimestamp field to the message with nanosecond precision.
No time zone or daylight savings time transformations are done to the timestamp.
tag | FIX tag. |
year | Year. |
month | Month. |
day | Day. |
hour | Hour. |
minute | Minute. |
second | Second. |
nanosecond | Nanosecond. |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Append a std::chrono::time_point
field to the message with nanosecond precision.
Fractional seconds will be written to the field, rounded to the nanosecond.
Uses algorithms from http://howardhinnant.github.io/date_algorithms.html , which implement a proleptic Gregorian calendar. This will probably be superseded by C++20.
tag | FIX tag. |
tp | std::chrono::time_point . |
std::out_of_range | When the remaining buffer size is too small. |
|
inline |
Write the CheckSum field to the buffer.
This function must be called after all other push_back
functions. It may only be called once for each message_writer.
calculate_checksum | If this flag is set to false, then instead of iterating over the entire message and calculating the CheckSum, the standard trailer will simply write CheckSum=000. This is fine if you're sending the message to a FIX parser that, like High Frequency FIX Parser, doesn't care about the CheckSum. |
std::out_of_range | When the remaining buffer size is too small. |
std::logic_error | When called before message_writer::push_back_header() |