Towards a persistent book.

This commit is contained in:
Pedro Pinto committed 2018-03-23 16:35:53 -04:00
1 parent bf01d8254e
commit 9392ba47e6
11 files changed
+230 -147

No files matched your search

+1 -1
View File
@@ -1 +1 @@
set(sources api/apicore.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/services/AccountService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/ShellDiagnosticService.proto;api/services/SyntheticSecurityService.proto;api/services/UserService.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/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/testkeys.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSim.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/quickbus_cfg.proto;config/protos/system.proto;config/protos/testkeys.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;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPriceLantencyTester.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/windows_test_driver.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp)
set(sources api/apicore.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/services/AccountService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/ShellDiagnosticService.proto;api/services/SyntheticSecurityService.proto;api/services/UserService.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/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/testkeys.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/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/quickbus_cfg.proto;config/protos/system.proto;config/protos/testkeys.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;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPriceLantencyTester.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/windows_test_driver.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp)
+26
View File
@@ -47,6 +47,32 @@ inline google::protobuf::Timestamp pb_now()
result.set_nanos(tv.tv_usec * 1000);
return result;
}
inline bool smaller(google::protobuf::Timestamp const &t1, google::protobuf::Timestamp const &t2)
{
if (t1.seconds() < t2.seconds())
return true;
else if (t1.seconds() > t2.seconds())
return false;
else
return t1.nanos() < t2.nanos();
}
inline bool greater(google::protobuf::Timestamp const &t1, google::protobuf::Timestamp const &t2)
{
if (t1.seconds() > t2.seconds())
return true;
else if (t1.seconds() < t2.seconds())
return false;
else
return t1.nanos() > t2.nanos();
}
inline bool equal(google::protobuf::Timestamp const &t1, google::protobuf::Timestamp const &t2)
{
return t1.seconds() == t2.seconds() && t1.nanos() == t2.nanos();
}
#endif
}}}
+1 -1
View File
@@ -1 +1 @@
set(sources ;Support/ErrorReportService.cpp;cmds/Benchmark.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/Help.cpp;cmds/Md.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/RunSim.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;dspark/mirage.cpp;dspark/mirage/routing/Router.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.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;main.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/MDP3Utils.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;mercury/actors/Actor.cpp;mercury/broker/AsyncEventBroker.cpp;mercury/broker/CoreEventBroker.cpp;mercury/broker/IEventBroker.cpp;mercury/events/TimerEvent.cpp;mercury/mercury_utils/Executor.cpp;mercury/mercury_utils/IPollableActor.cpp;mercury/mercury_utils/mercury_common.cpp;mercury/synopsis/SynopsisBuilder.cpp;mercury/topics/ITopic.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/order_factory/OrderFactory.cpp;orderman/orderman_utils/fix_order_codec.cpp;orderman/orders/IcebergOrder.cpp;orderman/orders/NativeOrder.cpp;orderman/orders/Order.cpp;orderman/orders/TimeBoxOrder.cpp;orderman/orders/spreader_orders/SpreaderOrder.cpp;orderman/orders/spreader_orders/spreader/SingleFillHedger.cpp;orderman/orders/spreader_orders/spreader/SingleLegQuoter.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForSizeStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderEndStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderStartStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWaitingForCancelAllStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWorkingStateWorker.cpp;orderman/orders/spreader_orders/tests/spreader_tests.cpp;orderman/server/OrderServiceServer.cpp;orderman/tests/fat_wrapper_tests.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/tests/PersistenceServiceTests.cpp;position/IMarginObserver.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/PositionServiceCore.cpp;position/tests/PositionTests.cpp;risk_limits/AccountRiskLimiter.cpp;risk_limits/IRiskLimitObserver.cpp;risk_limits/OperatorRiskLimiter.cpp;risk_limits/RiskLimitManager.cpp;risk_limits/RiskLimiter.cpp;risk_limits/SymbolKey.cpp;risk_limits/tests/RiskLimitsTests.cpp;testing/catch_test_runner.cpp;tracing/bts_trace_c.c;user/AccountServiceServer.cpp;user/UserServiceServer.cpp;user/tests/UserAndAccountTests.cpp)
set(sources Support/ErrorReportService.cpp;cmds/Benchmark.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/Help.cpp;cmds/Md.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/RunSim.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;dspark/mirage.cpp;dspark/mirage/routing/Router.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.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;main.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/MDP3Utils.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;mercury/actors/Actor.cpp;mercury/broker/AsyncEventBroker.cpp;mercury/broker/CoreEventBroker.cpp;mercury/broker/IEventBroker.cpp;mercury/events/TimerEvent.cpp;mercury/mercury_utils/Executor.cpp;mercury/mercury_utils/IPollableActor.cpp;mercury/mercury_utils/mercury_common.cpp;mercury/synopsis/SynopsisBuilder.cpp;mercury/topics/ITopic.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/order_factory/OrderFactory.cpp;orderman/orderman_utils/fix_order_codec.cpp;orderman/orders/IcebergOrder.cpp;orderman/orders/NativeOrder.cpp;orderman/orders/Order.cpp;orderman/orders/TimeBoxOrder.cpp;orderman/orders/spreader_orders/SpreaderOrder.cpp;orderman/orders/spreader_orders/spreader/SingleFillHedger.cpp;orderman/orders/spreader_orders/spreader/SingleLegQuoter.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterEndStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterStartStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForFirstAckWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWaitingForSizeStateWorker.cpp;orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderEndStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderStartStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWaitingForCancelAllStateWorker.cpp;orderman/orders/spreader_orders/spreader_states/SpreaderWorkingStateWorker.cpp;orderman/orders/spreader_orders/tests/spreader_tests.cpp;orderman/server/OrderServiceServer.cpp;orderman/tests/fat_wrapper_tests.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/tests/PersistenceServiceTests.cpp;position/IMarginObserver.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/PositionServiceCore.cpp;position/tests/PositionTests.cpp;risk_limits/AccountRiskLimiter.cpp;risk_limits/IRiskLimitObserver.cpp;risk_limits/OperatorRiskLimiter.cpp;risk_limits/RiskLimitManager.cpp;risk_limits/RiskLimiter.cpp;risk_limits/SymbolKey.cpp;risk_limits/tests/RiskLimitsTests.cpp;testing/catch_test_runner.cpp;tracing/bts_trace_c.c;user/AccountServiceServer.cpp;user/UserServiceServer.cpp;user/tests/UserAndAccountTests.cpp)
@@ -3,7 +3,7 @@
#include "IDGenerator.h"
#include "lib/config/config.h"
#include "lib/config/protos/ExchangeSim.pb.h"
#include "lib/config/protos/ExchangeSimCfg.pb.h"
#include "lib/domain_model/Security.h"
#include "lib/logging/logging.h"
#include "lib/md/MDConsumer.h"
@@ -16,6 +16,7 @@
#include "server/sparkd/exchange_sim/book/Order.h"
#include "server/sparkd/exchange_sim/book/OrderMatcher.h"
#include "server/sparkd/exchange_sim/book/book_transform.h"
#include "server/sparkd/persistence/SqliteStore.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <fmt/format.h>
@@ -100,7 +101,9 @@ struct ExchangeSimApplication::PImpl {
consumer(api::VENUE_GLBX, co2::PLATFORM_MDP3ONIXS),
timer(utils::Dispatcher::background(), 200,
[=]() { producer.heartbeat(); }),
do_merge_with_md(config::get<config::ExchangeSim>().merge_with_md()) {}
do_merge_with_md(config::get<config::ExchangeSim>().merge_with_md()),
store(new persistence::SqliteStore("order_book"))
{}
IDGenerator m_generator;
md::MDProducer producer;
@@ -111,6 +114,7 @@ struct ExchangeSimApplication::PImpl {
std::map<std::string, ex_sim::OrderMatcher> matchers;
bool do_merge_with_md;
TimeStamp last_scan;
std::unique_ptr<persistence::IStore> store;
std::mutex lock;
};
@@ -185,23 +189,23 @@ void ExchangeSimApplication::onMessage(const FIX42::NewOrderSingle &message,
throw std::logic_error("Duplicate order");
ex_sim::Order order;
order.clordid = clOrdID;
order.sec_desc = sec_desc;
order.account = account;
order.owner = senderCompID;
order.target = targetCompID;
order.sender_sub_id = senderSubID;
order.side = convert(side);
order.type = convert(ordType);
order.price = Price(price);
order.quantity = Quantity(orderQty);
order.moi = convert(moi);
order.open_quantity = order.quantity;
order.executed_quantity = Quantity(0);
order.avg_executed_price = Price(0);
order.last_executed_price = Price(0);
order.last_executed_quantity = Quantity(0);
order.create_time = Timer::now();
order.set_clordid (clOrdID);
order.set_sec_desc(sec_desc);
order.set_account(account);
order.set_owner(senderCompID);
order.set_target(targetCompID);
order.set_sender_sub_id(senderSubID);
order.set_side(convert(side));
order.set_type(convert(ordType));
order.set_price(price);
order.set_quantity(orderQty);
order.set_moi(convert(moi));
order.set_open_quantity(order.quantity());
order.set_executed_quantity(0);
order.set_avg_executed_price(0);
order.set_last_executed_price(0);
order.set_last_executed_quantity(0);
*order.mutable_create_time() = utils::pb::pb_now();
updateOrder(order, FIX::OrdStatus_NEW);
std::vector<Order> updates;
@@ -246,8 +250,8 @@ void ExchangeSimApplication::onMessage(
throw std::logic_error("Unknown order");
else {
auto order_cpy = *order;
order_cpy.price = Price(price);
order_cpy.quantity = Quantity(orderQty);
order_cpy.set_price (price);
order_cpy.set_quantity(orderQty);
updateOrder(order_cpy, FIX::OrdStatus_REPLACED);
std::vector<Order> updates;
@@ -280,7 +284,7 @@ void ExchangeSimApplication::onMessage(const FIX42::OrderCancelRequest &message,
throw std::logic_error("Unknown order");
else {
auto order_cpy = *order;
order_cpy.open_quantity = Quantity(0);
order_cpy.set_open_quantity(0);
updateOrder(order_cpy, FIX::OrdStatus_CANCELED);
matcher.cancel(origClOrdID);
update_md(sec_desc);
@@ -295,15 +299,15 @@ void ExchangeSimApplication::rejectOrder(const Order &order) {
void ExchangeSimApplication::fillOrder(const Order &order) {
updateOrder(order,
order.open_quantity.value() == 0
order.open_quantity() == 0
? FIX::OrdStatus_FILLED
: FIX::OrdStatus_PARTIALLY_FILLED);
}
void ExchangeSimApplication::updateOrder(const Order &order, char status) {
FIX::TargetCompID targetCompID(order.owner);
FIX::SenderCompID senderCompID(order.target);
FIX::TargetSubID(order.sender_sub_id);
FIX::TargetCompID targetCompID(order.owner());
FIX::SenderCompID senderCompID(order.target());
FIX::TargetSubID(order.sender_sub_id());
FIX42::ExecutionReport fixOrder;
fixOrder.set(FIX::OrderID("12345678901234567"));
@@ -311,20 +315,20 @@ void ExchangeSimApplication::updateOrder(const Order &order, char status) {
fixOrder.set(FIX::ExecTransType(FIX::ExecTransType_NEW));
fixOrder.set(FIX::ExecType(status));
fixOrder.set(FIX::OrdStatus(status));
fixOrder.set(FIX::Account(order.account));
fixOrder.set(FIX::SecurityDesc(order.sec_desc));
fixOrder.set(FIX::Side(convert(order.side)));
fixOrder.set(FIX::LeavesQty(order.open_quantity.value()));
fixOrder.set(FIX::CumQty(order.executed_quantity.value()));
fixOrder.set(FIX::AvgPx(order.avg_executed_price.value()));
fixOrder.set(FIX::ClOrdID(order.clordid));
fixOrder.set(FIX::OrderQty(order.quantity.value()));
fixOrder.set(FIX::Account(order.account()));
fixOrder.set(FIX::SecurityDesc(order.sec_desc()));
fixOrder.set(FIX::Side(convert(order.side())));
fixOrder.set(FIX::LeavesQty(order.open_quantity()));
fixOrder.set(FIX::CumQty(order.executed_quantity()));
fixOrder.set(FIX::AvgPx(order.avg_executed_price()));
fixOrder.set(FIX::ClOrdID(order.clordid()));
fixOrder.set(FIX::OrderQty(order.quantity()));
fixOrder.set(FIX::TimeInForce(FIX::TimeInForce_DAY));
fixOrder.set(FIX::OrdType(convert(order.type)));
fixOrder.set(FIX::Price(order.price.value()));
fixOrder.set(FIX::OrderQty(order.quantity.value()));
fixOrder.set(FIX::OrdType(convert(order.type())));
fixOrder.set(FIX::Price(order.price()));
fixOrder.set(FIX::OrderQty(order.quantity()));
fixOrder.setField(convert(order.moi));
fixOrder.setField(convert(order.moi()));
boost::posix_time::ptime now =
boost::posix_time::second_clock::universal_time();
@@ -335,11 +339,11 @@ void ExchangeSimApplication::updateOrder(const Order &order, char status) {
true));
if (status == FIX::OrdStatus_FILLED ||
status == FIX::OrdStatus_PARTIALLY_FILLED) {
fixOrder.set(FIX::LastShares(order.last_executed_quantity.value()));
fixOrder.set(FIX::LastPx(order.last_executed_price.value()));
fixOrder.set(FIX::LastShares(order.last_executed_quantity()));
fixOrder.set(FIX::LastPx(order.last_executed_price()));
}
fixOrder.getHeader().set(FIX::TargetSubID(order.sender_sub_id));
fixOrder.getHeader().set(FIX::TargetSubID(order.sender_sub_id()));
try {
FIX::Session::sendToTarget(fixOrder, senderCompID, targetCompID);
} catch (FIX::SessionNotFound &) {
@@ -518,34 +522,34 @@ void ExchangeSimApplication::merge_with_md_book(std::string const &sec_desc,
switch (op.op) {
case BookOp::ORDER: {
ex_sim::Order order;
order.clordid = fmt::format("synth-{}", me->m_generator.genOrderID());
order.sec_desc = sec_desc;
order.account = "SYNTH";
order.owner = "SYNTH";
order.target = "SYNTH";
order.sender_sub_id = "SYNTH";
order.side = op.side;
order.type = api::orderman::NATIVE_ORDER_TYPE_LIMIT;
order.price = op.price;
order.quantity = op.quantity;
order.moi = api::orderman::MANUAL_ORDER_INDICATOR_NO;
order.open_quantity = order.quantity;
order.executed_quantity = Quantity(0);
order.avg_executed_price = Price(0);
order.last_executed_price = Price(0);
order.last_executed_quantity = Quantity(0);
order.create_time = Timer::now();
order.set_clordid (fmt::format("synth-{}", me->m_generator.genOrderID()));
order.set_sec_desc(sec_desc);
order.set_account("SYNTH");
order.set_owner("SYNTH");
order.set_target("SYNTH");
order.set_sender_sub_id("SYNTH");
order.set_side(op.side);
order.set_type(api::orderman::NATIVE_ORDER_TYPE_LIMIT);
order.set_price(op.price.value());
order.set_quantity(op.quantity.value());
order.set_moi(api::orderman::MANUAL_ORDER_INDICATOR_NO);
order.set_open_quantity(order.quantity());
order.set_executed_quantity(0);
order.set_avg_executed_price(0);
order.set_last_executed_price(0);
order.set_last_executed_quantity(0);
*order.mutable_create_time() = utils::pb::pb_now();
std::vector<Order> updates;
matcher.add(order, &updates);
for (auto const &o : updates)
if (o.account != "SYNTH") {
if (o.account() != "SYNTH") {
LOG(ExSim, Diag,
"Generating fill in response to md change for {}: {} {}@{}",
sec_desc,
o.side == api::SIDE_BUY ? std::string("Buy")
o.side() == api::SIDE_BUY ? std::string("Buy")
: std::string("Sell"),
o.open_quantity.value(), o.price.value());
o.open_quantity(), o.price());
fillOrder(o);
}
break;
@@ -557,8 +561,23 @@ void ExchangeSimApplication::merge_with_md_book(std::string const &sec_desc,
}
update_md(sec_desc);
auto order_book = matcher.get_order_book("SYNTH");
order_book.set_sec_desc(sec_desc);
persist_book(order_book);
}
void ExchangeSimApplication::persist_book(OrderBook const &b)
{
auto existing = me->store->retrieve_one("books",b.sec_desc());
auto val = utils::pb::to_string(b);
if (existing.first)
me->store->update("books", b.sec_desc(), val);
else
me->store->insert("books", b.sec_desc(), val);
}
GCC_DIAG_RESTORE()
GCC_DIAG_RESTORE()
}
@@ -44,8 +44,9 @@ namespace bts {
namespace api {class Security;}
namespace md {class MDConsumerHandle;}
namespace ex_sim {
struct Order;
class Order;
struct Book;
class OrderBook;
class ExchangeSimApplication
: public FIX::Application,
public FIX::MessageCracker
@@ -95,6 +96,7 @@ public:
void on_new_security(api::Security const&sec, md::MDConsumerHandle handle);
void merge_with_md_book(std::string const &sec_desc, Book const&previous,Book const&current);
void update_md(std::string const&sec_desc);
void persist_book(OrderBook const &b);
};
}}
@@ -0,0 +1,34 @@
syntax="proto3";
package bts.ex_sim;
import "lib/domain_model/Security.proto";
import "google/protobuf/timestamp.proto";
import "lib/api/services/OrderService.proto";
message Order {
string clordid = 1;
string sec_desc = 2;
string account = 3;
string owner = 4;
string target = 5;
string sender_sub_id = 6;
api.Side side = 7;
api.orderman.NativeOrderType type = 8;
double price = 9;
uint32 quantity = 10;
api.orderman.ManualOrderIndicator moi = 11;
uint32 open_quantity = 12;
uint32 executed_quantity = 13;
double avg_executed_price = 14;
double last_executed_price = 15;
uint32 last_executed_quantity = 16;
google.protobuf.Timestamp create_time = 17;
}
message OrderBook {
string sec_desc = 1;
repeated Order bids = 2;
repeated Order asks = 3;
}
@@ -3,16 +3,16 @@
namespace bts {
namespace ex_sim {
void Order::execute(Price price, Quantity quantity) {
avg_executed_price.value() =
void execute(Order *order, Price price, Quantity quantity) {
order->set_avg_executed_price(
((quantity.value() * price.value()) +
(avg_executed_price.value() * executed_quantity.value())) /
(quantity.value() + executed_quantity.value());
(order->avg_executed_price() * order->executed_quantity())) /
(quantity.value() + order->executed_quantity()));
open_quantity.value() -= quantity.value();
executed_quantity.value() += quantity.value();
last_executed_price.value() = price.value();
last_executed_quantity.value() = quantity.value();
order->set_open_quantity(order->open_quantity()- quantity.value());
order->set_executed_quantity(order->executed_quantity() + quantity.value());
order->set_last_executed_price(price.value());
order->set_last_executed_quantity(quantity.value());
}
+9 -28
View File
@@ -6,32 +6,13 @@
#include "lib/domain_model/Security.pb.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/utils/bts_chrono.h"
#include "server/sparkd/exchange_sim/book/ExchangeSim.pb.h"
#include "lib/utils/PBUtils.h"
namespace bts {
namespace ex_sim {
struct Order {
std::string clordid;
std::string sec_desc;
std::string account;
std::string owner;
std::string target;
std::string sender_sub_id;
api::Side side;
api::orderman::NativeOrderType type;
Price price;
Quantity quantity;
api::orderman::ManualOrderIndicator moi;
mutable Quantity open_quantity;
Quantity executed_quantity;
Price avg_executed_price;
Price last_executed_price;
Quantity last_executed_quantity;
TimeStamp create_time;
void execute(Price price, Quantity quantity);
};
void execute(Order *order, Price price, Quantity quantity);
struct OrderCmp {
OrderCmp(bool ascending) : ascending(ascending) {}
@@ -39,15 +20,15 @@ struct OrderCmp {
bool operator()(Order const &lhs, Order const &rhs) const {
if (ascending) {
if (lhs.price.value() != rhs.price.value())
return lhs.price.value() < rhs.price.value();
if (lhs.price() != rhs.price())
return lhs.price() < rhs.price();
else
return lhs.create_time < rhs.create_time;
return utils::pb::smaller(lhs.create_time(),rhs.create_time());
} else {
if (lhs.price.value() != rhs.price.value())
return lhs.price.value() > rhs.price.value();
if (lhs.price() != rhs.price())
return lhs.price() > rhs.price();
else
return lhs.create_time > rhs.create_time;
return utils::pb::greater(lhs.create_time(),rhs.create_time());
}
}
bool ascending;
@@ -9,19 +9,22 @@ namespace bts {
namespace ex_sim {
struct OrderMatcher::PImpl {
PImpl() : bids(OrderCmp(false)), asks(OrderCmp(true)) {}
PImpl()
: bids(OrderCmp(false)), asks(OrderCmp(true)) {}
OrdersSide bids;
OrdersSide asks;
std::vector<Trade> pending_trades;
};
OrderMatcher::OrderMatcher() : me(new PImpl()) {}
OrderMatcher::OrderMatcher()
: me(new PImpl()) {}
OrderMatcher::~OrderMatcher() {}
struct OrderFinder {
OrderFinder(std::string const &clordid) : clordid(clordid) {}
bool operator()(Order const &o) const { return o.clordid == clordid; }
bool operator()(Order const &o) const { return o.clordid() == clordid; }
std::string const &clordid;
};
@@ -37,8 +40,8 @@ Order const *OrderMatcher::get_order(std::string const &clordid) {
}
void OrderMatcher::add(Order const &o, std::vector<Order> *out) {
bts_assert(!get_order(o.clordid));
if (o.side == api::SIDE_BUY)
bts_assert(!get_order(o.clordid()));
if (o.side() == api::SIDE_BUY)
me->bids.insert(o);
else
me->asks.insert(o);
@@ -51,13 +54,13 @@ void OrderMatcher::update(std::string const &clordid, Price price, Quantity qty,
bts_assert(order);
auto order_cpy = *order;
order_cpy.price = price;
if (order_cpy.quantity != qty) {
order_cpy.quantity = qty;
order_cpy.open_quantity = qty;
order_cpy.set_price(price.value());
if (order_cpy.quantity() != qty.value()) {
order_cpy.set_quantity(qty.value());
order_cpy.set_open_quantity(qty.value());
}
if (order->side == api::SIDE_BUY) {
if (order->side() == api::SIDE_BUY) {
me->bids.erase(
std::find_if(me->bids.begin(), me->bids.end(), OrderFinder(clordid)));
me->bids.insert(order_cpy);
@@ -72,40 +75,41 @@ void OrderMatcher::update(std::string const &clordid, Price price, Quantity qty,
void OrderMatcher::cancel(std::string const &clordid) {
auto order = get_order(clordid);
bts_assert(order);
if (order->side == api::SIDE_BUY)
if (order->side() == api::SIDE_BUY)
me->bids.erase(
std::find_if(me->bids.begin(), me->bids.end(), OrderFinder(clordid)));
std::find_if(me->bids.begin(), me->bids.end(), OrderFinder(clordid)));
else
me->asks.erase(
std::find_if(me->asks.begin(), me->asks.end(), OrderFinder(clordid)));
std::find_if(me->asks.begin(), me->asks.end(), OrderFinder(clordid)));
}
void OrderMatcher::try_reduce_quantity_at_level(api::Side side,
Price level,
Quantity by_quantity,
std::string const& order_owner)
{
void OrderMatcher::try_reduce_quantity_at_level(
api::Side side, Price level, Quantity by_quantity,
std::string const &order_owner) {
std::pair<OrdersSide::iterator, OrdersSide::iterator> range;
Order k;
k.price = level;
k.set_price(level.value());
if (side == api::SIDE_BUY)
range = me->bids.equal_range(k);
else
range = me->asks.equal_range(k);
std::vector<std::string> orders_to_cancel;
for (auto it = range.first; it != range.second && by_quantity.value();it++) {
if (it->owner == order_owner) {
if (it->open_quantity.value() >= by_quantity.value()) {
it->open_quantity.value() = it->open_quantity.value()- by_quantity.value();
for (auto it = range.first; it != range.second && by_quantity.value();
it++) {
if (it->owner() == order_owner) {
if (it->open_quantity() >= by_quantity.value()) {
auto no_const = const_cast<Order *>(&(*it));
no_const->set_open_quantity(it->open_quantity() -
by_quantity.value());
by_quantity.value() = 0;
} else {
by_quantity.value() -= it->open_quantity();
auto no_const = const_cast<Order *>(&(*it));
no_const->set_open_quantity(0);
}
else {
by_quantity.value() -= it->open_quantity.value();
it->open_quantity.value() = 0;
}
if (it->open_quantity.value() == 0)
orders_to_cancel.push_back(it->clordid);
if (it->open_quantity() == 0)
orders_to_cancel.push_back(it->clordid());
}
}
@@ -121,7 +125,7 @@ void OrderMatcher::match(std::vector<Order> *out) {
auto iBid = me->bids.begin();
auto iAsk = me->asks.begin();
if (iBid->price.value() >= iAsk->price.value()) {
if (iBid->price() >= iAsk->price()) {
Order bid = *iBid;
Order ask = *iAsk;
@@ -134,9 +138,9 @@ void OrderMatcher::match(std::vector<Order> *out) {
me->bids.erase(iBid);
me->asks.erase(iAsk);
if (bid.open_quantity.value())
if (bid.open_quantity())
me->bids.insert(bid);
if (ask.open_quantity.value())
if (ask.open_quantity())
me->asks.insert(ask);
} else
break;
@@ -144,33 +148,45 @@ void OrderMatcher::match(std::vector<Order> *out) {
}
void OrderMatcher::match(Order *bid, Order *ask) {
auto price = ask->price;
auto price = Price(ask->price());
Quantity quantity;
if (bid->open_quantity.value() > ask->open_quantity.value())
quantity = ask->open_quantity;
if (bid->open_quantity() > ask->open_quantity())
quantity = Quantity(ask->open_quantity());
else
quantity = bid->open_quantity;
quantity = Quantity(bid->open_quantity());
me->pending_trades.push_back(Trade {price,quantity});
bid->execute(price, quantity);
ask->execute(price, quantity);
me->pending_trades.push_back(Trade{price, quantity});
execute(bid, price, quantity);
execute(ask, price, quantity);
}
std::vector<OrderMatcher::Trade> OrderMatcher::get_new_trades()
{
std::vector<OrderMatcher::Trade> OrderMatcher::get_new_trades() {
return std::move(me->pending_trades);
}
Book OrderMatcher::get_book() const {
Book result;
for (auto &b : me->bids)
result.bids[b.price].value() += b.open_quantity.value();
result.bids[Price(b.price())].value() += b.open_quantity();
for (auto &a : me->asks)
result.asks[a.price].value() += a.open_quantity.value();
result.asks[Price(a.price())].value() += a.open_quantity();
return result;
}
}
OrderBook OrderMatcher::get_order_book(std::string const&exclude_owner) const
{
OrderBook result;
for (auto &b : me->bids)
if (b.owner() != exclude_owner)
*result.add_bids() = b;
for (auto &a : me->asks)
if (a.owner() != exclude_owner)
*result.add_asks() = a;
return result;
}
}
}
@@ -5,6 +5,7 @@
#include "server/sparkd/orderman/orderman_utils/orderman_common.h"
#include "server/sparkd/exchange_sim/book/Book.h"
#include "server/sparkd/exchange_sim/book/Order.h"
#include "server/sparkd/exchange_sim/book/ExchangeSim.pb.h"
#include <memory>
#include <set>
@@ -16,6 +17,7 @@ class OrderMatcher {
public:
OrderMatcher();
~OrderMatcher();
void add(Order const &, std::vector<Order> *out);
void update(std::string const &clorid, Price, Quantity,
std::vector<Order> *out);
@@ -26,7 +28,8 @@ class OrderMatcher {
Quantity by_quantity,
std::string const& order_owner);
Book get_book() const;
OrderBook get_order_book(std::string const&exclude_owner) const;
Order const *get_order(std::string const &clorid);
using OrdersSide = std::multiset<Order, OrderCmp>;
@@ -36,12 +39,14 @@ class OrderMatcher {
Quantity quantity;
};
std::vector<Trade> get_new_trades();
private:
struct PImpl;
std::unique_ptr<PImpl> me;
void match(std::vector<Order> *out);
void match(Order *bid, Order *ask);
};
}
}