Files
spark/src/server/sparkd/orderman/native_orders/NativeOrder.cpp
T
2017-09-25 20:18:28 +00:00

121 lines
4.3 KiB
C++

#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<fix::Price> (0,PriceFieldSz);
_fix_data.update_quantity_bm = encoding.add<fix::OrderQty> (0,SizeFieldSz);
_fix_data.update_transact_time_bm =
encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
encoding.add<fix::Account> (to_str(_header.account));
encoding.add<fix::SenderSubID> (to_str(_header.operator_id));
encoding.add<fix::Side> (_header.side);
encoding.add<fix::TimeInForce> (_header.time_in_force);
encoding.add<fix::OrdType> (_header.order_type);
encoding.add<fix::CustomerOrFirm> (_header.customer_or_firm);
encoding.add<fix::CtiCode> (_header.cti_code);
encoding.add<fix::SecurityDesc> (_header.security->glbx().security_desc());
std::string clordid(clordid_sz(),' ');
encode_clorid(_header.order_key,SecurityKey(_header.security->id()),&clordid);
encoding.add<fix::ClOrdID> (clordid);
encoding.add<fix::OrigClOrdID> (clordid);
encoding.add<fix::CorrelationClOrdID> (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<fix::Price> (0,PriceFieldSz);
_fix_data.create_quantity_bm = encoding.add<fix::OrderQty> (0,SizeFieldSz);
_fix_data.create_transact_time_bm =
encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
encoding.add<fix::Account> (to_str(_header.account));
encoding.add<fix::SenderSubID> (to_str(_header.operator_id));
encoding.add<fix::Side> (_header.side);
encoding.add<fix::TimeInForce> (_header.time_in_force);
encoding.add<fix::OrdType> (_header.order_type);
encoding.add<fix::CustomerOrFirm> (_header.customer_or_firm);
encoding.add<fix::CtiCode> (_header.cti_code);
encoding.add<fix::SecurityDesc> (_header.security->glbx().security_desc());
std::string clordid(clordid_sz(),' ');
encode_clorid(_header.order_key,SecurityKey(_header.security->id()),&clordid);
encoding.add<fix::ClOrdID> (clordid);
}
void NativeOrder::init_cancel_fix()
{
auto &encoding = _fix_data.update_encoding;
using namespace jetfix;
_fix_data.cancel_transact_time_bm =
encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
encoding.add<fix::Account> (to_str(_header.account));
encoding.add<fix::SenderSubID> (to_str(_header.operator_id));
encoding.add<fix::Side> (_header.side);
encoding.add<fix::TimeInForce> (_header.time_in_force);
encoding.add<fix::OrdType> (_header.order_type);
encoding.add<fix::CustomerOrFirm> (_header.customer_or_firm);
encoding.add<fix::CtiCode> (_header.cti_code);
encoding.add<fix::SecurityDesc> (_header.security->glbx().security_desc());
std::string clordid(clordid_sz(),' ');
encode_clorid(_header.order_key,SecurityKey(_header.security->id()),&clordid);
encoding.add<fix::ClOrdID> (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<fix::OrderID> (tstr.first,tstr.second);
_fix_data.cancel_encoding.add<fix::OrderID> (tstr.first,tstr.second);
}
}}