diff --git a/.gitignore b/.gitignore index c7a63b0b8..cf4c7c358 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,4 @@ trace_data/ /src/lib/orderman/perf_analysis/last_pretty_log.csv /src/lib/orderman/perf_analysis/log.csv /doc/user/public/* -.ionide/ +.ionide/* diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index f2ba4c36e..1c9a618eb 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -4,6 +4,15 @@ weight = 3 sort_by = "weight" insert_anchor_links = "right" +++ +## 2.6.0 +### User Visible Changes + - In the ladder made last trade more distinctive when overlayed on the volumn column + - In the ladder, corrected display of volume tool tip + - In the ladder, changed the consolidation of last trade to consider only the price ignoring aggressor changes + - Address a rare issue that could lead to an error report on UI exit +### Internal Changes + - Ensure that admin logins are always allowed to login, regardless of keycode status. + ## 2.5.0 ### User Visible Changes - Added loss limit risk check diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs index 2a2af3223..b78519f62 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs @@ -694,12 +694,14 @@ namespace mbts.spark { // At any rate, we need this part hiding the tooltip so that we don't leave random tooltips around // and we have to reset to old row so that when we go back to what could be our preivous row, the tooltip gets drawn again //System.Diagnostics.Debug.WriteLine(" Tooltip - Volume is 0"); + _old_tooltip_row = int.MaxValue; _hide_tool_tip(); //_old_tooltip_row = Int32.MaxValue; } } } else { //System.Diagnostics.Debug.WriteLine(" Tooltip - not over Volume column"); + _old_tooltip_row = int.MaxValue; _hide_tool_tip(); } } diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs index 8f0168332..d12c79a6c 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs @@ -215,16 +215,16 @@ namespace mbts.spark { Brush total_brush = null; if (settings.total.bars.result.HasValue) { total_brush = new SolidColorBrush(settings.total.bars.result.Value); - } else if (components.Count == 0) { + } else if (components.Count == 0 && !settings.show_ltq) { _clear_visual(dv); return; } // inflate the max so that the graph never fills the available space double max = data.Max(v => v.Volume) * 1.1; - Brush text_brush = settings.general.foreground.rgb_brush(); _render_cells(dv, row_height, data.Select(d => (d.Price, d)), settings.general, prices, spec, render_cell); /// local methods void render_cell(DrawingContext dc, int r, VolumeAtPriceLevelImmutable vap) { + Brush text_brush = settings.general.foreground.rgb_brush(); double y = row_height * r; var last_trade_here = r == last_index; @@ -259,6 +259,7 @@ namespace mbts.spark { if (settings.show_ltq && last_trade_here) { numbers_text.Clear(); numbers_text.Add(last_size_and_direction); + text_brush = BTSCoreColors.white; } if (numbers_text.Count > 0) { string str = string.Join("/", numbers_text); diff --git a/src/client/spark_api/Co2/MDConsumerHandle.cs b/src/client/spark_api/Co2/MDConsumerHandle.cs index d13ef5b08..7b03bdaee 100644 --- a/src/client/spark_api/Co2/MDConsumerHandle.cs +++ b/src/client/spark_api/Co2/MDConsumerHandle.cs @@ -253,14 +253,13 @@ namespace mbts.co2 { } } - [StructLayout(LayoutKind.Sequential, Size = 712)] + [StructLayout(LayoutKind.Sequential, Size = 704)] internal struct ColdEntry { public int exchange_status; // Last trade public AtomicPriceSize last_trade; public ulong total_volume; public utils.LLDateTime last_trade_time; - private AggressorSide last_side; //// Settlement public UInt64 misc_timestamp; diff --git a/src/lib/md/MDProducerHandle.cpp b/src/lib/md/MDProducerHandle.cpp index 471fd53e1..a52292972 100644 --- a/src/lib/md/MDProducerHandle.cpp +++ b/src/lib/md/MDProducerHandle.cpp @@ -102,14 +102,13 @@ void MDProducerHandle::set_status(CoconutSecurityStatus status) { } void MDProducerHandle::add_trade(TimeStamp time, const PriceSize price, LLDateTime tradetime, co2::AggressorSide agside, uint32_t volume) { - // Add this trade to the last trade if price/side match + // Add this trade to the last trade if price match auto current = std::get(cdata().last_trade.load()); - if (current.int_price() == price.int_price() && agside == cdata().last_side) { + if (current.int_price() == price.int_price()) { cdata().last_trade.store(PriceSize { price.int_price(), price.size() + current.size() }, time); } else { cdata().last_trade.store(price,time); - cdata().last_side = agside; } cdata().last_trade_time = tradetime; cdata().total_volume = volume; diff --git a/src/lib/md/SecurityCache.cpp b/src/lib/md/SecurityCache.cpp index 160633145..63a181a5d 100644 --- a/src/lib/md/SecurityCache.cpp +++ b/src/lib/md/SecurityCache.cpp @@ -22,6 +22,7 @@ void SecurityCacheImpl::enqueue_update_db(const SecurityPtr& security) { } void SecurityCacheImpl::flush() { + #ifndef _WIN32 if (!update_queue.empty()) { std::vector work; SecurityPtr temp; @@ -33,6 +34,7 @@ void SecurityCacheImpl::flush() { } } } + #endif } ////////////////// diff --git a/src/lib/md/Shm/MDStructure.h b/src/lib/md/Shm/MDStructure.h index dd5dbb6b5..3553b71d8 100644 --- a/src/lib/md/Shm/MDStructure.h +++ b/src/lib/md/Shm/MDStructure.h @@ -26,7 +26,7 @@ namespace md { using utils::TimeStamp; -const uint32_t shm_version = 101; +const uint32_t shm_version = 102; struct ALIGNED_(CACHE_LINE) HotHeader { size_t count; @@ -214,7 +214,6 @@ struct ColdEntry { last_trade(), total_volume(0), last_trade_time(), - last_side(co2::AggressorSide::AGGRESSOR_SIDE_NONE), misc(), deleted(false) { @@ -230,7 +229,6 @@ struct ColdEntry { AtomicPriceSize last_trade; size_t total_volume; datetime::LLDateTime last_trade_time; - co2::AggressorSide last_side; MiscData misc; diff --git a/src/lib/md/test/synthetic_book_merge_tests.cpp b/src/lib/md/test/synthetic_book_merge_tests.cpp index 25d97cfab..63d1914c9 100644 --- a/src/lib/md/test/synthetic_book_merge_tests.cpp +++ b/src/lib/md/test/synthetic_book_merge_tests.cpp @@ -111,7 +111,7 @@ tuple,vector> make_securities(c l->mutable_security()->mutable_contract_spec()->set_low_tick(tick_size); l->mutable_security()->mutable_contract_spec()->set_high_tick(tick_size); l->set_quantity(quantity); - l->set_price_multiplier(quantity * (side == api::SIDE_BUY ? 1.0 : -1)); + l->set_price_multiplier(mult); l->set_side(side); synthetic->legs.push_back(instr.consumer()); legs.push_back(instr); @@ -126,7 +126,8 @@ tuple,vector> make_securities(c double quantity, tick_size; api::Side side; std::tie(quantity, tick_size, side) = t; - legs.push_back({ quantity, quantity, tick_size, side }); + double mult = quantity * (side == api::SIDE_BUY ? 1.0 : -1); + legs.push_back({ quantity, mult, tick_size, side }); } return make_securities(legs); } @@ -457,6 +458,113 @@ TEST_CASE("Synthetic_net_change", "[md][synthetic]") { } } +TEST_CASE("HCL_SP_104", "[md][synthetic]") { + shared_ptr synthetic; + vector test_instr; + tie(synthetic, test_instr) = make_securities({ + // (quantity, multiplier, tick_size, side) + {1.0, 1.0, 0.01, api::SIDE_BUY}, + {1.0, 1.0, 0.01, api::SIDE_BUY}, + {1.0, -1.0, 0.01, api::SIDE_SELL}, + {1.0, -1.0, 0.01, api::SIDE_SELL } + }); + auto leg1 = test_instr[0]; // CLQ9-CLU9 + auto leg2 = test_instr[1]; // HCLQ9-CLQ9 + auto leg3 = test_instr[2]; // HCLQ9-HCLU9 + auto leg4 = test_instr[3]; // HCLU9-CLU9 + + setup_market(leg1.producer(), + { + { -0.10, 3299 }, + { -0.11, 2885 }, + { -0.12, 2558 }, + { -0.13, 2447 }, + { -0.14, 1540 }, + { -0.15, 2334 }, + { -0.16, 1396 }, + { -0.17, 1190 }, + { -0.18, 1221 }, + { -0.19, 812 } + }, + { + { -0.09, 1318 }, + { -0.08, 2174 }, + { -0.07, 3057 }, + { -0.06, 2331 }, + { -0.05, 2543 }, + { -0.04, 2638 }, + { -0.03, 2232 }, + { -0.02, 3221 }, + { -0.01, 2863 }, + { 0.00, 3327 } + }); + + setup_market(leg2.producer(), + { + { 4.06, 1 }, + { 4.05, 2 }, + { 4.04, 3 }, + { 4.03, 12 }, + { 4.02, 6 }, + { 4.01, 1 } + }, + { + { 4.07, 1 }, + { 4.08, 2 }, + { 4.10, 8 }, + { 4.11, 10 }, + { 4.12, 2 }, + { 4.14, 1 } + }); + + setup_market(leg3.producer(), + { + { 0.20, 2 }, + { 0.19, 6 }, + { 0.18, 5 }, + { 0.17, 18 }, + { 0.16, 2 }, + { 0.15, 3 }, + { 0.14, 2 } + }, + { + { 0.22, 2 }, + { 0.23, 4 }, + { 0.24, 9 }, + { 0.25, 17}, + { 0.26, 5 }, + { 0.27, 5 }, + { 0.28, 4 }, + { 0.29, 2 }, + { 0.30, 2 } + }); + + setup_market(leg4.producer(), + { + { 3.75, 1 }, + { 3.74, 3 }, + { 3.73, 4 }, + { 3.72, 12 }, + { 3.71, 1 }, + { 3.70, 3 } + }, + { + { 3.78, 1 }, + { 3.79, 2 }, + { 3.80, 6 }, + { 3.81, 1 }, + { 3.82, 10 }, + { 3.83, 1 } + }); + + MDConsumerHandle synthetic_handle(synthetic); + // dump_market(synthetic_handle); + expect_market(synthetic_handle, + { { -0.04,1 },{ -0.06,1 },{ -0.07,1 },{ -0.09,3 },{ -0.11,3 },{ -0.12,1 },{ -0.13,5 },{ -0.14,3 },{ -0.15,2 },{ -0.16,1 } }, + { { 0.03,1 },{ 0.05,1 },{ 0.06,1 },{ 0.08,1 },{ 0.09,4 },{ 0.11,3 },{ 0.12,2 },{ 0.13,7 },{ 0.14,1 },{ 0.16,2 } } + ); +} + // // Benchmarks diff --git a/src/lib/utils/AuthSessionManager.cpp b/src/lib/utils/AuthSessionManager.cpp index 11d620282..dddb415fd 100644 --- a/src/lib/utils/AuthSessionManager.cpp +++ b/src/lib/utils/AuthSessionManager.cpp @@ -86,7 +86,7 @@ bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& t return true; if(datetime::ll_diff_in_us(datetime::ll_now(), _expiration) < 0) { - LOG(Gen,Error, "Your BTS Keycode is expired!"); + LOG(User,Error, "Your BTS Keycode is expired!"); if(msg) *msg = "Your BTS Keycode is EXPIRED! Please contact sales@bluetradesys.com"; return false; @@ -105,13 +105,18 @@ bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& t if(it != _map.end()) { _map[tok.id()] = Session{tok}; + LOG(User, Warn, "KEYCODE: Replacing session {} ", tok.id()); return true; } else if(_map.size() < _nusers) { _map[tok.id()] = Session{tok}; + LOG(User, Warn, "KEYCODE: Creating session {} ", tok.id()); return true; } + if(msg) + *msg = "KEYCODES: Not Enough Logins available for session"; + LOG(User, Error, "KEYCODES: Not Enough Logins available for session {}", tok.id()); return false; } diff --git a/src/lib/utils/AuthToken.cpp b/src/lib/utils/AuthToken.cpp index e1292b595..2423638a8 100644 --- a/src/lib/utils/AuthToken.cpp +++ b/src/lib/utils/AuthToken.cpp @@ -51,6 +51,35 @@ AuthSessionManager& session_manager() return mgr; } +bool requires_auth_session(const admin::BTSUser& user) +{ + //if the user can trade in any account or see market data, it needs a session + if(user.has_user_data() && + user.user_data().has_account_permissions() && + user.user_data().account_permissions().account_permissions_size()) + { + for(const auto& i: user.user_data().account_permissions().account_permissions()) + { + if(i.second.has_trading_permission() && i.second.trading_permission().has_permissions()) + return true; + } + } + + if(user.has_user_data() && + user.user_data().has_exchange_user_data()) + { + if(user.user_data().exchange_user_data().has_cme_data()) + { + for(const auto& i: user.user_data().exchange_user_data().cme_data().md_permissions()) + { + if(i.enabled()) + return true; + } + } + } + return false; +} + AuthToken generate_token(const admin::BTSUser& user, std::string* msg) { api::user::TokenPayload payload; @@ -58,7 +87,9 @@ AuthToken generate_token(const admin::BTSUser& user, std::string* msg) payload.set_id(user.id()); if(user.name() == "bts") payload.set_wheel(true); - session_manager().add_or_replace_session(payload, msg); + + if(requires_auth_session(user)) + session_manager().add_or_replace_session(payload, msg); auto token = encrypt(payload.SerializeAsString()); bts_assert_d(token.size() < 255-8); AuthToken result; diff --git a/src/lib/utils/tests/AuthTokenTests.cpp b/src/lib/utils/tests/AuthTokenTests.cpp index 51de507f7..6bcbe52d8 100644 --- a/src/lib/utils/tests/AuthTokenTests.cpp +++ b/src/lib/utils/tests/AuthTokenTests.cpp @@ -5,19 +5,34 @@ namespace bts { namespace test { TEST_CASE("AuthToken", "[security]") { - api::admin::BTSUser user; - user.set_id(42); - user.set_name("user1"); + api::admin::BTSUser admin_user; + admin_user.set_id(42); + admin_user.set_name("user1"); + + api::admin::BTSUser trader_user; + trader_user.set_id(43); + trader_user.set_name("trader1"); + trader_user.mutable_user_data()->mutable_exchange_user_data()->mutable_cme_data()->add_md_permissions()->set_enabled(true); - SECTION("round trip") { - auto token = api::auth::generate_token(user); + SECTION("round trip admin") { + auto token = api::auth::generate_token(admin_user); + // We use 1 byte for api header size + REQUIRE(token.ByteSize() <= 240); + api::user::TokenPayload payload; + REQUIRE(!api::auth::decode_token(token, &payload)); + REQUIRE(payload.id() == admin_user.id()); + REQUIRE(payload.wheel() == false); + } + + SECTION("round trip trader") { + auto token = api::auth::generate_token(trader_user); // We use 1 byte for api header size REQUIRE(token.ByteSize() <= 240); api::user::TokenPayload payload; REQUIRE(api::auth::decode_token(token, &payload)); - REQUIRE(payload.id() == user.id()); + REQUIRE(payload.id() == trader_user.id()); REQUIRE(payload.wheel() == false); - } + } SECTION("empty token") { api::user::TokenPayload payload; @@ -28,11 +43,11 @@ TEST_CASE("AuthToken", "[security]") { } SECTION("bts is the big wheel") { - user.set_name("bts"); - auto token = api::auth::generate_token(user); + admin_user.set_name("bts"); + auto token = api::auth::generate_token(admin_user); api::user::TokenPayload payload; REQUIRE(api::auth::decode_token(token, &payload)); - REQUIRE(payload.id() == user.id()); + REQUIRE(payload.id() == admin_user.id()); REQUIRE(payload.wheel()); } } diff --git a/src/server/sparkd/user/AdminServiceServer.cpp b/src/server/sparkd/user/AdminServiceServer.cpp index 9e317e7fc..b795c7f39 100644 --- a/src/server/sparkd/user/AdminServiceServer.cpp +++ b/src/server/sparkd/user/AdminServiceServer.cpp @@ -155,7 +155,7 @@ void AdminServiceServer::get_filtered_admin_data( const api::Response& reply) { bts::api::user::TokenPayload toke; - if(bts::api::auth::decode_token(token, &toke)) + bts::api::auth::decode_token(token, &toke); { if(toke.wheel()) reply(_state); diff --git a/src/web/CMakeDeps.cmake b/src/web/CMakeDeps.cmake index bc74cb4cf..1843aaacb 100644 --- a/src/web/CMakeDeps.cmake +++ b/src/web/CMakeDeps.cmake @@ -1 +1 @@ -set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarginService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/psl/scripts/ci-build.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs) \ No newline at end of file +set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/psl/scripts/ci-build.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs) \ No newline at end of file diff --git a/testing/manual/keycodes/keycode.txt b/testing/manual/keycodes/keycode.txt index ffd573a26..ed9535602 100644 --- a/testing/manual/keycodes/keycode.txt +++ b/testing/manual/keycodes/keycode.txt @@ -15,7 +15,7 @@ This will test our ability to generate and enforce keycodes. You should see keycode details printed to screen -4) Now test concurrent logins. Start a sparkd. +4) Now test concurrent logins. Start a sparkd. Make sure bts_2 and bts_3 have market data permission a) Start a spark -multiple login as bts and go to where you would see some market data b) Start another spark -multiple but log in as bts_2 and display some data c) Start a third spark -multiple, log in as bts_2 and display some data. @@ -37,5 +37,19 @@ You should see keycode details printed to screen d) remove the expired keycode you just generated by: rm ~/sparkdata/conf/keycode.conf e) restart sparkd, you should see data as normal in bts_2 + +6) Test admin vs trading logins +Note that an admin login is one that does not have trading permission in any account +AND does not have the ability to see any market data + + a) start sparkd again. make sure bts_2 and bts_3 have market data and trading permissions in webui + b) Start a spark -multiple login as bts_2 and go to where you would see some market data. You should see data + c) Start a webui and log in as bts_3, you should see data + d) close your shell and log out of web ui, now log in bts_3 into the webui and log in bts_2 in a shell ( + this is the reverse of the previous order), you should see a message in the shell about keycodes, but it will let you log in, just not see market data + e) from the webui, de-permission bts_3 from trading AND market data, + f) exit shell, log out of webui and kill sparkd, restart sparkd + + g)now try d again-- you should not get the same shell error