Files
spark/src/client/spark_api/security/GlbxSecurityFormatter.cs
T

196 lines
8.0 KiB
C#

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
namespace bts.api
{
/// <summary>
/// https://www.cmegroup.com/confluence/display/EPICSANDBOX/Futures+Spreads
/// </summary>
internal static class GlbxSecurityFormatter {
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');
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'
var space_split = colon_split[1].Split(' ');
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));
formatted_spread = string.Format("{0} {1} {2}yr {3}", s.Symbol, $"{first} - {second}", num_years, "Bundle Spread");
return true;
}
if (security_sub_type == "BF") {
// 'GE:BF Z4-U5-M6'
var space_split = colon_split[1].Split(' ');
var dash_split = space_split[1].Split('-');
string first = DateFormatter.Format(dash_split[0]);
string second = DateFormatter.Format(dash_split[1]);
string third = DateFormatter.Format(dash_split[2]);
formatted_spread = string.Format("{0} {1} {2}", s.Symbol, $"{first} - {second} - {third}", "Butterfly");
return true;
}
if (security_sub_type == "SP") {
//return "a Calendar Spread";
return false;
}
if (security_sub_type == "EQ") {
//return "an Equity Calendar Spread";
return false;
}
if (security_sub_type == "FX") {
//return "an Foreign Exchange Calendar Spread";
return false;
}
if (security_sub_type == "SD") {
//return "an SD Calendar Spread";
return false;
}
if (security_sub_type == "CF") {
// 'GE:CF H0H1H2H3'
var space_split = colon_split[1].Split(' ');
string first = space_split[1].Substring(0, 2);
string date_first = DateFormatter.Format(first);
string second = space_split[1].Substring(2, 2);
string date_second = DateFormatter.Format(second);
string diff = DateFormatter.GetMonthDifference(date_first, date_second);
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";
return false;
}
if (security_sub_type == "DF") {
// 'GE:DF Z7H8M8U8'
var space_split = colon_split[1].Split(' ');
string first = space_split[1].Substring(0, 2);
string date_first = DateFormatter.Format(first);
string second = space_split[1].Substring(2, 2);
string date_second = DateFormatter.Format(second);
string diff = DateFormatter.GetMonthDifference(date_first, date_second);
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";
return false;
}
if (security_sub_type == "IS") {
//return "an Inter-Commodity";
return false;
}
if (security_sub_type == "MP") {
// 'GE:MP H0 1YM0'
var space_split = colon_split[1].Split(' ');
string first = space_split[1].Substring(0, 2);
string date_first = DateFormatter.Format(first);
string second = space_split[2].Substring(2, 2);
string date_second = DateFormatter.Format(second);
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";
return false;
}
if (security_sub_type == "PB") {
// 'GE:PB Z7-Z8-Z9'
var space_split = colon_split[1].Split(' ');
var dash_split = space_split[1].Split('-');
string first = DateFormatter.Format(dash_split[0]);
string second = DateFormatter.Format(dash_split[1]);
string third = DateFormatter.Format(dash_split[2]);
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'
var space_split = colon_split[1].Split(' ');
var dash_split = space_split[1].Split('-');
string first = DateFormatter.Format(dash_split[0]);
string second = DateFormatter.Format(dash_split[1]);
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";
return false;
}
if (security_sub_type == "FS") {
//return "an FS Strip";
return false;
}
if (security_sub_type == "SA") {
//return "an SA Strip";
return false;
}
if (security_sub_type == "SB") {
//return "an SB Strip";
return false;
}
if (security_sub_type == "WS") {
//return "an Unblanced Strip";
return false;
}
if (security_sub_type == "XS") {
//return "an Energy Inter-Commodity Strip";
return false;
}
if (security_sub_type == "DI") {
//return "an Interest Rate Inter-Commodity Spread";
return false;
}
if (security_sub_type == "IV") {
//return "an Inter-Commodity Spread";
return false;
}
if (security_sub_type == "SI") {
//return "a Commodities Intercommodity Spread";
return false;
}
if (security_sub_type == "MS") {
//return "a BMD Futures Strip";
return false;
}
if (security_sub_type == "IN") {
//return "an Invoice Swap Spread";
return false;
}
if (security_sub_type == "SC") {
//return "an Invoice Swap Calendar Spread";
return false;
}
if (security_sub_type == "SW") {
//return "an Invoice Swap Switch Spread";
return false;
}
if (security_sub_type == "TL") {
//return "a Treasure Tail Spread";
return false;
}
if (security_sub_type == "BC") {
//return "a Henry Hub Intercommodity spread";
return false;
}
return false;
}
}
}