my head hurts from the f#
This commit is contained in:
1 parent
fe8f217587
commit
81d67f640b
23 files changed
+316
-77
No files matched your search
@@ -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<user.UserService> _auth = new Lazy<user.UserService>(() => Locator.locate<user.UserService>(), true);
|
||||
user.AuthToken _token = null;
|
||||
public Authenticator() { }
|
||||
|
||||
public user.AuthToken last_token => _token;
|
||||
public async Task<user.AuthToken> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts
|
||||
{
|
||||
public class AsyncLazy<T> : Lazy<Task<T>>
|
||||
{
|
||||
public AsyncLazy(Func<T> valueFactory) :
|
||||
base(() => Task.Factory.StartNew(valueFactory))
|
||||
{ }
|
||||
|
||||
public AsyncLazy(Func<Task<T>> taskFactory) :
|
||||
base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap())
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -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<ServiceContext> _context = new Lazy<ServiceContext>(() => new ServiceContext(), true);
|
||||
public static T locate<T>(string qualifier="") where T : class, IApiClient
|
||||
{
|
||||
return _context.Value.locate<T>(qualifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,49 +33,48 @@ namespace bts.api.md
|
||||
readonly ConcurrentDictionary<security_key, Data> _data = new ConcurrentDictionary<security_key, Data>();
|
||||
readonly ConcurrentDictionary<security_key, string> _security_key_to_desc= new ConcurrentDictionary<security_key, string>();
|
||||
readonly ConcurrentDictionary<string, security_key> _security_desc_to_key = new ConcurrentDictionary<string, security_key>();
|
||||
readonly Lazy<MDRequest> _subscription;
|
||||
readonly MDRequest _subscription;
|
||||
readonly Venue _venue;
|
||||
|
||||
readonly static Lazy<MarketDataRelay> _md = new Lazy<MarketDataRelay>(() => locate(), true);
|
||||
readonly static Lazy<MarketDataRelay> _md = new Lazy<MarketDataRelay>(() => Locator.locate<MarketDataRelay>(), true);
|
||||
readonly static ConcurrentDictionary<api.Venue, MarketDataClient> _venue_cache = new ConcurrentDictionary<api.Venue, api.md.MarketDataClient>();
|
||||
static readonly List<Product> _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<api.Venue> 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<MDRequest>(() => 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<MarketDataRelay>();
|
||||
}
|
||||
}
|
||||
|
||||
public Security lookup(security_key key)
|
||||
{
|
||||
Data value;
|
||||
@@ -217,7 +216,7 @@ namespace bts.api.md
|
||||
|
||||
bool check_subscriptions(uint flags, Func<SecurityChannel, bool> 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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ namespace bts.api.orderman
|
||||
{
|
||||
public partial class OrderService_Excel
|
||||
{
|
||||
readonly static Lazy<user.UserService> _users = new Lazy<user.UserService>(() => locate<user.UserService>(), true);
|
||||
readonly static Lazy<admin.AdminService> _admin = new Lazy<admin.AdminService>(() => locate<admin.AdminService>(), true);
|
||||
readonly static Lazy<user.UserService> _users = new Lazy<user.UserService>(() => Locator.locate<user.UserService>(), true);
|
||||
readonly static Lazy<admin.AdminService> _admin = new Lazy<admin.AdminService>(() => Locator.locate<admin.AdminService>(), true);
|
||||
|
||||
|
||||
[ExcelFunction(Category = "BTS", Description = "Cancel an Order by Order ID", IsMacroType = true)]
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -26,16 +26,9 @@ namespace bts.sdk
|
||||
_md = client;
|
||||
}
|
||||
|
||||
readonly static Lazy<OrderService> _orders = new Lazy<OrderService>(() => locate<OrderService>(), true);
|
||||
readonly static Lazy<UserService> _users = new Lazy<UserService>(() => locate<UserService>(), true);
|
||||
readonly static Lazy<AdminService> _admin = new Lazy<AdminService>(() => locate<AdminService>(), true);
|
||||
static T locate<T>() where T : class, IApiClient
|
||||
{
|
||||
using (var ctx = new api.core.ServiceContext())
|
||||
{
|
||||
return ctx.locate<T>();
|
||||
}
|
||||
}
|
||||
readonly static Lazy<OrderService> _orders = new Lazy<OrderService>(() => Locator.locate<OrderService>(), true);
|
||||
readonly static Lazy<UserService> _users = new Lazy<UserService>(() => Locator.locate<UserService>(), true);
|
||||
readonly static Lazy<AdminService> _admin = new Lazy<AdminService>(() => Locator.locate<AdminService>(), true);
|
||||
|
||||
void print_update<T>(T update)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
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)
|
||||
@@ -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<T>() where T : class, IApiClient
|
||||
{
|
||||
using (var ctx = new api.core.ServiceContext())
|
||||
{
|
||||
return ctx.locate<T>();
|
||||
}
|
||||
}
|
||||
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<T>() where T : class, IApiClient
|
||||
// {
|
||||
// if(_ctx == null)
|
||||
// {
|
||||
// lock(_lock)
|
||||
// {
|
||||
// if (_ctx == null)
|
||||
// _ctx = new api.core.ServiceContext();
|
||||
// }
|
||||
// }
|
||||
// return _ctx.locate<T>();
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -230,7 +230,7 @@ public:
|
||||
std::vector<MDEntitlementReportUnit>& 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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<std::unordered_map<uint32_t, Entitlements>>();
|
||||
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<config::CmeSymbolMics>().cme_mic();
|
||||
auto entitlements = std::make_shared<std::unordered_map<uint32_t, Entitlements>>();
|
||||
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();
|
||||
|
||||
@@ -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<UserSymbolMDPermissionUnit> 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<UserSymbolMDPermissionUnit> 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();
|
||||
// }
|
||||
}}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -25,6 +25,8 @@ type UserField =
|
||||
| AddAccount of string
|
||||
| RemoveAccount of string
|
||||
| CMEMic of CMEMicData
|
||||
| CMEProNonPro of ProfessionalDesignation
|
||||
| CMEDisplayNonDisplay of DisplayDesignation
|
||||
|
||||
|
||||
type Msg =
|
||||
|
||||
@@ -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)
|
||||
""
|
||||
|
||||
Reference in new issue
Block a user