From f6b5635715693cc03e224a272a082774e35ed4ea Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 5 Oct 2018 15:45:42 -0400 Subject: [PATCH 01/14] SPARK-1659 packet may contain implied or direct or both. need to preserve the other market. --- src/lib/md/Diag/ShmDumper.cpp | 10 +++---- src/lib/md/PriceSize.h | 2 +- .../md/platforms/mdp3_onixs/MDP3Listener.cpp | 26 +++++++++++++------ .../md/platforms/mdp3_onixs/MDP3Listener.h | 24 +++++++++++------ 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/lib/md/Diag/ShmDumper.cpp b/src/lib/md/Diag/ShmDumper.cpp index b60bbb98d..914f58897 100644 --- a/src/lib/md/Diag/ShmDumper.cpp +++ b/src/lib/md/Diag/ShmDumper.cpp @@ -163,31 +163,31 @@ string dump_entry(const HotDepthEntry& entry) { res << "'timestamp': " << dump(entry.time()) << ", "; res << "'key': " << entry.key << ", "; - res << "'bid': ["; + res << "\n'bid': ["; for (const auto& level : entry.direct) { res << dump(level.bid()) << ", "; } res << "], "; - res << "'ask': ["; + res << "\n'ask': ["; for (const auto& level : entry.direct) { res << dump(level.ask()) << ", "; } res << "], "; - res << "'implied_bid': ["; + res << "'\nimplied_bid': ["; for (const auto& level : entry.implied) { res << dump(level.bid()) << ", "; } res << "], "; - res << "'implied_ask': ["; + res << "'\nimplied_ask': ["; for (const auto& level : entry.implied) { res << dump(level.ask()) << ", "; } res << "], "; - res << "'settlement': '" << dump(entry.settlement) << "', "; + res << "\n'settlement': '" << dump(entry.settlement) << "', "; res << "'status': '" << CoconutSecurityStatus_Name((CoconutSecurityStatus)entry.status) << "', "; res << "'sequence': '" << entry.sequence << "', "; res << " }"; diff --git a/src/lib/md/PriceSize.h b/src/lib/md/PriceSize.h index fc78701fd..c8b647d39 100644 --- a/src/lib/md/PriceSize.h +++ b/src/lib/md/PriceSize.h @@ -32,7 +32,7 @@ class PriceSize { public: PriceSize(IntPrice price, Size size) : - _price(price), + _price(size == 0 ? INT_NAN : price), _size(size), _direct_size(size) { } diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.cpp b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.cpp index 0acd2b757..de7fd2d39 100644 --- a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.cpp +++ b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.cpp @@ -113,11 +113,11 @@ void MDP3Listener::onEndOfPacket(onixs::Handler&, const onixs::PacketArgs&) { // Security discovery void MDP3Listener::onBookUpdate(onixs::Handler&, const onixs::Security& sec, const onixs::DirectBook& book) { - onBookUpdate(sec, book); + onBookUpdate(sec, book, book_type_direct); } void MDP3Listener::onBookUpdate(onixs::Handler&, const onixs::Security& sec, const onixs::ImpliedBook& book) { - onBookUpdate(sec, book); + onBookUpdate(sec, book, book_type_implied); } // @@ -239,11 +239,21 @@ void MDP3Listener::flush_books() { // This is called at the end of the packet // Write all book updates to shared memory and reset for the next packet for (auto& entry : _book_updates) { - uint16_t sequence = (_latest_sequence & 0xFFFF); - entry.handle.update_books(_packet_arrived, - entry.bids.first, entry.asks.first, - entry.bids.second, entry.asks.second, - sequence); + uint32_t sequence = _latest_sequence; + if (entry.type_flags == book_type_direct) { + entry.handle.update_direct(_packet_arrived, + entry.bids.first, entry.asks.first, sequence); + } + else if (entry.type_flags == book_type_implied) { + entry.handle.update_implied(_packet_arrived, + entry.bids.second, entry.asks.second, sequence); + } + else if (entry.type_flags == book_type_both) { + entry.handle.update_books(_packet_arrived, + entry.bids.first, entry.asks.first, + entry.bids.second, entry.asks.second, + sequence); + } } // Reset pending updates _book_updates.clear(); @@ -255,7 +265,7 @@ void MDP3Listener::update_all_status(CoconutSecurityStatus status) { }); } -md::MDP3Listener::BookData::BookData(MDProducerHandle & handle) : handle(handle), bids(), asks() { } +md::MDP3Listener::BookData::BookData(MDProducerHandle & handle) : handle(handle), type_flags(0), bids(), asks() { } }}//namespace diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.h b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.h index 6c53abdd7..f0dfb43f6 100644 --- a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.h +++ b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Listener.h @@ -23,6 +23,11 @@ class MDP3Listener : public onixs::MarketDataListener, public onixs::SecurityListener { + typedef uint32_t BookType; + static constexpr BookType book_type_direct=1; + static constexpr BookType book_type_implied=2; + static constexpr BookType book_type_both=(book_type_direct|book_type_implied); + public: MDP3Listener(CMESecurityIndex& index, MDProducer&, @@ -76,7 +81,7 @@ public: // void onBookUpdate(onixs::Handler&, const onixs::Security&, const onixs::ConsolidatedBook&) override; template - void onBookUpdate(const onixs::Security& sec, const TBook& book); + void onBookUpdate(const onixs::Security& sec, const TBook& book, BookType booktype); // // Trades @@ -197,7 +202,7 @@ private: struct BookData { BookData(MDProducerHandle& handle); MDProducerHandle handle; - + BookType type_flags; std::pair, std::array> bids; std::pair, std::array> asks; }; @@ -352,7 +357,7 @@ void MDP3Listener::onSpread(onixs::Handler&, const onixs::Security&, const Instr } template -void MDP3Listener::onBookUpdate(const onixs::Security& sec, const TBook& onixs_book) { +void MDP3Listener::onBookUpdate(const onixs::Security& sec, const TBook& onixs_book, BookType booktype) { tracepoint (bts_trace,trace_order,(char*) "onBookUpdate", _latest_sequence, (uint16_t) _latest_sequence, 0); auto data = _index.get_security(sec.id()); @@ -370,6 +375,7 @@ void MDP3Listener::onBookUpdate(const onixs::Security& sec, const TBook& onixs_b _book_updates.emplace_back(data->handle); } BookData& cache = found ? *find_iter : _book_updates.back(); + cache.type_flags |= booktype; auto& cache_bids = std::get>(cache.bids); auto& cache_asks = std::get>(cache.asks); @@ -386,12 +392,14 @@ void MDP3Listener::onBookUpdate(const onixs::Security& sec, const TBook& onixs_b for (size_t x = 0; x < asks_size; ++x) { cache_asks[x] = pricesize_of_price_size(onixs_book.offers()[x].price(), display_factor, onixs_book.offers()[x].quantity()); } + if (!found) { // NaN out the remaining depth - for (size_t x = bids_size; x < MAX_DEPTH; ++x) { - cache_bids[x] = NO_MARKET; - } - for (size_t x = asks_size; x < MAX_DEPTH; ++x) { - cache_asks[x] = NO_MARKET; + for (size_t x = bids_size; x < MAX_DEPTH; ++x) { + cache_bids[x] = NO_MARKET; + } + for (size_t x = asks_size; x < MAX_DEPTH; ++x) { + cache_asks[x] = NO_MARKET; + } } } From b47055d814b978c16cbd12a12bf9674262f48d13 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Fri, 5 Oct 2018 18:36:25 -0400 Subject: [PATCH 02/14] increasing log period of VAP publisher --- src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp index c1546403c..98675ba97 100644 --- a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp +++ b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp @@ -36,7 +36,7 @@ struct MarketDataAuxiliaryServiceServer::PImpl{ poll_period_ms(100), state(), log_counter(0), - log_trunc(10){ + log_trunc(300){ } }; From 9630851f1ff861206fa957df76d1a73d183e3012 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Tue, 9 Oct 2018 09:52:42 -0400 Subject: [PATCH 03/14] Add ToString to managed PriceSize --- src/client/spark_core/Co2/PriceSize.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/spark_core/Co2/PriceSize.cs b/src/client/spark_core/Co2/PriceSize.cs index 040bdbd6f..3b91b089c 100644 --- a/src/client/spark_core/Co2/PriceSize.cs +++ b/src/client/spark_core/Co2/PriceSize.cs @@ -26,6 +26,9 @@ namespace mbts.co2 { } internal static NativePriceLevel empty => new NativePriceLevel(IntPrice.NaN, 0, IntPrice.NaN, 0); + public override string ToString() { + return $"b [{bid.price} {bid.size}] a [{ask.price} {ask.size}]"; + } } public readonly struct ImpliedPriceLevel { readonly IntPrice _bid; @@ -85,7 +88,7 @@ namespace mbts.co2 { public override string ToString() { - return "{0} {1}".fmt(price, size); + return "{0} {1} ({2})".fmt(price, size, implied_size); } public override bool Equals(object obj) { From 1e64f930d98777b4451f730512a42af8be1b3715 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Tue, 9 Oct 2018 09:52:52 -0400 Subject: [PATCH 04/14] Pass though impileds and settles in simulator --- .../sparkd/exchange_sim/ExchangeSim.cpp | 31 ++++++++++++++++++- .../exchange_sim/ExchangeSimApplication.cpp | 25 +++++++++++++-- .../exchange_sim/ExchangeSimApplication.h | 5 ++- .../sparkd/exchange_sim/IMDPlayerObserver.h | 5 ++- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/server/sparkd/exchange_sim/ExchangeSim.cpp b/src/server/sparkd/exchange_sim/ExchangeSim.cpp index 7eb6662fd..1e1894157 100644 --- a/src/server/sparkd/exchange_sim/ExchangeSim.cpp +++ b/src/server/sparkd/exchange_sim/ExchangeSim.cpp @@ -75,7 +75,36 @@ struct MDPlayer : md::IRelayWriter size_t n = 0; for (auto &a : book.asks()) asks[n++] = md::PriceSize({a.mantissa(),(int8_t)a.exponent()},a.size()); - obs.on_depth(*sec_ptr, bids, asks); + + + std::array implied_bids, implied_asks; + bool has_implied = false; + {size_t x = 0; + for (const auto& b : cr.implied().bids()) { + implied_bids[x] = md::PriceSize({b.mantissa(), (int8_t)b.exponent()}, b.size()); + x += 1; + has_implied = true; + }} + {size_t x = 0; + for (const auto& b : cr.implied().asks()) { + implied_bids[x] = md::PriceSize({b.mantissa(), (int8_t)b.exponent()}, b.size()); + x += 1; + has_implied = true; + }} + + if (has_implied) { + obs.on_depth(*sec_ptr, bids, asks, &implied_bids, &implied_asks); + } + else { + obs.on_depth(*sec_ptr, bids, asks, nullptr, nullptr); + } + + if (cr.has_misc()) { + if (cr.misc().has_settlement()) { + const auto& s = cr.misc().settlement(); + obs.on_settlement(*sec_ptr, { s.mantissa(), (int8_t)s.exponent() }); + } + } } } IMDPlayerObserver &obs; diff --git a/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp b/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp index 9ea11d065..3fd537de6 100644 --- a/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp +++ b/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp @@ -527,9 +527,21 @@ void ExchangeSimApplication::on_new_security(api::Security const &s) { } } +void ExchangeSimApplication::on_settlement(md::Security const& sec, md::IntPrice price) { + auto sec_desc = get_sim_sec_desc(sec); + auto iter = me->md_producer_handles.find(sec_desc); + if (iter != me->md_producer_handles.end()) { + auto &handle = iter->second; + handle.update_settlement(utils::TimeStamp::now(), price, datetime::today()); + } +} + void ExchangeSimApplication::on_depth( - md::Security const &sec, md::PriceSize bids[md::COCONUT_MAX_DEPTH], - md::PriceSize asks[md::COCONUT_MAX_DEPTH]) { + md::Security const &sec, + md::PriceSize bids[md::COCONUT_MAX_DEPTH], + md::PriceSize asks[md::COCONUT_MAX_DEPTH], + std::array* implied_bids, + std::array* implied_asks) { std::lock_guard l(me->lock); if (sec.has_synthetic()) @@ -564,6 +576,15 @@ void ExchangeSimApplication::on_depth( // we generate a set of orders that we apply to our order book merge_with_order_book(it->second.security.glbx().security_desc(), previous_md_book, current_md_book); + + // pass on implied market unchanged + if (implied_bids || implied_asks) { + auto iter = me->md_producer_handles.find(get_sim_sec_desc(sec)); + if (iter != me->md_producer_handles.end()) { + auto &handle = iter->second; + handle.update_implied(utils::TimeStamp::now(), *implied_bids, *implied_asks); + } + } } void ExchangeSimApplication::merge_with_order_book(std::string const &sec_desc, diff --git a/src/server/sparkd/exchange_sim/ExchangeSimApplication.h b/src/server/sparkd/exchange_sim/ExchangeSimApplication.h index 8f7cdc54e..248017519 100644 --- a/src/server/sparkd/exchange_sim/ExchangeSimApplication.h +++ b/src/server/sparkd/exchange_sim/ExchangeSimApplication.h @@ -99,9 +99,12 @@ public: void persist_book(OrderBook const &b); void on_new_security(md::Security const&) override; + void on_settlement(md::Security const&, md::IntPrice) override; void on_depth(md::Security const&s, md::PriceSize bids[md::COCONUT_MAX_DEPTH], - md::PriceSize asks[md::COCONUT_MAX_DEPTH]) override; + md::PriceSize asks[md::COCONUT_MAX_DEPTH], + std::array* implied_bids, + std::array* implied_asks) override; void merge_with_order_book(std::string const &sec_desc, Book const&previous,Book const¤t); }; }} diff --git a/src/server/sparkd/exchange_sim/IMDPlayerObserver.h b/src/server/sparkd/exchange_sim/IMDPlayerObserver.h index 6ba748133..b2e194b34 100644 --- a/src/server/sparkd/exchange_sim/IMDPlayerObserver.h +++ b/src/server/sparkd/exchange_sim/IMDPlayerObserver.h @@ -9,9 +9,12 @@ namespace sim { struct IMDPlayerObserver { virtual void on_new_security(md::Security const&) = 0; + virtual void on_settlement(const md::Security&, md::IntPrice) = 0; virtual void on_depth(md::Security const&s, md::PriceSize bids[md::COCONUT_MAX_DEPTH], - md::PriceSize asks[md::COCONUT_MAX_DEPTH]) = 0; + md::PriceSize asks[md::COCONUT_MAX_DEPTH], + std::array* implied_bids, + std::array* implied_asks) = 0; }; }} From 1b5256d6993a8949b48480a5e2d0512afc02f490 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 1 Oct 2018 14:56:35 -0400 Subject: [PATCH 05/14] SPARK-1742 test can fail when time moves foward --- src/client/spark_test/Co2/Co2Tests.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/client/spark_test/Co2/Co2Tests.cs b/src/client/spark_test/Co2/Co2Tests.cs index 98767cbda..a1e17e81f 100644 --- a/src/client/spark_test/Co2/Co2Tests.cs +++ b/src/client/spark_test/Co2/Co2Tests.cs @@ -270,10 +270,21 @@ namespace mbts.co2.tests public void lldatetime_test() { utils.LLDateTime now = DateTime.MinValue, utc_now = DateTime.MinValue; Co2NativeTestMethods.co2_get_sample_datetime(ref now, ref utc_now); - Assert.AreEqual(((DateTime)now).ToShortDateString(), DateTime.Now.ToShortDateString()); - Assert.AreEqual(((DateTime)utc_now).ToShortDateString(), DateTime.UtcNow.ToShortDateString()); - Assert.AreEqual(((DateTime)now).ToString("T"), DateTime.Now.ToString("T")); - Assert.AreEqual(((DateTime)utc_now).ToString("T"), DateTime.UtcNow.ToString("T")); + DateTime dt_now = now; + DateTime dt_utc_now = utc_now; + Assert.AreEqual(dt_now.ToShortDateString(), DateTime.Now.ToShortDateString()); + Assert.AreEqual(dt_utc_now.ToShortDateString(), DateTime.UtcNow.ToShortDateString()); + void assert_about_equal(int a, int b) { + Assert.That(Math.Abs(a - b) <= 1); + } + + assert_about_equal(dt_now.Hour, DateTime.Now.Hour); + assert_about_equal(dt_now.Minute, DateTime.Now.Minute); + assert_about_equal(dt_now.Second, DateTime.Now.Second); + + assert_about_equal(dt_utc_now.Hour, DateTime.UtcNow.Hour); + assert_about_equal(dt_utc_now.Minute, DateTime.UtcNow.Minute); + assert_about_equal(dt_utc_now.Second, DateTime.UtcNow.Second); } From 58481c9b1752cc71e32ef0a95b7e2a5a217b2091 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Thu, 4 Oct 2018 15:00:33 -0400 Subject: [PATCH 06/14] SPARK-1538: Clones incoming --- src/web/ui/src/Users/State.fs | 4 ++-- src/web/ui/src/Users/Types.fs | 2 +- src/web/ui/src/Users/View.fs | 31 +++++++++---------------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/web/ui/src/Users/State.fs b/src/web/ui/src/Users/State.fs index 40db505a7..f2d8dd611 100644 --- a/src/web/ui/src/Users/State.fs +++ b/src/web/ui/src/Users/State.fs @@ -227,8 +227,8 @@ let update msg (model:Users.Types.Model) : Model * Cmd = model, Cmd.Empty | UpdateField field -> { model with scratchUser = applyUpdate field model.scratchUser; ConfirmModal = ("", Msg.SwitchTab model.currentTab) } , Cmd.Empty - | Clone usr -> - { model with scratchUser = { usr with id = 0u; name = usr.name + "_copy" }}, Cmd.Empty + | CloneUser -> + { model with PreviousScratchUser = model.scratchUser; scratchUser = { model.scratchUser with id = 0u; name = sprintf "%s_clone" model.scratchUser.name }; OptionsMenuOpen = ""}, Cmd.ofMsg (SwitchTab General) | CopyFrom (usrSrc, usrDest) -> let nusr = { usrSrc with id = usrDest.id diff --git a/src/web/ui/src/Users/Types.fs b/src/web/ui/src/Users/Types.fs index 985232714..a4f71feca 100644 --- a/src/web/ui/src/Users/Types.fs +++ b/src/web/ui/src/Users/Types.fs @@ -36,7 +36,7 @@ type Msg = | RpcResponse of string | UpdateAdminData of AdminData | UpdateField of UserField - | Clone of BTSUser + | CloneUser | CopyFrom of BTSUser * BTSUser | Delete of BTSUser | AddUser diff --git a/src/web/ui/src/Users/View.fs b/src/web/ui/src/Users/View.fs index 4f3e8a72e..0ecb7f512 100644 --- a/src/web/ui/src/Users/View.fs +++ b/src/web/ui/src/Users/View.fs @@ -178,27 +178,6 @@ let userControls (model:Model) (dispatch:Msg->Unit) = [ saveButton model dispatch Button.button "Revert" "" "" (if dirty then Button.Enabled else Button.Disabled) (fun _ -> SwitchUser (currentUser) |> dispatch) - (*p [ ClassName "control" ] - [ a [ ClassName "button is-light" - Title "Clone" - OnClick (fun _ -> dispatch <| Clone currentUser) - Disabled disabled - ] - [ span [ ClassName "icon is-small" ] - [ i [ ClassName "fa fa-clone" ] - [ ] ] - ] - ]*) - (*p [ ClassName "control" ] - [ a [ ClassName "button is-light" ] - [ span [ ClassName "icon is-small" - Title "Copy from user 1 ..." - OnClick (fun _ -> dispatch <| CopyFrom (usersList.Head, currentUser)) - ] - [ i [ ClassName "fa fa-copy" ] - [ ] ] - ] - ]*) ] @@ -276,7 +255,11 @@ let userSelectionGrid (usersList:BTSUser list) (currentUser:BTSUser) (dispatch:M let menuItem (user:BTSUser) (selectedUser:BTSUser) model dispatch = a [ ClassName (isActiveUser user.id selectedUser) - OnClick (fun _ -> SwitchUser user |> dispatch) + OnClick (fun _ -> + match user.name = model.OptionsMenuOpen with + | false -> SwitchUser user |> dispatch + | _ -> () + ) ] [ span [] [ str user.name ] span [ Class "is-pulled-right menu-icon" ] @@ -305,6 +288,10 @@ let menuItem (user:BTSUser) (selectedUser:BTSUser) model dispatch = OnClick (fun _ -> dispatch <| Delete user) ] [ str "Remove" ] + a [ Class "dropdown-item" + OnClick (fun _ -> dispatch <| CloneUser) + ] + [ str "Clone" ] ] ] ] From 8cbe6d7199d32dfadd4a9bf19a260b16f674fdb7 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Tue, 9 Oct 2018 09:37:56 -0400 Subject: [PATCH 07/14] MD Aux Service's VAP now uses context.poll instead of its own thread --- .../md/MarketDataAuxiliaryServiceServer.cpp | 33 +++++++++---------- .../md/MarketDataAuxiliaryServiceServer.h | 1 + 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp index 98675ba97..17886e386 100644 --- a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp +++ b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.cpp @@ -20,6 +20,7 @@ using namespace bts::api::md::auxiliary; struct MarketDataAuxiliaryServiceServer::PImpl{ bool vap_enabled; + bts::api::ServiceContext& context; MarketDataRelay relay_service; MarketDataAuxiliaryServiceBase::Volume_at_priceStatefulPublisher publisher; std::unique_ptr trade_timer; @@ -30,6 +31,7 @@ struct MarketDataAuxiliaryServiceServer::PImpl{ const MarketDataAuxiliaryServiceBase::Volume_at_priceStatefulPublisher& publisher) : vap_enabled(config::get().enabled()), + context(context), relay_service(context.locate()), publisher(publisher), trade_timer(), @@ -46,21 +48,18 @@ MarketDataAuxiliaryServiceServer::MarketDataAuxiliaryServiceServer( MarketDataAuxiliaryServiceBase(context), me(new PImpl(context, make_volume_at_price_stateful_publisher())){ - if(me->vap_enabled){ - auto& threadpool = utils::Dispatcher::get_named("TradesQuery"); - me->trade_timer = - std::make_unique(threadpool, - me->poll_period_ms, - [this]() { - me->relay_service.requestmd(me->state.md_req(), - [this](const bts::api::Result& md_reply) - { - if(md_reply.result()!=nullptr) - _scan_trades(*md_reply.result());} - ); - }); - me->trade_timer->start(); - } + if(me->vap_enabled) + me->context.post([this](){_poll_md();},me->poll_period_ms); +} + +void MarketDataAuxiliaryServiceServer::_poll_md(){ + me->relay_service.requestmd(me->state.md_req(), + [this](const bts::api::Result& md_reply) + { + if(md_reply.result()!=nullptr) + _scan_trades(*md_reply.result()); + me->context.post([this](){_poll_md();},me->poll_period_ms); + }); } void MarketDataAuxiliaryServiceServer::_scan_trades(const MDReply& md_reply){ @@ -79,9 +78,9 @@ void MarketDataAuxiliaryServiceServer::_scan_trades(const MDReply& md_reply){ n_trades,total_unique_levels,usecs); me->log_counter=0; } - me->publisher.flush(); + me->publisher.flush(); } MarketDataAuxiliaryServiceServer::~MarketDataAuxiliaryServiceServer(){ } -}}} +}}} \ No newline at end of file diff --git a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.h b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.h index c762545eb..04bbd3b3e 100644 --- a/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.h +++ b/src/server/sparkd/md/MarketDataAuxiliaryServiceServer.h @@ -18,6 +18,7 @@ private: struct PImpl; std::unique_ptr me; private: + void _poll_md(); void _scan_trades(const bts::co2::MDReply&); public: MarketDataAuxiliaryServiceServer(bts::api::ServiceContext& context); From 21a47e2d43955964d5dcfb6ce8e75f773b47110c Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Tue, 9 Oct 2018 12:13:54 -0400 Subject: [PATCH 08/14] VAP merging into 1659 made the price go to NAN because of the PrizeSize changes --- src/server/sparkd/md/ChannelVolume.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/sparkd/md/ChannelVolume.cpp b/src/server/sparkd/md/ChannelVolume.cpp index ac047b9c5..89a6132a0 100644 --- a/src/server/sparkd/md/ChannelVolume.cpp +++ b/src/server/sparkd/md/ChannelVolume.cpp @@ -27,7 +27,7 @@ const VolumeAtPriceLevel& ChannelVolume::add_trade(const TradeMessage& m, VolumeAtPriceLevel vol; vol.set_record_id(record_id++); vol.set_security_id(m.key()); - auto p = md::PriceSize({m.mantissa(),(int8_t)m.exponent()},0); + IntPrice p = md::IntPrice (m.mantissa(),(int8_t)m.exponent()); vol.set_price(p.price()); price_map[m.mantissa()] = vol; price_it=price_map.find(m.mantissa()); From c331c8dde53decc39027be9375d12cb3fa50d553 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Tue, 9 Oct 2018 14:08:15 -0400 Subject: [PATCH 09/14] Add flag to enable/disable implied forwarding in simulator --- src/lib/config/protos/ExchangeSimCfg.proto | 1 + src/server/sparkd/exchange_sim/ExchangeSim.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/config/protos/ExchangeSimCfg.proto b/src/lib/config/protos/ExchangeSimCfg.proto index 790ef5779..4702536b5 100644 --- a/src/lib/config/protos/ExchangeSimCfg.proto +++ b/src/lib/config/protos/ExchangeSimCfg.proto @@ -3,5 +3,6 @@ package bts.config; message ExchangeSim { optional bool merge_with_md = 1 [default=true]; + optional bool forward_implied = 2 [default = false]; } diff --git a/src/server/sparkd/exchange_sim/ExchangeSim.cpp b/src/server/sparkd/exchange_sim/ExchangeSim.cpp index 1e1894157..549d0cd3a 100644 --- a/src/server/sparkd/exchange_sim/ExchangeSim.cpp +++ b/src/server/sparkd/exchange_sim/ExchangeSim.cpp @@ -11,6 +11,7 @@ #include "lib/os/os.h" #include "lib/config/protos/Ports.pb.h" +#include "lib/config/protos/ExchangeSimCfg.pb.h" #include "lib/config/config.h" #include @@ -46,7 +47,8 @@ struct MDPlayer : md::IRelayWriter { MDPlayer (IMDPlayerObserver &obs,std::map &known_securities) : obs (obs), - known_securities(known_securities) + known_securities(known_securities), + forward_implied(config::get().forward_implied()) {} @@ -109,6 +111,7 @@ struct MDPlayer : md::IRelayWriter } IMDPlayerObserver &obs; std::map &known_securities; + bool forward_implied; }; From 1e8fd9589b8cd1125f819a432db470d8336445d1 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Tue, 9 Oct 2018 11:50:52 -0400 Subject: [PATCH 10/14] Fix logging crash during shell shutdown --- src/lib/logging/logging.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/logging/logging.cpp b/src/lib/logging/logging.cpp index 68e03a1f0..429e6cb4b 100644 --- a/src/lib/logging/logging.cpp +++ b/src/lib/logging/logging.cpp @@ -209,7 +209,9 @@ const char* intern(const char* str) { extern "C" BTS_EXPORT void Logger_log (int level, int subsystem, const char *message, const char *file, int line) { - bts::log::_thread_logger.logger->enqueue(log::log_ts(),log::Subsystem{(uint8_t)subsystem}, log::Level{(uint8_t)level}, intern(file), line, "{}", std::string(message)); + if (bts::log::_thread_logger.logger != nullptr) { + bts::log::_thread_logger.logger->enqueue(log::log_ts(), log::Subsystem{ (uint8_t)subsystem }, log::Level{ (uint8_t)level }, intern(file), line, "{}", std::string(message)); + } } } #endif From 74b18cf71a77acfffe35ed65b42ecab0d8c5f377 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Tue, 9 Oct 2018 17:23:33 -0400 Subject: [PATCH 11/14] added a manual test for implieds in the UI --- testing/manual/forms/implied_markets_ui.txt | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 testing/manual/forms/implied_markets_ui.txt diff --git a/testing/manual/forms/implied_markets_ui.txt b/testing/manual/forms/implied_markets_ui.txt new file mode 100644 index 000000000..8970b116b --- /dev/null +++ b/testing/manual/forms/implied_markets_ui.txt @@ -0,0 +1,23 @@ +0. This test should run in sim market with merged turned on + +ExchangeSim {value {merge_with_md:true}} + +1. Bring up a market view for SI futures. There are 3 quantity columns +a. Implied : This is the quantity coming purely from implieds (ex for the spreads, this is +'implied' from the legs) +b. Direct : This comes purely from markets in the security itself +c. Qty (or Merged Qty) == Implied + Direct. + +2. Select a future with only implied markets (SI should have lots of them). Verify that the ladder +agrees with the market view (the ladder shows merged by default). + + +3. Enter buy and sell orders away from the market and make sure they show up as direct market in the ladder. + +4. In the ladder settings -> Market Data, select Direct Only. Make sure the ladder does the right thing. + +5. Go back to Merged and make sure the Ladder does the right thing. + +6. Make you direct bid better than the implied bid (by moving your buy order) and make sure MView does the right thing. + +7. Repeat 6 for sell/ask. \ No newline at end of file From 746e858f765b05c9bd548b2ce563fecae134aa50 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Wed, 10 Oct 2018 09:16:24 -0400 Subject: [PATCH 12/14] SPARK-1659 Typo in simulator implieds --- src/server/sparkd/exchange_sim/ExchangeSim.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/sparkd/exchange_sim/ExchangeSim.cpp b/src/server/sparkd/exchange_sim/ExchangeSim.cpp index 549d0cd3a..4678da3b6 100644 --- a/src/server/sparkd/exchange_sim/ExchangeSim.cpp +++ b/src/server/sparkd/exchange_sim/ExchangeSim.cpp @@ -89,7 +89,7 @@ struct MDPlayer : md::IRelayWriter }} {size_t x = 0; for (const auto& b : cr.implied().asks()) { - implied_bids[x] = md::PriceSize({b.mantissa(), (int8_t)b.exponent()}, b.size()); + implied_asks[x] = md::PriceSize({b.mantissa(), (int8_t)b.exponent()}, b.size()); x += 1; has_implied = true; }} From a174336baf1622f52b0359164baf4b659215139c Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Wed, 10 Oct 2018 11:22:51 -0400 Subject: [PATCH 13/14] MDSource should always use the complete book --- src/lib/orderman/actors/MDSource.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/orderman/actors/MDSource.h b/src/lib/orderman/actors/MDSource.h index 28b832254..519b54c8b 100644 --- a/src/lib/orderman/actors/MDSource.h +++ b/src/lib/orderman/actors/MDSource.h @@ -82,7 +82,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor { auto start = Timer::now(); for (auto &h : _handles) { auto &handle = h.handle; - if (handle.get_direct_book(h.last, std::tuple_size(), + if (handle.get_book(h.last, std::tuple_size(), &book.bid()[0], &book.ask()[0]) == md::HandleReadResult::SUCCESS) { book._security_key = SecurityKey(handle.key()); From e85d7b5d0cef52e98879e49eb03554eba0b18e8d Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Thu, 11 Oct 2018 17:19:48 -0400 Subject: [PATCH 14/14] 1.IntPrice comparison can now compare IntPrices of different exponents 2.copy_book for direct with holes fixed --- src/lib/md/IntPrice.h | 5 +++- .../spreader_orders/spreader/SpreaderUtils.h | 29 +++++++++++++------ .../spreader_orders/tests/spreader_tests.cpp | 24 +++++++++++++++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/lib/md/IntPrice.h b/src/lib/md/IntPrice.h index 725c8a6a0..c3c6c3573 100644 --- a/src/lib/md/IntPrice.h +++ b/src/lib/md/IntPrice.h @@ -39,7 +39,10 @@ class IntPrice { // logically 100*pow10(1) == 10*pow10(2) // HOWEVER, once converted to double there are subtelties that can make them not equal so // this function is conservative - return _mantissa == other._mantissa && _exponent == other._exponent; + if(_exponent == other._exponent) + return _mantissa == other._mantissa; + else + return price()==other.price(); } bool operator!=(const IntPrice& other) const { return !(*this == other); diff --git a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h index 2374c3ea0..2c28b2e0b 100644 --- a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h +++ b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h @@ -160,14 +160,24 @@ public: if(md_type==bts::spark::LegSpreaderParams::DIRECT){ // since the "size()" in Book is the merged size // we put the direct in the size - for(size_t i=0;i0){ + target.bid()[target_i]=md::PriceSize(b.int_price(),b.direct_size()); + target_i++; + } } - for(size_t i=0;i0){ + target.ask()[target_i]=md::PriceSize(a.int_price(),a.direct_size()); + target_i++; + } } + empty_out_book(target.ask(),target_i,target.n_levels()); } else if(md_type==bts::spark::LegSpreaderParams::MERGED){ target.bid()=source.bid(); @@ -175,8 +185,8 @@ public: } if(leg_calc==bts::spark::LegSpreaderParams::NET_CHANGE){ if(settlement_price.is_nan()){ - empty_out_book(target.bid(),target.n_levels()); - empty_out_book(target.ask(),target.n_levels()); + empty_out_book(target.bid(),0,target.n_levels()); + empty_out_book(target.ask(),0,target.n_levels()); } else{ offset_book(target.bid(), target.n_levels(),settlement_price); @@ -196,9 +206,10 @@ public: } } void static empty_out_book (BookSide& book_side, + size_t start_index, size_t n_levels){ md::PriceSize empty_ps; - for(size_t i=0;i(1999.0), + bts::spark::LegSpreaderParams::DIRECT, + bts::spark::LegSpreaderParams::BOOK, + out_book); + + validate_book(out_book, + key, + api::Side::SIDE_BUY, + 0.01, + new double[5] {2000.01, 2000.04, 2000.10, os::nan(), os::nan()}, + new uint16_t[5] {1, 14, 20, 0, 0}, + true); + } SECTION ("direct, net_change"){ SecurityKey key(13579); Book in_book (key);