refactor: Clean up VolSurfaceExtensions
* Run formatter * Replace foreach loops w/ less verbose linq style extensions
This commit is contained in:
1 parent
fe7097771b
commit
6f7e2ab201
1 file changed
+33
-49
@@ -1,52 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using mbts.ui.controls;
|
||||
using bts.api;
|
||||
using bts.api.analytics;
|
||||
using Microsoft.Scripting.Actions;
|
||||
|
||||
|
||||
namespace mbts.spark {
|
||||
internal static class VolSurfaceExtensions {
|
||||
using bts.api;
|
||||
using bts.api.analytics;
|
||||
|
||||
using mbts.ui.controls;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
static class VolSurfaceExtensions {
|
||||
// VolSurfaceUsage
|
||||
public static IEnumerable<int> vss(this VolSurfaceUsageListImmutable list) {
|
||||
HashSet<int> rv = new HashSet<int>();
|
||||
foreach (VolSurfaceUsageEntryImmutable e in list.UsageList) {
|
||||
rv.Add(e.VsId);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static Nullable<int> get_vs_id(this VolSurfaceUsageListImmutable list, SecurityTuple security_tuple) {
|
||||
foreach (VolSurfaceUsageEntryImmutable e in list.UsageList) {
|
||||
if (e.SymbolName == security_tuple.security_name &&
|
||||
e.SymbolVenue == security_tuple.security_exchange) {
|
||||
return e.VsId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static Nullable<int> get_vs_id(this VolSurfaceUsageListImmutable list, string option_name) {
|
||||
SecurityTuple st = new SecurityTuple(SecurityType.Option, option_name, Venue.Unset);
|
||||
return get_vs_id(list, st);
|
||||
}
|
||||
public static bool symbol_driven_by_vs(this VolSurfaceUsageListImmutable list,
|
||||
string option_name, int vs_id) {
|
||||
foreach (var usage in list.UsageList) {
|
||||
if (usage.SymbolName == option_name &&
|
||||
usage.VsId == vs_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static HashSet<string> hidden_cols(this VolSurfaceMacroGridSettings gs) {
|
||||
return new HashSet<string>(gs.configuration.column_configurations.Where(cc => !cc.visible).Select(cc => cc.name));
|
||||
}
|
||||
public static mbts.analytics.VolSurfaceExpiration ToVSExp(this VolSurfaceDisplayGridExpiration vsdge) {
|
||||
return new mbts.analytics.VolSurfaceExpiration { expiration = vsdge.expiration, symbol = vsdge.symbol };
|
||||
}
|
||||
public static mbts.SecurityExpiration ToSecurityExp(this VolSurfaceDisplayGridExpiration vsdge) {
|
||||
return new mbts.SecurityExpiration(Venue.Unset, SecurityType.Option, vsdge.symbol, vsdge.expiration);
|
||||
}
|
||||
public static IEnumerable<int> vss(this VolSurfaceUsageListImmutable list) =>
|
||||
new HashSet<int>(list.UsageList.Select(e => e.VsId));
|
||||
|
||||
public static int? get_vs_id(this VolSurfaceUsageListImmutable list, SecurityTuple security_tuple) =>
|
||||
list.UsageList.TryGetFirst(e => e.SymbolName == security_tuple.security_name &&
|
||||
e.SymbolVenue == security_tuple.security_exchange, out var res) ?
|
||||
res.VsId : null;
|
||||
|
||||
public static int? get_vs_id(this VolSurfaceUsageListImmutable list, string option_name) =>
|
||||
get_vs_id(list, new SecurityTuple(SecurityType.Option, option_name, Venue.Unset));
|
||||
|
||||
public static bool symbol_driven_by_vs(this VolSurfaceUsageListImmutable list, string option_name, int vs_id) =>
|
||||
list.UsageList.Any(u => u.SymbolName == option_name && u.VsId == vs_id);
|
||||
|
||||
public static HashSet<string> hidden_cols(this VolSurfaceMacroGridSettings gs) =>
|
||||
new(gs.configuration.column_configurations.Where(cc => !cc.visible).Select(cc => cc.name));
|
||||
|
||||
public static analytics.VolSurfaceExpiration ToVSExp(this VolSurfaceDisplayGridExpiration vsdge) =>
|
||||
new() { expiration = vsdge.expiration, symbol = vsdge.symbol };
|
||||
|
||||
public static SecurityExpiration ToSecurityExp(this VolSurfaceDisplayGridExpiration vsdge) =>
|
||||
new(Venue.Unset, SecurityType.Option, vsdge.symbol, vsdge.expiration);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user