Iceberg that can attach.
This commit is contained in:
1 parent
cc381d605c
commit
af253198d2
10 files changed
+107
-193
No files matched your search
@@ -141,7 +141,7 @@ void ServiceBridge::create_order(uint32_t rid, api::orderman::Create const &c) {
|
||||
me->order_factory.create(null_order_key(), c.new_order());
|
||||
me->known_orders.insert(order.key());
|
||||
publish(me->activate_order_pub, rid, order, Price(c.price()),
|
||||
Quantity(c.quantity()), OrderKey(c.attach_target_order_key()));
|
||||
Quantity(c.quantity()));
|
||||
} else
|
||||
me->on_order_op_result(OrderOpResultEvent(
|
||||
null_order_key(), rid,
|
||||
|
||||
@@ -28,6 +28,12 @@ class ChildOrder {
|
||||
ChildOrder(ChildOrder &&src) { operator=(std::move(src)); }
|
||||
ChildOrder(ChildOrder const &src) { operator=(src); }
|
||||
|
||||
ChildOrder(api::orderman::OrderDefinition const &def,
|
||||
OrderServices &parent_services)
|
||||
: _child_order(&parent_services.make_child(def)),
|
||||
_parent_order_services(&parent_services), _child_order_services(),
|
||||
_active(false) {}
|
||||
|
||||
ChildOrder &operator=(ChildOrder &&src) {
|
||||
_child_order = src._child_order;
|
||||
_parent_order_services = src._parent_order_services;
|
||||
@@ -69,15 +75,6 @@ class ChildOrder {
|
||||
_child_order_services = _child_order->_services.get();
|
||||
_active = true;
|
||||
}
|
||||
void activate_attach(Price p, Quantity q, OrderKey attach_target) {
|
||||
bts_assert(_child_order);
|
||||
bts_assert(!_active);
|
||||
|
||||
_parent_order_services->activate_attach_child(*_child_order, p, q,
|
||||
attach_target);
|
||||
_child_order_services = _child_order->_services.get();
|
||||
_active = true;
|
||||
}
|
||||
template <class CB>
|
||||
void activate(Price p, Quantity q, CB const &on_activate_result) {
|
||||
bts_assert(_child_order);
|
||||
@@ -94,23 +91,6 @@ class ChildOrder {
|
||||
_child_order_services = _child_order->_services.get();
|
||||
_active = true;
|
||||
}
|
||||
template <class CB>
|
||||
void activate_attach(Price p, Quantity q, OrderKey attach_target,
|
||||
CB const &on_activate_result) {
|
||||
bts_assert(_child_order);
|
||||
bts_assert(!_active);
|
||||
|
||||
auto on_activate_result_wrapper = [this, on_activate_result](
|
||||
OrderOpResult const &r) {
|
||||
_parent_order_services->call_with_reentrancy_guard(
|
||||
[r, on_activate_result](auto const &) { on_activate_result(r); });
|
||||
};
|
||||
|
||||
_parent_order_services->activate_attach_child(
|
||||
*_child_order, p, q, attach_target, on_activate_result_wrapper);
|
||||
_child_order_services = _child_order->_services.get();
|
||||
_active = true;
|
||||
}
|
||||
// End Activate
|
||||
|
||||
// Update
|
||||
|
||||
@@ -216,12 +216,7 @@ void OrderManager::on_activate_order(
|
||||
publish(me->services_data.report_order_op_result_pub, k, rid,
|
||||
order_op_result);
|
||||
};
|
||||
if (ev.attach_target == null_order_key()) {
|
||||
order->_services->activate(ev.price, ev.quantity, on_response);
|
||||
} else {
|
||||
order->_services->activate_attach(ev.price, ev.quantity,
|
||||
ev.attach_target, on_response);
|
||||
}
|
||||
order->_services->activate(ev.price, ev.quantity, on_response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ class OrderServices {
|
||||
|
||||
securities::ISecurityDB &sec_db() { return _data->sec_db; }
|
||||
IOrderFactory &order_factory() { return _data->order_factory; }
|
||||
|
||||
Order &make_child (api::orderman::OrderDefinition const&def) {
|
||||
return _data->order_factory.create (_owner->key(),def);
|
||||
}
|
||||
|
||||
mercury::TimeStampStr const &get_time_str() const {
|
||||
return _data->last_timer_ev.ts_str;
|
||||
@@ -204,25 +208,29 @@ class OrderServices {
|
||||
|
||||
friend class ChildOrder;
|
||||
|
||||
// Activate this order
|
||||
// Activate this order
|
||||
template <class CB>
|
||||
void activate(Price p, Quantity q, CB const &on_order_op = ignore) {
|
||||
bts_assert(_owner->def());
|
||||
if (_owner->def()- n
|
||||
|
||||
if (_owner->def()->attach_target_order_key() !=
|
||||
null_order_key().value() &&
|
||||
!_owner->supports_attachment()) {
|
||||
auto msg = "Order does not support attachment";
|
||||
on_order_op(OrderOpResult {api::orderman::ORDER_ERROR_INVALID_OP,msg});
|
||||
|
||||
api::orderman::OrderState state;
|
||||
state.set_status(api::orderman::ORDER_STATUS_REJECTED_BY_SPARK);
|
||||
state.set_last_msg("Order does not support attachment");
|
||||
report_state(state);
|
||||
return;
|
||||
}
|
||||
|
||||
call_with_reentrancy_guard([p, q, on_order_op](OrderServices &self) {
|
||||
on_order_op(self._owner->on_activate(p, q, self));
|
||||
});
|
||||
}
|
||||
|
||||
// Activate/Attach this order
|
||||
template <class CB>
|
||||
void activate_attach(Price p, Quantity q, OrderKey k,
|
||||
CB const &on_order_op = ignore) {
|
||||
call_with_reentrancy_guard([p, q, k, on_order_op](OrderServices &self) {
|
||||
on_order_op(self._owner->on_activate_attach(p, q, k, self));
|
||||
});
|
||||
}
|
||||
|
||||
// Update
|
||||
void update(Price p, Quantity q,
|
||||
OrderOpCallback const &on_order_op = ignore) {
|
||||
@@ -257,13 +265,6 @@ class OrderServices {
|
||||
o._services->activate(p, q, cb);
|
||||
}
|
||||
|
||||
// Activate/Attach a child of this order
|
||||
void activate_attach_child(Order &o, Price p, Quantity q, OrderKey child,
|
||||
OrderOpCallback const &cb = ignore) {
|
||||
_data->owner.add_child_order(*this, o);
|
||||
o._services->activate_attach(p, q, child,cb);
|
||||
}
|
||||
|
||||
// Notify this order that a new parent wants to attach
|
||||
void on_attach(OrderServices &new_parent, AttachCallback const &);
|
||||
|
||||
|
||||
@@ -14,16 +14,14 @@ class ActivateOrderEvent : public mercury::Event<ActivateOrderEvent> {
|
||||
public:
|
||||
using SynopsisPolicy = mercury::NoSynopsis;
|
||||
|
||||
ActivateOrderEvent(uint32_t req_id, Order &o, Price p, Quantity q,
|
||||
OrderKey attach_target)
|
||||
: req_id(req_id), order(&o), price(p), quantity(q),
|
||||
attach_target(attach_target) {}
|
||||
ActivateOrderEvent(uint32_t req_id, Order &o, Price p, Quantity q)
|
||||
: req_id(req_id), order(&o), price(p), quantity(q)
|
||||
{}
|
||||
|
||||
uint32_t req_id;
|
||||
Order *order;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
OrderKey attach_target;
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
|
||||
@@ -84,24 +84,18 @@ void IcebergOrder2::on_init_new(OrderDefinition const &def,
|
||||
"Show quantity must be greater than 0");
|
||||
return;
|
||||
}
|
||||
if (!ib.has_child() && !def.attach_on_launch()) {
|
||||
auto attach_target = OrderKey(def.attach_target_order_key());
|
||||
if (!ib.has_child() && attach_target == null_order_key()) {
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK,
|
||||
"Iceberg order must have a child order definition or attach to "
|
||||
"an existing order");
|
||||
return;
|
||||
}
|
||||
if (!def.attach_on_launch())
|
||||
if (attach_target == null_order_key() ||
|
||||
should_forward_attachment(me->def.custom_def()))
|
||||
initialize_child_builder(services.order_factory);
|
||||
else {
|
||||
// If we are attaching we might not need an order builder, it
|
||||
// depends on wheter we will consume the attached order or
|
||||
// forward the attachment target to our child. We can infer that
|
||||
// we are consuming the attachment directly if we have no child
|
||||
// definition or if the child definition is for a "bottom
|
||||
// order", that is a native or spreader.
|
||||
if (should_forward_attachment(def.custom_def())) {
|
||||
initialize_child_builder(services.order_factory);
|
||||
}
|
||||
// when attaching directly we do not need an order builder
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,21 +139,12 @@ OrderOpResult IcebergOrder2::on_activate(Price p, Quantity q,
|
||||
|
||||
switch (me->internal_status) {
|
||||
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::INACTIVE: {
|
||||
me->child_builder.activate(services);
|
||||
|
||||
me->order_state.set_price(p.value());
|
||||
me->order_state.set_quantity(q.value());
|
||||
|
||||
if (me->def.attach_on_launch()) {
|
||||
// We were expecting on_activate_attach to be called since
|
||||
// the order definition stated that we were going to be
|
||||
// attached to an existing order.
|
||||
auto msg = "Expected an order to attach to";
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return report_and_return(ORDER_ERROR_INVALID_OP, msg);
|
||||
}
|
||||
|
||||
if (q.value() == 0) {
|
||||
terminate(ORDER_STATUS_COMPLETED);
|
||||
return report_and_return();
|
||||
@@ -169,10 +154,16 @@ OrderOpResult IcebergOrder2::on_activate(Price p, Quantity q,
|
||||
services.subscribe_to_time([this](auto const &) { this->on_time(); });
|
||||
services.subscribe_to_child_updates(
|
||||
[this](auto const &os) { this->on_child_order_update(os); });
|
||||
me->set_external_status(ORDER_STATUS_WORKING);
|
||||
work();
|
||||
return report_and_return();
|
||||
|
||||
auto ak = OrderKey(me->def.attach_target_order_key());
|
||||
if (ak != null_order_key()) {
|
||||
return on_activate_attach(ak);
|
||||
} else {
|
||||
me->set_external_status(ORDER_STATUS_WORKING);
|
||||
work();
|
||||
return report_and_return();
|
||||
}
|
||||
}
|
||||
case InternalStatus::COMPLETED:
|
||||
return report_and_return();
|
||||
|
||||
@@ -188,60 +179,22 @@ OrderOpResult IcebergOrder2::on_activate(Price p, Quantity q,
|
||||
return report_and_return();
|
||||
}
|
||||
|
||||
OrderOpResult IcebergOrder2::on_activate_attach(Price p, Quantity q,
|
||||
OrderKey attach_target,
|
||||
OrderServices &services) {
|
||||
bts_assert(!me->services);
|
||||
me->services = &services;
|
||||
OrderOpResult IcebergOrder2::on_activate_attach(OrderKey attach_target) {
|
||||
bts_assert(me->services);
|
||||
bts_assert(me->internal_status == InternalStatus::INACTIVE);
|
||||
bts_assert(!me->child_builder.is_activated());
|
||||
bts_assert(me->def.attach_target_order_key() != null_order_key().value());
|
||||
|
||||
switch (me->internal_status) {
|
||||
|
||||
case InternalStatus::INACTIVE:
|
||||
me->order_state.set_price(p.value());
|
||||
me->order_state.set_quantity(q.value());
|
||||
|
||||
if (!me->def.attach_on_launch()) {
|
||||
// We were expecting on_activate to be called since the order
|
||||
// definition stated that we were going to be attached to an
|
||||
// existing order.
|
||||
auto msg = "Unexpected attach call";
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return report_and_return(ORDER_ERROR_INVALID_OP, msg);
|
||||
}
|
||||
|
||||
if (q.value() == 0) {
|
||||
terminate(ORDER_STATUS_COMPLETED);
|
||||
return report_and_return();
|
||||
}
|
||||
|
||||
if (me->iceberg_def().pause_between_orders_ms())
|
||||
services.subscribe_to_time([this](auto const &) { this->on_time(); });
|
||||
services.subscribe_to_child_updates(
|
||||
[this](auto const &os) { this->on_child_order_update(os); });
|
||||
|
||||
if (should_forward_attachment(me->def.custom_def())) {
|
||||
// We are not attaching directly, but our child will
|
||||
me->set_external_status(ORDER_STATUS_WORKING);
|
||||
work(attach_target);
|
||||
} else {
|
||||
// We are attaching directly
|
||||
me->set_external_status(ORDER_STATUS_PENDING_WORKING);
|
||||
attach(attach_target);
|
||||
}
|
||||
return report_and_return();
|
||||
|
||||
case InternalStatus::COMPLETED:
|
||||
return report_and_return();
|
||||
|
||||
case InternalStatus::WORKING:
|
||||
case InternalStatus::PAUSED:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
bts_assert(false);
|
||||
return report_and_return();
|
||||
if (should_forward_attachment(me->def.custom_def())) {
|
||||
// We are not attaching directly, but our child will
|
||||
bts_assert(me->def.attach_target_order_key() != null_order_key().value());
|
||||
me->set_external_status(ORDER_STATUS_WORKING);
|
||||
work();
|
||||
} else {
|
||||
// We are attaching directly
|
||||
me->set_external_status(ORDER_STATUS_PENDING_WORKING);
|
||||
attach(attach_target);
|
||||
}
|
||||
|
||||
// compiler
|
||||
bts_assert(false);
|
||||
return report_and_return();
|
||||
}
|
||||
|
||||
@@ -468,7 +421,7 @@ void orderman::IcebergOrder2::on_child_activate_completed(OrderOpResult r) {
|
||||
}
|
||||
}
|
||||
|
||||
void orderman::IcebergOrder2::send_next_child_order(OrderKey attach_target) {
|
||||
void orderman::IcebergOrder2::send_next_child_order() {
|
||||
bts_assert(me->order_state.quantity() > me->order_state.filled_quantity());
|
||||
|
||||
auto remaining =
|
||||
@@ -486,26 +439,19 @@ void orderman::IcebergOrder2::send_next_child_order(OrderKey attach_target) {
|
||||
me->order_state.price(), me->order_state.filled_quantity(),
|
||||
me->order_state.quantity());
|
||||
|
||||
if (attach_target == null_order_key()) {
|
||||
me->active_child.order.activate(
|
||||
Price(me->order_state.price()), Quantity(to_send),
|
||||
[this](auto const &op) { this->on_child_activate_completed(op); });
|
||||
} else {
|
||||
// Forward attachment
|
||||
me->active_child.order.activate_attach(
|
||||
Price(me->order_state.price()), Quantity(to_send), attach_target,
|
||||
[this](auto const &op) { this->on_child_activate_completed(op); });
|
||||
}
|
||||
me->active_child.order.activate(
|
||||
Price(me->order_state.price()), Quantity(to_send),
|
||||
[this](auto const &op) { this->on_child_activate_completed(op); });
|
||||
}
|
||||
|
||||
void IcebergOrder2::work(OrderKey attach_target) {
|
||||
void IcebergOrder2::work() {
|
||||
switch (me->internal_status) {
|
||||
|
||||
case InternalStatus::PAUSED:
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
me->start_of_pause = TimeStamp();
|
||||
send_next_child_order(attach_target);
|
||||
send_next_child_order();
|
||||
transition(InternalStatus::WORKING);
|
||||
break;
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ class IcebergOrder2 : public Order {
|
||||
void on_init_recovered(api::orderman::OrderRecord const &,
|
||||
const PreActivationOrderServices &) override;
|
||||
OrderOpResult on_activate(Price, Quantity, OrderServices &) override;
|
||||
OrderOpResult on_activate_attach(Price, Quantity, OrderKey,
|
||||
OrderServices &) override;
|
||||
OrderOpResult on_update(api::orderman::Update const &) override;
|
||||
OrderOpResult on_update(Price, Quantity) override;
|
||||
OrderOpResult on_cancel() override;
|
||||
@@ -42,6 +40,8 @@ class IcebergOrder2 : public Order {
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
api::orderman::IcebergOrderDefinition &iceberg_def();
|
||||
|
||||
OrderOpResult on_activate_attach(OrderKey attach_target);
|
||||
void initialize_child_builder(IOrderFactory &);
|
||||
|
||||
// state transitions
|
||||
@@ -49,7 +49,6 @@ class IcebergOrder2 : public Order {
|
||||
std::string const &msg = "");
|
||||
void pause();
|
||||
void work();
|
||||
void work(OrderKey attach_target);
|
||||
void attach(OrderKey attach_target);
|
||||
void transition(InternalStatus);
|
||||
|
||||
@@ -60,7 +59,6 @@ class IcebergOrder2 : public Order {
|
||||
api::orderman::OrderState const &);
|
||||
|
||||
void send_next_child_order();
|
||||
void send_next_child_order(OrderKey attach_target);
|
||||
std::string internal_status_name(InternalStatus);
|
||||
void merge_states(api::orderman::OrderState const &iceberg_state,
|
||||
api::orderman::OrderState const &child_state,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "NativeOrder.h"
|
||||
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/jetfix/codec/FIXFragment.h"
|
||||
#include "lib/jetfix/codec/FieldDefinitions.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/orderman/order_factory/IOrderFactory.h"
|
||||
#include "lib/orderman/order_router/OrderRouter.h"
|
||||
#include "lib/orderman/orderman_utils/ExecutionReport.h"
|
||||
@@ -282,7 +282,7 @@ void NativeOrder::warm_up_activate(OrderServicesData &data,
|
||||
bts_assert(!me->services);
|
||||
me->services = &services;
|
||||
init_order_services(data, services);
|
||||
_on_activate(Price(0), Quantity(0), services);
|
||||
_on_activate(NoLog, NoLog, Price(0), Quantity(0), services);
|
||||
|
||||
me->services->unsubscribe_from_exe_report(*me->session_services,
|
||||
me->exe_report_sid);
|
||||
@@ -292,8 +292,10 @@ void NativeOrder::warm_up_activate(OrderServicesData &data,
|
||||
me->services = nullptr;
|
||||
}
|
||||
|
||||
OrderOpResult NativeOrder::_on_activate(Price p, Quantity q,
|
||||
bts::orderman::OrderServices &services) {
|
||||
OrderOpResult
|
||||
NativeOrder::_on_activate(log::Level reject_level, log::Level transition_level,
|
||||
Price p, Quantity q,
|
||||
bts::orderman::OrderServices &services) {
|
||||
me->state.set_price(p.value());
|
||||
me->state.set_quantity(q.value());
|
||||
me->state.set_filled_quantity(0);
|
||||
@@ -307,13 +309,13 @@ OrderOpResult NativeOrder::_on_activate(Price p, Quantity q,
|
||||
|
||||
// is our gateway connected?
|
||||
if (!me->services->is_gateway_connected(*me->session_services)) {
|
||||
LOG(OrderMan, Warn,
|
||||
LOG(OrderMan, reject_level,
|
||||
"Attempt to send order to a disconnected gateway. "
|
||||
"Dropping order {}",
|
||||
key().value());
|
||||
auto msg = "Exchange gateway is down";
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK,msg);
|
||||
return OrderOpResult{ORDER_ERROR_GATEWAY_NOT_READY,msg};
|
||||
auto msg = "Exchange gateway is down";
|
||||
transition(transition_level, ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return OrderOpResult{ORDER_ERROR_GATEWAY_NOT_READY, msg};
|
||||
}
|
||||
|
||||
// can we trade?
|
||||
@@ -321,15 +323,15 @@ OrderOpResult NativeOrder::_on_activate(Price p, Quantity q,
|
||||
UserID(me->definition.user_id()),
|
||||
AccountID(me->definition.account_id()));
|
||||
if (!lqr.ok) {
|
||||
LOG(OrderMan, Warn,
|
||||
LOG(OrderMan, reject_level,
|
||||
"Unauthorized order attempted. User: {} on "
|
||||
"Account: {}. Msg: {} Order: {}. Dropping order",
|
||||
me->definition.user(), me->definition.account(), lqr.error_msg,
|
||||
key().value());
|
||||
|
||||
auto msg = fmt::format("Unauthorized order: {}", lqr.error_msg);
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK,msg);
|
||||
return OrderOpResult{ORDER_ERROR_UNAUTHORIZED,msg};
|
||||
transition(transition_level, ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return OrderOpResult{ORDER_ERROR_UNAUTHORIZED, msg};
|
||||
}
|
||||
|
||||
// can we trade this security, with this size?
|
||||
@@ -338,26 +340,26 @@ OrderOpResult NativeOrder::_on_activate(Price p, Quantity q,
|
||||
q);
|
||||
|
||||
if (!lqr.ok) {
|
||||
LOG(OrderMan, Warn,
|
||||
LOG(OrderMan, reject_level,
|
||||
"New order would breach limit. User: {} Account: "
|
||||
"{} Msg: {} Order: {}. Dropping order",
|
||||
me->definition.user(), me->definition.account(), lqr.error_msg,
|
||||
key().value());
|
||||
|
||||
auto msg = fmt::format("Order would breach limit: {}", lqr.error_msg);
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK,msg);
|
||||
return OrderOpResult{ORDER_ERROR_LIMIT_BREACH,msg};
|
||||
transition(transition_level, ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return OrderOpResult{ORDER_ERROR_LIMIT_BREACH, msg};
|
||||
}
|
||||
|
||||
// are we under the messaging threshold?
|
||||
if (!me->services->governor(*me->session_services).can_send()) {
|
||||
LOG(OrderMan, Warn,
|
||||
LOG(OrderMan, reject_level,
|
||||
"New order would cause breach of messaging "
|
||||
"limits. Dropping order {}",
|
||||
key().value());
|
||||
auto msg = "Messaging threshold breached";
|
||||
transition(ORDER_STATUS_REJECTED_BY_SPARK,msg);
|
||||
return OrderOpResult(ORDER_ERROR_MESSAGING_LIMIT_BREACH,msg);
|
||||
transition(transition_level, ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return OrderOpResult(ORDER_ERROR_MESSAGING_LIMIT_BREACH, msg);
|
||||
}
|
||||
|
||||
// if we are here we are good.
|
||||
@@ -403,16 +405,16 @@ OrderOpResult NativeOrder::on_activate(Price p, Quantity q,
|
||||
bts::orderman::OrderServices &services) {
|
||||
bts_assert(!me->services);
|
||||
me->services = &services;
|
||||
auto result = OrderOpResult {};
|
||||
auto result = OrderOpResult{};
|
||||
switch (me->state.status()) {
|
||||
|
||||
case ORDER_STATUS_INACTIVE: {
|
||||
// this is a brand new order
|
||||
|
||||
result = _on_activate(p, q, services);
|
||||
result = _on_activate(Warn, Info, p, q, services);
|
||||
if (result.ok()) {
|
||||
auto scoped_log =
|
||||
services.log_scope("NativeOrder::on_activate", key().value());
|
||||
services.log_scope("NativeOrder::on_activate", key().value());
|
||||
me->services->queue_fix(*me->session_services,
|
||||
jetfix::MessageTypes::NewOrderSingle,
|
||||
me->create_encoding);
|
||||
@@ -504,7 +506,7 @@ OrderOpResult NativeOrder::on_activate(Price p, Quantity q,
|
||||
OrderOpResult NativeOrder::on_update(Price p, Quantity q) {
|
||||
auto scoped_log =
|
||||
me->services->log_scope("NativeOrder::on_update", key().value());
|
||||
auto result = OrderOpResult {};
|
||||
auto result = OrderOpResult{};
|
||||
|
||||
switch (me->state.status()) {
|
||||
|
||||
@@ -618,7 +620,7 @@ OrderOpResult NativeOrder::on_cancel() {
|
||||
auto scoped_log =
|
||||
me->services->log_scope("NativeOrder::on_cancel", key().value());
|
||||
auto result = OrderOpResult{};
|
||||
|
||||
|
||||
switch (me->state.status()) {
|
||||
|
||||
case ORDER_STATUS_WORKING: {
|
||||
@@ -641,19 +643,19 @@ OrderOpResult NativeOrder::on_cancel() {
|
||||
result.error = ORDER_ERROR_INVALID_OP;
|
||||
result.error_msg = "Order is already terminated";
|
||||
break;
|
||||
|
||||
|
||||
case ORDER_STATUS_DISCONNECTED: {
|
||||
auto msg = "Cannot cancel order";
|
||||
result.error = ORDER_ERROR_GATEWAY_NOT_READY;
|
||||
result.error_msg = msg;
|
||||
transition(me->state.status(),msg);
|
||||
transition(me->state.status(), msg);
|
||||
break;
|
||||
}
|
||||
case ORDER_STATUS_PENDING_WORKING: {
|
||||
auto msg = "Cannot cancel order";
|
||||
result.error = ORDER_ERROR_ORDER_NOT_ACK;
|
||||
result.error_msg = msg;
|
||||
transition(me->state.status(),msg);
|
||||
transition(me->state.status(), msg);
|
||||
break;
|
||||
}
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
@@ -1087,10 +1089,17 @@ bool NativeOrder::has_exchange_order_id() {
|
||||
|
||||
void NativeOrder::transition(api::orderman::OrderStatus new_status,
|
||||
std::string const &msg) {
|
||||
transition(Info,new_status,msg);
|
||||
}
|
||||
|
||||
void NativeOrder::transition(log::Level level,
|
||||
api::orderman::OrderStatus new_status,
|
||||
std::string const &msg) {
|
||||
auto const &from = OrderStatus_Name(me->state.status());
|
||||
auto const &to = OrderStatus_Name(new_status);
|
||||
LOG(OrderMan, Info, "Transitioning order {} from {} to {}. Msg: {}",
|
||||
key().value(), from, to, msg);
|
||||
if (from != to)
|
||||
LOG(OrderMan, level, "Transitioning order {} from {} to {}. Msg: {}",
|
||||
key().value(), from, to, msg);
|
||||
me->state.set_status(new_status);
|
||||
me->state.set_last_msg(msg);
|
||||
}
|
||||
|
||||
@@ -44,12 +44,14 @@ class NativeOrder : public Order {
|
||||
void on_gateway_status(const GatewayStatusChangeEvent &);
|
||||
void report_state();
|
||||
OrderOpResult _on_activate(log::Level reject_level,
|
||||
log::Level transition_level,
|
||||
Price p, Quantity q,
|
||||
log::Level transition_level, Price p, Quantity q,
|
||||
bts::orderman::OrderServices &services);
|
||||
void init_fix();
|
||||
void add_exchange_order_id_to_fix();
|
||||
|
||||
void transition(log::Level,
|
||||
api::orderman::OrderStatus new_state,
|
||||
std::string const &msg);
|
||||
void transition(api::orderman::OrderStatus new_state,
|
||||
std::string const &msg);
|
||||
void transition(api::orderman::OrderStatus new_state);
|
||||
|
||||
@@ -34,21 +34,6 @@ api::orderman::OrderStatus Order::status() const { return _status; }
|
||||
|
||||
void Order::set_parent_key(OrderKey parent_key) { _parent_key = parent_key; }
|
||||
|
||||
// Many algos will not support attach. To provide a meaningfull
|
||||
// default implementation we must report the state of the order, so
|
||||
// that the UI and monitoring algos are aware this order was rejected.
|
||||
OrderOpResult Order::on_activate_attach(Price, Quantity, OrderKey,
|
||||
OrderServices &services) {
|
||||
|
||||
api::orderman::OrderState state;
|
||||
state.set_status(api::orderman::ORDER_STATUS_REJECTED_BY_SPARK);
|
||||
state.set_last_msg("Order does not support attachment");
|
||||
services.report_state(state);
|
||||
|
||||
return OrderOpResult{api::orderman::ORDER_ERROR_INVALID_OP,
|
||||
"Not implemented"};
|
||||
}
|
||||
|
||||
OrderOpResult Order::on_update(api::orderman::Update const &) {
|
||||
return OrderOpResult{api::orderman::ORDER_ERROR_INVALID_OP,
|
||||
"Not implemented"};
|
||||
|
||||
Reference in new issue
Block a user