From 3581d058834b8143cee0e5cf3d7a091bdb82041f Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 27 Aug 2018 15:03:54 -0400 Subject: [PATCH 1/8] Add baseline benchmark for PriceSize --- src/lib/os/os.cpp | 13 +++++++++ src/lib/os/os.h | 1 + src/server/sparkd/cmds/Benchmark.cpp | 41 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/src/lib/os/os.cpp b/src/lib/os/os.cpp index a9dc9c1ec..f7f087633 100755 --- a/src/lib/os/os.cpp +++ b/src/lib/os/os.cpp @@ -975,6 +975,19 @@ BTS_EXPORT bool is_finite(double d) { #endif } +int cache_size_l3_bytes() { + // note: index1,2 are the L1 and L2 caches + std::fstream stream( "/sys/devices/system/cpu/cpu0/cache/index3/size", std::ios_base::in); + if (stream) { + int sz; + stream >> sz; + return sz * 1024; + } + else { + return -1; + } +} + // // Interop functions // diff --git a/src/lib/os/os.h b/src/lib/os/os.h index 1d1e4814e..5cfcbd910 100755 --- a/src/lib/os/os.h +++ b/src/lib/os/os.h @@ -85,6 +85,7 @@ inline bool is_nan(float f) { return std::isnan(f); } inline double nan () { return std::numeric_limits::quiet_NaN(); } BTS_EXPORT float fnan (); BTS_EXPORT bool is_finite(double d); +int cache_size_l3_bytes(); }} #endif diff --git a/src/server/sparkd/cmds/Benchmark.cpp b/src/server/sparkd/cmds/Benchmark.cpp index 4d2f1c0e7..bb4aeba0e 100644 --- a/src/server/sparkd/cmds/Benchmark.cpp +++ b/src/server/sparkd/cmds/Benchmark.cpp @@ -8,6 +8,8 @@ #include "lib/jetfix/jetfix.h" #include "lib/mercury/broker/CoreEventBroker.h" #include "lib/mercury/mercury_utils/FatWrapper.h" +#include "lib/os/os.h" +#include "lib/md/PriceSize.h" #include #include @@ -682,6 +684,45 @@ static void small_vec(benchmark::State &state) { } BENCHMARK(small_vec); + +static void price_size(benchmark::State& state) { + using namespace std; + // Randomize the access patterns a bit to attempt to fool the prefetch + // With a single vector the average assignment is 1.5ns, with this ordering it's ~100ns + vector>>> src; + vector>> dest; + size_t sz_mb = state.range(0) * (1024*1024); + size_t sz = sz_mb / 64; + src.resize(8); + dest.resize(8); + for (size_t x = 0; x < 8; ++x) { + src[x].resize(8); + dest[x].resize(8); + for (size_t y = 0; y < 8; ++y) { + src[x][y].resize(sz); + dest[x][y].resize(sz); + for (size_t z = 0; z < sz; ++z) { + src[x][y][z] = make_unique(); + src[x][y][z]->store(md::PriceSize::from_double<9>(z * 1024, x+y)); + } + } + } + + for (auto _ : state) { + for (size_t x = 0; x < 8; ++x) { + for (size_t y = 0; y < 8; ++y) { + for (size_t z = 0; z < sz; ++z) { + auto ps = src[x][y][z]->load(); + dest[x][y][z] = ps; + benchmark::DoNotOptimize(ps); + } + } + } + } +} +// specify range in megabytes from 4 to double cache size +BENCHMARK(price_size)->Range(4, (os::cache_size_l3_bytes()*2) / (1024*1024)); + std::string Benchmark::help() { return "Run micro-benchmarks. Use --benchmark_filter=regex to run only " "specific benchmarks."; From 1ca250ccb1e82e4a3616a377a900e5d1c9a470c6 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Wed, 29 Aug 2018 17:18:13 -0400 Subject: [PATCH 2/8] SPARK-1574 PriceSize Needs to be bigger (native) --- src/client/spark_test/Co2/Co2Tests.cs | 8 - src/lib/CMakeDeps.cmake | 2 +- src/lib/md/Diag/ShmDumper.cpp | 17 +-- src/lib/md/MDConsumer.cpp | 8 +- src/lib/md/MDConsumer.h | 1 - src/lib/md/MDConsumerHandle.cpp | 37 +---- src/lib/md/MDConsumerHandle.h | 1 - src/lib/md/MDProducer.cpp | 2 +- src/lib/md/MDProducerHandle.cpp | 23 +-- src/lib/md/MDProducerHandle.h | 4 +- src/lib/md/PriceSize.cpp | 2 +- src/lib/md/PriceSize.h | 143 +++++++++++------- src/lib/md/Shm/MDStructure.h | 84 +++++----- src/lib/md/protos/co2.proto | 3 +- src/lib/md/relay/QueryServer.cpp | 10 -- src/lib/md/relay/RelayClient.cpp | 3 - src/lib/md/test/Co2ManagedTestHelper.cpp | 17 +-- src/lib/md/test/md2_tests.cpp | 76 ++++++---- .../md/test/synthetic_book_merge_tests.cpp | 2 +- src/lib/utils/Optimistic.h | 47 ++++++ src/server/sparkd/cmds/Benchmark.cpp | 39 ----- 21 files changed, 264 insertions(+), 265 deletions(-) create mode 100644 src/lib/utils/Optimistic.h diff --git a/src/client/spark_test/Co2/Co2Tests.cs b/src/client/spark_test/Co2/Co2Tests.cs index 24b411f3f..2d76d9427 100644 --- a/src/client/spark_test/Co2/Co2Tests.cs +++ b/src/client/spark_test/Co2/Co2Tests.cs @@ -112,14 +112,6 @@ namespace mbts.co2.tests Assert.IsTrue(last.size == 101); Assert.IsTrue(entry.total_volume == 12345); Assert.IsTrue(compare_date(entry.last_trade_time, DateTime.Now)); - //// Customer bo - Assert.IsTrue(entry.customer_bbo_updated > 0); - var cask = entry.customer_ask.load(); - Assert.IsTrue(cask.price == 2.2); - Assert.IsTrue(cask.size == 202); - var cbid = entry.customer_bid.load(); - Assert.IsTrue(cbid.price == 1.1); - Assert.IsTrue(cbid.size == 101); //// Settlement Assert.AreEqual(entry.settlement_price, 3.3); Assert.IsTrue(entry.settlement_date == new DateTime(2015, 9, 3)); diff --git a/src/lib/CMakeDeps.cmake b/src/lib/CMakeDeps.cmake index 546b9e2e9..739e47c0c 100644 --- a/src/lib/CMakeDeps.cmake +++ b/src/lib/CMakeDeps.cmake @@ -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/services/AdminService.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/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.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/cpp_config.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orders_fills_cleanup.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/cpp_config.proto;config/protos/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/orders_fills_cleanup.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;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;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/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;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/catch_test_runner.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.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) \ No newline at end of file +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/services/AdminService.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/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.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/cpp_config.conf;config/defaults/dynamic_orders.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orders_fills_cleanup.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/cpp_config.proto;config/protos/dynamic_orders.proto;config/protos/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/orders_fills_cleanup.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;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;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/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;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/catch_test_runner.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.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) \ No newline at end of file diff --git a/src/lib/md/Diag/ShmDumper.cpp b/src/lib/md/Diag/ShmDumper.cpp index 45bf596ee..156feda4e 100644 --- a/src/lib/md/Diag/ShmDumper.cpp +++ b/src/lib/md/Diag/ShmDumper.cpp @@ -36,8 +36,8 @@ string dump(PriceSize ps) { return res.str(); } -string dump(const SingleWriterPriceSizeStore& pss) { - return dump(pss.load()); +string dump(const AtomicPriceSize& pss) { + return dump(std::get(pss.load())); } string dump_header(const ColdHeader& header) { @@ -55,7 +55,6 @@ string dump_header(const ColdHeader& header) { res << "'exchange_status_count': " << header.exchange_status_count << ", "; res << "'rfq_count': " << header.rfq_count << ", "; res << "'gaps':" << header.gap_count << ", "; - // res << "'customer_bbo_count': " << header.customer_bbo_count; res << "}"; return res.str(); } @@ -137,7 +136,7 @@ string dump(datetime::Date date) { } bool has_value(PriceSize p) { return p.size() > 0; } -bool has_value(const SingleWriterPriceSizeStore& p) { return has_value(p.load()); } +bool has_value(const AtomicPriceSize& p) { return has_value(std::get(p.load())); } string dump_entry(const ColdEntry& entry) { stringstream res; @@ -146,8 +145,6 @@ string dump_entry(const ColdEntry& entry) { if (has_value(entry.last_trade)) res << "'last_trade': " << dump(entry.last_trade) << ", "; if (entry.total_volume > 0) res << "'total_volume': " << entry.total_volume << ", "; if (entry.last_trade_time > 0) res << "'last_trade_time_ll': " << entry.last_trade_time << ", "; - if (has_value(entry.customer_bid)) res << "'customer_bid': " << dump(entry.customer_bid) << ", "; - if (has_value(entry.customer_ask)) res << "'customer_ask': " << dump(entry.customer_ask) << ", "; if (!os::is_nan(entry.misc.settlement_price)) res << "'settlement_price': " << entry.misc.settlement_price << ", "; if (entry.misc.settlement_date.year > 0) res << "'settlement_date': " << dump(entry.misc.settlement_date) << ", "; if (!os::is_nan(entry.misc.previous_settlement_price)) res << "'previous_settlement_price': " << entry.misc.previous_settlement_price << ", "; @@ -165,13 +162,13 @@ string dump_entry(const HotDepthEntry& entry) { res << "'bids': ["; for (uint32_t x = 0; x < COCONUT_MAX_DEPTH; ++x) { - res << dump(entry.bid(x)) << ", "; + res << dump(entry.at(x)->bid()) << ", "; } res << "], "; res << "'asks': ["; for (uint32_t x = 0; x < COCONUT_MAX_DEPTH; ++x) { - res << dump(entry.ask(x)) << ", "; + res << dump(entry.at(x)->ask()) << ", "; } res << "], "; @@ -186,8 +183,8 @@ string dump_entry(const HotEntry& entry) { res << "{ "; res << "'timestamp': " << dump(entry.time()) << ", "; res << "'key': " << entry.key << ", "; - res << "'bid': " << dump(entry.bid) << ", "; - res << "'ask': " << dump(entry.ask) << ", "; + res << "'bid': " << dump(entry.book.bid()) << ", "; + res << "'ask': " << dump(entry.book.ask()) << ", "; res << "'status': '" << CoconutSecurityStatus_Name((CoconutSecurityStatus)entry.status) << "', "; res << "'sequence': '" << entry.sequence << "', "; res << " }"; diff --git a/src/lib/md/MDConsumer.cpp b/src/lib/md/MDConsumer.cpp index bb6839abd..7e3c827c8 100644 --- a/src/lib/md/MDConsumer.cpp +++ b/src/lib/md/MDConsumer.cpp @@ -946,9 +946,6 @@ size_t MDConsumerChannel::trade_count() const { size_t MDConsumerChannel::rfq_count() const { return _pimpl->cold_header().rfq_count; } -size_t MDConsumerChannel::customer_bbo_count() const { - return _pimpl->cold_header().customer_bbo_count; -} size_t MDConsumerChannel::gap_count() const { return _pimpl->cold_header().gap_count; } @@ -959,7 +956,10 @@ bool is_heart_beat_ok(const ColdHeader &header ) { uint32_t s_grace_period_ms = header.heartbeat_boot_seconds * 1000; TimeStamp hb = header.heartbeat; TimeStamp now = TimeStamp::now(); - return s_disable_heartbeat || (now - hb).milliseconds() < s_heartbeat_ms || (now - header.create_time).milliseconds() < s_grace_period_ms; + return (header.version == shm_version) && + (s_disable_heartbeat || + (now - hb).milliseconds() < s_heartbeat_ms || + (now - header.create_time).milliseconds() < s_grace_period_ms); } }}//namespace diff --git a/src/lib/md/MDConsumer.h b/src/lib/md/MDConsumer.h index bdf0453ab..99aa40c7e 100644 --- a/src/lib/md/MDConsumer.h +++ b/src/lib/md/MDConsumer.h @@ -91,7 +91,6 @@ public: size_t depth_count() const; size_t trade_count() const; size_t rfq_count() const; - size_t customer_bbo_count() const; size_t gap_count() const; }; diff --git a/src/lib/md/MDConsumerHandle.cpp b/src/lib/md/MDConsumerHandle.cpp index 317d377ca..a172f1fa3 100644 --- a/src/lib/md/MDConsumerHandle.cpp +++ b/src/lib/md/MDConsumerHandle.cpp @@ -46,8 +46,8 @@ TimeStamp copy_bbo(const HotEntry& hot, PriceSize& out_bid, PriceSize& out_ask) const int max_attempts = 1619200; do { t = hot.time(); - out_bid = hot.bid.load(); - out_ask = hot.ask.load(); + out_bid = hot.book.bid(); + out_ask = hot.book.ask(); ++attempts; } while((t != hot.time() || t == TimeStamp::invalid()) && attempts < max_attempts); if (attempts >= max_attempts) { @@ -67,8 +67,7 @@ TimeStamp copy_depth( do { t = hot.time(); for (size_t x = 0; x < count; ++x) { - bid[x] = hot.bid(x).load(); - ask[x] = hot.ask(x).load(); + hot.read_level(x, &bid[x], &ask[x]); } ++attempts; } while((t != hot.time() || t == TimeStamp::invalid()) && attempts < max_attempts); @@ -215,42 +214,16 @@ TimeStamp MDConsumerHandle::last_market_update() const { never; } -bool MDConsumerHandle::get_customer_bbo(TimeStamp& time, PriceSize& out_bid, PriceSize& out_ask) const { - switch(_type) { - case HANDLETYPE_SYNTHETIC: - case HANDLETYPE_VOID: - return false; - case HANDLETYPE_DEPTH: - case HANDLETYPE_BBO: { - const ColdEntry* pcold = (_type == HANDLETYPE_BBO) ? bbo.cdata : book.cdata; - // This can loop forever if publisher crashes with an invalid time in shm - // good thing nobody uses customer_bbo - bool result = false; - while(pcold->customer_bbo_updated > time || time == TimeStamp::invalid()) { - time = pcold->customer_bbo_updated; - out_bid = pcold->customer_bid.load(); - out_ask = pcold->customer_ask.load(); - result = true; - } - return result; - } - } - never; -} - bool MDConsumerHandle::get_last_trade(TimeStamp& time, PriceSize& trade, datetime::LLDateTime& trade_timestamp, size_t* total_volume) const { switch(_type) { case HANDLETYPE_VOID: return false; case HANDLETYPE_DEPTH: case HANDLETYPE_BBO: { const ColdEntry* pcold = (_type == HANDLETYPE_BBO) ? bbo.cdata : book.cdata; - bool result = false; - while (pcold->last_trade_updated > time) { - time = pcold->last_trade_updated; - trade = pcold->last_trade.load(); + bool result = pcold->last_trade.load_if_new(time, trade); + if (result) { trade_timestamp = pcold->last_trade_time; if (total_volume) { *total_volume = pcold->total_volume; } - result = true; } return result; } diff --git a/src/lib/md/MDConsumerHandle.h b/src/lib/md/MDConsumerHandle.h index 6c360cd55..1f8904f22 100644 --- a/src/lib/md/MDConsumerHandle.h +++ b/src/lib/md/MDConsumerHandle.h @@ -136,7 +136,6 @@ public: bts_assert(false); } - bool get_customer_bbo(TimeStamp& time, PriceSize& out_bid, PriceSize& out_ask) const; bool get_last_trade(TimeStamp& time, PriceSize& out_trade, datetime::LLDateTime& out_trade_timestamp, size_t* total_volume=nullptr) const; TimeStamp misc_timestamp() const; diff --git a/src/lib/md/MDProducer.cpp b/src/lib/md/MDProducer.cpp index e87662222..b519f52d9 100644 --- a/src/lib/md/MDProducer.cpp +++ b/src/lib/md/MDProducer.cpp @@ -29,7 +29,7 @@ public: _cold.header().has_depth = enable_depth(symbol, type); _cold.header().platform = platform; - static_assert(sizeof(HotEntry) <= 32,"HotEntry should be less than 32 bytes"); + // static_assert(sizeof(HotEntry) <= 32,"HotEntry should be less than 32 bytes"); } MDProducerHandle add_security(const FixedSecurity& security) { diff --git a/src/lib/md/MDProducerHandle.cpp b/src/lib/md/MDProducerHandle.cpp index 39ae6578c..7fb5bd5d8 100644 --- a/src/lib/md/MDProducerHandle.cpp +++ b/src/lib/md/MDProducerHandle.cpp @@ -77,10 +77,9 @@ void MDProducerHandle::update_bbo(TimeStamp time, const PriceSize bid, const Pri if (!has_depth()) { auto oldtime = hdata().time(); hdata().set_time(TimeStamp::invalid()); - bool set_bid = hdata().bid.store(bid); - bool set_ask = hdata().ask.store(ask); + bool updated = hdata().book.update(PriceLevel(bid,ask)); hdata().status = COCONUTSECURITYSTATUS_OK; - if (set_bid || set_ask) { + if (updated) { hdata().set_time(time); hdata().sequence = seq; hheader().bbo_count++; @@ -92,10 +91,9 @@ void MDProducerHandle::update_bbo(TimeStamp time, const PriceSize bid, const Pri else { auto oldtime = hdepth().time(); hdepth().set_time(TimeStamp::invalid()); - bool set_bid = hdepth().bid(0).store(bid); - bool set_ask = hdepth().ask(0).store(ask); + bool updated = hdepth().write_level(0, bid,ask); hdepth().status = COCONUTSECURITYSTATUS_OK; - if (set_bid || set_ask) { + if (updated) { hdepth().set_time(time); hdepth().sequence = seq; hheader().bbo_count++; @@ -116,10 +114,9 @@ void MDProducerHandle::set_status(CoconutSecurityStatus status) { } void MDProducerHandle::add_trade(TimeStamp time, const PriceSize price, LLDateTime tradetime, co2::AggressorSide agside, uint32_t volume) { - cdata().last_trade.store(price); + cdata().last_trade.store(price, time); cdata().last_trade_time = tradetime; cdata().total_volume = volume; - cdata().last_trade_updated = time; if (key() != invalid_security_key) { co2::TradeMessage trade; @@ -134,10 +131,9 @@ void MDProducerHandle::add_trade(TimeStamp time, const PriceSize price, LLDateTi } } void MDProducerHandle::set_last_trade(TimeStamp time, const PriceSize ps, datetime::LLDateTime tradetime, uint32_t total_volume) { - cdata().last_trade.store(ps); + cdata().last_trade.store(ps,time); cdata().last_trade_time = tradetime; cdata().total_volume = total_volume; - cdata().last_trade_updated = time; } void MDProducerHandle::add_rfq(TimeStamp, const co2::QuoteRequestMessage& rfq) { @@ -147,13 +143,6 @@ void MDProducerHandle::add_rfq(TimeStamp, const co2::QuoteRequestMessage& rfq) { } } -void MDProducerHandle::update_customer_bbo(TimeStamp time, const PriceSize bid, const PriceSize ask) { - cdata().customer_bid.store(bid); - cdata().customer_ask.store(ask); - cdata().customer_bbo_updated = time; - cheader().customer_bbo_count++; -} - void MDProducerHandle::update_exchange_status(TimeStamp, TradingStatus status) { cdata().exchange_status = status; cheader().exchange_status_count++; diff --git a/src/lib/md/MDProducerHandle.h b/src/lib/md/MDProducerHandle.h index a3c530250..b30af47b0 100644 --- a/src/lib/md/MDProducerHandle.h +++ b/src/lib/md/MDProducerHandle.h @@ -43,8 +43,7 @@ public: auto& book = hdepth(); book.set_time(TimeStamp::invalid()); for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) { - book.bid(x).store(bids[x]); - book.ask(x).store(asks[x]); + book.write_level(x, bids[x], asks[x]); } book.status = co2::COCONUTSECURITYSTATUS_OK; book.sequence = seq; @@ -61,7 +60,6 @@ public: void set_last_trade(TimeStamp time, const PriceSize ps, datetime::LLDateTime date, uint32_t total_volume); void add_rfq(TimeStamp time, const co2::QuoteRequestMessage& rfq); // cold - void update_customer_bbo(TimeStamp time, const PriceSize bid, const PriceSize ask); // cold void update_exchange_status(TimeStamp time, TradingStatus status); // cold // Misc fields diff --git a/src/lib/md/PriceSize.cpp b/src/lib/md/PriceSize.cpp index de6f91a30..490e132b6 100644 --- a/src/lib/md/PriceSize.cpp +++ b/src/lib/md/PriceSize.cpp @@ -4,7 +4,7 @@ namespace bts { namespace md { -BTS_EXPORT PriceSize PriceSize::NO_MARKET = PriceSize(0, -128, 0); +BTS_EXPORT PriceSize PriceSize::NO_MARKET = PriceSize(); int to_exponent(double value) { if (value == 0 && os::is_nan(value)) return 0; diff --git a/src/lib/md/PriceSize.h b/src/lib/md/PriceSize.h index 850b78804..05374b628 100644 --- a/src/lib/md/PriceSize.h +++ b/src/lib/md/PriceSize.h @@ -6,6 +6,7 @@ #include "lib/utils/bts_array_size.h" #include "lib/utils/bts_assert.h" #include "lib/utils/bts_no_copy.h" +#include "lib/utils/Optimistic.h" #include #include @@ -15,10 +16,10 @@ namespace bts { namespace md { typedef double Price; -typedef uint16_t Size; +typedef uint32_t Size; -#define LOAD(x) x.load(std::memory_order_acquire) -#define STORE(x,value) x.store(value, std::memory_order_release) +// #define LOAD(x) x.load(std::memory_order_acquire) +// #define STORE(x,value) x.store(value, std::memory_order_release) static const double powers_10[] = { 1E-20, 1E-19, 1E-18, 1E-17, 1E-16, 1E-15, 1E-14, 1E-13, 1E-12, 1E-11, 1E-10, 1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3, 1E-2, 1E-1, @@ -49,54 +50,28 @@ inline bool compact_mantissa(Mantissa& mantissa, Exponent& exponent) { } class PriceSize { - union { - uint64_t _val64; - // ISO C++ prohibits anonymous structs - GCC_DIAG_OFF("-Wpedantic") - struct { -#ifdef _WIN32 - // VC++ only packs bit fields when the declared type is the same size - int64_t _mantissa : 40; - int64_t _exponent : 8; - uint64_t _size : 16; -#else - int64_t _mantissa : 40; - int8_t _exponent; - uint16_t _size; -#endif - }; - GCC_DIAG_RESTORE() - }; - friend class SingleWriterPriceSizeStore; - PriceSize(uint64_t val) : _val64(val) { } + int64_t _mantissa; + int8_t _exponent; + uint32_t _size; public: - // fast path PriceSize(int64_t mantissa, int8_t exponent, Size size) : _mantissa(mantissa), _exponent(exponent), _size(size) { - // Attempt to guard against too large mantissa - if (compact_mantissa(mantissa, exponent)) { - _mantissa = mantissa; - _exponent = exponent; - } + // bts_assert_d(exponent != 0); } - PriceSize() : _val64(PriceSize::NO_MARKET._val64) { } + PriceSize() : _mantissa(0), _exponent(), _size(0) { } - // quick copy - PriceSize(const PriceSize& other) : _val64(other._val64) { } - PriceSize& operator=(const PriceSize& other) { - _val64 = other._val64; - return *this; - } + PriceSize(const PriceSize& other) = default; + PriceSize& operator=(const PriceSize& other) = default; bool operator==(const PriceSize& other) const { - return _val64 == other._val64; + return (_size == other._size && _mantissa == other._mantissa && _exponent == other._exponent); } bool operator!=(const PriceSize& other) const { - return _val64 != other._val64; + return !(*this == other); } BTS_EXPORT static PriceSize NO_MARKET; @@ -136,35 +111,97 @@ public: } // This call is relatively slow so don't call it often double price() const { - if (_exponent == -128) return NO_PRICE; + if (*this == NO_MARKET) return NO_PRICE; return mantissa() * pow10(exponent()); } Size size() const { return _size; } }; -static_assert(sizeof(PriceSize) == sizeof(uint64_t), "PriceSize must be 64 bits for atomic assignment"); +static_assert(sizeof(PriceSize) == 16, "PriceSize should be small"); -class SingleWriterPriceSizeStore { - std::atomic _store; - BTS_NO_COPY(SingleWriterPriceSizeStore); -public: - SingleWriterPriceSizeStore() : _store() { - store(PriceSize::NO_MARKET); +typedef utils::Optimistic AtomicPriceSize; + +// +// PriceSize has grown to 12 bytes but because of 8 byte alignment it will pad out to 16 bytes +// This structure can store the same data in 24 bytes so it's more efficient for shared memory +struct PriceLevel { + PriceLevel() : + _mantissa_b(0), _exponent_b(0), + _mantissa_a(0), _exponent_a(0), + _size_b(0), _size_a(0) {} + PriceLevel( + int64_t bid_mantissa, + int8_t bid_exponent, + uint32_t bid_size, + int64_t ask_mantissa, + int8_t ask_exponent, + uint32_t ask_size) : + _mantissa_b(bid_mantissa), _exponent_b(bid_exponent), + _mantissa_a(ask_mantissa), _exponent_a(ask_exponent), + _size_b(bid_size), + _size_a(ask_size) + {} + PriceLevel(const PriceSize& bid, const PriceSize& ask): + _mantissa_b(bid.mantissa()), _exponent_b(bid.exponent()), + _mantissa_a(ask.mantissa()), _exponent_a(ask.exponent()), + _size_b(bid.size()), _size_a(ask.size()) + {} + +#ifdef _WIN32 + int64_t _mantissa_b : 54; + int64_t _exponent_b : 8; + int64_t _mantissa_a : 54; + int64_t _exponent_a : 8; +#else + int64_t _mantissa_b : 54; + int8_t _exponent_b : 8; + int64_t _mantissa_a : 54; + int8_t _exponent_a : 8; +#endif + uint32_t _size_b; + uint32_t _size_a; + + uint64_t bid_mantissa() const { return _mantissa_b; } + uint64_t ask_mantissa() const { return _mantissa_a; } + uint8_t bid_exponent() const { return _exponent_b; } + uint8_t ask_exponent() const { return _exponent_a; } + uint32_t bid_size() const { return _size_b; } + uint32_t ask_size() const { return _size_a; } + + bool operator==(const PriceLevel& other) const { + return _size_a == other._size_a && + _size_b == other._size_b && + _mantissa_a == other._mantissa_a && + _mantissa_b == other._mantissa_b && + _exponent_a == other._exponent_a && + _exponent_b == other._exponent_b; } - bool store(PriceSize ps) { - uint64_t cur = LOAD(_store); - if (cur != ps._val64) { - STORE(_store, ps._val64); + bool operator!=(const PriceLevel& other) const { + return _size_a != other._size_a || + _size_b != other._size_b || + _mantissa_a != other._mantissa_a || + _mantissa_b != other._mantissa_b || + _exponent_a != other._exponent_a || + _exponent_b != other._exponent_b; + } + + bool update(const PriceLevel& temp) { + if (*this != temp) { + *this = temp; return true; } return false; } - PriceSize load() const { - uint64_t val = LOAD(_store); - return PriceSize(val); + + PriceSize bid() const { + return PriceSize(_mantissa_b, _exponent_b, _size_b); + } + PriceSize ask() const { + return PriceSize(_mantissa_a, _exponent_a, _size_a); } }; +static_assert(sizeof(PriceLevel) == 24, "PriceLevel should be small"); }}//namespace diff --git a/src/lib/md/Shm/MDStructure.h b/src/lib/md/Shm/MDStructure.h index 9c3187ab5..09166d8ec 100644 --- a/src/lib/md/Shm/MDStructure.h +++ b/src/lib/md/Shm/MDStructure.h @@ -26,6 +26,8 @@ namespace md { using utils::TimeStamp; +const uint32_t shm_version = 100; + struct ALIGNED_(CACHE_LINE) HotHeader { size_t count; size_t segment_count; @@ -35,43 +37,64 @@ struct ALIGNED_(CACHE_LINE) HotHeader { }; // These should not be cache line aligned because they are small enough for multiple to fit on one line easily -struct ALIGNED_(32) HotEntry { - HotEntry() : timestamp(TimeStamp(0)), bid(), ask(), key(invalid_security_key), sequence(0), status(co2::COCONUTSECURITYSTATUS_OK) {} - uint32_t size() const { return sizeof(HotEntry); } - private: +class HotEntry { std::atomic timestamp; // 8 public: - SingleWriterPriceSizeStore bid; // 8 - SingleWriterPriceSizeStore ask; // 8 + HotEntry() : timestamp(TimeStamp(0)), book(), key(invalid_security_key), sequence(0), status(co2::COCONUTSECURITYSTATUS_OK) {} + uint32_t size() const { return sizeof(HotEntry); } + PriceLevel book; // 24 security_key key; // 4 - uint16_t sequence; // 2 + uint16_t sequence; // 4 uint8_t status; // 1 void set_time(const TimeStamp& t) { timestamp.store(t, std::memory_order_release); } TimeStamp time() const { return timestamp.load(std::memory_order_acquire); } }; +static_assert(sizeof(HotEntry) <= CACHE_LINE, "HotEntry should be small"); const uint32_t COCONUT_MAX_DEPTH = 10; -struct ALIGNED_(CACHE_LINE) HotDepthEntry { - HotDepthEntry() : - timestamp(TimeStamp(0)), key(invalid_security_key), status(co2::COCONUTSECURITYSTATUS_OK), book(), sequence(0) - { } - uint32_t size() const { return sizeof(HotDepthEntry); } - private: +class HotDepthEntry { std::atomic timestamp; // 8 public: - security_key key; // NOTE: key is at a different offset than it is in HotEntry - uint8_t status; // 1 - // Interleave bid/ask values so the top of book is always on the first line - SingleWriterPriceSizeStore book[COCONUT_MAX_DEPTH*2]; + HotDepthEntry() : + timestamp(TimeStamp(0)), + key(invalid_security_key), + sequence(0), + status(co2::COCONUTSECURITYSTATUS_OK), + book() + { } + uint32_t size() const { return sizeof(HotDepthEntry); } + security_key key; // 4 NOTE: key is at a different offset than it is in HotEntry uint16_t sequence; // 2 + uint8_t status; // 1 + std::array book; + + const PriceLevel* at(uint32_t depth) const { + if (depth < book.size()) { + return &book[depth]; + } + return nullptr; + } + void read_level(uint32_t depth, PriceSize* bid, PriceSize* ask) const { + if (depth < book.size()) { + *bid = book[depth].bid(); + *ask = book[depth].ask(); + } + } + bool write_level(uint32_t depth, const PriceSize& bid, const PriceSize& ask) { + if (depth < book.size()) { + auto temp = PriceLevel(bid,ask); + if (book[depth] != temp) { + book[depth] = PriceLevel(bid,ask); + return true; + } + } + return false; + } - SingleWriterPriceSizeStore& bid(uint32_t depth) { return book[depth*2]; } - const SingleWriterPriceSizeStore& bid(uint32_t depth) const { return book[depth*2]; } - SingleWriterPriceSizeStore& ask(uint32_t depth) { return book[depth*2+1]; } - const SingleWriterPriceSizeStore& ask(uint32_t depth) const { return book[depth*2+1]; } void set_time(const TimeStamp& t) { timestamp.store(t, std::memory_order_release); } TimeStamp time() const { return timestamp.load(std::memory_order_acquire); } }; +static_assert(sizeof(HotDepthEntry) == 256, "HotDepthEntry should be small"); // // COLD Data, brrr @@ -79,6 +102,7 @@ struct ALIGNED_(CACHE_LINE) HotDepthEntry { struct ALIGNED_(CACHE_LINE) ColdHeader { ColdHeader() : + version(shm_version), count(0), segment_count(0), create_time(TimeStamp::now()), @@ -92,11 +116,10 @@ struct ALIGNED_(CACHE_LINE) ColdHeader { trade_count(0), coconut_status_count(0), exchange_status_count(0), - rfq_count(0), - customer_bbo_count(0) + rfq_count(0) {} - // uint32_t version; + uint32_t version; size_t count; size_t segment_count; TimeStamp create_time; @@ -113,7 +136,6 @@ struct ALIGNED_(CACHE_LINE) ColdHeader { std::atomic coconut_status_count; std::atomic exchange_status_count; std::atomic rfq_count; - std::atomic customer_bbo_count; std::atomic gap_count; // Ring buffer for LastTrade for all securities in this list @@ -186,13 +208,9 @@ struct MiscData { struct ColdEntry { ColdEntry(size_t security_size) : exchange_status(co2::TRADINGSTATUS_UNKNOWN), - last_trade_updated(), last_trade(), total_volume(0), last_trade_time(), - customer_bbo_updated(), - customer_bid(), - customer_ask(), misc(), deleted(false) { @@ -205,16 +223,10 @@ struct ColdEntry { co2::TradingStatus exchange_status; // Last Trade - TimeStamp last_trade_updated; - SingleWriterPriceSizeStore last_trade; + AtomicPriceSize last_trade; size_t total_volume; datetime::LLDateTime last_trade_time; - // Customer BBO - TimeStamp customer_bbo_updated; - SingleWriterPriceSizeStore customer_bid; - SingleWriterPriceSizeStore customer_ask; - MiscData misc; bool deleted; diff --git a/src/lib/md/protos/co2.proto b/src/lib/md/protos/co2.proto index 89d83fa90..febeb7f29 100644 --- a/src/lib/md/protos/co2.proto +++ b/src/lib/md/protos/co2.proto @@ -55,7 +55,7 @@ message MDRequest { LAST_TRADE = 0x4; TRADE_LOG = 0x8; RFQ = 0x10; - CUSTOMER_BBO = 0x20; + // CUSTOMER_BBO = 0x20; MISC = 0x40; } string host = 2; @@ -65,7 +65,6 @@ message ChannelUpdate { uint32 key = 1; bts.api.Security security = 2; BookMessage book = 3; - TopBookMessage customer_bbo = 4; MiscMessage misc = 5; TradeMessage last_trade = 6; } diff --git a/src/lib/md/relay/QueryServer.cpp b/src/lib/md/relay/QueryServer.cpp index c6fe72617..af2e2e0fd 100644 --- a/src/lib/md/relay/QueryServer.cpp +++ b/src/lib/md/relay/QueryServer.cpp @@ -281,15 +281,6 @@ public: set_price(price, trade); } } - if (HASFLAG(flags, MDRequest::CUSTOMER_BBO)) { - TimeStamp time(snapshot ? 0 : chan.time()); - PriceSize bid, ask; - if (handle.get_customer_bbo(time, bid, ask)) { - auto* p = pupd->mutable_customer_bbo(); - convert(bid, p->mutable_bid()); - convert(ask, p->mutable_ask()); - } - } if (HASFLAG(flags, MDRequest::MISC)) { TimeStamp time(snapshot ? 0 : chan.time()); if (handle.misc_timestamp() > time) { @@ -298,7 +289,6 @@ public: } if (pupd->has_book() || pupd->has_last_trade() || - pupd->has_customer_bbo() || pupd->has_misc() || pupd->has_security()) { reply->add_updates()->CopyFrom(*pupd); diff --git a/src/lib/md/relay/RelayClient.cpp b/src/lib/md/relay/RelayClient.cpp index 7cd258631..f3aac8fb3 100644 --- a/src/lib/md/relay/RelayClient.cpp +++ b/src/lib/md/relay/RelayClient.cpp @@ -62,9 +62,6 @@ class RelayProducer : public IRelayWriter { } handle.update_book(updated, bids, asks); } - if (update.has_customer_bbo()) { - handle.update_customer_bbo(updated, convert(update.customer_bbo().bid()), convert(update.customer_bbo().ask())); - } if (update.has_misc()) { auto& misc = update.misc(); handle.update_settlement(updated, misc.settlement_price(), datetime::Date(misc.settlement_date())); diff --git a/src/lib/md/test/Co2ManagedTestHelper.cpp b/src/lib/md/test/Co2ManagedTestHelper.cpp index 022d537af..9267c7b36 100644 --- a/src/lib/md/test/Co2ManagedTestHelper.cpp +++ b/src/lib/md/test/Co2ManagedTestHelper.cpp @@ -29,8 +29,9 @@ extern "C" BTS_EXPORT void co2_get_1234_handle(size_t& size, MDConsumerHandle& extern "C" BTS_EXPORT void co2_get_sample_hot(size_t& size, HotEntry& entry) { size = sizeof(HotEntry); entry.key = 1234; - entry.bid.store(PriceSize::from_double<2>(7.2, 101)); - entry.ask.store(PriceSize::from_double<2>(-9.7, 245)); + entry.book = PriceLevel( + PriceSize::from_double<2>(7.2, 101), + PriceSize::from_double<2>(-9.7, 245)); entry.sequence = 777; entry.status = COCONUTSECURITYSTATUS_PACKET_LOSS; entry.set_time(utils::TimeStamp::now()); @@ -40,8 +41,9 @@ extern "C" BTS_EXPORT void co2_get_sample_depth(size_t& size, HotDepthEntry& ent size = sizeof(HotDepthEntry); entry.key = 1234; for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) { - entry.bid(x).store(PriceSize::from_double<2>(x + 0.5, x + 1)); - entry.ask(x).store(PriceSize::from_double<2>(x + 0.6, x + 2)); + entry.write_level(x, + PriceSize::from_double<2>(x + 0.5, x + 1), + PriceSize::from_double<2>(x + 0.6, x + 2)); } entry.set_time(utils::TimeStamp::now()); entry.status = COCONUTSECURITYSTATUS_PACKET_LOSS; @@ -53,14 +55,9 @@ extern "C" BTS_EXPORT void co2_get_sample_cold(size_t& size, ColdEntry& entry) { entry.exchange_status = TRADINGSTATUS_NORMAL; // Last trade - entry.last_trade_updated = utils::TimeStamp::now(); entry.last_trade.store(PriceSize::from_double<2>(4.2, 101)); entry.total_volume = 12345; entry.last_trade_time = datetime::ll_now(); - // Customer bbo - entry.customer_bbo_updated = utils::TimeStamp::now(); - entry.customer_bid.store(PriceSize::from_double<2>(1.1, 101)); - entry.customer_ask.store(PriceSize::from_double<2>(2.2, 202)); // Settlement entry.misc.settlement_price = 3.3; entry.misc.settlement_date = datetime::Date(2015, 9, 3); @@ -93,7 +90,6 @@ extern "C" BTS_EXPORT void co2_get_sample_cold_header(ColdHeader& header) { header.coconut_status_count = 101; header.exchange_status_count = 102; header.rfq_count = 103; - header.customer_bbo_count = 104; // Do not write to trade_buffer or rfq_buffer } @@ -110,7 +106,6 @@ extern "C" BTS_EXPORT MDProducer* co2_produce_test_md() { assign_ids(producers.begin(), producers.end()); for (auto& p : producers) { p.update_bbo(utils::TimeStamp::now(), PriceSize::from_double<3>(1.1, 101), PriceSize::from_double<3>(2.2,202)); - p.update_customer_bbo(utils::TimeStamp::now(), PriceSize::from_double<3>(3.3, 303), PriceSize::from_double<3>(4.4, 404)); p.add_trade(utils::TimeStamp::now(), PriceSize::from_double<3>(5.5, 505), datetime::ll_from_date(datetime::Date(2015, 9, 22)), AGGRESSOR_SIDE_NONE, 4200); p.update_settlement(utils::TimeStamp::now(), 6.6, datetime::Date(2000, 8, 8)); p.update_settlement(utils::TimeStamp::now(), 6.6, datetime::Date(2000, 8, 9)); diff --git a/src/lib/md/test/md2_tests.cpp b/src/lib/md/test/md2_tests.cpp index c906b6cb2..f98387ad6 100644 --- a/src/lib/md/test/md2_tests.cpp +++ b/src/lib/md/test/md2_tests.cpp @@ -197,52 +197,66 @@ public: void test_price_size() { // PriceSize violates some type punning rules // So it is important to have this test work correctly on the target platform - PriceSize p, p2; - p = PriceSize::from_double<2>(4.5, 14); - SingleWriterPriceSizeStore memory; - memory.store(p); - p2 = memory.load(); - REQUIRE(p.price() == 4.5); - REQUIRE(p.size() == 14); - REQUIRE(p2.price() == 4.5); - REQUIRE(p2.size() == 14); + PriceSize p2; + auto bid = PriceSize::from_double<2>(4.5, 14); + auto ask = PriceSize::from_double<9>(4.5, 14); + PriceLevel memory; + memory = PriceLevel(bid,ask); + REQUIRE(bid.price() == memory.bid().price()); + REQUIRE(bid.size() == memory.bid().size()); + REQUIRE(ask.price() == memory.ask().price()); + REQUIRE(ask.size() == memory.ask().size()); + for (auto p : { memory.bid(), memory.ask() }) { + REQUIRE(p.price() == 4.5); + REQUIRE(p.size() == 14); + } - p = PriceSize::from_double<2>(4.0, 5); - memory.store(p); - p2 = memory.load(); - REQUIRE(p2.price() == 4.0); - REQUIRE(p2.size() == 5); + auto p = PriceSize::from_double<2>(4.0, 5); + memory = PriceLevel(p,p); + for (auto p2 : { memory.bid(), memory.ask() }) { + REQUIRE(p2.price() == 4.0); + REQUIRE(p2.size() == 5); + } p = PriceSize::from_double<2>(-4.2, 6); - memory.store(p); - p2 = memory.load(); - REQUIRE(p2.price() == -4.2); - REQUIRE(p2.size() == 6); + memory = PriceLevel(p,p); + for (auto p2 : { memory.bid(), memory.ask() }) { + REQUIRE(p2.price() == -4.2); + REQUIRE(p2.size() == 6); + } p = PriceSize(4, -1, 2); - memory.store(p); - p2 = memory.load(); - REQUIRE(p2.price() == 0.4); - REQUIRE(p2.size() == 2); + memory = PriceLevel(p,p); + for (auto p2 : { memory.bid(), memory.ask() }) { + REQUIRE(p2.price() == 0.4); + REQUIRE(p2.size() == 2); + } // Test requirement for more than 32 bit mantissa double bigval = -9999.9921875; p = PriceSize::from_double<7>(bigval, 42); - memory.store(p); - p2 = memory.load(); - REQUIRE(p2.price() == bigval); - REQUIRE(p2.size() == 42); + memory = PriceLevel(p,p); + for (auto p2 : { memory.bid(), memory.ask() }) { + REQUIRE(p2.price() == bigval); + REQUIRE(p2.size() == 42); + } } void test_price_size_required_precision() { auto min_tick_2017 = 9999.0078125; auto p17 = PriceSize::from_double<7>(min_tick_2017, 2017); - REQUIRE(min_tick_2017 == p17.price()); - REQUIRE(p17.size() == 2017); + PriceLevel m17(p17, p17); + for (auto p : { m17.bid(), m17.ask() }) { + REQUIRE(min_tick_2017 == p.price()); + REQUIRE(p.size() == 2017); + } auto min_tick_2018 = 1999.00390625; - auto p18 = PriceSize::from_double<9>(min_tick_2018, 2018); - REQUIRE(min_tick_2018 == p18.price()); - REQUIRE(p18.size() == 2018); + auto p18 = PriceSize::from_double<8>(min_tick_2018, 2018); + PriceLevel m18(p18, p18); + for (auto p : { m18.bid(), m18.ask() }) { + REQUIRE(min_tick_2018 == p.price()); + REQUIRE(p.size() == 2018); + } } void test_slow_double_conversion() { diff --git a/src/lib/md/test/synthetic_book_merge_tests.cpp b/src/lib/md/test/synthetic_book_merge_tests.cpp index 64b26332f..8616446a9 100644 --- a/src/lib/md/test/synthetic_book_merge_tests.cpp +++ b/src/lib/md/test/synthetic_book_merge_tests.cpp @@ -20,7 +20,7 @@ namespace test { // std::tuple is hard to read in the debugger struct PS { double price; - uint16_t size; + Size size; bool operator == (const PS& other) const { return price == other.price && size == other.size; } diff --git a/src/lib/utils/Optimistic.h b/src/lib/utils/Optimistic.h new file mode 100644 index 000000000..73c51bcd2 --- /dev/null +++ b/src/lib/utils/Optimistic.h @@ -0,0 +1,47 @@ +#pragma once +#include "TimeStamp.h" +#include +#include + +namespace bts { +namespace utils { + +template +class Optimistic { + std::atomic _time; + T _data; + public: + Optimistic() : _time(TimeStamp(0)), _data(T()) {} + + void store(const T& t) { + store(t, TimeStamp::now()); + } + void store(const T& t, TimeStamp time) { + _time.store(TimeStamp::invalid(), std::memory_order_release); + _data = t; + _time.store(time, std::memory_order_release); + } + + std::tuple load() const { + TimeStamp temp; + T result; + int attempts = 0; + const int max_attempts = 1619200; + do { + ++attempts; + temp = _time; + result = _data; + } while((temp != _time || temp == TimeStamp::invalid()) && attempts < max_attempts); + if (attempts >= max_attempts) return std::make_tuple(TimeStamp::invalid(), result); + return std::make_tuple(temp,result); + } + bool load_if_new(TimeStamp& time, T& result) const { + if (_time > time || _time == TimeStamp::invalid()) { + std::tie(time, result) = load(); + return true; + } + return false; + } +}; + +}} \ No newline at end of file diff --git a/src/server/sparkd/cmds/Benchmark.cpp b/src/server/sparkd/cmds/Benchmark.cpp index bb4aeba0e..4b3378dee 100644 --- a/src/server/sparkd/cmds/Benchmark.cpp +++ b/src/server/sparkd/cmds/Benchmark.cpp @@ -684,45 +684,6 @@ static void small_vec(benchmark::State &state) { } BENCHMARK(small_vec); - -static void price_size(benchmark::State& state) { - using namespace std; - // Randomize the access patterns a bit to attempt to fool the prefetch - // With a single vector the average assignment is 1.5ns, with this ordering it's ~100ns - vector>>> src; - vector>> dest; - size_t sz_mb = state.range(0) * (1024*1024); - size_t sz = sz_mb / 64; - src.resize(8); - dest.resize(8); - for (size_t x = 0; x < 8; ++x) { - src[x].resize(8); - dest[x].resize(8); - for (size_t y = 0; y < 8; ++y) { - src[x][y].resize(sz); - dest[x][y].resize(sz); - for (size_t z = 0; z < sz; ++z) { - src[x][y][z] = make_unique(); - src[x][y][z]->store(md::PriceSize::from_double<9>(z * 1024, x+y)); - } - } - } - - for (auto _ : state) { - for (size_t x = 0; x < 8; ++x) { - for (size_t y = 0; y < 8; ++y) { - for (size_t z = 0; z < sz; ++z) { - auto ps = src[x][y][z]->load(); - dest[x][y][z] = ps; - benchmark::DoNotOptimize(ps); - } - } - } - } -} -// specify range in megabytes from 4 to double cache size -BENCHMARK(price_size)->Range(4, (os::cache_size_l3_bytes()*2) / (1024*1024)); - std::string Benchmark::help() { return "Run micro-benchmarks. Use --benchmark_filter=regex to run only " "specific benchmarks."; From 293dddc54fef4d5119340acef33741aad8199cb6 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 30 Aug 2018 10:41:57 -0400 Subject: [PATCH 3/8] SPARK-1574 Fix Co2Tests.BlitPointerTuple --- src/client/spark_core/Co2/Co2NativeMethods.cs | 2 +- src/client/spark_test/Co2/Co2Tests.cs | 10 +++++----- src/lib/md/test/Co2ManagedTestHelper.cpp | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/client/spark_core/Co2/Co2NativeMethods.cs b/src/client/spark_core/Co2/Co2NativeMethods.cs index 483021e09..7b83a9e28 100644 --- a/src/client/spark_core/Co2/Co2NativeMethods.cs +++ b/src/client/spark_core/Co2/Co2NativeMethods.cs @@ -90,7 +90,7 @@ namespace mbts.co2 internal static class Co2NativeTestMethods { [DllImport("libspark", EntryPoint = "co2_get_1234_handle")] - internal static extern void get_1234_handle(out UInt64 size, out Co2NativeMethods.BlitPointerTuple pt); + internal static extern void get_1234_handle(out UInt64 size, out Co2NativeMethods.BlitPointerTuple pt, out IntPtr hotaddr, out IntPtr coldaddr, out IntPtr headeraddr); [DllImport("libspark")] internal static extern void co2_get_sample_hot(out ulong size, ref MDConsumerHandle.HotEntry entry); diff --git a/src/client/spark_test/Co2/Co2Tests.cs b/src/client/spark_test/Co2/Co2Tests.cs index 2d76d9427..5371dcefd 100644 --- a/src/client/spark_test/Co2/Co2Tests.cs +++ b/src/client/spark_test/Co2/Co2Tests.cs @@ -14,15 +14,15 @@ namespace mbts.co2.tests [TestGroup] public class Co2Tests { - [Test,Ignore("AccessViolation")] + [Test] public void BlitPointerTuple() { UInt64 out_size; Co2NativeMethods.BlitPointerTuple tup; - Co2NativeTestMethods.get_1234_handle(out out_size, out tup); + Co2NativeTestMethods.get_1234_handle(out out_size, out tup, out IntPtr hotaddr, out IntPtr coldaddr, out IntPtr headeraddr); Assert.IsTrue(out_size == (ulong)Marshal.SizeOf(typeof(Co2NativeMethods.BlitPointerTuple))); - Assert.IsTrue(tup.hot == new IntPtr(100)); - Assert.IsTrue(tup.cold_data == new IntPtr(200)); - Assert.IsTrue(tup.cold_header == new IntPtr(300)); + Assert.IsTrue(tup.hot == hotaddr); + Assert.IsTrue(tup.cold_data == coldaddr); + Assert.IsTrue(tup.cold_header == headeraddr); } [Test] diff --git a/src/lib/md/test/Co2ManagedTestHelper.cpp b/src/lib/md/test/Co2ManagedTestHelper.cpp index 9267c7b36..b440e33fd 100644 --- a/src/lib/md/test/Co2ManagedTestHelper.cpp +++ b/src/lib/md/test/Co2ManagedTestHelper.cpp @@ -17,13 +17,20 @@ std::vector create_test_securities(MDProducer& producer, const void assign_ids(std::vector::iterator begin, std::vector::iterator end, security_key start_key = 1000); -extern "C" BTS_EXPORT void co2_get_1234_handle(size_t& size, MDConsumerHandle& handle) { +extern "C" BTS_EXPORT void co2_get_1234_handle(size_t& size, MDConsumerHandle& handle, uintptr_t* hotaddr, uintptr_t* coldaddr, uintptr_t* headeraddr) { // Test that marshaling is working - void* phot = reinterpret_cast(100); - ColdEntry* pcold = reinterpret_cast(200); - ColdHeader* pheader = reinterpret_cast(300); + auto phot = std::make_unique(); + auto pcold = std::make_unique(0); + std::vector buffer; + buffer.resize(1024); + auto pheader = reinterpret_cast(&buffer[0]); + pheader->has_depth = false; size = sizeof(MDConsumerHandle); - handle.init(*pheader, *pcold, phot); + handle.init(*pheader, *pcold, phot.get()); + // Copy the addresses for comparison + *hotaddr = (uintptr_t)phot.get(); + *coldaddr = (uintptr_t)pcold.get(); + *headeraddr = (uintptr_t)pheader; } extern "C" BTS_EXPORT void co2_get_sample_hot(size_t& size, HotEntry& entry) { From 6d7fbe5c84dcf56d70b5dda8d3d2aefe5fa51f52 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 30 Aug 2018 11:28:27 -0400 Subject: [PATCH 4/8] SPARK-1574 Add space for implied book --- src/lib/md/Diag/ShmDumper.cpp | 5 ++- src/lib/md/MDConsumer.cpp | 8 ++-- src/lib/md/MDConsumer.h | 4 +- src/lib/md/MDConsumerHandle.cpp | 2 +- src/lib/md/MDProducerHandle.cpp | 6 +-- src/lib/md/MDProducerHandle.h | 19 ++++++-- src/lib/md/Shm/MDStructure.h | 55 ++++++++++++++++-------- src/lib/md/relay/QueryServer.cpp | 4 +- src/lib/md/test/Co2ManagedTestHelper.cpp | 2 +- 9 files changed, 71 insertions(+), 34 deletions(-) diff --git a/src/lib/md/Diag/ShmDumper.cpp b/src/lib/md/Diag/ShmDumper.cpp index 156feda4e..976bd7461 100644 --- a/src/lib/md/Diag/ShmDumper.cpp +++ b/src/lib/md/Diag/ShmDumper.cpp @@ -213,7 +213,10 @@ void dump_hot_t(SharedListReader& reader) { if (!reader.is_initialized()) { LOG(md,Info,"Unable to initialize section "); return; } auto& header = reader.header(); cout << "{ " << endl; - cout << "'header': { 'count': " << header.count << ", 'segment_count': " << header.segment_count << ", 'bbo_count': " << header.bbo_count << ", 'depth_count': " << header.depth_count << "}," << endl; + cout << "'header': { 'count': " << header.count + << ", 'segment_count': " << header.segment_count + << ", 'direct_count': " << header.direct_count + << ", 'implied_count': " << header.implied_count << "}," << endl; cout << "'entries': [ " << endl; reader.all_entries([&](const TEntry& entry) { cout << dump_entry(entry) << "," << endl; }); cout << "] }" << endl; diff --git a/src/lib/md/MDConsumer.cpp b/src/lib/md/MDConsumer.cpp index 7e3c827c8..b534058ec 100644 --- a/src/lib/md/MDConsumer.cpp +++ b/src/lib/md/MDConsumer.cpp @@ -932,13 +932,13 @@ TimeStamp MDConsumerChannel::create_time() const { return _pimpl ? _pimpl->cold_ size_t MDConsumerChannel::security_count() const { return _pimpl->cold_header().security_count; } -size_t MDConsumerChannel::bbo_count() const { +size_t MDConsumerChannel::direct_count() const { return is_initialized() ? - _pimpl->hot_header().bbo_count : 0; + _pimpl->hot_header().direct_count : 0; } -size_t MDConsumerChannel::depth_count() const { +size_t MDConsumerChannel::implied_count() const { return is_initialized() ? - _pimpl->hot_header().depth_count : 0; + _pimpl->hot_header().implied_count : 0; } size_t MDConsumerChannel::trade_count() const { return _pimpl->cold_header().trade_count; diff --git a/src/lib/md/MDConsumer.h b/src/lib/md/MDConsumer.h index 99aa40c7e..643ef2635 100644 --- a/src/lib/md/MDConsumer.h +++ b/src/lib/md/MDConsumer.h @@ -87,8 +87,8 @@ public: // // Statistic counters size_t security_count() const; - size_t bbo_count() const; - size_t depth_count() const; + size_t direct_count() const; + size_t implied_count() const; size_t trade_count() const; size_t rfq_count() const; size_t gap_count() const; diff --git a/src/lib/md/MDConsumerHandle.cpp b/src/lib/md/MDConsumerHandle.cpp index a172f1fa3..0b82746bf 100644 --- a/src/lib/md/MDConsumerHandle.cpp +++ b/src/lib/md/MDConsumerHandle.cpp @@ -67,7 +67,7 @@ TimeStamp copy_depth( do { t = hot.time(); for (size_t x = 0; x < count; ++x) { - hot.read_level(x, &bid[x], &ask[x]); + hot.read_direct(x, &bid[x], &ask[x]); } ++attempts; } while((t != hot.time() || t == TimeStamp::invalid()) && attempts < max_attempts); diff --git a/src/lib/md/MDProducerHandle.cpp b/src/lib/md/MDProducerHandle.cpp index 7fb5bd5d8..3af9741da 100644 --- a/src/lib/md/MDProducerHandle.cpp +++ b/src/lib/md/MDProducerHandle.cpp @@ -82,7 +82,7 @@ void MDProducerHandle::update_bbo(TimeStamp time, const PriceSize bid, const Pri if (updated) { hdata().set_time(time); hdata().sequence = seq; - hheader().bbo_count++; + hheader().direct_count++; } else { hdata().set_time(oldtime); @@ -91,12 +91,12 @@ void MDProducerHandle::update_bbo(TimeStamp time, const PriceSize bid, const Pri else { auto oldtime = hdepth().time(); hdepth().set_time(TimeStamp::invalid()); - bool updated = hdepth().write_level(0, bid,ask); + bool updated = hdepth().write_direct(0, bid,ask); hdepth().status = COCONUTSECURITYSTATUS_OK; if (updated) { hdepth().set_time(time); hdepth().sequence = seq; - hheader().bbo_count++; + hheader().direct_count++; } else { hdepth().set_time(oldtime); diff --git a/src/lib/md/MDProducerHandle.h b/src/lib/md/MDProducerHandle.h index b30af47b0..4203c1fe4 100644 --- a/src/lib/md/MDProducerHandle.h +++ b/src/lib/md/MDProducerHandle.h @@ -35,7 +35,7 @@ public: void set_legs(const std::vector& legs); void update_bbo(TimeStamp time, const PriceSize bid_price, const PriceSize ask_price, uint16_t seq=0); // hot - void update_book(TimeStamp time, std::array& bids, std::array& asks, uint16_t seq=0) { + void update_book(TimeStamp time, std::array& bids, std::array& asks, uint32_t seq=0) { if (!has_depth()) { update_bbo(time, bids[0], asks[0], seq); } @@ -43,12 +43,25 @@ public: auto& book = hdepth(); book.set_time(TimeStamp::invalid()); for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) { - book.write_level(x, bids[x], asks[x]); + book.write_direct(x, bids[x], asks[x]); } book.status = co2::COCONUTSECURITYSTATUS_OK; book.sequence = seq; book.set_time(time); - hheader().depth_count++; + hheader().direct_count += 1; + } + } + void update_implied(TimeStamp time, std::array& bids, std::array& asks, uint32_t seq=0) { + if (has_depth()) { + auto& book = hdepth(); + book.set_time(TimeStamp::invalid()); + for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) { + book.write_implied(x, bids[x], asks[x]); + } + book.status = co2::COCONUTSECURITYSTATUS_OK; + book.sequence = seq; + book.set_time(time); + hheader().implied_count += 1; } } diff --git a/src/lib/md/Shm/MDStructure.h b/src/lib/md/Shm/MDStructure.h index 09166d8ec..177235ea9 100644 --- a/src/lib/md/Shm/MDStructure.h +++ b/src/lib/md/Shm/MDStructure.h @@ -32,8 +32,8 @@ struct ALIGNED_(CACHE_LINE) HotHeader { size_t count; size_t segment_count; // Just the counters. Publisher process can compute messages/second by polling these counters - size_t bbo_count; - size_t depth_count; + size_t direct_count; + size_t implied_count; }; // These should not be cache line aligned because they are small enough for multiple to fit on one line easily @@ -44,7 +44,7 @@ class HotEntry { uint32_t size() const { return sizeof(HotEntry); } PriceLevel book; // 24 security_key key; // 4 - uint16_t sequence; // 4 + uint32_t sequence; // 4 uint8_t status; // 1 void set_time(const TimeStamp& t) { timestamp.store(t, std::memory_order_release); } TimeStamp time() const { return timestamp.load(std::memory_order_acquire); } @@ -52,6 +52,7 @@ class HotEntry { static_assert(sizeof(HotEntry) <= CACHE_LINE, "HotEntry should be small"); const uint32_t COCONUT_MAX_DEPTH = 10; +const uint32_t COCONUT_IMPLIED_DEPTH = 2; class HotDepthEntry { std::atomic timestamp; // 8 public: @@ -59,32 +60,50 @@ class HotDepthEntry { timestamp(TimeStamp(0)), key(invalid_security_key), sequence(0), - status(co2::COCONUTSECURITYSTATUS_OK), - book() + direct(), + implied(), + status(co2::COCONUTSECURITYSTATUS_OK) { } uint32_t size() const { return sizeof(HotDepthEntry); } security_key key; // 4 NOTE: key is at a different offset than it is in HotEntry - uint16_t sequence; // 2 + uint32_t sequence; // 4 + std::array implied; + std::array direct; uint8_t status; // 1 - std::array book; const PriceLevel* at(uint32_t depth) const { - if (depth < book.size()) { - return &book[depth]; + if (depth < direct.size()) { + return &direct[depth]; } return nullptr; } - void read_level(uint32_t depth, PriceSize* bid, PriceSize* ask) const { - if (depth < book.size()) { - *bid = book[depth].bid(); - *ask = book[depth].ask(); + void read_direct(uint32_t depth, PriceSize* bid, PriceSize* ask) const { + if (depth < direct.size()) { + *bid = direct[depth].bid(); + *ask = direct[depth].ask(); } } - bool write_level(uint32_t depth, const PriceSize& bid, const PriceSize& ask) { - if (depth < book.size()) { + void read_implied(uint32_t depth, PriceSize* bid, PriceSize* ask) const { + if (depth < implied.size()) { + *bid = implied[depth].bid(); + *ask = implied[depth].ask(); + } + } + bool write_direct(uint32_t depth, const PriceSize& bid, const PriceSize& ask) { + if (depth < direct.size()) { auto temp = PriceLevel(bid,ask); - if (book[depth] != temp) { - book[depth] = PriceLevel(bid,ask); + if (direct[depth] != temp) { + direct[depth] = PriceLevel(bid,ask); + return true; + } + } + return false; + } + bool write_implied(uint32_t depth, const PriceSize& bid, const PriceSize& ask) { + if (depth < implied.size()) { + auto temp = PriceLevel(bid,ask); + if (implied[depth] != temp) { + implied[depth] = PriceLevel(bid,ask); return true; } } @@ -94,7 +113,7 @@ class HotDepthEntry { void set_time(const TimeStamp& t) { timestamp.store(t, std::memory_order_release); } TimeStamp time() const { return timestamp.load(std::memory_order_acquire); } }; -static_assert(sizeof(HotDepthEntry) == 256, "HotDepthEntry should be small"); +static_assert(sizeof(HotDepthEntry) <= 320, "HotDepthEntry should be small"); // // COLD Data, brrr diff --git a/src/lib/md/relay/QueryServer.cpp b/src/lib/md/relay/QueryServer.cpp index af2e2e0fd..d6252b220 100644 --- a/src/lib/md/relay/QueryServer.cpp +++ b/src/lib/md/relay/QueryServer.cpp @@ -80,7 +80,9 @@ struct MDConsumerGroup { labels.push_back({ "type", SecurityType_Name(symbol.type()).substr(13) /*SECURITYTYPE_*/ }); labels.push_back({ "exch", Venue_Name(symbol.exchange()).substr(6) /*VENUE_*/ }); stats.publish( - std::make_shared("spark_md_book_updates", [=]() { return std::max(channel.bbo_count(), channel.depth_count()); }, labels)); + std::make_shared("spark_md_book_updates", [=]() { + return channel.direct_count() + channel.implied_count(); + }, labels)); stats.publish( std::make_shared("spark_md_security_count", [=]() { return channel.security_count(); }, labels)); stats.publish( diff --git a/src/lib/md/test/Co2ManagedTestHelper.cpp b/src/lib/md/test/Co2ManagedTestHelper.cpp index b440e33fd..b0444b350 100644 --- a/src/lib/md/test/Co2ManagedTestHelper.cpp +++ b/src/lib/md/test/Co2ManagedTestHelper.cpp @@ -48,7 +48,7 @@ extern "C" BTS_EXPORT void co2_get_sample_depth(size_t& size, HotDepthEntry& ent size = sizeof(HotDepthEntry); entry.key = 1234; for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) { - entry.write_level(x, + entry.write_direct(x, PriceSize::from_double<2>(x + 0.5, x + 1), PriceSize::from_double<2>(x + 0.6, x + 2)); } From 4256c5199368b05daeb58fdb16a97f4b10484466 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 30 Aug 2018 13:47:35 -0400 Subject: [PATCH 5/8] Move EqualityComparer and MathUtils to spark_core --- src/client/spark/Modules/Spreader/VM/RowVM.cs | 1 + .../spark/Modules/Spreader/VM/SyntheticEditorVM.cs | 1 + .../spark/Modules/Trading/OrderBook/OrderBookCell.cs | 3 ++- .../spark/Modules/Trading/OrderBook/OrderBookColumns.cs | 1 + src/client/spark/Notifications/ToastNotification.cs | 1 + src/client/spark/Orders/FillTuple.cs | 1 + src/client/spark/Orders/OrderActivitySummarizer.cs | 2 +- src/client/spark/Orders/OrderRecordTuple.cs | 1 + .../Data/DiscreteValues/DiscreteValuesPredicate.cs | 3 ++- .../Data/Events/OrderCanceledEventPredicate.cs | 1 + .../Data/Events/OrderCompletedEventPredicate.cs | 1 + .../Predicates/Data/Events/OrderEventPredicateHelper.cs | 1 + .../spark/Predicates/Data/OrderRecordTuplePredicate.cs | 1 + .../spark/Predicates/Data/Primitive/DoublePredicate.cs | 1 + .../spark/Predicates/Data/Primitive/SidePredicate.cs | 1 + .../spark/Predicates/Data/Primitive/StringPredicate.cs | 1 + .../spark/Predicates/Data/Primitive/TimePredicate.cs | 1 + .../spark/Predicates/Data/Primitive/UIntPredicate.cs | 1 + .../spark/Predicates/Data/Primitive/UShortPredicate.cs | 1 + src/client/spark/Predicates/IPredicate.cs | 1 + .../core/GlobalExtensions/GenericCollectionExtensions.cs | 3 ++- src/client/spark/core/GlobalExtensions/TickExtensions.cs | 2 +- src/client/spark/core/data/Proto/ColorOpacityProto.cs | 3 ++- .../spark/core/data/Proto/DateTimePeriodProvider.cs | 3 ++- src/client/spark/core/data/Proto/DateTimeProvider.cs | 3 ++- src/client/spark/core/data/Proto/DoubleRange.cs | 3 ++- src/client/spark/core/data/Proto/ExpDate.cs | 1 + src/client/spark/core/data/Proto/NullableColorProto.cs | 3 ++- src/client/spark/core/data/Proto/NullableFontWeight.cs | 3 ++- src/client/spark/core/data/Proto/StringIgnoreCase.cs | 3 ++- src/client/spark/core/data/Proto/ThicknessProto.cs | 3 ++- src/client/spark/core/data/Proto/UIntRange.cs | 3 ++- src/client/spark/core/data/Proto/UShortRange.cs | 3 ++- .../core/user/settings/ticks/RegionalTickFactors.cs | 3 ++- .../view/Controls/ColorPicker/ColorPickerControl.xaml.cs | 3 ++- src/client/spark/view/Controls/DIYGrid/DIYGrid.cs | 2 +- src/client/spark/view/Controls/DIYGrid/Row/RowBase.cs | 2 +- .../DIYGrid/Settings/Animation/AnimationDefinition.cs | 3 ++- .../DIYGrid/Settings/Animation/BackgroundAnimation.cs | 1 + .../Controls/DIYGrid/Settings/Animation/CellAnimation.cs | 1 + .../Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs | 3 ++- .../spark/view/Controls/TickUpDown/TickUpDownInt.cs | 3 ++- .../spark/view/Spark/ContractPicker/SecurityCriteria.cs | 2 +- src/client/spark/view/Spark/Core/TickUtils.cs | 1 + src/client/spark/view/Spark/Grid/SecurityMDGrid.cs | 2 +- src/client/spark/view/Spark/Ladder/LadderSettings.cs | 2 +- src/client/spark/view/Spark/Utilities/OrderDataHelper.cs | 1 + .../spark/view/Spark/Utilities/SecurityDataHelper.cs | 4 ++-- src/client/spark/view/Utility/IVisualContentRect.cs | 3 ++- src/client/spark/view/Utility/TextUtils.cs | 3 ++- src/client/spark/view/Utility/WPFHelper.cs | 1 + .../utils/EqualityComparer.cs} | 9 ++++----- .../Spark/Utilities => spark_core/utils}/MathUtils.cs | 2 +- 53 files changed, 77 insertions(+), 35 deletions(-) rename src/client/{spark/core/Utility/AnonymousEqualityComparer.cs => spark_core/utils/EqualityComparer.cs} (93%) rename src/client/{spark/view/Spark/Utilities => spark_core/utils}/MathUtils.cs (95%) diff --git a/src/client/spark/Modules/Spreader/VM/RowVM.cs b/src/client/spark/Modules/Spreader/VM/RowVM.cs index 25173515a..31b68a903 100644 --- a/src/client/spark/Modules/Spreader/VM/RowVM.cs +++ b/src/client/spark/Modules/Spreader/VM/RowVM.cs @@ -1,4 +1,5 @@ using bts.api; +using bts.utils; using mbts.collections; using mbts.ui.controls; using mbts.ui.spark; diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs index 0ec61d681..96d766b6b 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs @@ -1,6 +1,7 @@ using bts.api; using bts.shell; using bts.spark; +using bts.utils; using mbts.spark.utilities; using mbts.ui; using mbts.ui.shell; diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookCell.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookCell.cs index 028ac5213..36c27d336 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookCell.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookCell.cs @@ -1,4 +1,5 @@ -using mbts.ui; +using bts.utils; +using mbts.ui; using mbts.ui.controls; using mbts.utils; using System; diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs index 67f181a95..8d4141ce0 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookColumns.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.orderman; using bts.shell; +using bts.utils; using mbts.spark.filters; using mbts.ui; using mbts.ui.converters; diff --git a/src/client/spark/Notifications/ToastNotification.cs b/src/client/spark/Notifications/ToastNotification.cs index e9542cc27..f2590e5db 100644 --- a/src/client/spark/Notifications/ToastNotification.cs +++ b/src/client/spark/Notifications/ToastNotification.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.orderman; using bts.spark; +using bts.utils; using mbts; using mbts.spark; using mbts.utils; diff --git a/src/client/spark/Orders/FillTuple.cs b/src/client/spark/Orders/FillTuple.cs index 1cc929bcb..8e2d53958 100644 --- a/src/client/spark/Orders/FillTuple.cs +++ b/src/client/spark/Orders/FillTuple.cs @@ -1,5 +1,6 @@ using bts.api; using bts.api.orderman; +using bts.utils; using mbts.utils; using System; diff --git a/src/client/spark/Orders/OrderActivitySummarizer.cs b/src/client/spark/Orders/OrderActivitySummarizer.cs index 6466c90bc..37f1845dc 100644 --- a/src/client/spark/Orders/OrderActivitySummarizer.cs +++ b/src/client/spark/Orders/OrderActivitySummarizer.cs @@ -24,7 +24,7 @@ namespace bts.spark { IReadOnlyDictionary _security = new Dictionary(); IDisposable _dispose; static readonly IEqualityComparer _id_comparer = - mbts.utils.EqualityComparer.Create(a => a.Key); + bts.utils.EqualityComparer.Create(a => a.Key); public OrderActivitySummarizer(IBus bus, IObservable> orders) { _bus = bus; diff --git a/src/client/spark/Orders/OrderRecordTuple.cs b/src/client/spark/Orders/OrderRecordTuple.cs index 194da8563..4e420335b 100644 --- a/src/client/spark/Orders/OrderRecordTuple.cs +++ b/src/client/spark/Orders/OrderRecordTuple.cs @@ -1,4 +1,5 @@ using bts.api.orderman; +using bts.utils; using mbts.utils; using System; diff --git a/src/client/spark/Predicates/Data/DiscreteValues/DiscreteValuesPredicate.cs b/src/client/spark/Predicates/Data/DiscreteValues/DiscreteValuesPredicate.cs index 0a6b872a0..f885c60e9 100644 --- a/src/client/spark/Predicates/Data/DiscreteValues/DiscreteValuesPredicate.cs +++ b/src/client/spark/Predicates/Data/DiscreteValues/DiscreteValuesPredicate.cs @@ -1,4 +1,5 @@ -using mbts.spark; +using bts.utils; +using mbts.spark; using mbts.spark.utilities; using mbts.ui.spark; using mbts.ui.utility; diff --git a/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs b/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs index fa8ebf3db..4546dfd6d 100644 --- a/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs +++ b/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.orderman; using bts.shell; +using bts.utils; using mbts.spark; using mbts.ui.settings; using mbts.utils; diff --git a/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs b/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs index 29337ee26..881201de5 100644 --- a/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs +++ b/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.orderman; using bts.shell; +using bts.utils; using mbts.spark; using mbts.ui.settings; using mbts.utils; diff --git a/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs b/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs index 9582b6089..9fa542867 100644 --- a/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs +++ b/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.orderman; using bts.shell; +using bts.utils; using mbts.spark; using mbts.utils; using System; diff --git a/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs b/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs index e54713357..0b83d2fcf 100644 --- a/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs +++ b/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.orderman; using bts.shell; +using bts.utils; using mbts.spark; using mbts.ui; using mbts.ui.settings; diff --git a/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs b/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs index 93ae66b55..d0a5dfb16 100644 --- a/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs +++ b/src/client/spark/Predicates/Data/Primitive/DoublePredicate.cs @@ -1,4 +1,5 @@ using bts.proto; +using bts.utils; using mbts.spark; using mbts.spark.utilities; using mbts.ui.spark; diff --git a/src/client/spark/Predicates/Data/Primitive/SidePredicate.cs b/src/client/spark/Predicates/Data/Primitive/SidePredicate.cs index 70cf176bd..b15486b76 100644 --- a/src/client/spark/Predicates/Data/Primitive/SidePredicate.cs +++ b/src/client/spark/Predicates/Data/Primitive/SidePredicate.cs @@ -1,4 +1,5 @@ using bts.api; +using bts.utils; using mbts.spark; using mbts.spark.utilities; using mbts.ui.spark; diff --git a/src/client/spark/Predicates/Data/Primitive/StringPredicate.cs b/src/client/spark/Predicates/Data/Primitive/StringPredicate.cs index 66a2dcb9f..3f7a9679f 100644 --- a/src/client/spark/Predicates/Data/Primitive/StringPredicate.cs +++ b/src/client/spark/Predicates/Data/Primitive/StringPredicate.cs @@ -1,4 +1,5 @@ using bts.proto; +using bts.utils; using mbts.spark; using mbts.spark.utilities; using mbts.ui.spark; diff --git a/src/client/spark/Predicates/Data/Primitive/TimePredicate.cs b/src/client/spark/Predicates/Data/Primitive/TimePredicate.cs index 93052cceb..2ee8a55f7 100644 --- a/src/client/spark/Predicates/Data/Primitive/TimePredicate.cs +++ b/src/client/spark/Predicates/Data/Primitive/TimePredicate.cs @@ -1,4 +1,5 @@ using bts.proto; +using bts.utils; using mbts.spark; using mbts.spark.utilities; using mbts.ui.spark; diff --git a/src/client/spark/Predicates/Data/Primitive/UIntPredicate.cs b/src/client/spark/Predicates/Data/Primitive/UIntPredicate.cs index ae9cc4279..8d0df7dea 100644 --- a/src/client/spark/Predicates/Data/Primitive/UIntPredicate.cs +++ b/src/client/spark/Predicates/Data/Primitive/UIntPredicate.cs @@ -1,4 +1,5 @@ using bts.proto; +using bts.utils; using mbts.spark; using mbts.spark.utilities; using mbts.ui.spark; diff --git a/src/client/spark/Predicates/Data/Primitive/UShortPredicate.cs b/src/client/spark/Predicates/Data/Primitive/UShortPredicate.cs index 27af16634..c3f61af67 100644 --- a/src/client/spark/Predicates/Data/Primitive/UShortPredicate.cs +++ b/src/client/spark/Predicates/Data/Primitive/UShortPredicate.cs @@ -1,4 +1,5 @@ using bts.proto; +using bts.utils; using mbts.spark; using mbts.spark.utilities; using mbts.ui.spark; diff --git a/src/client/spark/Predicates/IPredicate.cs b/src/client/spark/Predicates/IPredicate.cs index e2f766a3a..5f1b376cc 100644 --- a/src/client/spark/Predicates/IPredicate.cs +++ b/src/client/spark/Predicates/IPredicate.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.utils; using mbts.utils; using System; using System.Collections.Generic; diff --git a/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs b/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs index aeb7db9fd..851d21db9 100644 --- a/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using System; using System.Collections.Generic; using System.Collections.ObjectModel; diff --git a/src/client/spark/core/GlobalExtensions/TickExtensions.cs b/src/client/spark/core/GlobalExtensions/TickExtensions.cs index 8400fc04b..e46e9392c 100644 --- a/src/client/spark/core/GlobalExtensions/TickExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/TickExtensions.cs @@ -1,7 +1,7 @@ using mbts.user.settings; using System; using System.Globalization; -using static mbts.spark.utilities.MathUtils; +using static bts.utils.MathUtils; namespace mbts { static class TickExtensions { diff --git a/src/client/spark/core/data/Proto/ColorOpacityProto.cs b/src/client/spark/core/data/Proto/ColorOpacityProto.cs index 3c9927d9c..c67e51d37 100644 --- a/src/client/spark/core/data/Proto/ColorOpacityProto.cs +++ b/src/client/spark/core/data/Proto/ColorOpacityProto.cs @@ -1,4 +1,5 @@ -using mbts.ui; +using bts.utils; +using mbts.ui; using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/DateTimePeriodProvider.cs b/src/client/spark/core/data/Proto/DateTimePeriodProvider.cs index 03400089e..53d7cc6a7 100644 --- a/src/client/spark/core/data/Proto/DateTimePeriodProvider.cs +++ b/src/client/spark/core/data/Proto/DateTimePeriodProvider.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/DateTimeProvider.cs b/src/client/spark/core/data/Proto/DateTimeProvider.cs index 43fc36d38..8224670bb 100644 --- a/src/client/spark/core/data/Proto/DateTimeProvider.cs +++ b/src/client/spark/core/data/Proto/DateTimeProvider.cs @@ -1,4 +1,5 @@ -using mbts.spark; +using bts.utils; +using mbts.spark; using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/DoubleRange.cs b/src/client/spark/core/data/Proto/DoubleRange.cs index 718bad18f..0ea3f9890 100644 --- a/src/client/spark/core/data/Proto/DoubleRange.cs +++ b/src/client/spark/core/data/Proto/DoubleRange.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/ExpDate.cs b/src/client/spark/core/data/Proto/ExpDate.cs index 0193130ab..301497e78 100644 --- a/src/client/spark/core/data/Proto/ExpDate.cs +++ b/src/client/spark/core/data/Proto/ExpDate.cs @@ -1,4 +1,5 @@ using bts.api; +using bts.utils; using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/NullableColorProto.cs b/src/client/spark/core/data/Proto/NullableColorProto.cs index 81afa85f3..3fa15eba3 100644 --- a/src/client/spark/core/data/Proto/NullableColorProto.cs +++ b/src/client/spark/core/data/Proto/NullableColorProto.cs @@ -1,4 +1,5 @@ -using mbts.ui; +using bts.utils; +using mbts.ui; using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/NullableFontWeight.cs b/src/client/spark/core/data/Proto/NullableFontWeight.cs index 05ed2cc45..8f4a6ddee 100644 --- a/src/client/spark/core/data/Proto/NullableFontWeight.cs +++ b/src/client/spark/core/data/Proto/NullableFontWeight.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using ProtoBuf; using System; using System.Windows; diff --git a/src/client/spark/core/data/Proto/StringIgnoreCase.cs b/src/client/spark/core/data/Proto/StringIgnoreCase.cs index 86a20e4f8..9896b9b17 100644 --- a/src/client/spark/core/data/Proto/StringIgnoreCase.cs +++ b/src/client/spark/core/data/Proto/StringIgnoreCase.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/ThicknessProto.cs b/src/client/spark/core/data/Proto/ThicknessProto.cs index 9383bcdac..d49d1030a 100644 --- a/src/client/spark/core/data/Proto/ThicknessProto.cs +++ b/src/client/spark/core/data/Proto/ThicknessProto.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using ProtoBuf; using System; using System.Windows; diff --git a/src/client/spark/core/data/Proto/UIntRange.cs b/src/client/spark/core/data/Proto/UIntRange.cs index ccb6c6418..58bbdc8a4 100644 --- a/src/client/spark/core/data/Proto/UIntRange.cs +++ b/src/client/spark/core/data/Proto/UIntRange.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/data/Proto/UShortRange.cs b/src/client/spark/core/data/Proto/UShortRange.cs index b9a2bc429..f0de510ec 100644 --- a/src/client/spark/core/data/Proto/UShortRange.cs +++ b/src/client/spark/core/data/Proto/UShortRange.cs @@ -1,4 +1,5 @@ -using mbts.utils; +using bts.utils; +using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/core/user/settings/ticks/RegionalTickFactors.cs b/src/client/spark/core/user/settings/ticks/RegionalTickFactors.cs index 4d4648ca0..b648e10e1 100644 --- a/src/client/spark/core/user/settings/ticks/RegionalTickFactors.cs +++ b/src/client/spark/core/user/settings/ticks/RegionalTickFactors.cs @@ -1,4 +1,5 @@ -using mbts.spark.utilities; +using bts.utils; +using mbts.spark.utilities; using mbts.ui; using ProtoBuf; using System; diff --git a/src/client/spark/view/Controls/ColorPicker/ColorPickerControl.xaml.cs b/src/client/spark/view/Controls/ColorPicker/ColorPickerControl.xaml.cs index 6ab77b596..c5681bd77 100644 --- a/src/client/spark/view/Controls/ColorPicker/ColorPickerControl.xaml.cs +++ b/src/client/spark/view/Controls/ColorPicker/ColorPickerControl.xaml.cs @@ -1,4 +1,5 @@ -using mbts.spark.utilities; +using bts.utils; +using mbts.spark.utilities; using mbts.ui.extensions; using mbts.ui.utility; using System; diff --git a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs index 955c60ead..a1fff7a7c 100644 --- a/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs +++ b/src/client/spark/view/Controls/DIYGrid/DIYGrid.cs @@ -2,7 +2,7 @@ using mbts.ui.controls.adorners; using mbts.ui.extensions; using mbts.ui.utility; -using mbts.utils; +using bts.utils; using System; using System.Collections; using System.Collections.Generic; diff --git a/src/client/spark/view/Controls/DIYGrid/Row/RowBase.cs b/src/client/spark/view/Controls/DIYGrid/Row/RowBase.cs index 1f084a9d6..a48ecc63c 100644 --- a/src/client/spark/view/Controls/DIYGrid/Row/RowBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Row/RowBase.cs @@ -1,7 +1,7 @@ using mbts.spark; using mbts.ui.extensions; using mbts.ui.settings; -using mbts.utils; +using bts.utils; using System; using System.Collections.Generic; using System.Collections.ObjectModel; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/AnimationDefinition.cs b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/AnimationDefinition.cs index 422628da0..1703e5f94 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/AnimationDefinition.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/AnimationDefinition.cs @@ -1,4 +1,5 @@ -using mbts.spark.utilities; +using bts.utils; +using mbts.spark.utilities; using mbts.ui.settings; using System; using static mbts.ui.controls.DIYGrid; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/BackgroundAnimation.cs b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/BackgroundAnimation.cs index 7f3aae649..768460c0a 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/BackgroundAnimation.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/BackgroundAnimation.cs @@ -1,4 +1,5 @@ using bts.proto; +using bts.utils; using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/CellAnimation.cs b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/CellAnimation.cs index 827342302..8cba56daf 100644 --- a/src/client/spark/view/Controls/DIYGrid/Settings/Animation/CellAnimation.cs +++ b/src/client/spark/view/Controls/DIYGrid/Settings/Animation/CellAnimation.cs @@ -1,4 +1,5 @@ using bts.proto; +using bts.utils; using mbts.utils; using ProtoBuf; using System; diff --git a/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs b/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs index a9ff8fd3c..37c782162 100644 --- a/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs +++ b/src/client/spark/view/Controls/TickFactorsPicker/TickFactorsPicker.xaml.cs @@ -1,4 +1,5 @@ -using mbts.spark; +using bts.utils; +using mbts.spark; using mbts.spark.utilities; using mbts.ui.converters; using mbts.ui.shell; diff --git a/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs b/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs index c7b75553b..b92fb47be 100644 --- a/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs +++ b/src/client/spark/view/Controls/TickUpDown/TickUpDownInt.cs @@ -1,4 +1,5 @@ -using mbts.spark.utilities; +using bts.utils; +using mbts.spark.utilities; using System; using System.Windows; using System.Windows.Controls; diff --git a/src/client/spark/view/Spark/ContractPicker/SecurityCriteria.cs b/src/client/spark/view/Spark/ContractPicker/SecurityCriteria.cs index 2c5bb13d6..003cebc94 100644 --- a/src/client/spark/view/Spark/ContractPicker/SecurityCriteria.cs +++ b/src/client/spark/view/Spark/ContractPicker/SecurityCriteria.cs @@ -1,5 +1,5 @@ using bts.api; -using mbts.utils; +using bts.utils; using ProtoBuf; using System; using System.Collections.Generic; diff --git a/src/client/spark/view/Spark/Core/TickUtils.cs b/src/client/spark/view/Spark/Core/TickUtils.cs index 5252064cc..fad161d3e 100644 --- a/src/client/spark/view/Spark/Core/TickUtils.cs +++ b/src/client/spark/view/Spark/Core/TickUtils.cs @@ -1,4 +1,5 @@ using bts.api; +using bts.utils; using mbts.co2; using mbts.spark.utilities; using mbts.user.settings; diff --git a/src/client/spark/view/Spark/Grid/SecurityMDGrid.cs b/src/client/spark/view/Spark/Grid/SecurityMDGrid.cs index 9a05a9553..77d1aeb29 100644 --- a/src/client/spark/view/Spark/Grid/SecurityMDGrid.cs +++ b/src/client/spark/view/Spark/Grid/SecurityMDGrid.cs @@ -1,6 +1,6 @@ using mbts.ui; using mbts.ui.utility; -using mbts.utils; +using bts.utils; using System; using System.Collections.Generic; using System.Reactive.Linq; diff --git a/src/client/spark/view/Spark/Ladder/LadderSettings.cs b/src/client/spark/view/Spark/Ladder/LadderSettings.cs index 4d6f9131e..e71eca84d 100644 --- a/src/client/spark/view/Spark/Ladder/LadderSettings.cs +++ b/src/client/spark/view/Spark/Ladder/LadderSettings.cs @@ -1,6 +1,6 @@ using bts.api.orderman; using mbts.ui; -using mbts.utils; +using bts.utils; using ProtoBuf; using System; using System.Linq; diff --git a/src/client/spark/view/Spark/Utilities/OrderDataHelper.cs b/src/client/spark/view/Spark/Utilities/OrderDataHelper.cs index f22d53d7f..7998aa3bc 100644 --- a/src/client/spark/view/Spark/Utilities/OrderDataHelper.cs +++ b/src/client/spark/view/Spark/Utilities/OrderDataHelper.cs @@ -3,6 +3,7 @@ using bts.api; using bts.api.admin; using bts.api.orderman; using bts.spark; +using bts.utils; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using mbts.ui; diff --git a/src/client/spark/view/Spark/Utilities/SecurityDataHelper.cs b/src/client/spark/view/Spark/Utilities/SecurityDataHelper.cs index e5a51422a..6b7e465c7 100644 --- a/src/client/spark/view/Spark/Utilities/SecurityDataHelper.cs +++ b/src/client/spark/view/Spark/Utilities/SecurityDataHelper.cs @@ -4,11 +4,11 @@ using System.Collections.Generic; namespace mbts.spark { static class SecurityDataHelper { public static class EqualityComparer { - public static readonly IEqualityComparer MDComparer = utils.EqualityComparer.Create(Equals, GetHashCode); + public static readonly IEqualityComparer MDComparer = bts.utils.EqualityComparer.Create(Equals, GetHashCode); public static bool Equals(SecurityMD x, SecurityMD y) => x.security.Id == y.security.Id; public static int GetHashCode(SecurityMD security_md) => security_md.security.Id.GetHashCode(); - public static readonly IEqualityComparer IDComparer = utils.EqualityComparer.Create(s => s.Id); + public static readonly IEqualityComparer IDComparer = bts.utils.EqualityComparer.Create(s => s.Id); } public static class Defaults { diff --git a/src/client/spark/view/Utility/IVisualContentRect.cs b/src/client/spark/view/Utility/IVisualContentRect.cs index ad99873df..8d42f7d29 100644 --- a/src/client/spark/view/Utility/IVisualContentRect.cs +++ b/src/client/spark/view/Utility/IVisualContentRect.cs @@ -1,4 +1,5 @@ -using mbts.ui.utility.text; +using bts.utils; +using mbts.ui.utility.text; using mbts.utils; using System.Collections.Generic; using System.Windows; diff --git a/src/client/spark/view/Utility/TextUtils.cs b/src/client/spark/view/Utility/TextUtils.cs index ecc05da06..b29b2cb87 100644 --- a/src/client/spark/view/Utility/TextUtils.cs +++ b/src/client/spark/view/Utility/TextUtils.cs @@ -1,4 +1,5 @@ -using mbts.spark.utilities; +using bts.utils; +using mbts.spark.utilities; using System.Collections.Generic; using System.Globalization; using System.Linq; diff --git a/src/client/spark/view/Utility/WPFHelper.cs b/src/client/spark/view/Utility/WPFHelper.cs index ea2b51498..dad292484 100644 --- a/src/client/spark/view/Utility/WPFHelper.cs +++ b/src/client/spark/view/Utility/WPFHelper.cs @@ -1,3 +1,4 @@ +using bts.utils; using mbts.spark.utilities; using mbts.utils; using System; diff --git a/src/client/spark/core/Utility/AnonymousEqualityComparer.cs b/src/client/spark_core/utils/EqualityComparer.cs similarity index 93% rename from src/client/spark/core/Utility/AnonymousEqualityComparer.cs rename to src/client/spark_core/utils/EqualityComparer.cs index 1604ae8ed..21710ba6e 100644 --- a/src/client/spark/core/Utility/AnonymousEqualityComparer.cs +++ b/src/client/spark_core/utils/EqualityComparer.cs @@ -1,10 +1,9 @@ -using mbts.spark.utilities; -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; -namespace mbts.utils { +namespace bts.utils { public static class EqualityComparer { const int _hash_seed = 63607, _hash_multiplier = 6451; @@ -15,13 +14,13 @@ namespace mbts.utils { new AnonymousEqualityComparer(equals, get_hash_code); public static IEqualityComparer Create(Func key_selector) => - Create(key_selector, EqualityComparer.Default); + Create(key_selector, System.Collections.Generic.EqualityComparer.Default); public static IEqualityComparer Create(Func key_selector, IEqualityComparer key_comparer) => Create((x, y) => key_comparer.Equals(key_selector(x), (key_selector(y))), x => key_selector(x).GetHashCode()); public static IEqualityComparer CreateNullable(Func key_selector) where T : struct { - var eqc = EqualityComparer.Default; + var eqc = System.Collections.Generic.EqualityComparer.Default; return Create((x, y) => x.HasValue ? y.HasValue && eqc.Equals(key_selector(x.Value), key_selector(y.Value)) : !y.HasValue); } diff --git a/src/client/spark/view/Spark/Utilities/MathUtils.cs b/src/client/spark_core/utils/MathUtils.cs similarity index 95% rename from src/client/spark/view/Spark/Utilities/MathUtils.cs rename to src/client/spark_core/utils/MathUtils.cs index 0c7103c8c..416e2c12f 100644 --- a/src/client/spark/view/Spark/Utilities/MathUtils.cs +++ b/src/client/spark_core/utils/MathUtils.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; -namespace mbts.spark.utilities { +namespace bts.utils { static class MathUtils { public const double epsilon = 1E-12; public static bool epsilon_equals(double x, double y) => From c53c12b5d83e90b18b3dac20d5783e93a524b1a2 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 31 Aug 2018 09:42:48 -0400 Subject: [PATCH 6/8] SPARK-1574 Changes from ushort to uint in shell --- .../Market/MarketView/MarketViewRow.cs | 18 +++++++------ .../Modules/Market/MarketView/MarketViewVM.cs | 6 ++--- .../MarketView/MarketViewWindowFactory.cs | 6 ++--- .../spark/view/Spark/Ladder/LadderGridHost.cs | 9 ++++--- .../spark/view/Spark/Ladder/LaderRender.cs | 2 +- .../spark/view/Spark/Utilities/BBOVM.cs | 10 +++---- .../view/Spark/Utilities/ISecurityMDPump.cs | 26 +++++++++---------- 7 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index fdefb8074..e5b9b360d 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -9,6 +9,7 @@ using mbts.ui.settings; using mbts.ui.spark; using mbts.ui.utility; using mbts.utils; +using bts.utils; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -17,6 +18,7 @@ using System.Linq; using System.Reactive.Linq; using System.Windows.Input; + namespace mbts.spark { partial class MarketViewVM { public class Row : SecurityMDRow, IDisposable, IEquatable, DIYGrid.IRowVM, DIYGrid.IActionableRowVM { @@ -27,9 +29,9 @@ namespace mbts.spark { readonly ObservableFilterCollection _working_orders, _working_bids, _working_asks; readonly string _security_text, _security_key_text; readonly Property _bid_price, _ask_price, _last_price, _day_change, _settlement, _session_high, _session_low; - readonly Property _bid_size, _ask_size; + readonly Property _bid_size, _ask_size; readonly CellProperty _position; - readonly CellProperty _last_size; + readonly CellProperty _last_size; readonly CellProperty _volume; readonly CellProperty _inside_bids, _inside_asks; readonly CellProperty _working_bid_volume, _working_ask_volume; @@ -47,10 +49,10 @@ namespace mbts.spark { _position = new CellProperty(0); _bid_price = backing(nameof(bid_price), double.NaN); _ask_price = backing(nameof(ask_price), double.NaN); - _bid_size = backing(nameof(bid_size), 0); - _ask_size = backing(nameof(ask_size), 0); + _bid_size = backing(nameof(bid_size), 0); + _ask_size = backing(nameof(ask_size), 0); _last_price = backing(nameof(last_price), double.NaN); - _last_size = new CellProperty(0); + _last_size = new CellProperty(0); _day_change = backing(nameof(day_change), double.NaN); _session_low = backing(nameof(session_low), double.NaN); _session_high = backing(nameof(session_high), double.NaN); @@ -95,11 +97,11 @@ namespace mbts.spark { public bool inside_asks => _inside_asks.value; public int position => _position.value; public double last_price => _last_price.Value; - public ushort last_size => _last_size.value; + public uint last_size => _last_size.value; public double bid_price => _bid_price.Value; - public ushort bid_size => _bid_size.Value; + public uint bid_size => _bid_size.Value; public double ask_price => _ask_price.Value; - public ushort ask_size => _ask_size.Value; + public uint ask_size => _ask_size.Value; public ulong volume => _volume.value; public double settlement => _settlement.Value; public double day_change => _day_change.Value; diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index 00f7fafc9..8fd9cc57b 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -116,11 +116,11 @@ namespace mbts.spark { #region Filters public IDataGridColumnPersistentFilter security_filter { get; } public IDataGridColumnPersistentFilter bid_price_filter { get; } = new DoubleMinMax(r => r.bid_price, nameof(Row.bid_price)); - public IDataGridColumnPersistentFilter bid_size_filter { get; } = new UShortMinMax(r => r.bid_size, nameof(Row.bid_size)); + public IDataGridColumnPersistentFilter bid_size_filter { get; } = new UIntMinMax(r => r.bid_size, nameof(Row.bid_size)); public IDataGridColumnPersistentFilter ask_price_filter { get; } = new DoubleMinMax(r => r.ask_price, nameof(Row.ask_price)); - public IDataGridColumnPersistentFilter ask_size_filter { get; } = new UShortMinMax(r => r.ask_size, nameof(Row.ask_size)); + public IDataGridColumnPersistentFilter ask_size_filter { get; } = new UIntMinMax(r => r.ask_size, nameof(Row.ask_size)); public IDataGridColumnPersistentFilter last_price_filter { get; } = new DoubleMinMax(r => r.last_price, nameof(Row.last_price)); - public IDataGridColumnPersistentFilter last_size_filter { get; } = new UShortMinMax(r => r.last_size, nameof(Row.last_size)); + public IDataGridColumnPersistentFilter last_size_filter { get; } = new UIntMinMax(r => r.last_size, nameof(Row.last_size)); public IDataGridColumnPersistentFilter day_change_filter { get; } = new DoubleMinMax(r => r.day_change, nameof(Row.day_change)); public IDataGridColumnPersistentFilter settlement_filter { get; } = new DoubleMinMax(r => r.settlement, nameof(Row.settlement)); public IDataGridColumnPersistentFilter session_low_filter { get; } = new DoubleMinMax(r => r.session_low, nameof(Row.session_low)); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index 9cc4e3e94..46b4e2764 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -57,15 +57,15 @@ namespace bts.shell { [ProtoMember(2)] public DoubleMinMaxState bid_price; [ProtoMember(3)] - public UShortMinMaxState bid_size; + public UIntMinMaxState bid_size; [ProtoMember(4)] public DoubleMinMaxState ask_price; [ProtoMember(5)] - public UShortMinMaxState ask_size; + public UIntMinMaxState ask_size; [ProtoMember(6)] public DoubleMinMaxState last_price; [ProtoMember(7)] - public UShortMinMaxState last_size; + public UIntMinMaxState last_size; [ProtoMember(8)] public DoubleMinMaxState day_change; [ProtoMember(9)] diff --git a/src/client/spark/view/Spark/Ladder/LadderGridHost.cs b/src/client/spark/view/Spark/Ladder/LadderGridHost.cs index 3b241b30e..e226c8d12 100644 --- a/src/client/spark/view/Spark/Ladder/LadderGridHost.cs +++ b/src/client/spark/view/Spark/Ladder/LadderGridHost.cs @@ -1,4 +1,5 @@ using bts.api; +using bts.utils; using mbts.co2; using mbts.ui; using mbts.ui.controls; @@ -238,12 +239,12 @@ namespace mbts.spark { internal double price_for_point(Point point) => _price_for_row(_row_for_point(point)); - static ushort? _size_from_row(int row, double[] price_list, NativePriceSize[] depth, ContractSpecificationImmutable spec) { + static uint? _size_from_row(int row, double[] price_list, NativePriceSize[] depth, ContractSpecificationImmutable spec) { if (price_list == null || depth == null) return null; else return row <= price_list.Length ? _size_from_price(price_list[row], depth, spec) : null; } - static ushort? _size_from_price(double price, NativePriceSize[] depth, ContractSpecificationImmutable spec) { + static uint? _size_from_price(double price, NativePriceSize[] depth, ContractSpecificationImmutable spec) { if (!double.IsNaN(price) && depth.TryGetFirst(nps => spec.tick_equals(price, nps.price), out NativePriceSize result)) return result.size; return null; @@ -258,10 +259,10 @@ namespace mbts.spark { double _price_for_row(int row) => _price_list == null ? double.NaN : _price_list[row]; - ushort? _bid_size_from_row(int row) => + uint? _bid_size_from_row(int row) => _size_from_row(row, _price_list, _bids, _vm.security.ContractSpec); - ushort? _ask_size_from_row(int row) => + uint? _ask_size_from_row(int row) => _size_from_row(row, _price_list, _asks, _vm.security.ContractSpec); int _row_for_price(double price) => LadderRender.index_of(_price_list, price, _price_comparer); diff --git a/src/client/spark/view/Spark/Ladder/LaderRender.cs b/src/client/spark/view/Spark/Ladder/LaderRender.cs index 67afb3566..e85093b05 100644 --- a/src/client/spark/view/Spark/Ladder/LaderRender.cs +++ b/src/client/spark/view/Spark/Ladder/LaderRender.cs @@ -141,7 +141,7 @@ namespace mbts.spark { foreach (var nps in rungs) { if (nps.is_nan) break; double price = nps.price; - ushort size = nps.size; + uint size = nps.size; // prices are in descending order, so get diff from curr_price - price int tick_diff = TickUtils.normalized_tick_diff(spec, curr_price, price); curr_index += tick_diff; diff --git a/src/client/spark/view/Spark/Utilities/BBOVM.cs b/src/client/spark/view/Spark/Utilities/BBOVM.cs index 19eb1b2c9..ddf44404f 100644 --- a/src/client/spark/view/Spark/Utilities/BBOVM.cs +++ b/src/client/spark/view/Spark/Utilities/BBOVM.cs @@ -8,7 +8,7 @@ namespace mbts.spark { class BBOVM : DisposableViewModelBase { readonly Property _security; readonly Property _bid, _ask; - readonly Property _bid_size, _ask_size; + readonly Property _bid_size, _ask_size; public BBOVM(IObservable security_md) : this(security_md.Select(smd => smd.security).OnDispatcher(), new SecurityMDPump(security_md.Select(smd => smd.md))) { } @@ -17,14 +17,14 @@ namespace mbts.spark { _security = backing(nameof(security), security, SecurityDataHelper.Defaults.SecurityImmutable); _bid = backing(nameof(bid), md_pump.bid_price, double.NaN); _ask = backing(nameof(ask), md_pump.ask_price, double.NaN); - _bid_size = backing(nameof(bid_size), md_pump.bid_size, (ushort)0); - _ask_size = backing(nameof(ask_size), md_pump.ask_size, (ushort)0); + _bid_size = backing(nameof(bid_size), md_pump.bid_size, (uint)0); + _ask_size = backing(nameof(ask_size), md_pump.ask_size, (uint)0); } public SecurityImmutable security => _security.Value; public double bid => _bid.Value; public double ask => _ask.Value; - public ushort bid_size => _bid_size.Value; - public ushort ask_size => _ask_size.Value; + public uint bid_size => _bid_size.Value; + public uint ask_size => _ask_size.Value; } } \ No newline at end of file diff --git a/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs b/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs index 44dbd7e78..8648d226f 100644 --- a/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs +++ b/src/client/spark/view/Spark/Utilities/ISecurityMDPump.cs @@ -11,14 +11,14 @@ namespace mbts.spark.utilities { internal interface ISecurityMDPump { - IObservable<(double bid, ushort bid_size, double ask, ushort ask_size)> bbo { get; } - IObservable<(double last, ushort last_size, DateTime time_stamp, ulong volume)> last_trade { get; } + IObservable<(double bid, uint bid_size, double ask, uint ask_size)> bbo { get; } + IObservable<(double last, uint last_size, DateTime time_stamp, ulong volume)> last_trade { get; } IObservable bid_price { get; } - IObservable bid_size { get; } + IObservable bid_size { get; } IObservable ask_price { get; } - IObservable ask_size { get; } + IObservable ask_size { get; } IObservable last_price { get; } - IObservable last_size { get; } + IObservable last_size { get; } IObservable volume { get; } IObservable session_low { get; } IObservable session_high { get; } @@ -59,7 +59,7 @@ namespace mbts.spark.utilities private ulong _bbo_ref, _last_ref; private double _bid_price, _ask_price, _last_price; - private ushort _bid_size, _ask_size, _last_size; + private uint _bid_size, _ask_size, _last_size; private ulong _volume; private DateTime _last_time; @@ -85,17 +85,17 @@ namespace mbts.spark.utilities return false; } - private (double, ushort, double, ushort) _select_bbo() { return (_bid_price, _bid_size, _ask_price, _ask_size); } - private (double, ushort, DateTime, ulong) _select_last() { return (_last_price, _last_size, _last_time, _volume); } + private (double, uint, double, uint) _select_bbo() { return (_bid_price, _bid_size, _ask_price, _ask_size); } + private (double, uint, DateTime, ulong) _select_last() { return (_last_price, _last_size, _last_time, _volume); } - public IObservable<(double bid, ushort bid_size, double ask, ushort ask_size)> bbo => _bbo_pump.Select(_ => _select_bbo()).StartWith(_select_bbo()); - public IObservable<(double last, ushort last_size, DateTime time_stamp, ulong volume)> last_trade => _last_pump.Select(_ => _select_last()).StartWith(_select_last()); + public IObservable<(double bid, uint bid_size, double ask, uint ask_size)> bbo => _bbo_pump.Select(_ => _select_bbo()).StartWith(_select_bbo()); + public IObservable<(double last, uint last_size, DateTime time_stamp, ulong volume)> last_trade => _last_pump.Select(_ => _select_last()).StartWith(_select_last()); public IObservable bid_price => _bbo_pump.Select(_ => _bid_price).DistinctUntilChanged().StartWith(_bid_price); - public IObservable bid_size => _bbo_pump.Select(_ => _bid_size).DistinctUntilChanged().StartWith(_bid_size); + public IObservable bid_size => _bbo_pump.Select(_ => _bid_size).DistinctUntilChanged().StartWith(_bid_size); public IObservable ask_price => _bbo_pump.Select(_ => _ask_price).DistinctUntilChanged().StartWith(_ask_price); - public IObservable ask_size => _bbo_pump.Select(_ => _ask_size).DistinctUntilChanged().StartWith(_ask_size); + public IObservable ask_size => _bbo_pump.Select(_ => _ask_size).DistinctUntilChanged().StartWith(_ask_size); public IObservable last_price => _bbo_pump.Select(_ => _last_price).DistinctUntilChanged().StartWith(_last_price); - public IObservable last_size => _bbo_pump.Select(_ => _last_size).DistinctUntilChanged().StartWith(_last_size); + public IObservable last_size => _bbo_pump.Select(_ => _last_size).DistinctUntilChanged().StartWith(_last_size); public IObservable last_time => _last_pump.Select(_ => _last_time).DistinctUntilChanged().StartWith(_last_time); public IObservable volume => _last_pump.Select(_ => _volume).DistinctUntilChanged().StartWith(_volume); public IObservable session_low => _root_pump.Select(md => md.session_low).DistinctUntilChanged(); From c4c8bb6f5e6d31be46d139303029b50595945ec1 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 31 Aug 2018 10:35:58 -0400 Subject: [PATCH 7/8] SPARK-1574 Fix manaaged market data for new layout --- src/client/spark_core/Co2/MDConsumerHandle.cs | 164 ++++++------- src/client/spark_core/Co2/PriceSize.cs | 220 +++++++++--------- src/client/spark_core/spark_core.csproj | 1 + src/client/spark_test/Co2/Co2Tests.cs | 25 +- src/client/sparkcmd/sparkcmd.csproj | 2 +- src/lib/md/PriceSize.h | 12 +- src/lib/md/Shm/MDStructure.h | 10 +- src/lib/md/test/Co2ManagedTestHelper.cpp | 1 + 8 files changed, 196 insertions(+), 239 deletions(-) diff --git a/src/client/spark_core/Co2/MDConsumerHandle.cs b/src/client/spark_core/Co2/MDConsumerHandle.cs index c397f3aed..9158a5d72 100644 --- a/src/client/spark_core/Co2/MDConsumerHandle.cs +++ b/src/client/spark_core/Co2/MDConsumerHandle.cs @@ -30,18 +30,18 @@ namespace mbts.co2 // This property exists for specific performance optimization purposes // Most callers should just use get_bbo/get_depth - public ulong market_timestamp { get { return has_depth ? _hot_depth->timestamp : _hot->timestamp; } } + public ulong market_timestamp { get { return has_depth ? _hot_depth->timestamp.time : _hot->timestamp.time; } } public bool get_bbo(ref ulong time, out NativePriceSize bid, out NativePriceSize ask) { var updated = market_timestamp; - if (updated > time && updated != UInt64.MaxValue) { + if (updated > time && updated != TimeStamp.invalid_value) { if (has_depth) { bid = _hot_depth->bid(0); ask = _hot_depth->ask(0); } else { - bid = _hot->bid.load(); - ask = _hot->ask.load(); + bid = _hot->book.bid; + ask = _hot->book.ask; } time = updated; return true; @@ -71,35 +71,10 @@ namespace mbts.co2 return false; } - public bool get_customer_bbo(ref ulong time, out NativePriceSize customer_bid, out NativePriceSize customer_ask) { - var updated = _cold->customer_bbo_updated; - if (updated > time) { - time = updated; - customer_bid = _cold->customer_bid.load(); - customer_ask = _cold->customer_ask.load(); - return true; - } - customer_bid = customer_ask = NativePriceSize.no_market; - return false; - } - - // This property is for specific optimization purposes - // you should probably just call get_last_trade() - public ulong trade_timestamp { get { return _cold->last_trade_updated; } } public bool get_last_trade(ref ulong time, out NativePriceSize ps, out DateTime timestamp, out ulong total_volume) { - var updated = _cold->last_trade_updated; - if (updated > time) { - time = updated; - timestamp = _cold->last_trade_time; - timestamp = timestamp.ToUniversalTime(); - ps = _cold->last_trade.load(); - total_volume = _cold->total_volume; - return true; - } - ps = NativePriceSize.no_market; - timestamp = new utils.LLDateTime(); - total_volume = 0; - return false; + timestamp = _cold->last_trade_time; + total_volume = _cold->total_volume; + return (_cold->last_trade.load_if_new(ref time, out ps)); } public ulong misc_timestamp { get { return _cold->misc_timestamp; } } @@ -157,96 +132,86 @@ namespace mbts.co2 [StructLayout(LayoutKind.Sequential)] internal struct HotEntry { - // I don't actually need to decode timestamp. If it goes up data has changed - public readonly UInt64 timestamp; - public readonly AtomicPriceSizeStore bid; - public readonly AtomicPriceSizeStore ask; - public readonly security_key key; - public readonly UInt16 sequence; - public readonly byte _status; + // we don't actually need to decode timestamp. If it goes up data has changed + public readonly TimeStamp timestamp; // 8 + public readonly NativePriceLevel book; // 24 + public readonly security_key key; // 4 + public readonly UInt32 sequence; // 4 + public readonly byte _status; // 1 + public CoconutSecurityStatus status { get { return (CoconutSecurityStatus)_status; } } } - [StructLayout(LayoutKind.Sequential, Size = 192)] + [StructLayout(LayoutKind.Sequential)] internal struct HotDepthEntry { - public readonly UInt64 timestamp; - public readonly security_key key; + public readonly TimeStamp timestamp; // 8 + public readonly security_key key; // 4 + public readonly UInt32 sequence; // 4 + + // The ByValArray type would be more elegant but it does not allocate inline. + // [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] + + // 10 direct levels + private readonly NativePriceLevel direct0; + private readonly NativePriceLevel direct1; + private readonly NativePriceLevel direct2; + private readonly NativePriceLevel direct3; + private readonly NativePriceLevel direct4; + private readonly NativePriceLevel direct5; + private readonly NativePriceLevel direct6; + private readonly NativePriceLevel direct7; + private readonly NativePriceLevel direct8; + private readonly NativePriceLevel direct9; + // 2 implied levels + private readonly NativePriceLevel implied0; + private readonly NativePriceLevel implied1; private readonly byte _status; + + public CoconutSecurityStatus status { get { return (CoconutSecurityStatus)_status; } } public NativePriceSize bid(int depth) { switch (depth) { - case 0: return bid0.load(); - case 1: return bid1.load(); - case 2: return bid2.load(); - case 3: return bid3.load(); - case 4: return bid4.load(); - case 5: return bid5.load(); - case 6: return bid6.load(); - case 7: return bid7.load(); - case 8: return bid8.load(); - case 9: return bid9.load(); + case 0: return direct0.bid; + case 1: return direct1.bid; + case 2: return direct2.bid; + case 3: return direct3.bid; + case 4: return direct4.bid; + case 5: return direct5.bid; + case 6: return direct6.bid; + case 7: return direct7.bid; + case 8: return direct8.bid; + case 9: return direct9.bid; default: throw new ArgumentException("depth"); } } public NativePriceSize ask(int depth) { switch (depth) { - case 0: return ask0.load(); - case 1: return ask1.load(); - case 2: return ask2.load(); - case 3: return ask3.load(); - case 4: return ask4.load(); - case 5: return ask5.load(); - case 6: return ask6.load(); - case 7: return ask7.load(); - case 8: return ask8.load(); - case 9: return ask9.load(); + case 0: return direct0.ask; + case 1: return direct1.ask; + case 2: return direct2.ask; + case 3: return direct3.ask; + case 4: return direct4.ask; + case 5: return direct5.ask; + case 6: return direct6.ask; + case 7: return direct7.ask; + case 8: return direct8.ask; + case 9: return direct9.ask; default: throw new ArgumentException("depth"); } } - private AtomicPriceSizeStore bid0; - private AtomicPriceSizeStore ask0; - private AtomicPriceSizeStore bid1; - private AtomicPriceSizeStore ask1; - private AtomicPriceSizeStore bid2; - private AtomicPriceSizeStore ask2; - private AtomicPriceSizeStore bid3; - private AtomicPriceSizeStore ask3; - private AtomicPriceSizeStore bid4; - private AtomicPriceSizeStore ask4; - private AtomicPriceSizeStore bid5; - private AtomicPriceSizeStore ask5; - private AtomicPriceSizeStore bid6; - private AtomicPriceSizeStore ask6; - private AtomicPriceSizeStore bid7; - private AtomicPriceSizeStore ask7; - private AtomicPriceSizeStore bid8; - private AtomicPriceSizeStore ask8; - private AtomicPriceSizeStore bid9; - private AtomicPriceSizeStore ask9; - - // This would look much more elegant but it only works by marshaling magic - the layout in memory is not contiguous - // [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] - // public PriceSize[] book = new PriceSize[20]; - public readonly UInt16 sequence; } - [StructLayout(LayoutKind.Sequential, Size = 408)] + [StructLayout(LayoutKind.Sequential, Size = 392)] internal struct ColdEntry { public int exchange_status; // Last trade - public UInt64 last_trade_updated; - public AtomicPriceSizeStore last_trade; + public AtomicPriceSize last_trade; public ulong total_volume; public utils.LLDateTime last_trade_time; - //// Customer BBO - public UInt64 customer_bbo_updated; - public AtomicPriceSizeStore customer_bid; - public AtomicPriceSizeStore customer_ask; - //// Settlement public UInt64 misc_timestamp; public double settlement_price; @@ -278,11 +243,12 @@ namespace mbts.co2 [StructLayout(LayoutKind.Sequential)] internal struct ColdHeader { + internal uint version; internal ulong count; internal ulong segment_count; - internal ulong create_time; - internal ulong heartbeat; + internal TimeStamp create_time; + internal TimeStamp heartbeat; internal bool disable_heartbeat; internal uint heartbeat_ms; internal uint heartbeat_boot_seconds; @@ -294,7 +260,9 @@ namespace mbts.co2 internal ulong coconut_status_count; // atomic internal ulong exchange_status_count; // atomic internal ulong rfq_count; // atomic - internal ulong customer_bbo_count; // atomic + internal ulong gap_count; // atomic + + // trade_buffer, rfq_buffer are not addressable } diff --git a/src/client/spark_core/Co2/PriceSize.cs b/src/client/spark_core/Co2/PriceSize.cs index c8dce89e2..b73439e42 100644 --- a/src/client/spark_core/Co2/PriceSize.cs +++ b/src/client/spark_core/Co2/PriceSize.cs @@ -8,25 +8,45 @@ using System.Threading.Tasks; namespace mbts.co2 { - public struct NativePriceSize : IEquatable - { - [StructLayout(LayoutKind.Explicit)] - private struct PriceSizeUnion - { - [FieldOffset(0)] - public UInt64 data; - [FieldOffset(0)] - public Int64 price; - [FieldOffset(5)] - public sbyte exponent; - [FieldOffset(6)] - public UInt16 size; - } - static NativePriceSize() { - Logger.assert(Marshal.SizeOf(typeof(PriceSizeUnion)) == 8); + [StructLayout(LayoutKind.Explicit)] + public readonly struct NativePriceLevel { + [FieldOffset(0)] + readonly Int64 _mantissa_b; // : 56; + [FieldOffset(7)] + readonly sbyte _exponent_b; // : 8; + [FieldOffset(8)] + readonly Int64 _mantissa_a; // : 56; + [FieldOffset(15)] + readonly sbyte _exponent_a; //: 8; + [FieldOffset(16)] + readonly UInt32 _size_b; + [FieldOffset(20)] + readonly UInt32 _size_a; + + long decode(long m) { + long mantissa = m & 0xFFFFFFFFFFFFFF; + // If the 56th bit is set this is negative + const long bit56 = 0x80000000000000; + if ((mantissa & bit56) != 0) { + mantissa = -1 * (((~mantissa) & (bit56 - 1)) + 1); + } + return mantissa; } + // todo: will this strip sign bit? + public Int64 bid_mantissa => decode(_mantissa_b); + public sbyte bid_exponent => _exponent_b; + public Int64 ask_mantissa => decode(_mantissa_a); + public sbyte ask_exponent => _exponent_a; + public UInt32 bid_size => _size_b; + public UInt32 ask_size => _size_a; + + public NativePriceSize bid => new NativePriceSize(bid_mantissa, bid_exponent, bid_size); + public NativePriceSize ask => new NativePriceSize(ask_mantissa, ask_exponent, ask_size); + } + + public static class NativePriceSizeHelpers { static double[] s_powers10 = { 1E-20, 1E-19, 1E-18, 1E-17, 1E-16, 1E-15, 1E-14, 1E-13, 1E-12, 1E-11, 1E-10, 1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3, 1E-2, 1E-1, 1E0, @@ -34,7 +54,7 @@ namespace mbts.co2 }; static int s_max_abs_pow10 = s_powers10.Length/2; - private double pow10(int power) { + public static double pow10(int power) { int offset = power + s_max_abs_pow10; Logger.assert_d(offset >= 0 && offset < s_powers10.Length); if (offset >= 0 && offset < s_powers10.Length) { @@ -42,84 +62,44 @@ namespace mbts.co2 } return double.NaN; } + } - internal NativePriceSize(UInt64 value) { - // appease the compiler - _value.price = 0; - _value.size = 0; - _value.exponent = 0; - // actual initialization - _value.data = value; - } - private static void compact_mantissa(ref Int64 mantissa, ref sbyte exponent) { - while (mantissa > 0x8000000000 || mantissa < -0x8000000000) { - mantissa /= 10; - exponent += 1; - } - } - public NativePriceSize(Int64 price, sbyte exponent, UInt16 size) { - _value.data = 0;//appeasement - compact_mantissa(ref price, ref exponent); - if (price >= 0) { - _value.price = price & 0x7FFFFFFFFF; - } - else { - _value.price = 0x8000000000 | (price & 0x7FFFFFFFFF); - } - _value.exponent = exponent; - _value.size = size; + public readonly struct NativePriceSize : IEquatable + { + public NativePriceSize(Int64 mantissa, sbyte exponent, uint size) { + this.mantissa = mantissa; + this.exponent = exponent; + this.size = size; } - public static NativePriceSize no_market = new NativePriceSize(0, -128, 0); + public static NativePriceSize no_market = new NativePriceSize(0, 0, 0); - public Int64 mantissa { - get { - Int64 price = _value.price & 0xFFFFFFFFFF; - // If the 40th bit is set it's negative - if ((price & 0x8000000000) != 0) { - // Take the 2s compliment of the first 39 bits then negate - price = -1 * (((~_value.price) & 0x7FFFFFFFFF) + 1); - } - return price; - } - } - public sbyte exponent { - get { - return _value.exponent; - } - } + public Int64 mantissa { get; } + public sbyte exponent {get;} - public double price { - get { - if (_value.exponent == -128) return double.NaN; - return mantissa * pow10(_value.exponent); - } - } + public double price => (is_nan) ? double.NaN : mantissa * NativePriceSizeHelpers.pow10(exponent); - public bool is_nan { - get { - return _value.data == no_market._value.data; - } - } + public bool is_nan => this == no_market; - public ushort size { get { return _value.size; } } - public UInt64 raw { get { return _value.data; } } + public uint size { get; } public override string ToString() { return "{0:0.00} {1}".fmt(price, size); } public override bool Equals(object obj) { - if (obj is NativePriceSize) return Equals((NativePriceSize)obj); + if (obj is NativePriceSize p) return Equals(p); return base.Equals(obj); } public override int GetHashCode() { - return _value.data.GetHashCode(); + return bts.utils.EqualityComparer.aggregate_hash(mantissa.GetHashCode(), exponent.GetHashCode(), size.GetHashCode()); } public bool Equals(NativePriceSize other) { - return _value.data == other._value.data; + return size == other.size && + mantissa == other.mantissa && + exponent == other.exponent; } public static bool operator ==(NativePriceSize a, NativePriceSize b) { return a.Equals(b); @@ -127,76 +107,86 @@ namespace mbts.co2 public static bool operator !=(NativePriceSize a, NativePriceSize b) { return !a.Equals(b); } - - private PriceSizeUnion _value; } - internal struct AtomicPriceSizeStore - { - UInt64 _value; - bool store(NativePriceSize ps) { - bool result = _value != ps.raw; - _value = ps.raw; - return result; - } + struct TimeStamp { + Int64 _value; + public UInt64 time => (UInt64)Interlocked.Read(ref _value); + public static UInt64 invalid_value => UInt64.MaxValue; + } - public NativePriceSize load() { - return new NativePriceSize(_value); + // This type cannot be generic because we will get error CS0208 + //internal struct Optimistic where T : struct {... + internal struct AtomicPriceSize { + TimeStamp _time; + NativePriceSize _value; + void store(NativePriceSize nps) { + _time = new TimeStamp(); + _value = new NativePriceSize(); + throw new NotImplementedException(); + } + public (UInt64 time, NativePriceSize value) load() { + UInt64 temp; + NativePriceSize result; + int attempts = 0; + do { + ++attempts; + temp = _time.time; + result = _value; + } while ((temp != _time.time || temp == TimeStamp.invalid_value) && attempts < 1619200); + return (temp, result); + } + public bool load_if_new(ref UInt64 time, out NativePriceSize t) { + if (_time.time > time || _time.time == TimeStamp.invalid_value) { + (time, t) = load(); + return (time != TimeStamp.invalid_value); + } + t = NativePriceSize.no_market; + return false; } } public struct PriceSize : IEquatable { - readonly double _price; - readonly uint _size; - public PriceSize(double price, uint size) { - _price = price; - _size = size; + this.price = price; + this.size = size; } - public PriceSize(NativePriceSize nps) - { - _price = nps.is_nan ? double.NaN : nps.price; - _size = nps.size; + public PriceSize(NativePriceSize nps) { + price = nps.price; + size = nps.size; } - public static implicit operator PriceSize(NativePriceSize nps) - { + public static implicit operator PriceSize(NativePriceSize nps) { return new PriceSize(nps); } public static PriceSize no_market = NativePriceSize.no_market; - public double price { get { return _price; } } - public uint size { get { return _size; } } + public double price { get; } + public uint size { get; } - public override string ToString() - { + public override string ToString() { return "{0:0.00} {1}".fmt(price, size); } - public override bool Equals(object obj) - { - if(obj is PriceSize) return Equals((PriceSize)obj); + public override bool Equals(object obj) { + if (obj is PriceSize p) return Equals(p); return base.Equals(obj); } - public override int GetHashCode() - { - return _price.GetHashCode() ^ _size.GetHashCode(); + public override int GetHashCode() { + return bts.utils.EqualityComparer.aggregate_hash(price.GetHashCode(), size.GetHashCode()); } - public bool Equals(PriceSize other) - { - return _price == other.price && _size == other.size; + public bool Equals(PriceSize other) { + return price == other.price && size == other.size; } - public static bool operator ==(PriceSize a, PriceSize b) - { + public static bool operator ==(PriceSize a, PriceSize b) { return a.Equals(b); } - public static bool operator !=(PriceSize a, PriceSize b) - { + public static bool operator !=(PriceSize a, PriceSize b) { return !a.Equals(b); } } diff --git a/src/client/spark_core/spark_core.csproj b/src/client/spark_core/spark_core.csproj index aae48cd35..4514324d0 100644 --- a/src/client/spark_core/spark_core.csproj +++ b/src/client/spark_core/spark_core.csproj @@ -8,6 +8,7 @@ true 1.0.0 + 7.2 diff --git a/src/client/spark_test/Co2/Co2Tests.cs b/src/client/spark_test/Co2/Co2Tests.cs index 5371dcefd..350179374 100644 --- a/src/client/spark_test/Co2/Co2Tests.cs +++ b/src/client/spark_test/Co2/Co2Tests.cs @@ -39,7 +39,7 @@ namespace mbts.co2.tests Assert.IsTrue(ps.size == 100); // Oversized value - ps = new NativePriceSize(2030000000000, -9, 1); + ps = new NativePriceSize(203000000000, -8, 1); Assert.AreEqual(ps.price, 2030); Assert.IsTrue(ps.size == 1); @@ -54,14 +54,15 @@ namespace mbts.co2.tests var entry = new MDConsumerHandle.HotEntry(); Co2NativeTestMethods.co2_get_sample_hot(out size, ref entry); Assert.IsTrue(size == (ulong)Marshal.SizeOf(entry)); - Assert.IsTrue(entry.timestamp > 0); - var bid = entry.bid.load(); - var ask = entry.ask.load(); + Assert.IsTrue(entry.timestamp.time > 0); + var bid = entry.book.bid; + var ask = entry.book.ask; Assert.IsTrue(bid.price == 7.2); Assert.IsTrue(bid.size == 101); - Assert.IsTrue(ask.price.ToString("0.00") == "-9.70"); + Assert.IsTrue(ask.size == 245); + Assert.AreEqual(ask.price.ToString("0.00"), "-9.70"); Assert.IsTrue(entry.status == CoconutSecurityStatus.PacketLoss); Assert.IsTrue(entry.key == 1234); Assert.IsTrue(entry.sequence == 777); @@ -106,8 +107,8 @@ namespace mbts.co2.tests Assert.AreEqual(entry_size, (ulong)Marshal.SizeOf(entry), "If this test fails it's probably due to an addition to the FixedSecurity struct in FixedSecurity.h"); // Last trade - Assert.IsTrue(entry.last_trade_updated > 0); - var last = entry.last_trade.load(); + (var time, var last) = entry.last_trade.load(); + Assert.IsTrue(time > 0); Assert.IsTrue(last.price == 4.2); Assert.IsTrue(last.size == 101); Assert.IsTrue(entry.total_volume == 12345); @@ -138,8 +139,8 @@ namespace mbts.co2.tests var header = new MDConsumerHandle.ColdHeader(); Co2NativeTestMethods.co2_get_sample_cold_header(ref header); Assert.IsTrue(header.segment_count == 1); - Assert.IsTrue(header.create_time > 0); - Assert.IsTrue(header.heartbeat > 0); + Assert.IsTrue(header.create_time.time > 0); + Assert.IsTrue(header.heartbeat.time > 0); Assert.IsTrue(header.security_count == 77000); Assert.IsTrue(header.has_depth == true); Assert.IsTrue(header.platform == Platform.Sim); @@ -147,7 +148,7 @@ namespace mbts.co2.tests Assert.IsTrue(header.coconut_status_count == 101); Assert.IsTrue(header.exchange_status_count == 102); Assert.IsTrue(header.rfq_count == 103); - Assert.IsTrue(header.customer_bbo_count == 104); + Assert.IsTrue(header.gap_count == 104); } [Test,Ignore("")] @@ -208,10 +209,6 @@ namespace mbts.co2.tests Assert.IsTrue(ask.price == 2.2); Assert.IsTrue(ask.size == 202); - time = 0; - Assert.IsTrue(handle.get_customer_bbo(ref time, out bid, out ask)); - Assert.IsTrue(fmt(bid.price) == fmt(3.3) && bid.size == 303); - Assert.IsTrue(ask.price == 4.4 && ask.size == 404); time = 0; DateTime trade_date; ulong total_volume; diff --git a/src/client/sparkcmd/sparkcmd.csproj b/src/client/sparkcmd/sparkcmd.csproj index 1c40c63e4..2c2241ba3 100644 --- a/src/client/sparkcmd/sparkcmd.csproj +++ b/src/client/sparkcmd/sparkcmd.csproj @@ -4,7 +4,7 @@ Exe net471 - win7-x64;ubuntu.16.04-x64;win7-x86 + win7-x64;ubuntu.16.04-x64 Blue Trading Systems Blue Trading Systems Spark diff --git a/src/lib/md/PriceSize.h b/src/lib/md/PriceSize.h index 05374b628..2b33551e3 100644 --- a/src/lib/md/PriceSize.h +++ b/src/lib/md/PriceSize.h @@ -149,14 +149,14 @@ struct PriceLevel { {} #ifdef _WIN32 - int64_t _mantissa_b : 54; + int64_t _mantissa_b : 56; int64_t _exponent_b : 8; - int64_t _mantissa_a : 54; + int64_t _mantissa_a : 56; int64_t _exponent_a : 8; #else - int64_t _mantissa_b : 54; + int64_t _mantissa_b : 56; int8_t _exponent_b : 8; - int64_t _mantissa_a : 54; + int64_t _mantissa_a : 56; int8_t _exponent_a : 8; #endif uint32_t _size_b; @@ -164,8 +164,8 @@ struct PriceLevel { uint64_t bid_mantissa() const { return _mantissa_b; } uint64_t ask_mantissa() const { return _mantissa_a; } - uint8_t bid_exponent() const { return _exponent_b; } - uint8_t ask_exponent() const { return _exponent_a; } + int8_t bid_exponent() const { return _exponent_b; } + int8_t ask_exponent() const { return _exponent_a; } uint32_t bid_size() const { return _size_b; } uint32_t ask_size() const { return _size_a; } diff --git a/src/lib/md/Shm/MDStructure.h b/src/lib/md/Shm/MDStructure.h index 177235ea9..c9fa769ac 100644 --- a/src/lib/md/Shm/MDStructure.h +++ b/src/lib/md/Shm/MDStructure.h @@ -65,11 +65,11 @@ class HotDepthEntry { status(co2::COCONUTSECURITYSTATUS_OK) { } uint32_t size() const { return sizeof(HotDepthEntry); } - security_key key; // 4 NOTE: key is at a different offset than it is in HotEntry - uint32_t sequence; // 4 - std::array implied; - std::array direct; - uint8_t status; // 1 + security_key key; // 4 NOTE: key is at a different offset than it is in HotEntry + uint32_t sequence; // 4 + std::array direct; // 240 + std::array implied; // 48 + uint8_t status; // 1 const PriceLevel* at(uint32_t depth) const { if (depth < direct.size()) { diff --git a/src/lib/md/test/Co2ManagedTestHelper.cpp b/src/lib/md/test/Co2ManagedTestHelper.cpp index b0444b350..4e70bd215 100644 --- a/src/lib/md/test/Co2ManagedTestHelper.cpp +++ b/src/lib/md/test/Co2ManagedTestHelper.cpp @@ -97,6 +97,7 @@ extern "C" BTS_EXPORT void co2_get_sample_cold_header(ColdHeader& header) { header.coconut_status_count = 101; header.exchange_status_count = 102; header.rfq_count = 103; + header.gap_count = 104; // Do not write to trade_buffer or rfq_buffer } From b4a8cf0cff916a1d0e6dada4a6cb1be167193f42 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 31 Aug 2018 17:37:03 -0400 Subject: [PATCH 8/8] SPARK-1574 code review feedback --- src/client/spark_core/Co2/Co2NativeMethods.cs | 3 +++ src/client/spark_core/Co2/PriceSize.cs | 2 +- src/client/spark_test/Co2/Co2Tests.cs | 17 +++++++++++++++++ src/lib/md/test/Co2ManagedTestHelper.cpp | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/client/spark_core/Co2/Co2NativeMethods.cs b/src/client/spark_core/Co2/Co2NativeMethods.cs index 7b83a9e28..e32741403 100644 --- a/src/client/spark_core/Co2/Co2NativeMethods.cs +++ b/src/client/spark_core/Co2/Co2NativeMethods.cs @@ -110,5 +110,8 @@ namespace mbts.co2 [DllImport("libspark")] internal static extern void co2_destroy_test_md(IntPtr handle); + [DllImport("libspark")] + internal static extern void co2_get_zero_and_nan_book(ref NativePriceLevel nps); + } } diff --git a/src/client/spark_core/Co2/PriceSize.cs b/src/client/spark_core/Co2/PriceSize.cs index 2318b922d..8f1e14e9f 100644 --- a/src/client/spark_core/Co2/PriceSize.cs +++ b/src/client/spark_core/Co2/PriceSize.cs @@ -30,12 +30,12 @@ namespace mbts.co2 // If the 56th bit is set this is negative const long bit56 = 0x80000000000000; if ((mantissa & bit56) != 0) { + // Compute 2's compliment manually mantissa = -1 * (((~mantissa) & (bit56 - 1)) + 1); } return mantissa; } - // todo: will this strip sign bit? public Int64 bid_mantissa => decode(_mantissa_b); public sbyte bid_exponent => _exponent_b; public Int64 ask_mantissa => decode(_mantissa_a); diff --git a/src/client/spark_test/Co2/Co2Tests.cs b/src/client/spark_test/Co2/Co2Tests.cs index 350179374..4d852861f 100644 --- a/src/client/spark_test/Co2/Co2Tests.cs +++ b/src/client/spark_test/Co2/Co2Tests.cs @@ -235,5 +235,22 @@ namespace mbts.co2.tests } } + [Test] + public void price_size_nan() { + NativePriceLevel npl = new NativePriceLevel(); + Assert.IsTrue(npl.bid.is_nan); + Assert.IsTrue(double.IsNaN(npl.bid.price)); + Assert.IsTrue(npl.ask.is_nan); + Assert.IsTrue(double.IsNaN(npl.ask.price)); + + Co2NativeTestMethods.co2_get_zero_and_nan_book(ref npl); + Assert.AreEqual(npl.ask.price, 0); + Assert.AreEqual(npl.ask.size, 1u); + Assert.AreEqual(npl.bid.size, 0u); + Assert.IsTrue(npl.bid.is_nan); + Assert.IsTrue(double.IsNaN(npl.bid.price)); + } + + } } diff --git a/src/lib/md/test/Co2ManagedTestHelper.cpp b/src/lib/md/test/Co2ManagedTestHelper.cpp index 4e70bd215..7e11ecd18 100644 --- a/src/lib/md/test/Co2ManagedTestHelper.cpp +++ b/src/lib/md/test/Co2ManagedTestHelper.cpp @@ -137,6 +137,10 @@ extern "C" BTS_EXPORT void co2_destroy_test_md(MDProducer* producer) { config::internal::reset(); } +extern "C" BTS_EXPORT void co2_get_zero_and_nan_book(PriceLevel& price) { + price = { PriceSize::NO_MARKET, PriceSize::from_double<7>(0,1) }; +} + }}}//namespace #endif