initial native order support
This commit is contained in:
1 parent
c1aa9a2068
commit
cc23cf0d4c
9 files changed
+209
-74
No files matched your search
@@ -46,15 +46,16 @@ message OrderDefinition {
|
||||
TimeInForce time_in_force = 7;
|
||||
ManualOrderIndicator manual_order_indicator = 8;
|
||||
CTICode cti_code = 9;
|
||||
|
||||
CustomerOrFirm customer_or_firm = 10;
|
||||
|
||||
oneof custom {
|
||||
LimitOrderDefinition limit = 10;
|
||||
MarketOrderDefinition market = 11;
|
||||
StopMarketOrderDefinition stop_market = 12;
|
||||
StopLimitOrderDefinition stop_limit = 13;
|
||||
IcebergOrderDefinition iceberg = 14;
|
||||
SpreaderOrderDefinition spreader = 15;
|
||||
TimeBoxOrderDefinition time_box = 16;
|
||||
LimitOrderDefinition limit = 11;
|
||||
MarketOrderDefinition market = 12;
|
||||
StopMarketOrderDefinition stop_market = 13;
|
||||
StopLimitOrderDefinition stop_limit = 14;
|
||||
IcebergOrderDefinition iceberg = 15;
|
||||
SpreaderOrderDefinition spreader = 16;
|
||||
TimeBoxOrderDefinition time_box = 17;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -2,9 +2,10 @@
|
||||
|
||||
#include <string>
|
||||
#include <google/protobuf/text_format.h>
|
||||
#include <google/protobuf/timestamp.pb.h>
|
||||
#include <sys/time.h>
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
#include "bts_export.h"
|
||||
|
||||
namespace google {
|
||||
@@ -32,9 +33,18 @@ template <class T> T from_string(const std::string &str)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
google::protobuf::Timestamp pb_now()
|
||||
{
|
||||
::google::protobuf::Timestamp result;
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
result.set_seconds(tv.tv_sec);
|
||||
result.set_nanos(tv.tv_usec * 1000);
|
||||
return result;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <atomic>
|
||||
#include "server/sparkd/orderman2/orderman2_utils/orderman2_common.h"
|
||||
#include "lib/api/services/OrderService2.pb.h"
|
||||
#include "server/sparkd/orderman2/orders/PreActivationServices.h"
|
||||
#include "server/sparkd/orderman2/orders/PreActivationOrderServices.h"
|
||||
#include "server/sparkd/orderman2/actors/order_manager/OrderServices.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "server/sparkd/orderman2/actors/order_manager/ChildOrder.h"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "server/sparkd/orderman2/orders/LimitOrder.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "server/sparkd/orderman2/orderman2_utils/ExecutionReport.h"
|
||||
#include "server/sparkd/orderman2/orders/PreActivationServices.h"
|
||||
#include "server/sparkd/orderman2/orders/PreActivationOrderServices.h"
|
||||
|
||||
|
||||
#include <limits>
|
||||
@@ -42,13 +42,20 @@ OrderKey gen_order_id()
|
||||
|
||||
struct OrderFactory::PImpl
|
||||
{
|
||||
PImpl(securities::ISecurityDB &db) : my_orders(), sec_db(db) {}
|
||||
PImpl(securities::ISecurityDB &db,
|
||||
config::JetFIX::Connection const&cfg) :
|
||||
my_orders(), sec_db(db),cfg(cfg) {}
|
||||
|
||||
std::vector<std::unique_ptr<Order>> my_orders;
|
||||
securities::ISecurityDB &sec_db;
|
||||
config::JetFIX::Connection const cfg;
|
||||
};
|
||||
|
||||
OrderFactory::OrderFactory (securities::ISecurityDB &db) : me (new PImpl(db)) {}
|
||||
OrderFactory::OrderFactory (securities::ISecurityDB &db,
|
||||
config::JetFIX::Connection const&cfg) :
|
||||
me (new PImpl(db,cfg))
|
||||
{}
|
||||
|
||||
OrderFactory::~OrderFactory () {}
|
||||
|
||||
Order &OrderFactory::create (OrderKey parent,api::orderman2::OrderDefinition const&def)
|
||||
@@ -56,7 +63,7 @@ Order &OrderFactory::create (OrderKey parent,api::orderman2::OrderDefinition con
|
||||
auto k = gen_order_id();
|
||||
auto pk = parent;
|
||||
auto &order = allocate(k,pk,def);
|
||||
order.on_init_new(def, PreActivationOrderServices{me->sec_db,*this});
|
||||
order.on_init_new(def, PreActivationOrderServices{me->sec_db,me->cfg,*this});
|
||||
return order;
|
||||
}
|
||||
|
||||
@@ -65,7 +72,7 @@ Order &OrderFactory::recover(api::orderman2::OrderRecord const&rec)
|
||||
auto k = OrderKey(rec.key());
|
||||
auto pk = OrderKey(rec.parent_key());
|
||||
auto &order = allocate(k,pk,rec.def());
|
||||
order.on_init_recovered (rec, PreActivationOrderServices{me->sec_db,*this});
|
||||
order.on_init_recovered (rec, PreActivationOrderServices{me->sec_db,me->cfg,*this});
|
||||
return order;
|
||||
}
|
||||
|
||||
@@ -97,7 +104,7 @@ Order &OrderFactory::recreate_from_exe_report(ExecutionReport const&r)
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
native_order->on_init_from_exe_report(r,PreActivationOrderServices{me->sec_db,*this});
|
||||
native_order->on_init_from_exe_report(r,PreActivationOrderServices{me->sec_db,me->cfg,*this});
|
||||
native_order->_key = r.order_key;
|
||||
native_order->_parent_key = null_order_key();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include "server/sparkd/orderman2/order_factory/IOrderFactory.h"
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
|
||||
// fwd
|
||||
namespace bts {
|
||||
@@ -17,7 +18,8 @@ namespace orderman2 {
|
||||
class OrderFactory : public IOrderFactory
|
||||
{
|
||||
public:
|
||||
OrderFactory(securities::ISecurityDB &db);
|
||||
OrderFactory(securities::ISecurityDB &db,
|
||||
config::JetFIX::Connection const&cfg);
|
||||
~OrderFactory();
|
||||
|
||||
Order &create (OrderKey parent,api::orderman2::OrderDefinition const&) override;
|
||||
|
||||
@@ -1,12 +1,117 @@
|
||||
#include "LimitOrder.h"
|
||||
|
||||
#include "server/sparkd/orderman2/orderman2_utils/ExecutionReport.h"
|
||||
#include "lib/api/services/OrderService2.pb.h"
|
||||
#include "server/sparkd/orderman2/order_factory/IOrderFactory.h"
|
||||
#include "server/sparkd/jetfix/codec/FIXFragment.h"
|
||||
#include "server/sparkd/jetfix/codec/FieldDefinitions.h"
|
||||
#include "server/sparkd/orderman2/orderman2_utils/fix_order_codec.h"
|
||||
#include "server/sparkd/orderman2/orders/PreActivationOrderServices.h"
|
||||
#include "server/sparkd/securities/ISecurityDB.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman2 {
|
||||
|
||||
api::orderman2::OrderStatus map_status(api::orderman2::NativeOrderStatus );
|
||||
|
||||
struct LimitOrder::PImpl
|
||||
{
|
||||
api::orderman2::OrderDefinition definition;
|
||||
api::orderman2::OrderState state;
|
||||
|
||||
jetfix::FIXFragment update_encoding;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::Price> update_price_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::OrderQty> update_quantity_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::TransactTimeStr> update_transact_time_bm;
|
||||
|
||||
jetfix::FIXFragment create_encoding;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::Price> create_price_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::OrderQty> create_quantity_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::TransactTimeStr> create_transact_time_bm;
|
||||
|
||||
jetfix::FIXFragment cancel_encoding;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::TransactTimeStr> cancel_transact_time_bm;
|
||||
};
|
||||
|
||||
LimitOrder::LimitOrder() : me (new PImpl()) {}
|
||||
|
||||
void LimitOrder::on_init_new(api::orderman2::OrderDefinition const&def,
|
||||
const PreActivationOrderServices&serv)
|
||||
{
|
||||
me->definition = def;
|
||||
me->state.limit();
|
||||
auto sec = serv.sec_db.resolve(SecurityKey(def.security_key()));
|
||||
if (!sec) {
|
||||
me->state.set_status(api::orderman2::ORDER_STATUS_ERROR);
|
||||
me->state.set_last_msg(fmt::format ("Unknown security: {}",def.security_key()));
|
||||
}
|
||||
else {
|
||||
me->state.set_status(api::orderman2::ORDER_STATUS_INACTIVE);
|
||||
init_fix(*sec);
|
||||
}
|
||||
}
|
||||
|
||||
void LimitOrder::on_init_recovered(api::orderman2::OrderRecord const&rec,
|
||||
const PreActivationOrderServices &serv)
|
||||
{
|
||||
me->definition = rec.def();
|
||||
me->state = rec.state();
|
||||
|
||||
if (me->state.status() == api::orderman2::ORDER_STATUS_ACTIVE) {
|
||||
auto const &def = rec.def();
|
||||
auto sec = serv.sec_db.resolve(SecurityKey(def.security_key()));
|
||||
if (!sec) {
|
||||
me->state.set_status(api::orderman2::ORDER_STATUS_ERROR);
|
||||
me->state.set_last_msg(fmt::format ("Unknown security: {}",def.security_key()));
|
||||
}
|
||||
else
|
||||
init_fix(*sec);
|
||||
}
|
||||
}
|
||||
|
||||
void LimitOrder::on_init_from_exe_report(ExecutionReport const&er, const PreActivationOrderServices &os)
|
||||
{
|
||||
auto k = er.order_key;
|
||||
|
||||
api::orderman2::OrderRecord orecord;
|
||||
orecord.set_key(k.value());
|
||||
orecord.set_parent_key(null_order_key().value());
|
||||
|
||||
auto &def = *orecord.mutable_def();
|
||||
def.set_security_key(er.security->id());
|
||||
def.set_side(er.side);
|
||||
def.set_login(to_str(er.operator_id));
|
||||
def.set_account(to_str(er.account_name));
|
||||
def.set_time_in_force(er.time_in_force);
|
||||
def.set_manual_order_indicator(er.manual_order_indicator);
|
||||
def.set_cti_code(api::orderman2::CTICode(er.cfg->cti_code()[0]));
|
||||
def.set_customer_or_firm(api::orderman2::CustomerOrFirm(er.cfg->customer_or_firm()));
|
||||
def.mutable_limit();
|
||||
|
||||
auto &state = *orecord.mutable_state();
|
||||
state.set_status(map_status(er.order_status));
|
||||
state.set_price(er.price.value());
|
||||
state.set_quantity(er.quantity.value());
|
||||
state.set_filled_quantity(er.filled_quantity.value());
|
||||
state.set_last_price(er.last_price.value());
|
||||
state.set_avg_price(er.avg_price.value());
|
||||
state.set_last_msg(er.msg);
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
state.mutable_last_change()->set_seconds(tv.tv_sec);
|
||||
state.mutable_last_change()->set_nanos(tv.tv_usec * 1000);
|
||||
|
||||
auto &limit_state = *state.mutable_limit();
|
||||
limit_state.set_exchange_order_id(to_str(er.exchange_order_id));
|
||||
|
||||
on_init_recovered(orecord,os);
|
||||
}
|
||||
|
||||
LimitOrder::~LimitOrder() {}
|
||||
|
||||
api::orderman2::OrderStatus map_status(api::orderman2::NativeOrderStatus status)
|
||||
{
|
||||
using namespace api::orderman2;
|
||||
@@ -49,45 +154,63 @@ api::orderman2::OrderStatus map_status(api::orderman2::NativeOrderStatus status)
|
||||
}
|
||||
}
|
||||
|
||||
void LimitOrder::on_init_from_exe_report(ExecutionReport const&er, const PreActivationOrderServices &os)
|
||||
void LimitOrder::init_fix(api::Security const&sec)
|
||||
{
|
||||
auto k = er.order_key;
|
||||
using namespace jetfix;
|
||||
auto const&def = me->definition;
|
||||
// initialize update FIX
|
||||
auto &update_encoding = me->update_encoding;
|
||||
update_encoding.add<fix::SenderSubID> (def.login());
|
||||
me->update_price_bm = update_encoding.add<fix::Price> (0,price_sz());
|
||||
me->update_quantity_bm = update_encoding.add<fix::OrderQty> (0,quantity_sz());
|
||||
me->update_transact_time_bm =
|
||||
update_encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
|
||||
update_encoding.add<fix::Account> (def.account());
|
||||
update_encoding.add<fix::Side> (def.side());
|
||||
update_encoding.add<fix::TimeInForce> (def.time_in_force());
|
||||
update_encoding.add<fix::OrdType> (api::orderman2::NATIVE_ORDER_TYPE_LIMIT);
|
||||
update_encoding.add<fix::ManualOrderIndicator> (def.manual_order_indicator());
|
||||
update_encoding.add<fix::CtiCode> (def.cti_code());
|
||||
update_encoding.add<fix::CustomerOrFirm> (def.customer_or_firm());
|
||||
update_encoding.add<fix::SecurityDesc> (sec.glbx().security_desc());
|
||||
std::string clordid(clordid_sz(),' ');
|
||||
encode_clorid(key(),SecurityKey(sec.id()),&clordid);
|
||||
update_encoding.add<fix::ClOrdID> (clordid);
|
||||
update_encoding.add<fix::OrigClOrdID> (clordid);
|
||||
update_encoding.add<fix::CorrelationClOrdID> (clordid);
|
||||
|
||||
api::orderman2::OrderRecord orecord;
|
||||
orecord.set_key(k.value());
|
||||
orecord.set_parent_key(null_order_key().value());
|
||||
// initialize create FIX
|
||||
auto &create_encoding = me->create_encoding;
|
||||
create_encoding.add<fix::SenderSubID> (def.login());
|
||||
me->create_price_bm = create_encoding.add<fix::Price> (0,price_sz());
|
||||
me->create_quantity_bm = create_encoding.add<fix::OrderQty> (0,quantity_sz());
|
||||
me->create_transact_time_bm = create_encoding.add<fix::TransactTimeStr> (
|
||||
datetime::FIX_timestamp(datetime::now()));
|
||||
create_encoding.add<fix::Account> (def.account());
|
||||
create_encoding.add<fix::Side> (def.side());
|
||||
create_encoding.add<fix::TimeInForce> (def.time_in_force());
|
||||
create_encoding.add<fix::OrdType> (api::orderman2::NATIVE_ORDER_TYPE_LIMIT);
|
||||
create_encoding.add<fix::ManualOrderIndicator> (def.manual_order_indicator());
|
||||
create_encoding.add<fix::CustomerOrFirm> (def.customer_or_firm());
|
||||
create_encoding.add<fix::CtiCode> (def.cti_code());
|
||||
create_encoding.add<fix::SecurityDesc> (sec.glbx().security_desc());
|
||||
create_encoding.add<fix::ClOrdID> (clordid);
|
||||
|
||||
auto &def = *orecord.mutable_def();
|
||||
def.set_security_key(er.security->id());
|
||||
def.set_side(er.side);
|
||||
def.set_login(to_str(er.operator_id));
|
||||
def.set_account(to_str(er.account_name));
|
||||
def.set_time_in_force(er.time_in_force);
|
||||
def.set_manual_order_indicator(er.manual_order_indicator);
|
||||
def.set_cti_code(api::orderman2::CTICode(er.cfg->cti_code()[0]));
|
||||
|
||||
def.mutable_limit();
|
||||
|
||||
auto &state = *orecord.mutable_state();
|
||||
state.set_status(map_status(er.order_status));
|
||||
state.set_price(er.price.value());
|
||||
state.set_quantity(er.quantity.value());
|
||||
state.set_filled_quantity(er.filled_quantity.value());
|
||||
state.set_last_price(er.last_price.value());
|
||||
state.set_avg_price(er.avg_price.value());
|
||||
state.set_last_msg(er.msg);
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
state.mutable_last_change()->set_seconds(tv.tv_sec);
|
||||
state.mutable_last_change()->set_nanos(tv.tv_usec * 1000);
|
||||
|
||||
auto &limit_state = *state.mutable_limit();
|
||||
limit_state.set_exchange_order_id(to_str(er.exchange_order_id));
|
||||
|
||||
on_init_recovered(orecord,os);
|
||||
// initialize cancel FIX
|
||||
auto &cancel_encoding = me->cancel_encoding;
|
||||
cancel_encoding.add<fix::SenderSubID> (def.login());
|
||||
me->cancel_transact_time_bm =
|
||||
cancel_encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
|
||||
cancel_encoding.add<fix::Account> (def.account());
|
||||
cancel_encoding.add<fix::Side> (def.side());
|
||||
cancel_encoding.add<fix::TimeInForce> (def.time_in_force());
|
||||
cancel_encoding.add<fix::OrdType> (api::orderman2::NATIVE_ORDER_TYPE_LIMIT);
|
||||
cancel_encoding.add<fix::ManualOrderIndicator> (def.manual_order_indicator());
|
||||
cancel_encoding.add<fix::SecurityDesc> (sec.glbx().security_desc());
|
||||
cancel_encoding.add<fix::ClOrdID> (clordid);
|
||||
cancel_encoding.add<fix::OrigClOrdID> (clordid);
|
||||
cancel_encoding.add<fix::CorrelationClOrdID> (clordid);
|
||||
}
|
||||
|
||||
LimitOrder::~LimitOrder() {}
|
||||
|
||||
|
||||
}}
|
||||
@@ -11,12 +11,13 @@ namespace orderman2 {
|
||||
class LimitOrder : public NativeOrder
|
||||
{
|
||||
public:
|
||||
LimitOrder();
|
||||
~LimitOrder() override;
|
||||
|
||||
void on_init_new(api::orderman2::OrderDefinition const&,
|
||||
const PreActivationOrderServices&) override {}
|
||||
const PreActivationOrderServices&) override;
|
||||
void on_init_recovered(api::orderman2::OrderRecord const&,
|
||||
const PreActivationOrderServices &) override {}
|
||||
const PreActivationOrderServices &) override;
|
||||
void on_init_from_exe_report(ExecutionReport const&,
|
||||
const PreActivationOrderServices &) override ;
|
||||
void on_activate(Price,Quantity,OrderServices &) override {}
|
||||
@@ -24,7 +25,11 @@ public:
|
||||
void on_update(Price , Quantity ) override {}
|
||||
void on_crack() override {}
|
||||
void on_cancel() override {}
|
||||
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
void init_fix(api::Security const&sec);
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "server/sparkd/mercury/actors/ContentSubscription.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman2 {
|
||||
|
||||
class PostActivationServices
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
+4
-2
@@ -12,11 +12,13 @@ class PreActivationOrderServices
|
||||
{
|
||||
public:
|
||||
PreActivationOrderServices (securities::ISecurityDB &db,
|
||||
OrderFactory &f)
|
||||
: sec_db(db), order_factory(f)
|
||||
config::JetFIX::Connection const &cfg,
|
||||
OrderFactory &f)
|
||||
: sec_db(db), cfg(cfg),order_factory(f)
|
||||
{}
|
||||
|
||||
securities::ISecurityDB &sec_db;
|
||||
config::JetFIX::Connection const &cfg;
|
||||
OrderFactory &order_factory;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user