diff --git a/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs b/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs index 590784e95..c7788de53 100644 --- a/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs +++ b/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs @@ -622,9 +622,7 @@ namespace bts.shell.pnl { static class PNLDataExtensions { public static string pnl_symbol(this SecurityImmutable security) { - if(security.HasIce) - return PNLICEHelper.get_symbol(security); - return security.Symbol; + return bts.api.ExchangeSpecificUitlities.get_pnl_symbol(security); } // while override_cpp could use double.NaN to indicate the lack of an override, @@ -636,7 +634,7 @@ namespace bts.shell.pnl { public static (double default_cpp, double? override_cpp) pnl_cpp_tuple(this PNLUnitImmutable pnl_unit, SecurityImmutable security) { // TODO: actual impl - double calced_pnl = PNLICEHelper.get_cpp(pnl_unit,security); + double calced_pnl = bts.api.ExchangeSpecificUitlities.get_cpp(pnl_unit,security); return (calced_pnl, pnl_unit.HasCppOverride ? pnl_unit.CppOverride.Value : (double?)null); } } diff --git a/src/client/spark/Modules/Trading/PNL/Data/PNLICEHelper.cs b/src/client/spark/Modules/Trading/PNL/Data/PNLICEHelper.cs deleted file mode 100644 index e00e6ef34..000000000 --- a/src/client/spark/Modules/Trading/PNL/Data/PNLICEHelper.cs +++ /dev/null @@ -1,75 +0,0 @@ -using bts.api; -using bts.api.orderman; -using bts.api.position; -using bts.utils; -using mbts; -using System; -using System.Collections.Generic; -using System.Collections.Immutable; - - -namespace bts.shell.pnl { - -static class PNLICEHelper{ - - public static bool is_spread(SecurityImmutable sec){ - return sec.HasSpread && sec.Ice.StripName.Contains("/"); - } - - public static bool is_strip(SecurityImmutable sec){ - return sec.HasSpread && !is_spread(sec); - } - - public static bool is_ice_lots(SecurityImmutable sec){ - return sec.Ice.MarketDescription.Contains("ICE Lots"); - } - - public static double get_future_cpp (SecurityImmutable sec){ - if(sec.Symbol == "HHD") - return 1; - if(is_ice_lots(sec)) - return 2500; - else{ - var days_in_month = DateTime.DaysInMonth(Convert.ToInt32(sec.Future.ExpirationYear), - Convert.ToInt32(sec.Future.ExpirationMonth)); - return days_in_month; // because the size is multiplied by 2500 already - } - } - - public static double get_spread_cpp(SecurityImmutable sec){ - return 0; - } - - public static double get_strip_cpp(PNLUnitImmutable pnl, - SecurityImmutable sec){ - double rv = 0; - foreach (var l in sec.Spread.Legs) - if(l.Security.HasFuture) - rv += get_cpp(pnl,l.Security); - return rv; - } - - public static string get_symbol (SecurityImmutable sec){ - var rv = String.Format("{0}{1}{2}", - sec.Symbol, - is_ice_lots(sec)? " ICE LOTS" : String.Empty, - is_spread(sec)? " Spread" : String.Empty); - return rv; - } - - public static double get_cpp (PNLUnitImmutable pnl, - SecurityImmutable sec){ - if (sec.HasGlbx) - return pnl.CashValue; - else if (sec.HasIce){ - if(sec.HasFuture) - return get_future_cpp(sec); - else if(is_spread(sec)) - return get_spread_cpp(sec); - else if(is_strip(sec)) - return get_strip_cpp(pnl,sec); - } - return Double.NaN; - } - -}} \ No newline at end of file diff --git a/src/client/spark_api/security/ExchangeSpecificUitlities.cs b/src/client/spark_api/security/ExchangeSpecificUitlities.cs new file mode 100644 index 000000000..fc459d4b8 --- /dev/null +++ b/src/client/spark_api/security/ExchangeSpecificUitlities.cs @@ -0,0 +1,128 @@ +using bts.api; +using bts.api.orderman; +using bts.api.position; +using bts.utils; +using mbts; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; + + +namespace bts.api { + +static class ExchangeSpecificUitlities{ + private static string _default_hub = "Henry"; + static class ICE{ + + #region Contract Type + public static bool is_spread(SecurityImmutable sec){ + return sec.HasSpread && sec.Ice.StripName.Contains("/"); + } + + public static bool is_strip(SecurityImmutable sec){ + return sec.HasSpread && !is_spread(sec); + } + + public static bool is_ice_lots(SecurityImmutable sec){ + return sec.Ice.MarketDescription.Contains("ICE Lots"); + } + + public static bool is_tas(SecurityImmutable sec){ + return sec.Ice.MarketDescription.Contains("TAS"); + } + + #endregion + + #region CPP + public static double get_future_cpp (SecurityImmutable sec){ + if(sec.Symbol == "HHD") + // only futures in HHD are the dailies, everything + // else is a strip or spread + return 1; + if(is_ice_lots(sec)) + return 2500; + else{ + var days_in_month = DateTime.DaysInMonth(Convert.ToInt32(sec.Future.ExpirationYear), + Convert.ToInt32(sec.Future.ExpirationMonth)); + return days_in_month; // because the size is multiplied by 2500 already + } + } + + public static double get_spread_cpp(SecurityImmutable sec){ + return 0; + } + + public static double get_strip_cpp(PNLUnitImmutable pnl, + SecurityImmutable sec){ + // add up all the legs + double rv = 0; + foreach (var l in sec.Spread.Legs) + if(l.Security.HasFuture) + rv += get_cpp(pnl,l.Security); + return rv; + } + + public static double get_cpp (PNLUnitImmutable pnl, + SecurityImmutable sec){ + if(sec.HasFuture) + return get_future_cpp(sec); + else if(is_spread(sec)) + return get_spread_cpp(sec); + else if(is_strip(sec)) + return get_strip_cpp(pnl,sec); + return Double.NaN; + } + #endregion + + #region Symbol + public static string get_pnl_symbol (SecurityImmutable sec){ + // for pnl purposes, for a symbol, the division is : + // Futures and Strips + // ICE Lots + // Spreads + var rv = String.Format("{0}{1}{2}", + sec.Symbol, + is_ice_lots(sec)? " ICE LOTS" : String.Empty, + is_spread(sec)? " Spread" : String.Empty); + return rv; + } + #endregion + + #region Formatting + public static string format_security (SecurityImmutable? security){ + if(security.HasValue && security.Value.HasIce){ + bool ice_lots = is_ice_lots(security.Value), + tas = is_tas(security.Value); + return String.Format("{0}{1}{2}{3}{4}", + security?.Symbol, + ice_lots? " ICE Lots" : String.Empty, + tas ? " TAS" : String.Empty, + String.Compare(security.Value.Ice.HubAlias, _default_hub,true)==0 ? String.Empty : + " " + security.Value.Ice.HubAlias, + " " + security?.Ice.StripName); + } + return String.Empty; + } + #endregion + } + + public static double get_cpp (PNLUnitImmutable pnl, + SecurityImmutable sec){ + if(sec.HasIce) + return ICE.get_cpp(pnl,sec); + return pnl.CashValue; + } + + public static string get_pnl_symbol (SecurityImmutable sec){ + if(sec.HasIce) + return ICE.get_pnl_symbol(sec); + return sec.Symbol; + } + + public static string format_security(SecurityImmutable? security){ + if(security?.HasIce == true) + return ICE.format_security(security); + return security?.ToString(); + } + +}} \ No newline at end of file diff --git a/src/client/spark_api/security/SecurityFormatter.cs b/src/client/spark_api/security/SecurityFormatter.cs index 14ffdfbd3..421659a0c 100644 --- a/src/client/spark_api/security/SecurityFormatter.cs +++ b/src/client/spark_api/security/SecurityFormatter.cs @@ -41,7 +41,7 @@ namespace bts.api { switch (security?.ContractCase) { case ContractOneofCase.Future: if(security?.HasIce == true) - return _format_ICE(security); + return bts.api.ExchangeSpecificUitlities.format_security(security); return format_future(security?.Symbol, security?.security_desc(), security.Value.Future); case ContractOneofCase.Spread: if (security?.HasGlbx == true) { @@ -50,7 +50,7 @@ namespace bts.api { return security?.Glbx.SecurityDesc; } else if(security?.HasIce == true) - return _format_ICE(security); + return bts.api.ExchangeSpecificUitlities.format_security(security); return string.Join("", _format_future_legs(SecurityHelper.get_flat_future_legs(security?.Spread.Legs))); case ContractOneofCase.Synthetic: return security?.Synthetic.Name; default: return "Unknown-security"; @@ -84,28 +84,5 @@ namespace bts.api { default: return $"{fl.quantity:+0;-0}{sym_exp_name}"; } } - - static string _format_ICE (SecurityImmutable? security){ - string symbol = security?.Symbol, - strip = security?.Ice.StripName, - md_desc = security?.Ice.MarketDescription, - type_append = ""; - - if(md_desc.Contains("25k ICE Lots")){ - if(md_desc.Contains("TAS")) - type_append = "TAS"; - } - else if(md_desc.Contains("ICE Lots")){ - if(md_desc.Contains("TAS")) - type_append = "ICE Lots TAS"; - else - type_append = "ICE Lots"; - } - else if(md_desc.Contains("TAS")) - type_append = "TAS"; - type_append = string.IsNullOrEmpty(type_append) ? - " " : $" {type_append} "; - return $"{symbol}{type_append}{strip}"; - } } } \ No newline at end of file diff --git a/src/lib/domain_model/Security.h b/src/lib/domain_model/Security.h index 2494738a6..6fa026c78 100644 --- a/src/lib/domain_model/Security.h +++ b/src/lib/domain_model/Security.h @@ -213,30 +213,16 @@ inline bool gr_than(double p1, double p2, double tick_size) { !test_price_equality(p1, p2, tick_size); } -// Works only if ICEExchangeData is part of the a spread security -// inline bool is_ice_strip(const bts::api::ICEExchangeData& ice_data){ -// return ice_data.is_strip(); -// } +// ice specialization ///////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// -inline bool is_ice_strip(const bts::api::ICEExchangeData& ice_data){ - // TODO, put this in the security +inline bool is_ice_spread(const bts::api::ICEExchangeData& ice_data){ const auto& strip = ice_data.strip_name(); - auto find = [&](const std::string& sub) -> bool { - return strip.find(sub) != std::string::npos; - }; - if(!find("/")) - return find("-") || - find("Q1") || find("Q2") || find("Q3") || find("Q4") || - find("Cal"); - else - return false; + return strip.find("/") != std::string::npos; } inline bool is_strip(const bts::api::Security& sec){ - if(sec.has_spread()) - if (sec.has_ice()) - return is_ice_strip(sec.ice()); - return false; + return sec.has_ice() && sec.has_spread() && !is_ice_spread(sec.ice()); } inline bool is_spread_of_strips(const bts::api::Security& sec){ diff --git a/src/lib/orderman/actors/FillStore.cpp b/src/lib/orderman/actors/FillStore.cpp index fa229c2b9..7cbb5864a 100644 --- a/src/lib/orderman/actors/FillStore.cpp +++ b/src/lib/orderman/actors/FillStore.cpp @@ -39,6 +39,7 @@ struct FillStore::PImpl { FillStore::FillStore(md::SecurityOracle o) : me(new PImpl(o)) {} +// returns the sod type of a non sod type fill auto sod_fill_kind (const api::orderman::Fill& fill){ auto rv = Fill::FILL_KIND_SOD; switch (fill.fill_kind()){ @@ -52,6 +53,7 @@ auto sod_fill_kind (const api::orderman::Fill& fill){ rv = Fill::FILL_KIND_SOD_STRIP_LEG; break; default: + LOG(persist, Error, "Stored fill kinds can not be SOD"); rv = Fill::FILL_KIND_SOD; break; } @@ -60,24 +62,19 @@ auto sod_fill_kind (const api::orderman::Fill& fill){ auto leg_fill_kind (const api::Security& parent, const api::Security& child){ - if (parent.has_ice()){ - if(securities::is_strip(parent)) - return Fill::FILL_KIND_STRIP_LEG; - else{ - // parent is a spread - if(securities::is_spread_of_strips(parent)){ - // this has 3 levels strip spread -> strip -> outright - // first level is an ordinary leg and second is a strip leg. - // since we dont get the level passed we have to - // use the following heurestics - if(securities::is_strip(child)) - return Fill::FILL_KIND_LEG; - else - return Fill::FILL_KIND_STRIP_LEG; - } - else - // regular spread + if(securities::is_strip(parent)) + return Fill::FILL_KIND_STRIP_LEG; + else{ + // parent is a spread + if(securities::is_spread_of_strips(parent)){ + // this has 3 levels strip spread -> strip -> outright + // first level is an ordinary leg and second is a strip leg. + // since we dont get the level passed we have to + // use the following heurestics + if(securities::is_strip(child)) return Fill::FILL_KIND_LEG; + else + return Fill::FILL_KIND_STRIP_LEG; } } return Fill::FILL_KIND_LEG;