diff --git a/src/client/spark_api/md/Authenticator.cs b/src/client/spark_api/md/Authenticator.cs new file mode 100644 index 000000000..34aca3bfc --- /dev/null +++ b/src/client/spark_api/md/Authenticator.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; +using bts.api; +using bts.api.core; + +namespace bts.api +{ + public class Authenticator + { + readonly static Lazy _auth = new Lazy(() => Locator.locate(), true); + user.AuthToken _token = null; + public Authenticator() { } + + public user.AuthToken last_token => _token; + public async Task login(string login, string password) + { + var res = await _auth.Value.authenticate_login_async(new user.AuthenticateLoginRequest { Login = login, Password = password }); + if (res.success) + _token = res.value.Token; + return _token; + } + } +} \ No newline at end of file diff --git a/src/client/spark_api/md/LazyAsync.cs b/src/client/spark_api/md/LazyAsync.cs new file mode 100644 index 000000000..c83dd4095 --- /dev/null +++ b/src/client/spark_api/md/LazyAsync.cs @@ -0,0 +1,17 @@ + +using System; +using System.Threading.Tasks; + +namespace bts +{ + public class AsyncLazy : Lazy> + { + public AsyncLazy(Func valueFactory) : + base(() => Task.Factory.StartNew(valueFactory)) + { } + + public AsyncLazy(Func> taskFactory) : + base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap()) + { } + } +} \ No newline at end of file diff --git a/src/client/spark_api/md/Locator.cs b/src/client/spark_api/md/Locator.cs new file mode 100644 index 000000000..e86c98a05 --- /dev/null +++ b/src/client/spark_api/md/Locator.cs @@ -0,0 +1,16 @@ +using System; +using System.Threading.Tasks; +using bts.api; +using bts.api.core; + +namespace bts.api +{ + public static class Locator + { + readonly static Lazy _context = new Lazy(() => new ServiceContext(), true); + public static T locate(string qualifier="") where T : class, IApiClient + { + return _context.Value.locate(qualifier); + } + } +} diff --git a/src/client/spark_api/md/MarketDataClient.cs b/src/client/spark_api/md/MarketDataClient.cs index 748ffdea8..9f06f6aeb 100644 --- a/src/client/spark_api/md/MarketDataClient.cs +++ b/src/client/spark_api/md/MarketDataClient.cs @@ -33,49 +33,48 @@ namespace bts.api.md readonly ConcurrentDictionary _data = new ConcurrentDictionary(); readonly ConcurrentDictionary _security_key_to_desc= new ConcurrentDictionary(); readonly ConcurrentDictionary _security_desc_to_key = new ConcurrentDictionary(); - readonly Lazy _subscription; + readonly MDRequest _subscription; readonly Venue _venue; - readonly static Lazy _md = new Lazy(() => locate(), true); + readonly static Lazy _md = new Lazy(() => Locator.locate(), true); readonly static ConcurrentDictionary _venue_cache = new ConcurrentDictionary(); static readonly List _all_products; static MarketDataClient() { _all_products = _md.Value.request_products(new VoidMessage()).Products.ToList(); } - public static bool create_or_get(api.Venue exchange, out MarketDataClient md) + + public static IEnumerable cached_exchanges => _venue_cache.Keys; + public static bool create_or_get(api.Venue exchange, out MarketDataClient md, user.AuthToken token = null) { if (!_venue_cache.TryGetValue(exchange, out md)) { - _venue_cache[exchange] = md = new MarketDataClient(exchange); + _venue_cache[exchange] = md = new MarketDataClient(exchange, token); return true; } return false; } - public MarketDataClient(bts.api.Venue exchange = Venue.Unset) + public MarketDataClient(bts.api.Venue exchange = Venue.Unset, user.AuthToken token = null) { _venue = exchange; - _subscription = new Lazy(() => load_request(exchange)); + _subscription = load_request(exchange, token); } - MDRequest load_request(bts.api.Venue exchange) + public void set_auth_token(user.AuthToken toke) { - var req = new MDRequest(); + _subscription.Token = toke?.Token ?? string.Empty; + } + + MDRequest load_request(bts.api.Venue exchange, user.AuthToken token) + { + var req = new MDRequest() { Token = token?.Token ?? string.Empty } ; var prods = _all_products.Where(x=>x.Exchange == exchange || exchange == bts.api.Venue.Unset); foreach(var prod in prods) req.Channels.Add(new SecurityChannel() { Exchange = prod.Exchange, Type = prod.Type, Symbol = prod.Symbol, Flags = 0 }); return req; } - static MarketDataRelay locate() - { - using (var ctx = new api.core.ServiceContext()) - { - return ctx.locate(); - } - } - public Security lookup(security_key key) { Data value; @@ -217,7 +216,7 @@ namespace bts.api.md bool check_subscriptions(uint flags, Func selector) { - foreach (var sub in _subscription.Value.Channels) + foreach (var sub in _subscription.Channels) { if (selector(sub)) { @@ -251,7 +250,7 @@ namespace bts.api.md while (!rep.success && count++ < 5); while (true) { - var reply = await _md.Value.requestmd_async(_subscription.Value); + var reply = await _md.Value.requestmd_async(_subscription); if (reply.success) { foreach (var channel in reply.value.Channels) diff --git a/src/client/spark_excel/ExcelAddin.cs b/src/client/spark_excel/ExcelAddin.cs index 60e03aa99..421639146 100644 --- a/src/client/spark_excel/ExcelAddin.cs +++ b/src/client/spark_excel/ExcelAddin.cs @@ -69,5 +69,21 @@ namespace bts.excel Utilities.bts_load_assembly(ass); } } + + public static void calculate_full_rebuild() + { + object app = ExcelDnaUtil.Application; + var mi = app?.GetType().GetMethod("CalculateFullRebuild", BindingFlags.Instance | BindingFlags.Public); + if(mi != null) + mi.Invoke(app, null); + } + + public static void calculate_full() + { + object app = ExcelDnaUtil.Application; + var mi = app?.GetType().GetMethod("CalculateFull", BindingFlags.Instance | BindingFlags.Public); + if (mi != null) + mi.Invoke(app, null); + } } } \ No newline at end of file diff --git a/src/client/spark_excel/extensions/OrderService_Excel.cs b/src/client/spark_excel/extensions/OrderService_Excel.cs index 399369e46..dcdb0dec6 100644 --- a/src/client/spark_excel/extensions/OrderService_Excel.cs +++ b/src/client/spark_excel/extensions/OrderService_Excel.cs @@ -14,8 +14,8 @@ namespace bts.api.orderman { public partial class OrderService_Excel { - readonly static Lazy _users = new Lazy(() => locate(), true); - readonly static Lazy _admin = new Lazy(() => locate(), true); + readonly static Lazy _users = new Lazy(() => Locator.locate(), true); + readonly static Lazy _admin = new Lazy(() => Locator.locate(), true); [ExcelFunction(Category = "BTS", Description = "Cancel an Order by Order ID", IsMacroType = true)] diff --git a/src/client/spark_excel/rtd/formatting/TopMDFormatter.cs b/src/client/spark_excel/rtd/formatting/TopOfBookMDFormatter.cs similarity index 88% rename from src/client/spark_excel/rtd/formatting/TopMDFormatter.cs rename to src/client/spark_excel/rtd/formatting/TopOfBookMDFormatter.cs index 5a8e65fb7..82cb46be8 100644 --- a/src/client/spark_excel/rtd/formatting/TopMDFormatter.cs +++ b/src/client/spark_excel/rtd/formatting/TopOfBookMDFormatter.cs @@ -3,10 +3,10 @@ using System; namespace bts.excel.rtd { - class TopMDFormatter : IExcelFormatter + class TopOfBookMDFormatter : IExcelFormatter { readonly co2.ChannelUpdate _update; - public TopMDFormatter(co2.ChannelUpdate upd) + public TopOfBookMDFormatter(co2.ChannelUpdate upd) { _update = upd; } diff --git a/src/client/spark_excel/rtd/formatting/TopicMDFormatter.cs b/src/client/spark_excel/rtd/formatting/TopicMDFormatter.cs new file mode 100644 index 000000000..92af1f8a3 --- /dev/null +++ b/src/client/spark_excel/rtd/formatting/TopicMDFormatter.cs @@ -0,0 +1,90 @@ + +using System; + +namespace bts.excel.rtd +{ + class TopicMDFormatter : IExcelFormatter + { + readonly co2.ChannelUpdate _update; + readonly string _topic; + public TopicMDFormatter(co2.ChannelUpdate upd, string topic) + { + _update = upd; + _topic = topic; + } + + public object[,] format(bool include_headers = false) + { + var retval = new object[1, 1]; + switch (_topic.ToLower()) + { + case "bid": + case "bidprice": + retval[0, 0] = BookMDFormatter.format_md(_update?.Direct?.Bids?[0]?.Mantissa ?? 0, _update?.Direct?.Bids?[0]?.Exponent ?? 0); + break; + case "ask": + case "askprice": + retval[0, 0] = BookMDFormatter.format_md(_update?.Direct?.Asks?[0]?.Mantissa ?? 0, _update?.Direct?.Asks?[0]?.Exponent ?? 0); + break; + case "bidsize": + case "bidqty": + retval[0, 0] = _update?.Direct?.Bids?[0]?.Size; + break; + case "asksize": + case "askqty": + retval[0, 0] = _update?.Direct?.Asks?[0]?.Size; + break; + case "impliedbid": + case "impliedbidprice": + retval[0, 0] = BookMDFormatter.format_md(_update?.Implied?.Bids?[0]?.Mantissa ?? 0, _update?.Implied?.Bids?[0]?.Exponent ?? 0); + break; + case "impliedask": + case "impliedaskprice": + retval[0, 0] = BookMDFormatter.format_md(_update?.Implied?.Asks?[0]?.Mantissa ?? 0, _update?.Implied?.Asks?[0]?.Exponent ?? 0); + break; + case "impliedbidsize": + case "impliedbidqty": + retval[0, 0] = _update?.Implied?.Bids?[0]?.Size; + break; + case "impliedasksize": + case "impliedaskqty": + retval[0, 0] = _update?.Implied?.Asks?[0]?.Size; + break; + case "settlement": + case "settlementprice": + retval[0, 0] = BookMDFormatter.format_md(_update?.Misc?.Settlement?.Mantissa ?? 0, _update?.Misc?.Settlement?.Exponent ?? 0); + break; + case "previoussettlement": + case "previoussettlementprice": + retval[0, 0] = BookMDFormatter.format_md(_update?.Misc?.PreviousSettlementPrice?.Mantissa ?? 0, _update?.Misc?.PreviousSettlementPrice?.Exponent ?? 0); + break; + case "open": + case "openprice": + retval[0, 0] = _update?.Misc?.OpenPrice; + break; + case "close": + case "closeprice": + retval[0, 0] = _update?.Misc?.ClosePrice; + break; + case "high": + case "highprice": + retval[0, 0] = _update?.Misc?.SessionHigh; + break; + case "low": + case "lowprice": + retval[0, 0] = _update?.Misc?.SessionLow; + break; + case "last": + case "lastprice": + retval[0, 0] = BookMDFormatter.format_md(_update?.LastTrade?.Mantissa ?? 0, _update?.LastTrade?.Exponent ?? 0); + break; + case "lastsize": + case "lastqty": + retval[0, 0] = _update?.LastTrade?.Size; + break; + } + return retval; + } + } + +} \ No newline at end of file diff --git a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs index 88f408c7e..8b60cdcfd 100644 --- a/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs +++ b/src/client/spark_excel/rtd/subscriptions/MDSubscribe.cs @@ -14,6 +14,25 @@ namespace bts.excel.rtd { public class MDSubscribe { + static Authenticator _auth = new Authenticator(); + async public static void spark_login(string login, string password, ExcelAsyncHandle handle) + { + try + { + var toke = await _auth.login(login, password); + foreach (var ven in MarketDataClient.cached_exchanges) + { + MarketDataClient.create_or_get(ven, out MarketDataClient md); + md?.set_auth_token(toke); + } + handle.SetResult(toke?.Token ?? "Could not log in check user/pass"); + } + catch(Exception ex) + { + handle.SetException(ex); + } + } + public static MarketDataClient market_data(api.Venue exchange) { var newc = MarketDataClient.create_or_get(exchange, out MarketDataClient md); @@ -83,18 +102,18 @@ namespace bts.excel.rtd [ExcelFunction(Category = "BTS", Description = "Subscribe to BTS Spark top of book market data")] - public static object spark_md_top( + public static object spark_md_top_of_book( [ExcelArgument("Required. The specific contract, GCZ8 or ZNU8-ZNZ8, etc")] string contract, [ExcelArgument("Required. The symbol, GC or ZN, etc")] string symbol, [ExcelArgument("Optional. The type, Future or Spread, default = Future")] string security_type = null, [ExcelArgument("Optional. The exchange, default = GLBX")] string exchange = null) { var param = new object[] { contract, symbol, security_type, exchange }; - return ObservableRtdUtil.Observe(nameof(spark_md_top), param, + return ObservableRtdUtil.Observe(nameof(spark_md_top_of_book), param, () => md_observable(contract, symbol, security_type, exchange).Select(x => { if (x is co2.ChannelUpdate upd) - return new TopMDFormatter(upd).format(); + return new TopOfBookMDFormatter(upd).format(); return x; })); } @@ -116,5 +135,23 @@ namespace bts.excel.rtd })); } + + [ExcelFunction(Category = "BTS", Description = "Subscribe to BTS Spark top of book market data")] + public static object spark_md( + [ExcelArgument("Required. The 'Topic' string, 'bid', 'ask', etc")] string topic, + [ExcelArgument("Required. The specific contract, GCZ8 or ZNU8-ZNZ8, etc")] string contract, + [ExcelArgument("Required. The symbol, GC or ZN, etc")] string symbol, + [ExcelArgument("Optional. The type, Future or Spread, default = Future")] string security_type = null, + [ExcelArgument("Optional. The exchange, default = GLBX")] string exchange = null) + { + var param = new object[] { topic, contract, symbol, security_type, exchange }; + return ObservableRtdUtil.Observe(nameof(spark_md), param, + () => md_observable(contract, symbol, security_type, exchange).Select(x => + { + if (x is co2.ChannelUpdate upd) + return new TopicMDFormatter(upd, topic).format(); + return x; + })); + } } } \ No newline at end of file diff --git a/src/client/spark_excel/spark_excel_example.xlsm b/src/client/spark_excel/spark_excel_example.xlsm index ebca73ad1..c7cd7d17d 100644 Binary files a/src/client/spark_excel/spark_excel_example.xlsm and b/src/client/spark_excel/spark_excel_example.xlsm differ diff --git a/src/client/spark_sdk/samples/OrderSample.cs b/src/client/spark_sdk/samples/OrderSample.cs index 3847b0069..251b9a192 100644 --- a/src/client/spark_sdk/samples/OrderSample.cs +++ b/src/client/spark_sdk/samples/OrderSample.cs @@ -26,16 +26,9 @@ namespace bts.sdk _md = client; } - readonly static Lazy _orders = new Lazy(() => locate(), true); - readonly static Lazy _users = new Lazy(() => locate(), true); - readonly static Lazy _admin = new Lazy(() => locate(), true); - static T locate() where T : class, IApiClient - { - using (var ctx = new api.core.ServiceContext()) - { - return ctx.locate(); - } - } + readonly static Lazy _orders = new Lazy(() => Locator.locate(), true); + readonly static Lazy _users = new Lazy(() => Locator.locate(), true); + readonly static Lazy _admin = new Lazy(() => Locator.locate(), true); void print_update(T update) { diff --git a/src/lib/CMakeDeps.cmake b/src/lib/CMakeDeps.cmake index 5022d6833..255a29c21 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/MarketDataAuxiliaryService.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/cme_reference_data.conf;config/defaults/dynamic_orders.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.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/cme_reference_data.proto;config/protos/dynamic_orders.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.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/GrowableSPSCQueue.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;utils/stats.cpp;utils/thread_manager.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/MarketDataAuxiliaryService.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/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.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/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.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/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.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;utils/stats.cpp;utils/thread_manager.cpp) \ No newline at end of file diff --git a/src/lib/api/service_compiler/templates/excel/excel.pb.cs b/src/lib/api/service_compiler/templates/excel/excel.pb.cs index 1ed7feef3..c3c2f3b5c 100644 --- a/src/lib/api/service_compiler/templates/excel/excel.pb.cs +++ b/src/lib/api/service_compiler/templates/excel/excel.pb.cs @@ -25,14 +25,21 @@ namespace {{package}} // {{comment}} public partial class {{name}}_Excel : IDisposable { - readonly static Lazy<{{name}}> _service = new Lazy<{{name}}>(() => locate<{{name}}>(), true); - static T locate() where T : class, IApiClient - { - using (var ctx = new api.core.ServiceContext()) - { - return ctx.locate(); - } - } + readonly static object _lock = new object(); + readonly static Lazy<{{name}}> _service = new Lazy<{{name}}>(() => bts.api.Locator.locate<{{name}}>(), true); + // volatile static api.core.ServiceContext _ctx; + // static T locate() where T : class, IApiClient + // { + // if(_ctx == null) + // { + // lock(_lock) + // { + // if (_ctx == null) + // _ctx = new api.core.ServiceContext(); + // } + // } + // return _ctx.locate(); + // } public void Dispose() { diff --git a/src/lib/api/service_helpers/AdminServiceUtils.cpp b/src/lib/api/service_helpers/AdminServiceUtils.cpp index ea073db71..2c0c0106d 100644 --- a/src/lib/api/service_helpers/AdminServiceUtils.cpp +++ b/src/lib/api/service_helpers/AdminServiceUtils.cpp @@ -883,7 +883,7 @@ void AdminServiceUtils::get_md_entitlement_report(const AdminData& admin_data, admin_data); if(cme_data!=nullptr){ for (const auto& cme_mic_data : cme_data->md_permissions()){ - MDEntitlementReportUnit rv=get_cme_md_entitlement_unit(user.name(), + MDEntitlementReportUnit rv=get_cme_md_entitlement_unit(user, cme_mic_data); entitlements.push_back(rv); } @@ -891,10 +891,11 @@ void AdminServiceUtils::get_md_entitlement_report(const AdminData& admin_data, } } MDEntitlementReportUnit AdminServiceUtils::get_cme_md_entitlement_unit( - const std::string& user, + const BTSUser& user, const CMEMicData& cme_mic_data){ MDEntitlementReportUnit rv; - rv.set_user(user); + rv.set_user(user.name()); + rv.set_user_id(user.id()); rv.set_exchange("GLBX"); switch(cme_mic_data.mic()) { diff --git a/src/lib/api/service_helpers/AdminServiceUtils.h b/src/lib/api/service_helpers/AdminServiceUtils.h index 9836c65ee..5e001ebf0 100644 --- a/src/lib/api/service_helpers/AdminServiceUtils.h +++ b/src/lib/api/service_helpers/AdminServiceUtils.h @@ -230,7 +230,7 @@ public: std::vector& entitlements); // Gets a reporting unit out of CMEMicData static MDEntitlementReportUnit get_cme_md_entitlement_unit( - const std::string& user, + const BTSUser& user, const CMEMicData& cme_mic_data); static void get_user_symbol_permissions( const AdminData& data, diff --git a/src/lib/api/services/AdminService.proto b/src/lib/api/services/AdminService.proto index f77a11eb8..e9df474d8 100644 --- a/src/lib/api/services/AdminService.proto +++ b/src/lib/api/services/AdminService.proto @@ -277,6 +277,18 @@ message SIMAccountData { string clearing_account = 40; } +enum ProfessionalDesignation +{ + PROFESSIONALDESIGNATION_PRO = 0; + PROFESSIONALDESIGNATION_NONPRO = 1; +} + +enum DisplayDesignation +{ + DISPLAYDESIGNATION_DISPLAY = 0; + DISPLAYDESIGNATION_NONDISPLAY = 1; +} + message CMEUserData{ string operator_id = 10; string ats_operator_id = 20; @@ -287,6 +299,8 @@ message CMEUserData{ string smp_instruction = 70; string max_order_rate_per_connection = 80; string location = 90; + ProfessionalDesignation pro_nonpro = 100; + DisplayDesignation display_nondisplay = 110; // add suff here repeated CMEMicData md_permissions = 1000; } @@ -371,6 +385,7 @@ message OrderCancelRequest{ message MDEntitlementReportUnit{ string record_id = 1 [(bts.api.key)=true]; string user = 10; + uint32 user_id=11; string exchange = 20; string mic = 30; bool enabled = 40; diff --git a/src/lib/domain_model/Security.proto b/src/lib/domain_model/Security.proto index 3d2b5f738..5e921021e 100644 --- a/src/lib/domain_model/Security.proto +++ b/src/lib/domain_model/Security.proto @@ -53,7 +53,11 @@ enum CMEMics { } enum ICEMics{ - ICE_FUTURES_CANADA=0; + ICE_UNSET=0; + ICE_US = 1; + ICE_EU = 2; + ICE_LIFFE = 3; + ICE_CA = 4; } enum Side { diff --git a/src/lib/md/relay/QueryServer.cpp b/src/lib/md/relay/QueryServer.cpp index 6cbfcfc08..e5fc8c2c4 100644 --- a/src/lib/md/relay/QueryServer.cpp +++ b/src/lib/md/relay/QueryServer.cpp @@ -17,6 +17,8 @@ #include "lib/api/services/MarketDataRelay.server.pb.h" #include "lib/api/public/ServiceContext.h" #include "lib/api/services/AdminService.client.pb.h" +#include "lib/api/service_helpers/AdminServiceUtils.h" +#include "lib/config/protos/cme_reference_data.pb.h" #ifndef _WIN32 #include "lib/metrics/metrics.h" #endif @@ -357,7 +359,7 @@ public: if (groupiter != _groups.end()) { auto& group = groupiter->second; bool is_entitled = bypass_entitlement || - ch.exchange() == api::VENUE_SIM || + /*ch.exchange() == api::VENUE_SIM || */ ch.exchange() == api::VENUE_BTS || (entitlements && entitlements->count(ch.symbol())); fill(ch, *group, reply->add_channels(), is_entitled); @@ -517,28 +519,39 @@ QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, std::shared db.check_heartbeats(threadpool); }); container->health_timer->start(); - + // Subscribe to entitlement data container->entitlement_sub = - container->admin_client.subscribe_md_permissions_data().subscribe([=](const api::admin::Md_permissions_dataUpdate& update) { - auto entitlements = std::make_shared>(); - for (const auto& row : update.all()) { - if (row && row->enabled()) { - auto iter = entitlements->find(row->user_id()); - if (iter == entitlements->end()) { - Entitlements ents; - ents.insert(row->symbol()); - entitlements->insert(iter, std::make_pair(row->user_id(), std::move(ents))); - } - else { - iter->second.insert(row->symbol()); + container->admin_client.subscribe_md_entitlement_data().subscribe([=](const api::admin::Md_entitlement_dataUpdate& update) { + const auto& all_updates = update.all(); + utils::Dispatcher::background().post([all_updates, container]() + { + const auto& cme_symb_mics = config::get().cme_mic(); + auto entitlements = std::make_shared>(); + for (const auto& row : all_updates) { + if (row && row->enabled()) { + for(auto mic=cme_symb_mics.begin();mic!=cme_symb_mics.end();mic++){ + if(api::CMEMics_Name(mic->second) == row->mic()) { + const auto& symbol = mic->first; + auto iter = entitlements->find(row->user_id()); + if (iter == entitlements->end()) { + Entitlements ents; + ents.insert(symbol); + ents.insert("SIM:" + symbol); + entitlements->insert(iter, std::make_pair(row->user_id(), std::move(ents))); + } + else { + iter->second.insert(symbol); + iter->second.insert("SIM:" + symbol); + } + } + } } } - } - container->relay.update_entitlements(entitlements); + container->relay.update_entitlements(entitlements); + }); }); - // Add a few threads to keep md latency low for (int x = 1; x < std::min(4, os::num_cores()); ++x) { threadpool.add_thread(); diff --git a/src/server/sparkd/user/AdminServiceServer.cpp b/src/server/sparkd/user/AdminServiceServer.cpp index ff1505cb9..526ff3804 100644 --- a/src/server/sparkd/user/AdminServiceServer.cpp +++ b/src/server/sparkd/user/AdminServiceServer.cpp @@ -241,12 +241,12 @@ void AdminServiceServer::_publish_md_entitlements(){ _md_entit_publisher.add_or_update(e); _md_entit_publisher.flush(); } -void AdminServiceServer::_publish_md_permissions(){ - std::vector perms; - for (const BTSUser* user : AdminServiceUtils::users(_state,false)) - AdminServiceUtils::get_user_symbol_permissions(_state,*user,perms); - for (const auto& p : perms) - _md_perm_publisher.add_or_update(p); - _md_perm_publisher.flush(); -} +// void AdminServiceServer::_publish_md_permissions(){ +// std::vector perms; +// for (const BTSUser* user : AdminServiceUtils::users(_state,false)) +// AdminServiceUtils::get_user_symbol_permissions(_state,*user,perms); +// for (const auto& p : perms) +// _md_perm_publisher.add_or_update(p); +// _md_perm_publisher.flush(); +// } }} diff --git a/src/web/ui/src/Accounts/Types.fs b/src/web/ui/src/Accounts/Types.fs index 402f009e8..a4eb88d62 100644 --- a/src/web/ui/src/Accounts/Types.fs +++ b/src/web/ui/src/Accounts/Types.fs @@ -14,8 +14,9 @@ type Tab = | ConnectionsTab | OrdersTab -let venues = Venue.values |> Array.skip 1 -let securityTypes = SecurityType.values |> Array.skip 1 +let venues = [| Venue.GLBX; Venue.SIM |] + +let securityTypes = [| SecurityType.FUTURE; SecurityType.SPREAD |] let emptyAccount = Access.Accounts.empty diff --git a/src/web/ui/src/Users/State.fs b/src/web/ui/src/Users/State.fs index e8b73011e..e4ee5b4c9 100644 --- a/src/web/ui/src/Users/State.fs +++ b/src/web/ui/src/Users/State.fs @@ -62,6 +62,8 @@ let defaultScratchUser = { smpInstruction = "" maxOrderRatePerConnection = "" location = "" + proNonpro = ProfessionalDesignation.PRO + displayNondisplay = DisplayDesignation.DISPLAY mdPermissions = [||] } simData = { @@ -186,6 +188,8 @@ let applyUpdate (field:UserField) (user:BTSUser) = | SimOperatorID oid -> updateSIMExchangeUserData user { user.userData.exchangeUserData.simData with operatorId = oid } | SMPID smpid -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with smpId = smpid } | CMELocation loc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with location = loc } + | CMEProNonPro loc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with proNonpro = loc } + | CMEDisplayNonDisplay loc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with displayNondisplay = loc } | SimLocation loc -> updateSIMExchangeUserData user { user.userData.exchangeUserData.simData with location = loc } | SMPInstruction smpi -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with smpInstruction = smpi } | MaxOrderRatePerConnection morpc -> updateCMEExchangeUserData user { user.userData.exchangeUserData.cmeData with maxOrderRatePerConnection = morpc } diff --git a/src/web/ui/src/Users/Types.fs b/src/web/ui/src/Users/Types.fs index 1beeb47f8..5f58e4854 100644 --- a/src/web/ui/src/Users/Types.fs +++ b/src/web/ui/src/Users/Types.fs @@ -25,6 +25,8 @@ type UserField = | AddAccount of string | RemoveAccount of string | CMEMic of CMEMicData +| CMEProNonPro of ProfessionalDesignation +| CMEDisplayNonDisplay of DisplayDesignation type Msg = diff --git a/src/web/ui/src/Users/View.fs b/src/web/ui/src/Users/View.fs index 5388afa8c..9ed2fba4c 100644 --- a/src/web/ui/src/Users/View.fs +++ b/src/web/ui/src/Users/View.fs @@ -142,7 +142,8 @@ let MarketDataTabView (model:Model) (dispatch:Msg->Unit) = let micList = [ for micValue in bts.api.CMEMics.values do yield ( - if (micValue = bts.api.CMEMics.UNSET) |> not then + if (micValue = bts.api.CMEMics.UNSET || micValue = bts.api.CMEMics.MGE || + micValue = bts.api.CMEMics.DME || micValue = bts.api.CMEMics.NYMSW || micValue = bts.api.CMEMics.FXS) |> not then Fields.checkbox (sprintf "%O" micValue) ""