-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement 'Order Executed' message for PITCH-2.X.
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} |