#include "NativeOrder.h" #include "server/sparkd/orderman/utils/fix_order_codec.h" #include "server/sparkd/jetfix/codec/FieldDefinitions.h" namespace bts { namespace orderman { static auto const PriceFieldSz=20; static auto const SizeFieldSz=6; void NativeOrder::init_update_fix() { auto &encoding = _fix_data.update_encoding; using namespace jetfix; // price, quantity, transact time will all be changing on every order update _fix_data.update_price_bm = encoding.add (0,PriceFieldSz); _fix_data.update_quantity_bm = encoding.add (0,SizeFieldSz); _fix_data.update_transact_time_bm = encoding.add (datetime::FIX_timestamp(datetime::now())); encoding.add (to_str(_header.account)); encoding.add (to_str(_header.operator_id)); encoding.add (_header.side); encoding.add (_header.time_in_force); encoding.add (_header.order_type); encoding.add (_header.customer_or_firm); encoding.add (_header.cti_code); encoding.add (_header.security->glbx().security_desc()); std::string clordid(clordid_sz(),' '); encode_clorid(_header.order_key,SecurityKey(_header.security->id()),&clordid); encoding.add (clordid); encoding.add (clordid); encoding.add (clordid); // if we have an exchange order id use it, otherwise we will // do it when get our first execution report if (_state.exchange_order_id) update_exchange_order_id(*_state.exchange_order_id); } void NativeOrder::init_create_fix() { auto &encoding = _fix_data.update_encoding; using namespace jetfix; // price, quantity, transact time will all be changing on every order update _fix_data.create_price_bm = encoding.add (0,PriceFieldSz); _fix_data.create_quantity_bm = encoding.add (0,SizeFieldSz); _fix_data.create_transact_time_bm = encoding.add (datetime::FIX_timestamp(datetime::now())); encoding.add (to_str(_header.account)); encoding.add (to_str(_header.operator_id)); encoding.add (_header.side); encoding.add (_header.time_in_force); encoding.add (_header.order_type); encoding.add (_header.customer_or_firm); encoding.add (_header.cti_code); encoding.add (_header.security->glbx().security_desc()); std::string clordid(clordid_sz(),' '); encode_clorid(_header.order_key,SecurityKey(_header.security->id()),&clordid); encoding.add (clordid); } void NativeOrder::init_cancel_fix() { auto &encoding = _fix_data.update_encoding; using namespace jetfix; _fix_data.cancel_transact_time_bm = encoding.add (datetime::FIX_timestamp(datetime::now())); encoding.add (to_str(_header.account)); encoding.add (to_str(_header.operator_id)); encoding.add (_header.side); encoding.add (_header.time_in_force); encoding.add (_header.order_type); encoding.add (_header.customer_or_firm); encoding.add (_header.cti_code); encoding.add (_header.security->glbx().security_desc()); std::string clordid(clordid_sz(),' '); encode_clorid(_header.order_key,SecurityKey(_header.security->id()),&clordid); encoding.add (clordid); // if we have an exchange order id use it, otherwise we will // do it when get our first execution report if (_state.exchange_order_id) update_exchange_order_id(*_state.exchange_order_id); } void NativeOrder::init_fix() { init_update_fix(); init_create_fix(); init_cancel_fix(); } void NativeOrder::update_exchange_order_id(ExchangeOrderID const&id) { using namespace jetfix; bts_assert(_state.exchange_order_id == nullptr); _exchange_order_id = id; _state.exchange_order_id = &_exchange_order_id; auto tstr = to_trim_str(_exchange_order_id.value()); _fix_data.update_encoding.add (tstr.first,tstr.second); _fix_data.cancel_encoding.add (tstr.first,tstr.second); } }}