Add SecType, Venue arg parser for streams
This commit is contained in:
1 parent
eda34e0e3b
commit
4e198183eb
2 files changed
+87
No files matched your search
@@ -0,0 +1,43 @@
|
||||
namespace Bts.SharedStreams.MarketData;
|
||||
|
||||
using bts.api;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
public class SecurityTypeArgumentParser : IStreamArgumentParser<SecurityType> {
|
||||
public static bool TryParse(string? str, out SecurityType result) {
|
||||
if (str is null) {
|
||||
result = SecurityType.Unset;
|
||||
return false;
|
||||
}
|
||||
if (Enum.TryParse(str, true, out result) || Enum.TryParse("SECURITYTYPE_" + str, true, out result)) {
|
||||
return true;
|
||||
}
|
||||
result = str.ToUpper() switch {
|
||||
"F" or "FUT" or "FUTURE" => SecurityType.Future,
|
||||
"O" or "OPT" or "OPTION" => SecurityType.Option,
|
||||
"SPOT" or "STOCK" => SecurityType.Spot,
|
||||
"SPD" or "SPREAD" or "COMBO" => SecurityType.Spread,
|
||||
_ => SecurityType.Unset,
|
||||
};
|
||||
return result != SecurityType.Unset;
|
||||
}
|
||||
|
||||
public bool TryParse(StreamArgument arg, out SecurityType result, out string? error) {
|
||||
error = null;
|
||||
result = SecurityType.Unset;
|
||||
var val = arg.Value;
|
||||
if (val is SecurityType secType) {
|
||||
result = secType;
|
||||
return true;
|
||||
} else if (val is string str) {
|
||||
if (TryParse(str, out result)) {
|
||||
return true;
|
||||
}
|
||||
error = $"Failed to parse secType from string '{str}'";
|
||||
} else {
|
||||
error = $"Venue parser received input of unexpected type '{val?.GetType()}'";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace Bts.SharedStreams.MarketData;
|
||||
|
||||
using bts.api;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
public class VenueArgumentParser : IStreamArgumentParser<Venue> {
|
||||
public static bool TryParse(string? str, out Venue v) {
|
||||
if (str is null) {
|
||||
v = Venue.Unset;
|
||||
return false;
|
||||
}
|
||||
if (Enum.TryParse(str, true, out v) || Enum.TryParse("VENUE_" + str, true, out v)) {
|
||||
return true;
|
||||
}
|
||||
v = str.ToUpper() switch {
|
||||
"CME" or "XCME" or "CEC" or "XCEC" => Venue.Glbx,
|
||||
"CBOT" or "CBT" or "XCBT" => Venue.Cboe,
|
||||
_ => Venue.Unset,
|
||||
};
|
||||
return v != Venue.Unset;
|
||||
}
|
||||
|
||||
public bool CanParse(StreamArgument arg, Type outputType) =>
|
||||
TryParse(arg, out _, out _);
|
||||
|
||||
public bool TryParse(StreamArgument arg, out Venue result, out string? error) {
|
||||
error = null;
|
||||
result = Venue.Unset;
|
||||
var val = arg.Value;
|
||||
if (val is Venue venue) {
|
||||
result = venue;
|
||||
return true;
|
||||
} else if (val is string str) {
|
||||
if (TryParse(str, out result)) {
|
||||
return true;
|
||||
}
|
||||
error = $"Failed to parse venue from string '{str}'";
|
||||
} else {
|
||||
error = $"Venue parser received input of unexpected type '{val?.GetType()}'";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user