More changes to attach/detach API
This commit is contained in:
1 parent
e79a73147a
commit
c2f954a79d
9 files changed
+161
-52
No files matched your search
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServices.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/core/IOrderServices.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderman/limiter/Limiter.Line truncated
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServices.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/core/IOrderServices.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderman/limiter/Limiter.Line truncated
|
||||
@@ -38,7 +38,6 @@ message Create {
|
||||
OrderDefinition new_order = 1;
|
||||
double price = 2;
|
||||
uint32 quantity = 3;
|
||||
uint32 attach_target_order_key = 4;
|
||||
}
|
||||
|
||||
message Update {
|
||||
@@ -71,8 +70,7 @@ message OrderDefinition {
|
||||
CTICode cti_code = 9;
|
||||
CustomerOrFirm customer_or_firm = 10;
|
||||
OrderSubType sub_type = 12;
|
||||
|
||||
bool attach_on_launch = 16;
|
||||
uint32 attach_target_order_key = 16;
|
||||
CustomOrderDefinition custom_def = 11;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,6 +154,7 @@ void OrderServices::on_attach(OrderServices &new_parent,
|
||||
// at this point this must work because orders cannot refuse attachments
|
||||
cb({}, me_as_child, *self._owner->def(),
|
||||
self._last_state_update.rebuild_state());
|
||||
|
||||
self._owner->on_attached(*new_parent._owner->def());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ class OrderServices {
|
||||
|
||||
// Caller is the future parent of an existing order,
|
||||
// i.e. caller will attach to an existing order.
|
||||
void attach(OrderKey child_key, AttachCallback const &);
|
||||
void attach(OrderKey attach_target, AttachCallback const &);
|
||||
|
||||
private:
|
||||
friend class OrderBuilder;
|
||||
@@ -207,6 +207,8 @@ class OrderServices {
|
||||
// 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
|
||||
call_with_reentrancy_guard([p, q, on_order_op](OrderServices &self) {
|
||||
on_order_op(self._owner->on_activate(p, q, self));
|
||||
});
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "orderman_utils.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
bool should_forward_attachment(const api::orderman::CustomOrderDefinition &cdef) {
|
||||
switch (cdef.custom_case()) {
|
||||
case CustomOrderDefinition::kMarket:
|
||||
case CustomOrderDefinition::kLimit:
|
||||
case CustomOrderDefinition::kStop:
|
||||
case CustomOrderDefinition::kStopLimit:
|
||||
case CustomOrderDefinition::kSpreader:
|
||||
return false;
|
||||
|
||||
case CustomOrderDefinition::kIceberg:
|
||||
return
|
||||
!cdef.iceberg().has_child() ||
|
||||
!should_forward_attachment(cdef.iceberg().child());
|
||||
|
||||
case CustomOrderDefinition::kTimeBox:
|
||||
case CustomOrderDefinition::kTick:
|
||||
case CustomOrderDefinition::kLean:
|
||||
case CustomOrderDefinition::kJoin:
|
||||
case CustomOrderDefinition::kTop:
|
||||
case CustomOrderDefinition::kTrigger:
|
||||
case CustomOrderDefinition::kCover:
|
||||
case CustomOrderDefinition::kOffset:
|
||||
case CustomOrderDefinition::kOco:
|
||||
case CustomOrderDefinition::kPricer:
|
||||
case CustomOrderDefinition::kDynamic:
|
||||
return false;
|
||||
|
||||
case CustomOrderDefinition::CUSTOM_NOT_SET:
|
||||
bts_assert(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
@@ -3,27 +3,31 @@
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
|
||||
inline bool order_in_error_state(OrderStatus order_status) {
|
||||
inline bool order_in_error_state(bts::api::orderman::OrderStatus order_status) {
|
||||
using namespace bts::api::orderman;
|
||||
return order_status == OrderStatus::ORDER_STATUS_ERROR ||
|
||||
order_status == OrderStatus::ORDER_STATUS_DISCONNECTED ||
|
||||
order_status == OrderStatus::ORDER_STATUS_REJECTED_BY_SPARK;
|
||||
}
|
||||
|
||||
inline bool order_in_working_state(OrderStatus order_status) {
|
||||
inline bool order_in_working_state(bts::api::orderman::OrderStatus order_status) {
|
||||
using namespace bts::api::orderman;
|
||||
return order_status == OrderStatus::ORDER_STATUS_WORKING ||
|
||||
order_status == OrderStatus::ORDER_STATUS_PENDING_WORKING;
|
||||
}
|
||||
|
||||
inline bool is_exchange_order(const OrderState &state) {
|
||||
inline bool is_exchange_order(const bts::api::orderman::OrderState &state) {
|
||||
using namespace bts::api::orderman;
|
||||
return state.has_market() || state.has_limit() || state.has_stop() ||
|
||||
state.has_stop_limit();
|
||||
}
|
||||
|
||||
inline bool is_parent_order(const OrderRecord &ord) {
|
||||
inline bool is_parent_order(const bts::api::orderman::OrderRecord &ord) {
|
||||
return ord.parent_key() == 0;
|
||||
}
|
||||
|
||||
bool should_forward_attachment(const api::orderman::CustomOrderDefinition &def);
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "lib/config/protos/system.pb.h"
|
||||
#include "lib/orderman/actors/order_manager/ChildOrder.h"
|
||||
#include "lib/orderman/actors/order_manager/OrderBuilder.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_utils.h"
|
||||
#include "lib/plugin/SparkServices.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
|
||||
@@ -14,6 +15,7 @@ namespace orderman {
|
||||
using namespace api::orderman;
|
||||
enum class IcebergOrder2::InternalStatus {
|
||||
INACTIVE,
|
||||
PENDING_ATTACH,
|
||||
PAUSED,
|
||||
WORKING,
|
||||
COMPLETED
|
||||
@@ -93,10 +95,13 @@ void IcebergOrder2::on_init_new(OrderDefinition const &def,
|
||||
else {
|
||||
// If we are attaching we might not need an order builder, it
|
||||
// depends on wheter we will consume the attached order or
|
||||
// forward that attachment to our child. We can infer that we
|
||||
// are consuming the attachment directly if we have no child
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +115,7 @@ void IcebergOrder2::on_init_recovered(OrderRecord const &rec,
|
||||
switch (me->external_status()) {
|
||||
|
||||
case ORDER_STATUS_WORKING:
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK,
|
||||
"System restarted with active iceberg order");
|
||||
return;
|
||||
@@ -123,7 +129,6 @@ void IcebergOrder2::on_init_recovered(OrderRecord const &rec,
|
||||
break;
|
||||
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
case OrderStatus_INT_MAX_SENTINEL_DO_NOT_USE_:
|
||||
@@ -137,11 +142,12 @@ OrderOpResult IcebergOrder2::on_activate(Price p, Quantity q,
|
||||
OrderServices &services) {
|
||||
bts_assert(!me->services);
|
||||
me->services = &services;
|
||||
me->child_builder.activate(services);
|
||||
|
||||
switch (me->internal_status) {
|
||||
|
||||
case InternalStatus::INACTIVE:
|
||||
me->child_builder.activate(services);
|
||||
|
||||
me->order_state.set_price(p.value());
|
||||
me->order_state.set_quantity(q.value());
|
||||
|
||||
@@ -152,25 +158,27 @@ OrderOpResult IcebergOrder2::on_activate(Price p, Quantity q,
|
||||
auto msg = "Expected an order to attach to";
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return report_and_return(ORDER_ERROR_INVALID_OP, msg);
|
||||
} else if (q.value()) {
|
||||
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); });
|
||||
me->set_external_status(ORDER_STATUS_WORKING);
|
||||
work();
|
||||
return report_and_return();
|
||||
} else {
|
||||
}
|
||||
|
||||
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); });
|
||||
me->set_external_status(ORDER_STATUS_WORKING);
|
||||
work();
|
||||
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();
|
||||
}
|
||||
@@ -181,16 +189,10 @@ OrderOpResult IcebergOrder2::on_activate(Price p, Quantity q,
|
||||
}
|
||||
|
||||
OrderOpResult IcebergOrder2::on_activate_attach(Price p, Quantity q,
|
||||
OrderKey attach_to_target,
|
||||
OrderKey attach_target,
|
||||
OrderServices &services) {
|
||||
// Should we consume or forward the attachment? If our child does
|
||||
// not exist or is a bottom order (spreader or native) then we
|
||||
// assume we want to attach directly otherwise we will forward the
|
||||
// attachment to our child, after we created it.
|
||||
|
||||
bts_assert(!me->services);
|
||||
me->services = &services;
|
||||
me->child_builder.activate(services);
|
||||
|
||||
switch (me->internal_status) {
|
||||
|
||||
@@ -205,25 +207,35 @@ OrderOpResult IcebergOrder2::on_activate_attach(Price p, Quantity q,
|
||||
auto msg = "Unexpected attach call";
|
||||
terminate(ORDER_STATUS_REJECTED_BY_SPARK, msg);
|
||||
return report_and_return(ORDER_ERROR_INVALID_OP, msg);
|
||||
} else if (q.value()) {
|
||||
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); });
|
||||
me->set_external_status(ORDER_STATUS_WORKING);
|
||||
work();
|
||||
return report_and_return();
|
||||
} else {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -231,7 +243,6 @@ OrderOpResult IcebergOrder2::on_activate_attach(Price p, Quantity q,
|
||||
// compiler
|
||||
bts_assert(false);
|
||||
return report_and_return();
|
||||
return OrderOpResult{};
|
||||
}
|
||||
|
||||
OrderOpResult IcebergOrder2::on_update(api::orderman::Update const &update) {
|
||||
@@ -284,6 +295,11 @@ OrderOpResult IcebergOrder2::on_update(api::orderman::Update const &update) {
|
||||
return report_and_return(ORDER_ERROR_INVALID_OP,
|
||||
"Order is already completed");
|
||||
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
return report_and_return(
|
||||
ORDER_ERROR_INVALID_OP,
|
||||
"Order cannot be modified while waiting for attach to complete");
|
||||
|
||||
case InternalStatus::INACTIVE:
|
||||
bts_assert(false);
|
||||
return report_and_return();
|
||||
@@ -299,6 +315,7 @@ orderman::OrderOpResult orderman::IcebergOrder2::on_cancel() {
|
||||
switch (me->internal_status) {
|
||||
case InternalStatus::PAUSED:
|
||||
case InternalStatus::WORKING:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
terminate(ORDER_STATUS_CANCELED);
|
||||
return report_and_return();
|
||||
case InternalStatus::COMPLETED:
|
||||
@@ -405,6 +422,7 @@ void IcebergOrder2::on_child_order_update(OrderStateUpdateEvent const &ev) {
|
||||
return;
|
||||
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
bts_assert(false);
|
||||
return;
|
||||
}
|
||||
@@ -420,6 +438,7 @@ void IcebergOrder2::on_time() {
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::COMPLETED:
|
||||
case InternalStatus::WORKING:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -443,12 +462,13 @@ void orderman::IcebergOrder2::on_child_activate_completed(OrderOpResult r) {
|
||||
case InternalStatus::COMPLETED:
|
||||
return;
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
bts_assert(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void orderman::IcebergOrder2::send_next_child_order() {
|
||||
void orderman::IcebergOrder2::send_next_child_order(OrderKey attach_target) {
|
||||
bts_assert(me->order_state.quantity() > me->order_state.filled_quantity());
|
||||
|
||||
auto remaining =
|
||||
@@ -466,18 +486,26 @@ void orderman::IcebergOrder2::send_next_child_order() {
|
||||
me->order_state.price(), me->order_state.filled_quantity(),
|
||||
me->order_state.quantity());
|
||||
|
||||
me->active_child.order.activate(
|
||||
Price(me->order_state.price()), Quantity(to_send),
|
||||
[this](auto const &op) { this->on_child_activate_completed(op); });
|
||||
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); });
|
||||
}
|
||||
}
|
||||
|
||||
void IcebergOrder2::work() {
|
||||
void IcebergOrder2::work(OrderKey attach_target) {
|
||||
switch (me->internal_status) {
|
||||
|
||||
case InternalStatus::PAUSED:
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
me->start_of_pause = TimeStamp();
|
||||
send_next_child_order();
|
||||
send_next_child_order(attach_target);
|
||||
transition(InternalStatus::WORKING);
|
||||
break;
|
||||
|
||||
@@ -488,6 +516,18 @@ void IcebergOrder2::work() {
|
||||
}
|
||||
}
|
||||
|
||||
void IcebergOrder2::attach(OrderKey target) {
|
||||
bts_assert(me->internal_status == InternalStatus::INACTIVE);
|
||||
|
||||
AttachCallback cb([this](auto result, auto const &child_order,
|
||||
auto const &child_def, auto const &child_state) {
|
||||
on_attach_complete(result, child_order, child_def, child_state);
|
||||
});
|
||||
|
||||
me->services->attach(target, cb);
|
||||
transition(InternalStatus::PENDING_ATTACH);
|
||||
}
|
||||
|
||||
void IcebergOrder2::pause() {
|
||||
switch (me->internal_status) {
|
||||
|
||||
@@ -500,6 +540,7 @@ void IcebergOrder2::pause() {
|
||||
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::PAUSED:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
case InternalStatus::COMPLETED:
|
||||
bts_assert(false);
|
||||
break;
|
||||
@@ -512,6 +553,7 @@ void IcebergOrder2::terminate(api::orderman::OrderStatus reason,
|
||||
case InternalStatus::INACTIVE:
|
||||
case InternalStatus::PAUSED:
|
||||
case InternalStatus::WORKING:
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
if (!me->active_child.is_empty()) {
|
||||
me->active_child.order.cancel();
|
||||
me->active_child.reset();
|
||||
@@ -565,7 +607,14 @@ void IcebergOrder2::check_invariants() {
|
||||
bts_assert(me->active_child.is_empty());
|
||||
bts_assert(me->start_of_pause == TimeStamp());
|
||||
break;
|
||||
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
bts_assert(me->external_status() == ORDER_STATUS_PENDING_WORKING);
|
||||
bts_assert(me->active_child.is_empty());
|
||||
bts_assert(me->start_of_pause == TimeStamp());
|
||||
bts_assert(!me->child_builder.is_activated());
|
||||
bts_assert(me->order_state.filled_quantity() == 0);
|
||||
bts_assert(me->order_state.quantity() > 0);
|
||||
break;
|
||||
case InternalStatus::INACTIVE:
|
||||
bts_assert(false);
|
||||
break;
|
||||
@@ -642,6 +691,8 @@ std::string orderman::IcebergOrder2::internal_status_name(InternalStatus st) {
|
||||
return "COMPLETED";
|
||||
case InternalStatus::WORKING:
|
||||
return "WORKING";
|
||||
case InternalStatus::PENDING_ATTACH:
|
||||
return "PENDING_ATTACH";
|
||||
}
|
||||
bts_assert(false);
|
||||
return "";
|
||||
|
||||
@@ -30,7 +30,8 @@ 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_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;
|
||||
@@ -48,11 +49,18 @@ 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);
|
||||
|
||||
void on_time();
|
||||
void on_child_order_update(OrderStateUpdateEvent const &ev);
|
||||
void on_attach_complete(OrderOpResult, ChildOrder const &,
|
||||
api::orderman::OrderDefinition const &,
|
||||
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,
|
||||
|
||||
@@ -56,8 +56,6 @@ class Order {
|
||||
|
||||
// Activation, the order is now live, these should be fast
|
||||
virtual OrderOpResult on_activate(Price, Quantity, OrderServices &) = 0;
|
||||
virtual OrderOpResult on_activate_attach(Price, Quantity, OrderKey target,
|
||||
OrderServices &);
|
||||
|
||||
// Order Updates, post activation
|
||||
virtual OrderOpResult on_update(Price, Quantity) = 0;
|
||||
@@ -72,6 +70,9 @@ class Order {
|
||||
// Order has been attached to
|
||||
virtual void on_attached(api::orderman::OrderDefinition const &);
|
||||
|
||||
// Order types have to explicitly opt in to support attachment
|
||||
virtual bool supports_attachment() {return false;}
|
||||
|
||||
protected:
|
||||
virtual void warm_up_activate(OrderServicesData &, OrderServices &) {}
|
||||
void init_order_services(OrderServicesData &);
|
||||
|
||||
Reference in new issue
Block a user