Skip to content

Commit

Permalink
Implement 'Order Executed' message for PITCH-2.X.
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan committed May 28, 2017
1 parent b24ed48 commit 4a8259a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jb_pitch2_unit_tests = \
jb/pitch2/ut_add_order_message \
jb/pitch2/ut_auction_update_message \
jb/pitch2/ut_expanded_add_order_message \
jb/pitch2/ut_order_executed_message \
jb/pitch2/ut_short_add_order_message \
jb/pitch2/ut_time_message \
jb/pitch2/ut_unit_clear_message
Expand Down Expand Up @@ -482,6 +483,7 @@ jb_libjb_pitch2_a_SOURCES = \
jb/pitch2/add_order_message.cpp \
jb/pitch2/auction_update_message.cpp \
jb/pitch2/expanded_add_order_message.cpp \
jb/pitch2/order_executed_message.cpp \
jb/pitch2/short_add_order_message.cpp \
jb/pitch2/time_message.cpp \
jb/pitch2/unit_clear_message.cpp
Expand All @@ -491,6 +493,7 @@ jb_libjb_pitch2_a_HEADERS = \
jb/pitch2/base_add_order_message.hpp \
jb/pitch2/base_add_order_message_streaming.hpp \
jb/pitch2/expanded_add_order_message.hpp \
jb/pitch2/order_executed_message.hpp \
jb/pitch2/short_add_order_message.hpp \
jb/pitch2/time_message.hpp \
jb/pitch2/unit_clear_message.hpp
Expand Down Expand Up @@ -1255,6 +1258,11 @@ jb_pitch2_ut_expanded_add_order_message_CPPFLAGS = $(UT_CPPFLAGS) -DBOOST_TEST_M
jb_pitch2_ut_expanded_add_order_message_LDFLAGS = $(jb_ut_pitch2_ldflags)
jb_pitch2_ut_expanded_add_order_message_LDADD = $(jb_ut_pitch2_ldadd)

jb_pitch2_ut_order_executed_message_SOURCES = jb/pitch2/ut_order_executed_message.cpp
jb_pitch2_ut_order_executed_message_CPPFLAGS = $(UT_CPPFLAGS) -DBOOST_TEST_MODULE=jb_pitch2_ut_order_executed_message
jb_pitch2_ut_order_executed_message_LDFLAGS = $(jb_ut_pitch2_ldflags)
jb_pitch2_ut_order_executed_message_LDADD = $(jb_ut_pitch2_ldadd)

jb_pitch2_ut_short_add_order_message_SOURCES = jb/pitch2/ut_short_add_order_message.cpp
jb_pitch2_ut_short_add_order_message_CPPFLAGS = $(UT_CPPFLAGS) -DBOOST_TEST_MODULE=jb_pitch2_ut_short_add_order_message
jb_pitch2_ut_short_add_order_message_LDFLAGS = $(jb_ut_pitch2_ldflags)
Expand Down
19 changes: 19 additions & 0 deletions jb/pitch2/order_executed_message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <jb/pitch2/order_executed_message.hpp>

#include <boost/io/ios_state.hpp>
#include <ostream>

namespace jb {
namespace pitch2 {

std::ostream& operator<<(std::ostream& os, order_executed_message const& x) {
return os << "length=" << static_cast<int>(x.length.value())
<< ",message_type=" << static_cast<int>(x.message_type.value())
<< ",time_offset=" << x.time_offset.value()
<< ",order_id=" << x.order_id.value()
<< ",executed_quantity=" << x.executed_quantity.value()
<< ",execution_id=" << x.execution_id.value();
}

} // namespace pitch2
} // namespace jb
36 changes: 36 additions & 0 deletions jb/pitch2/order_executed_message.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef jb_pitch2_order_executed_message_hpp
#define jb_pitch2_order_executed_message_hpp

#include <boost/endian/buffers.hpp>

#include <iosfwd>

namespace jb {
namespace pitch2 {

/**
* Represent the 'Order Executed' message in the PITCH-2.X protocol.
*
* A full description of the fields can be found in the BATS PITCH-2.X
* specification:
* https://www.batstrading.com/resources/membership/BATS_MC_PITCH_Specification.pdf
*/
struct order_executed_message {
/// Define the messsage type
constexpr static int type = 0x23;

boost::endian::little_uint8_buf_t length;
boost::endian::little_uint8_buf_t message_type;
boost::endian::little_uint32_buf_t time_offset;
boost::endian::little_uint64_buf_t order_id;
boost::endian::little_uint32_buf_t executed_quantity;
boost::endian::little_uint64_buf_t execution_id;
};

/// Streaming operator for jb::pitch2::order_executed_message.
std::ostream& operator<<(std::ostream& os, order_executed_message const& x);

} // namespace pitch2
} // namespace jb

#endif // jb_pitch2_order_executed_message_hpp
38 changes: 38 additions & 0 deletions jb/pitch2/ut_order_executed_message.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <jb/pitch2/order_executed_message.hpp>

#include <boost/test/unit_test.hpp>
#include <type_traits>

/**
* @test Verify that jb::pitch2::order_executed_message works as expected.
*/
BOOST_AUTO_TEST_CASE(order_executed_message_basic) {
using namespace jb::pitch2;
BOOST_CHECK_EQUAL(true, std::is_pod<order_executed_message>::value);
BOOST_CHECK_EQUAL(sizeof(order_executed_message), std::size_t(26));

char const buf[] = u8"\x1A" // Length (26)
"\x23" // Message Type (0x23)
"\x18\xD2\x06\x00" // Time Offset (447,000 ns)
"\x05\x40\x5B\x77\x8F\x56\x1D\x0B" // Order Id
"\x64\x00\x00\x00" // Executed Quantity (100)
"\x34\x2B\x46\xE0\xBB\x00\x00\x00" // Execution Id
;
order_executed_message msg;
BOOST_REQUIRE_EQUAL(sizeof(buf) - 1, sizeof(msg));
std::memcpy(&msg, buf, sizeof(msg));
BOOST_CHECK_EQUAL(int(msg.length.value()), 26);
BOOST_CHECK_EQUAL(int(msg.message_type.value()), 0x23);
BOOST_CHECK_EQUAL(msg.time_offset.value(), 447000);
BOOST_CHECK_EQUAL(msg.order_id.value(), 0x0B1D568F775B4005ULL);
BOOST_CHECK_EQUAL(msg.executed_quantity.value(), 100);
BOOST_CHECK_EQUAL(msg.execution_id.value(), 0x000000BBE0462B34ULL);

std::ostringstream os;
os << msg;
BOOST_CHECK_EQUAL(
os.str(), std::string(
"length=26,message_type=35,time_offset=447000"
",order_id=800891482924597253,executed_quantity=100"
",execution_id=806921579316"));
}

0 comments on commit 4a8259a

Please sign in to comment.