SPARK-599 - Exceptions are now exceptional
This commit is contained in:
1 parent
dc6bce362f
commit
206f2d3c3c
2 files changed
+47
-37
No files matched your search
@@ -10,15 +10,16 @@ namespace bts.api
|
||||
/// </summary>
|
||||
internal static class GlbxSecurityFormatter {
|
||||
|
||||
public static string FormatSpread(SecurityImmutable s) {
|
||||
string result = string.Empty;
|
||||
public static bool FormatSpread(SecurityImmutable s, out string formatted_spread) {
|
||||
formatted_spread = string.Empty;
|
||||
var colon_split = s.Glbx.SecurityDesc.Split(':');
|
||||
string security_sub_type = colon_split[1].Substring(0, 2);
|
||||
if (security_sub_type == "FB") {
|
||||
// 'GE:FB 02Y H0'
|
||||
var space_split = colon_split[1].Split(' ');
|
||||
string num_years = space_split[1].Substring(0, space_split[1].IndexOf("Y")).TrimStart('0');
|
||||
return string.Format("{0} {1} {2}yr {3}", s.Symbol, DateFormatter.Format(space_split[2]), num_years, "Bundle");
|
||||
formatted_spread = string.Format("{0} {1} {2}yr {3}", s.Symbol, DateFormatter.Format(space_split[2]), num_years, "Bundle");
|
||||
return true;
|
||||
}
|
||||
if (security_sub_type == "BS") {
|
||||
// 'GE:BS 2YH0 2YH2'
|
||||
@@ -26,7 +27,8 @@ namespace bts.api
|
||||
string num_years = space_split[1].Substring(0, space_split[1].IndexOf("Y")).TrimStart('0');
|
||||
string first = DateFormatter.Format(space_split[1].Substring(2));
|
||||
string second = DateFormatter.Format(space_split[2].Substring(2));
|
||||
return string.Format("{0} {1} {2}yr {3}", s.Symbol, $"{first} - {second}", num_years, "Bundle Spread");
|
||||
formatted_spread = string.Format("{0} {1} {2}yr {3}", s.Symbol, $"{first} - {second}", num_years, "Bundle Spread");
|
||||
return true;
|
||||
|
||||
}
|
||||
if (security_sub_type == "BF") {
|
||||
@@ -36,24 +38,25 @@ namespace bts.api
|
||||
string first = DateFormatter.Format(dash_split[0]);
|
||||
string second = DateFormatter.Format(dash_split[1]);
|
||||
string third = DateFormatter.Format(dash_split[2]);
|
||||
return string.Format("{0} {1} {2}", s.Symbol, $"{first} - {second} - {third}", "Butterfly");
|
||||
formatted_spread = string.Format("{0} {1} {2}", s.Symbol, $"{first} - {second} - {third}", "Butterfly");
|
||||
return true;
|
||||
}
|
||||
if (security_sub_type == "SP") {
|
||||
//return "a Calendar Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "EQ") {
|
||||
//return "an Equity Calendar Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
|
||||
}
|
||||
if (security_sub_type == "FX") {
|
||||
//return "an Foreign Exchange Calendar Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "SD") {
|
||||
//return "an SD Calendar Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "CF") {
|
||||
// 'GE:CF H0H1H2H3'
|
||||
@@ -63,11 +66,12 @@ namespace bts.api
|
||||
string second = space_split[1].Substring(2, 2);
|
||||
string date_second = DateFormatter.Format(second);
|
||||
string diff = DateFormatter.GetMonthDifference(date_first, date_second);
|
||||
return string.Format("{0} {1} {2}mo {3}", s.Symbol, DateFormatter.Format(first), diff, "Condor");
|
||||
formatted_spread = string.Format("{0} {1} {2}mo {3}", s.Symbol, DateFormatter.Format(first), diff, "Condor");
|
||||
return true;
|
||||
}
|
||||
if (security_sub_type == "C1") {
|
||||
//return "a Crack One-One";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "DF") {
|
||||
// 'GE:DF Z7H8M8U8'
|
||||
@@ -77,15 +81,16 @@ namespace bts.api
|
||||
string second = space_split[1].Substring(2, 2);
|
||||
string date_second = DateFormatter.Format(second);
|
||||
string diff = DateFormatter.GetMonthDifference(date_first, date_second);
|
||||
return string.Format("{0} {1} {2}mo {3}", s.Symbol, DateFormatter.Format(first), diff, "Double Butterfly");
|
||||
formatted_spread = string.Format("{0} {1} {2}mo {3}", s.Symbol, DateFormatter.Format(first), diff, "Double Butterfly");
|
||||
return true;
|
||||
}
|
||||
if (security_sub_type == "EC") {
|
||||
//return "a TAS Calendar";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "IS") {
|
||||
//return "an Inter-Commodity";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "MP") {
|
||||
// 'GE:MP H0 1YM0'
|
||||
@@ -94,12 +99,13 @@ namespace bts.api
|
||||
string date_first = DateFormatter.Format(first);
|
||||
string second = space_split[2].Substring(2, 2);
|
||||
string date_second = DateFormatter.Format(second);
|
||||
return string.Format("{0} {1}-({2} PK) {3}", s.Symbol, date_first, date_second, "Month Pack");
|
||||
formatted_spread = string.Format("{0} {1}-({2} PK) {3}", s.Symbol, date_first, date_second, "Month Pack");
|
||||
return true;
|
||||
}
|
||||
if (security_sub_type == "PK") {
|
||||
// 'GE:PK 01Y H0'
|
||||
//return "a PK Pack";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "PB") {
|
||||
// 'GE:PB Z7-Z8-Z9'
|
||||
@@ -108,7 +114,8 @@ namespace bts.api
|
||||
string first = DateFormatter.Format(dash_split[0]);
|
||||
string second = DateFormatter.Format(dash_split[1]);
|
||||
string third = DateFormatter.Format(dash_split[2]);
|
||||
return string.Format("{0} {1} {2}", s.Symbol, $"{first} - {second} - {third}", "Pack Butterfly");
|
||||
formatted_spread = string.Format("{0} {1} {2}", s.Symbol, $"{first} - {second} - {third}", "Pack Butterfly");
|
||||
return true;
|
||||
}
|
||||
if (security_sub_type == "PS") {
|
||||
// 'GE:PS H0-H1'
|
||||
@@ -116,73 +123,73 @@ namespace bts.api
|
||||
var dash_split = space_split[1].Split('-');
|
||||
string first = DateFormatter.Format(dash_split[0]);
|
||||
string second = DateFormatter.Format(dash_split[1]);
|
||||
return string.Format("{0} {1} {2}", s.Symbol, $"{first} - {second}", "Pack Spread");
|
||||
formatted_spread = string.Format("{0} {1} {2}", s.Symbol, $"{first} - {second}", "Pack Spread");
|
||||
return true;
|
||||
}
|
||||
if (security_sub_type == "RT") {
|
||||
// TODO:
|
||||
// Need SecuritySubType in Security as I believe the lack of :XX in the security
|
||||
// means different things depending on the security
|
||||
//return "Reduced Tick Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "FS") {
|
||||
//return "an FS Strip";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "SA") {
|
||||
//return "an SA Strip";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "SB") {
|
||||
//return "an SB Strip";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "WS") {
|
||||
//return "an Unblanced Strip";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "XS") {
|
||||
//return "an Energy Inter-Commodity Strip";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "DI") {
|
||||
//return "an Interest Rate Inter-Commodity Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "IV") {
|
||||
//return "an Inter-Commodity Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "SI") {
|
||||
//return "a Commodities Intercommodity Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "MS") {
|
||||
//return "a BMD Futures Strip";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "IN") {
|
||||
//return "an Invoice Swap Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "SC") {
|
||||
//return "an Invoice Swap Calendar Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "SW") {
|
||||
//return "an Invoice Swap Switch Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "TL") {
|
||||
//return "a Treasure Tail Spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
if (security_sub_type == "BC") {
|
||||
//return "a Henry Hub Intercommodity spread";
|
||||
throw new NotImplementedException();
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new FormatException($"Could not parse spread with a security description of {s.Glbx.SecurityDesc}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,11 @@ namespace bts.api
|
||||
case Security.ContractOneofCase.Spread:
|
||||
if (s.Glbx != null && s.Glbx.SecurityDesc.Contains(":")) {
|
||||
try {
|
||||
formatted_security_name = GlbxSecurityFormatter.FormatSpread(s);
|
||||
break;
|
||||
if (GlbxSecurityFormatter.FormatSpread(s, out formatted_security_name)) {
|
||||
break;
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
} catch (Exception) {
|
||||
goto default;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user