This commit is contained in:
Pedro Pinto committed 2017-09-19 15:45:45 -04:00
1 parent ef1e4e9481
commit 8975a4ee53
18 files changed
+1756 -1865

No files matched your search

+1 -1
View File
@@ -1,2 +1,2 @@
# generated by make process
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/ApiUnitTestService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.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/Account.conf;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Symbols.conf;config/defaults/User.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/logging.conf;config/defaults/testkeys.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/Account.proto;config/protos/Executor.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Securities.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/User.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.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/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Structure/FixedSecurity.cpp;md/Structure/PriceSize.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;order_man/protos/OrderMan.proto;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;security_model/SecurityHelper.cpp;security_model/old_security.proto;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/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/ApiUnitTestService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.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/Account.conf;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Symbols.conf;config/defaults/User.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/logging.conf;config/defaults/testkeys.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/Account.proto;config/protos/Executor.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Securities.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/User.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.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/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Structure/FixedSecurity.cpp;md/Structure/PriceSize.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;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;security_model/SecurityHelper.cpp;security_model/old_security.proto;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/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp)
+6 -4
View File
@@ -48,13 +48,14 @@ unique_ptr<MDRecoverableConsumer::MDConsumerGroup> MDRecoverableConsumer::init(s
return result;
}
size_t MDRecoverableConsumer::walk_security_list(OldSecurityCallback callback) {
size_t MDRecoverableConsumer::walk_security_list(SecurityCallback callback) {
return _current->consumer.walk_security_list(callback);
}
void MDRecoverableConsumer::on_security(OldSecurityCallback cb) {
void MDRecoverableConsumer::on_security(SecurityCallback cb) {
// Add a filter to the callback to avoid calling the on_security callback with duplicates
auto filtered_cb = [this,cb](const OldSecurity& security, MDConsumerHandle handle) {
auto key = security.security_key();
auto filtered_cb = [this,cb](const Security& security, MDConsumerHandle handle) {
auto key = security.id();
if (_seen.find(key) == _seen.end()) {
_seen.insert(key);
cb(security, handle);
@@ -153,3 +154,4 @@ set<UserSymbol> get_symbols(Exchange::type exchange) {
}}//namespace
#endif
+3 -3
View File
@@ -23,8 +23,8 @@ public:
//
// Security functions
size_t walk_security_list(md2::OldSecurityCallback callback);
void on_security(md2::OldSecurityCallback cb);
size_t walk_security_list(md2::SecurityCallback callback);
void on_security(md2::SecurityCallback cb);
// Scans for added securities - updates managed handles
size_t scan_securities();
@@ -53,7 +53,7 @@ private:
std::unique_ptr<MDConsumerGroup> _current;
std::vector<std::unique_ptr<MDConsumerGroup>> _old;
std::vector<md2::OldSecurityCallback> _callbacks;
std::vector<md2::SecurityCallback> _callbacks;
std::set<security_key> _seen;
typedef tbb::mutex Mutex;
Mutex _lock;
+1498 -1498
View File
File diff suppressed because it is too large. Load diff
-7
View File
@@ -1,7 +0,0 @@
syntax='proto3' ;
package bts.orderman ;
message B{}
message C{}
+1 -1
View File
@@ -1,2 +1,2 @@
# generated by make process
set(sources ;fabric/Actor.cpp;fabric/Domain.cpp;fabric/Executor.cpp;fabric/IActor.cpp;fabric/IDomain.cpp;fabric/TopicDirectory.cpp;fabric/tests/baseline_perf_fabric_test.cpp;fabric/tests/fabric_test.cpp;grid/Node.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/store_tests.cpp;main.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;order_man/IFIXGateway.cpp;order_man/IOrderObserver.cpp;order_man/OldOrderMan.cpp;order_man/OrderMan.cpp;order_man/OrderState.cpp;order_man/OrderStore.cpp;order_man/WorkingOrder.cpp;order_man/fix_order_codec.cpp;order_man/order_man_common.cpp;order_man/order_man_utils.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/tests/PersistenceServiceTests.cpp;risk_limits/IRiskLimitObserver.cpp;risk_limits/RiskLimitManager.cpp;risk_limits/RiskLimiter.cpp;setup/BootstrapActor.cpp;setup/ServiceHostActor.cpp;spreader/SimpleSpreader.cpp;spreader/SpreaderBase.cpp;testing/catch_test_runner.cpp;user/UserServiceServer.cpp)
set(sources ;fabric/Actor.cpp;fabric/Domain.cpp;fabric/Executor.cpp;fabric/IActor.cpp;fabric/IDomain.cpp;fabric/TopicDirectory.cpp;fabric/tests/baseline_perf_fabric_test.cpp;fabric/tests/fabric_test.cpp;grid/Node.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/store_tests.cpp;main.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;order_man/IFIXGateway.cpp;order_man/IOrderObserver.cpp;order_man/OldOrderMan.cpp;order_man/OrderMan.cpp;order_man/OrderState.cpp;order_man/OrderStore.cpp;order_man/WorkingOrder.cpp;order_man/components/MDSource.cpp;order_man/components/SecuritySource.cpp;order_man/fix_order_codec.cpp;order_man/order_man_common.cpp;order_man/order_man_utils.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/tests/PersistenceServiceTests.cpp;risk_limits/IRiskLimitObserver.cpp;risk_limits/RiskLimitManager.cpp;risk_limits/RiskLimiter.cpp;setup/BootstrapActor.cpp;setup/ServiceHostActor.cpp;spreader/SimpleSpreader.cpp;spreader/SpreaderBase.cpp;testing/catch_test_runner.cpp;user/UserServiceServer.cpp)
+17
View File
@@ -10,11 +10,28 @@
#include "testing/catch_test_runner.h"
#include <boost/container/small_vector.hpp>
#include "lib/md/MDConsumerHandle.h"
namespace bts {
namespace api {class Security;}
struct NewSecurities
{
boost::container::small_vector<std::tuple<const api::Security*,md2::MDConsumerHandle>,1> value;
};
}
int main( int argc, char*argv [] )
{
using namespace bts;
os::set_thread_name("main");
std::cout <<sizeof(NewSecurities) << std::endl;
std::cout <<sizeof(md2::MDConsumerHandle) << std::endl;
return 1;
if (argc > 1 && std::string(argv[1]) == "test")
bts::run_tests(--argc, ++argv);
else {
+14 -183
View File
@@ -1,189 +1,20 @@
// #include "OrderMan.h"
#include "OrderMan.h"
#include "server/sparkd/grid/Node.h"
#include "events/NewSecurities.h"
// namespace bts {
// namespace orderman {
namespace bts {
namespace orderman {
// OrderMan::OrderMan(IOrderManObserver &o,
// IFIXGateway &gw,
// OrderKeyGenerator const &key_gen) :
// state_(State::IN_RECOVERY),
// observer_(o),
// fix_gw_(gw),
// orders_(),
// key_gen_(key_gen),
// keys_left_(0),
// next_key_(),
// outgoing_fix_msgs_(),
// time_observers_()
// {
// gen_key();
// }
// OrderMan::~OrderMan() {}
// void OrderMan::on_end_recovery()
// {
// bts_assert(state_ == State::IN_RECOVERY);
// transition(State::DISCONNECTED);
// }
// void OrderMan::send_pending_messages()
// {
// if (outgoing_fix_msgs_->first_stream().n_msgs()) {
// if (state_ == State::READY) {
// outgoing_fix_msgs_->first_stream().close();
// fix_gw_.send(outgoing_fix_msgs_);
// }
// outgoing_fix_msgs_ = fix_gw_.make_outfix_buffer();
// }
// }
// void OrderMan::on_venue_ready() {
// bts_assert(state_ == State::DISCONNECTED);
// transition(State::READY);
// }
// void OrderMan::on_venue_disconnect() {
// bts_assert(state_ == State::READY);
// transition(State::DISCONNECTED);
// }
// void OrderMan::on_begin_replay()
// {
// bts_assert(state_ == State::DISCONNECTED);
// transition(State::REPLAYING);
// }
// void OrderMan::on_end_replay()
// {
// bts_assert(state_ == State::REPLAYING);
// transition(State::DISCONNECTED);
// }
// void OrderMan::on_exe_report(api::Security const &sec,
// OrderKey order_key,
// jetfix::fix::ExecutionReportMsg const&exe_report)
// {
// using namespace jetfix;
// LOG(OrderMan,Info,
// "Received execution report {} for order {} on {}",
// exe_report.get<fix::ExecID>(),
// order_key.value(),
// fix_gw_.name());
// auto it =orders_.find(order_key);
// bool is_new_order = it == orders_.end();
// // is this an order we know about?
// if (is_new_order) {
// // we have never seen this order so we must have crashed
// // before we could persist it. see if we can recover the
// // order from the execution report
// if (exe_report.get<fix::OrdType>() == api::orderman::OT_LIMIT &&
// (exe_report.get<fix::ExecType>() == api::orderman::ET_NEW ||
// exe_report.get<fix::ExecType>() == api::orderman::ET_REJECTED)) {
// // recoverable
// LOG(OrderMan,Error,
// "Received execution report for unknown limit order {} on {}. "
// "This should be investigated."
// " Will try to recreate the order from the execution report",
// order_key.value(),fix_gw_.name());
// it = orders_.emplace(order_key,
// std::unique_ptr<Order>
// (new LimitOrder(order_key,*this,exe_report))).first;
// }
// else {
// // unrecoverable
// LOG(OrderMan,Error,
// "Received execution report for unknown order {} on {}. "
// "Will not be able to recover "
// "order state. This should never happen. Please investigate",
// order_key.value(),fix_gw_.name());
// return;
// }
// }
// it->second->on_exe_report(exe_report);
// observer_.on_order_change(*(it->second));
// if (exe_report.get<fix::ExecType> () == api::orderman::ET_FILL ||
// exe_report.get<fix::ExecType> () == api::orderman::ET_PARTIAL_FILL) {
// OrderFill fill;
// extract_fill(sec,exe_report,&fill);
// observer_.on_fill(*(it->second),fill);
// }
// }
// void OrderMan::on_cancel_reject(api::Security const&,
// OrderKey order_key,
// jetfix::fix::CancelRejectMsg const&msg)
// {
// using namespace jetfix;
// LOG(OrderMan,Error, "Received cancel reject {} for order {} on {}",
// msg.get<fix::ExecID>(),
// order_key.value(),fix_gw_.name());
// auto it = orders_.find(order_key);
// if (it == orders_.end()) {
// LOG(OrderMan,Error,
// "Received cancel rejection for unknown order {} on {}. "
// " This should never happen. Please investigate",
// order_key.value(),fix_gw_.name());
// return;
// }
// else {
// it->second->on_cancel_reject(msg);
// observer_.on_order_change(*(it->second));
// }
// }
struct OrderMan::PImpl
{
PImpl(OnOrderState const&s,OnFill const&f) : on_state(s), on_fills(f) {}
OnOrderState on_state;
OnFill on_fills;
// void OrderMan::on_time( const OrderManTime&t)
// {
// for (auto &o : time_observers_)
// o(t);
// }
};
// OrderKey OrderMan::gen_key()
// {
// const auto KEY_BATCH_SIZE = 1000;
OrderMan::OrderMan(OnOrderState const&s,OnFill const&f) : me (new PImpl(s,f)) {}
OrderMan::~OrderMan () {}
// if (keys_left_ == 0) {
// keys_left_ = KEY_BATCH_SIZE - 1;
// next_key_ = key_gen_(KEY_BATCH_SIZE);
// }
// auto result = next_key_;
// keys_left_--;
// next_key_ = OrderKey(next_key_.value()+1);
// return result;
// }
// const char* OrderMan::state_name(State state)
// {
// switch (state) {
// case State::IN_RECOVERY:
// return "IN_RECOVERY";
// case State::DISCONNECTED:
// return "DISCONNECTED";
// case State::REPLAYING:
// return "REPLAYING";
// case State::READY:
// return "READY";
// }
// }
// void OrderMan::transition(State new_state) {
// LOG(OrderMan,Info, "Order man for {} transitioning from {} to {}",
// fix_gw_.name(),state_name(state_),state_name(new_state));
// state_ = new_state;
// }
// }}
}}
+18 -167
View File
@@ -1,186 +1,37 @@
#pragma once
#include <memory>
#include "lib/api/services/OrderService.pb.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
#include "server/sparkd/jetfix/codec/MessageDefinitions.h"
#include "server/sparkd/jetfix/common/OutFIX.h"
#include "order_man_common.h"
#include "IFIXGateway.h"
#include "fix_order_codec.h"
#include <boost/container/flat_map.hpp>
namespace bts {
namespace api {
namespace orderman {
class OrderState;
class Fill;
class CreateOrderRequest;
class UpdateOrderRequest;
class CancelOrderRequest;
}}
class OrderManTime;
class IMDSource;
class OrderFill {};
using TimeObserver = std::function<void(OrderManTime const&)>;
class Order {
public:
virtual void on_exe_report(jetfix::fix::ExecutionReportMsg const&) {}
virtual void on_cancel_reject(jetfix::fix::CancelRejectMsg const&) {}
};
class IOrderManObserver {
public:
virtual void on_order_change(Order const &order) = 0;
virtual void on_fill(Order const&order, OrderFill const &rf) = 0;
};
class IFIXGateway;
class CreateOrder;
class UpdateOrder;
class CancelOrder;
class OrderMan;
class LimitOrder : public Order{
public:
LimitOrder(OrderKey, OrderMan &,jetfix::fix::ExecutionReportMsg const&);
};
namespace orderman {
class OrderMan
{
public:
struct Result {api::orderman::OrderError error;OrderKey key;};
OrderMan(IOrderManObserver &o,
IFIXGateway &gw, OrderKeyGenerator const &key_gen) ;
using OnOrderState = std::function<void(api::orderman::OrderState const&)>;
using OnFill = std::function<void(api::orderman::Fill const&f)>;
OrderMan(OnOrderState const&,OnFill const&);
~OrderMan();
template <class OrderType>
Result create(typename OrderType::Create const &create_arg)
{
if (state_!= State::READY) {
LOG(OrderMan,Info, "Cannot create order because venue {} is not ready", fix_gw_.name());
return Result {api::orderman::OE_VENUE_NOT_READY,OrderKey(0)};
}
auto k = gen_key();
auto order_ptr = new OrderType (k,*this,create_arg);
auto &order_slot = orders_[k];
bts_assert(!order_slot);
order_slot = std::unique_ptr<Order>(order_ptr);
return {api::orderman::OE_OK,k};
}
template <class OrderType>
Result update(OrderKey k, typename OrderType::Update const& update_arg)
{
if (state_!= State::READY) {
LOG(OrderMan,Info, "Cannot update order {} because venue {} is not ready", k.value(),fix_gw_.name());
return Result {api::orderman::OE_VENUE_NOT_READY,k};
}
auto it = orders_.find(k);
if (it == orders_.end()) {
LOG(OrderMan,Error,
"Cannot update order: {} on venue {} because no such order exists",
k.value(),fix_gw_.name());
return Result {api::orderman::OE_UNKNOWN_ORDER,k};
}
auto abstract_order_ptr = it->second.get();
auto concrete_order_ptr = dynamic_cast<OrderType*> (abstract_order_ptr);
if (!concrete_order_ptr) {
LOG(OrderMan,Error,
"Cannot update order: {} on venue {} because its type does not match the requested type. "
"This is a serious problem. Contact development immediately",
k.value(),fix_gw_.name());
return Result {api::orderman::OE_ORDER_TYPE_MISMATCH,k};
}
concrete_order_ptr->update(update_arg);
return Result {api::orderman::OE_OK,k};
}
template <class OrderType>
Result cancel(OrderKey k, typename OrderType::Cancel const& cancel_arg)
{
if (state_!= State::READY) {
LOG(OrderMan,Info, "Cannot cancel order {} because venue {} is not ready", k.value(),fix_gw_.name());
return Result {api::orderman::OE_VENUE_NOT_READY,k};
}
auto it = orders_.find(k);
if (it == orders_.end()) {
LOG(OrderMan,Error,
"Cannot cancel order: {} on venue {} because no such order exists",
k.value(),fix_gw_.name());
return Result {api::orderman::OE_UNKNOWN_ORDER,k};
}
auto abstract_order_ptr = it->second.get();
auto concrete_order_ptr = dynamic_cast<OrderType*> (abstract_order_ptr);
if (!concrete_order_ptr) {
LOG(OrderMan,Error,
"Cannot cancel order: {} on venue {} because its type does not match the requested type. "
"This is a serious problem. Contact development immediately",
k.value(),fix_gw_.name());
return Result {api::orderman::OE_ORDER_TYPE_MISMATCH,k};
}
concrete_order_ptr->cancel(cancel_arg);
return Result {api::orderman::OE_OK,k};
}
template <class OrderType>
Result recover(OrderKey k,typename OrderType::State const&recovered_state)
{
bts_assert(state_ == State::IN_RECOVERY);
auto order_ptr = new OrderType (k,*this,recovered_state);
auto &order_slot = orders_[k];
bts_assert(!order_slot);
order_slot = std::unique_ptr<Order>(order_ptr);
return {api::orderman::OE_OK,k};
}
void on_end_recovery();
void send_pending_messages();
void on_venue_ready();
void on_venue_disconnect();
void on_begin_replay();
void on_end_replay();
void on_exe_report(api::Security const &sec, OrderKey order_key,
jetfix::fix::ExecutionReportMsg const&exe_report);
void on_cancel_reject(api::Security const&, OrderKey order_key,
jetfix::fix::CancelRejectMsg const&msg);
void on_time( const OrderManTime&t);
void start();
void create_order(OrderKey key,api::orderman::CreateOrderRequest const&r);
void update_order(api::orderman::UpdateOrderRequest const&r);
void cancel_order(api::orderman::CancelOrderRequest const&r);
private:
enum class State {IN_RECOVERY,DISCONNECTED, REPLAYING, READY };
using OrderMap = boost::container::flat_map<OrderKey,std::unique_ptr<Order>> ;
OrderKey gen_key();
const char* state_name(State state);
void transition(State new_state) ;
State state_;
// IMDSource &md_src_;
IOrderManObserver &observer_;
IFIXGateway &fix_gw_;
OrderMap orders_;
OrderKeyGenerator key_gen_;
size_t keys_left_;
OrderKey next_key_;
jetfix::OutFIXPtr outgoing_fix_msgs_;
std::vector<TimeObserver> time_observers_;
struct PImpl;
std::unique_ptr<PImpl> me;
};
}}
@@ -0,0 +1,18 @@
#pragma once
#include <memory>
namespace bts {
namespace orderman {
class OrderManSetup
{
public:
OrderManSetup();
~OrderManSetup();
private:
struct PImpl;
std::unique_ptr<PImpl> me;
};
}}
@@ -0,0 +1 @@
#include "MDSource.h"
@@ -0,0 +1,47 @@
#pragma once
#include "server/sparkd/order_man/events/NewSecurities.h"
#include "server/sparkd/order_man/events/BookUpdate.h"
#include "lib/utils/TimeStamp.h"
#include "lib/md/MDConsumerHandle.h"
namespace bts {
namespace orderman {
class MDSource
{
public:
using OnBook = std::function<void(event::BookUpdate const&)>;
MDSource(OnBook const&cb) : _on_book(cb), _handles() {}
void on(event::NewSecurities const&secs)
{
for (auto const &s : secs.value)
_handles.push_back({utils::TimeStamp(),s.handle});
}
void poll_md() {
event::BookUpdate book;
for (auto &h : _handles)
if (h.handle->get_depth(h.last,
std::tuple_size<event::BookSide>(),
&book.bid()[0],
&book.ask()[0]) == md2::HandleReadResult::SUCCESS) {
book.security_key = SecurityKey(h.handle->key());
_on_book(book);
}
}
private:
OnBook _on_book;
struct HandleRecord {
utils::TimeStamp last;
md2::MDConsumerHandle* handle;
};
std::vector<HandleRecord> _handles;
};
}}
@@ -0,0 +1,52 @@
#include "SecuritySource.h"
#include "lib/domain_model/common.h"
#include "lib/md/MDRecoverableConsumer.h"
#include "lib/utils/bts_assert.h"
#include "server/sparkd/order_man/events/NewSecurities.h"
#include "server/sparkd/order_man/order_man_utils.h"
#include <map>
namespace bts {
namespace orderman {
struct SecuritySource::PImpl
{
PImpl(OnSecurities const&cb)
: on_securities(cb),md_consumer(),known_securities(),pending_event(),
keep_alive()
{}
OnSecurities on_securities;
md::MDRecoverableConsumer md_consumer;
std::map<SecurityKey,std::unique_ptr<api::Security>> known_securities;
event::NewSecurities pending_event;
std::vector<std::shared_ptr<md2::MDConsumerHandle>> keep_alive;
};
SecuritySource::SecuritySource (OnSecurities const&cb) : me (new PImpl(cb))
{
me->md_consumer.on_security ([this] (api::Security const &sec, md2::MDConsumerHandle ) {
auto &ptr = me->known_securities[SecurityKey(sec.id())];
bts_assert(!ptr);
ptr = std::make_unique<api::Security>(sec);
auto handle = me->md_consumer.get_managed_handle(sec.id());
me->keep_alive.push_back(handle);
me->pending_event.value.push_back({ptr.get(),handle.get()});
});
}
void SecuritySource::discover()
{
me->md_consumer.scan_securities ();
if (me->pending_event.value.size()) {
me->on_securities(me->pending_event);
me->pending_event.value.clear();
}
}
SecuritySource::~SecuritySource () {}
}}
@@ -0,0 +1,23 @@
#pragma once
#include <memory>
namespace bts {
namespace orderman {
namespace event {class NewSecurities;}
class SecuritySource
{
public:
using OnSecurities = std::function<void(event::NewSecurities const&)>;
SecuritySource(OnSecurities const&cb);
void discover();
~SecuritySource();
private:
struct PImpl;
std::unique_ptr<PImpl> me;
};
}}
@@ -0,0 +1,30 @@
#pragma once
#include <memory>
#include "lib/domain_model/common.h"
#include "lib/config/protos/MarketData.pb.h"
#include "lib/md/Structure/PriceSize.h"
namespace bts {
namespace orderman {
namespace event {
using BookSide = std::array<md2::PriceSize,5> ;
class BookUpdate {
public:
SecurityKey security_key;
BookSide &bid () {return _book[0];}
BookSide &ask () {return _book[1];}
BookSide& get_side(api::BuySell bs)
{
bts_assert_d(bs != api::UNDEFINED);
return _book[bs - api::BUY];
}
private:
std::array<BookSide,2> _book;
};
}}}
@@ -0,0 +1,23 @@
#pragma once
#include <vector>
namespace bts {
namespace api {class Security;}
namespace md2 {class MDConsumerHandle;}
namespace orderman {
namespace event {
class NewSecurities
{
public:
struct SecRec {
api::Security const* sec;
md2::MDConsumerHandle* handle;
};
std::vector<SecRec> value;
};
}}}
@@ -8,6 +8,7 @@
#include "lib/domain_model/common.h"
namespace bts {
namespace api {class Security;}
namespace orderman {
using OrderKey = utils::ValueWrapper<struct OrderKeyTag,uint32_t>;
using FIXSessionName = utils::ValueWrapper<struct FIXSessionNameTag,std::string>;
@@ -15,6 +16,6 @@ using OperatorID = utils::ValueWrapper<struct OperatorIDTag,std::string>;
using ExchangeOrderID = utils::ValueWrapper<struct ExchangeOrderIDTag,std::string>;
using OrderTimeStamp = std::array<char, sizeof("20121204-14:44:02.000")-1> ;
using SymbolName = utils::ValueWrapper<struct SymbolNameTag, std::string>;
using SecurityPtr = const api::Security *;
}}
+2
View File
@@ -7,3 +7,5 @@ cd $ROOT
# external includes
find externals/linux/include/ -name "*.h" -or -name "*.hpp" | sed s/externals\\/linux\\/include\\///
# stdlib includes
find /usr/include/c++/6 -maxdepth 1 | sed s/\\/usr\\/include\\/c\+\+\\/6\\///