diff --git a/src/client/spark/AlgoProvider/ISecurityAlgoProvider.cs b/src/client/spark/AlgoProvider/ISecurityAlgoProvider.cs index c24f3ab90..45ce5eb4e 100644 --- a/src/client/spark/AlgoProvider/ISecurityAlgoProvider.cs +++ b/src/client/spark/AlgoProvider/ISecurityAlgoProvider.cs @@ -26,12 +26,23 @@ namespace mbts.spark { class AlgoProvider : IAlgoProvider { readonly IEnumerable _security_algo_types; readonly IAlgoStudioModel _studio_model; + readonly IObservable> _studio_algos_source; readonly DynamicOrderHelper _dynamic_helper; public AlgoProvider(IEnumerable algo_sets, IAlgoStudioModel studio_model, DynamicOrderHelper dynamic_helper) { _security_algo_types = algo_sets; _studio_model = studio_model; - _dynamic_helper = dynamic_helper; + _dynamic_helper = dynamic_helper; + /// initialize with an empty table, so the + /// + /// calls made by the 'subscribe_algos' methods will fire at least once, even if the underlying + /// studio algos stream is empty have been created (this would be the case if the user had not yet created any studio algos). + /// , + /// , + /// + _studio_algos_source = studio_model.definitions + .StartWith(TableUpdate.mk_empty(AlgoData.key_fn)) + .Cache(); } public AlgoTypeSetImmutable get_permitted_algos(SecurityImmutable security) => @@ -45,21 +56,21 @@ namespace mbts.spark { .Aggregate(AlgoTypeSetImmutable.empty, (result, algos) => result.intersect_with(algos)); public IObservable> subscribe_algos() => - _studio_model.definitions + _studio_algos_source .AppendTable(_security_algo_types .Select(s => s.algo_type_set) .Aggregate(AlgoTypeSetImmutable.empty, (a, b) => a.union_with(b)) .define_algos(_dynamic_helper)); public IObservable> subscribe_algos(SecurityCriteriaClause security_clause) => - _studio_model.definitions.Select( + _studio_algos_source.Select( a => (algo: a, fitted_def: _fit_to_type(a.value, security_clause, _security_algo_types)), tup => tup.algo.key) .Select(tup => AlgoData.create(tup.fitted_def, tup.algo.name, tup.algo.key), a => a.key) .AppendTable(_security_algo_types.match_algos(security_clause, _dynamic_helper).Values); public IObservable> subscribe_algos(SecurityImmutable security) => - _studio_model.definitions.Select( + _studio_algos_source.Select( a => (algo: a, fitted_def: _fit_to_type(a.value, security, _security_algo_types)), tup => tup.algo.key) // filter out algos that use an unsupported root, because this would have the effect of duplicating the default algo