Add SecurityCriteriaExtensions
This commit is contained in:
1 parent
9e5c0e9c68
commit
cd45576fb0
2 files changed
+25
-3
No files matched your search
@@ -215,7 +215,7 @@ namespace mbts.spark {
|
||||
);
|
||||
}
|
||||
|
||||
private bool _security_in_criteria(SecurityImmutable sec_item)
|
||||
public static bool security_in_criteria(SecurityCriteria criteria, SecurityImmutable sec_item)
|
||||
{
|
||||
//// Mock criteria to test against
|
||||
//var item1 = new SecurityCriteriaClause()
|
||||
@@ -235,10 +235,10 @@ namespace mbts.spark {
|
||||
//SecurityCriteria a = new SecurityCriteria();
|
||||
//a.clauses.AddRange(new SecurityCriteriaClause[] { item1, item2 } );
|
||||
|
||||
List<bool> criteria_results = new List<bool>(_search_criteria.clauses.Length + 1);
|
||||
List<bool> criteria_results = new List<bool>(criteria.clauses.Length + 1);
|
||||
criteria_results.Add(false);
|
||||
// need to add another arg to class constructor to accept SecurityCriteria[]
|
||||
foreach (SecurityCriteriaClause x in _search_criteria.clauses)
|
||||
foreach (SecurityCriteriaClause x in criteria.clauses)
|
||||
{
|
||||
bool iteration_result = (x.exchanges.Length == 0 || x.exchanges.Any(exchange => exchange == sec_item.Exchange))
|
||||
&& (x.security_types.Length == 0 || x.security_types.Any(sec_type => sec_type == sec_item.security_type()))
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using bts.api;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reactive.Linq;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark {
|
||||
static class SecurityCriteriaExtensions {
|
||||
public static async Task<IEnumerable<SecurityMD>> securities(this SecurityCriteria self, IBus bus) {
|
||||
var all = await bus.subscribe(SparkTags.SecuritiesTag).FirstAsync();
|
||||
return all.Values.Where(md => ContractPickerModel.security_in_criteria(self, md.security));
|
||||
}
|
||||
public static IObservable<IEnumerable<SecurityMD>> subscribe(this SecurityCriteria self, IBus bus) {
|
||||
return
|
||||
bus
|
||||
.subscribe(SparkTags.SecuritiesTag)
|
||||
.Select(dict =>
|
||||
dict.Values.Where(md => ContractPickerModel.security_in_criteria(self, md.security)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user