diff --git a/src/client/spark/SpreadBox/Bus/SpreadDisplayForm.cs b/src/client/spark/SpreadBox/Bus/SpreadDisplayForm.cs index 467c0f22d..7c91769d0 100644 --- a/src/client/spark/SpreadBox/Bus/SpreadDisplayForm.cs +++ b/src/client/spark/SpreadBox/Bus/SpreadDisplayForm.cs @@ -539,7 +539,7 @@ namespace BCG { p.contract.expiration.ToShortDateString() + " " + p.contract.strike.ToString() + " " + (p.contract.isCall ? "C" : "P") + " " + p.position.ToString() + ";"; Type spread_type; - SpreadInterpreter.interpret(sprText, out detail, out summary, out spread_type); + SpreadInterpreter.interpret(sprText, out detail, out summary, out spread_type, spec.venue); if (spread_type != null) bts.Log.Gen.info($"{spread_type.ToString()}"); } diff --git a/src/client/spark/SpreadBox/SpreadDescription/SingleSpreadLeg.cs b/src/client/spark/SpreadBox/SpreadDescription/SingleSpreadLeg.cs index 565c161f2..e264e06b8 100644 --- a/src/client/spark/SpreadBox/SpreadDescription/SingleSpreadLeg.cs +++ b/src/client/spark/SpreadBox/SpreadDescription/SingleSpreadLeg.cs @@ -30,7 +30,7 @@ namespace BCG size = theSize; } - public static SingleSpreadLeg[] parse(string stringRep) + public static SingleSpreadLeg[] parse(string stringRep, Venue default_venue = Venue.Unset) { if(string.IsNullOrEmpty(stringRep)) return new SingleSpreadLeg[0]; @@ -39,7 +39,14 @@ namespace BCG string[] toks = stringRep.Split(' '); int i = 0; string symbol = toks[i++]; - Venue venue = Enum.Parse(toks[i++], true); + // We recently combined venue with symbol as a key for theos/greeks data. + // Try to parse the venue, but if it isn't there just use default_venue + // Note: this parameter presupposes all legs are at the same venue. + if (Enum.TryParse(toks[i], out var venue)) { + i++; + } else { + venue = default_venue; + } DateTime exp = DateTime.Parse(toks[i++]); double strike = Double.Parse(toks[i++]); char callPut = char.Parse(toks[i++]); diff --git a/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs b/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs index c5a92fa67..1d8071093 100644 --- a/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs +++ b/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs @@ -1,28 +1,45 @@ +using bts.api; + using System; using System.Collections.Generic; using System.Text; namespace BCG { public static class SpreadInterpreter { - public static void interpret(string bts_spread_def, out string detail) { + public static void interpret(string bts_spread_def, out string detail, Venue default_venue) { string summary; Type spread_type; - interpret(bts_spread_def, out detail, out summary, out spread_type); + interpret(bts_spread_def, out detail, out summary, out spread_type, default_venue); } public static void interpret(string blueSpreadDetail, out string detail, out string summary, - out Type spread_type) { + out Type spread_type, + Venue default_venue) { string symbol; List symbols; SingleSpreadLeg[] legs; string longSpec; interpret(blueSpreadDetail, out symbol, out symbols, out legs, out detail, - out summary, out longSpec, out spread_type); + out summary, out longSpec, out spread_type, default_venue); } + /// + /// Parses spread parameters from a string. + /// + /// The string to parse + /// The primary symbol in the spread + /// All symbol(s) involved in the spread + /// The spread legs + /// A string that concatenates each spread leg in uniform format. + /// Shorter form representation of the spread. + /// + /// The implementation type (implements ). + /// The venue common to all spread legs (because must be constructed with a venue). public static void interpret(string bts_spread_text, out string symbol, out List symbols, out SingleSpreadLeg[] legs, out string detail, out string summary, out string longSpec, - out Type spread_type) { + out Type spread_type, + Venue default_venue) { + // The venue arg is needed because bts_spread_text doesn't include the exchange spread_type = null; if (String.IsNullOrEmpty(bts_spread_text)) { symbol = String.Empty; @@ -31,7 +48,7 @@ namespace BCG { detail = longSpec = "Empty Spread"; summary = String.Empty; ; } else { - legs = SingleSpreadLeg.parse(bts_spread_text); + legs = SingleSpreadLeg.parse(bts_spread_text, default_venue); bool is_future_spread = true; foreach (SingleSpreadLeg l in legs) is_future_spread &= l.callPut.ToString().ToLower().StartsWith("f"); diff --git a/src/client/spark/SpreadBox/SpreadSpec.cs b/src/client/spark/SpreadBox/SpreadSpec.cs index 7b43a04ec..58b0b0c8d 100644 --- a/src/client/spark/SpreadBox/SpreadSpec.cs +++ b/src/client/spark/SpreadBox/SpreadSpec.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using BCG; using BCG.Utilities; @@ -69,6 +70,11 @@ namespace BCG { this.contracts = contracts; } + // TODO: remove this property when we are ready to support cross-exchange spreads. + // Throws an exception if the legs are not all at the same exchange. + public Venue venue => + contracts.Select(c => c.contract.exchange).Distinct().SingleOrDefault(Venue.Unset); + #region mutation objects public SpreadSpec multiplyPosition(double byValue) { diff --git a/src/client/spark/SpreadBox/SpreadUtilities.cs b/src/client/spark/SpreadBox/SpreadUtilities.cs index e453fdff1..0b08a3ebb 100644 --- a/src/client/spark/SpreadBox/SpreadUtilities.cs +++ b/src/client/spark/SpreadBox/SpreadUtilities.cs @@ -162,14 +162,14 @@ namespace BCG { /// the second and third are negated values private static Dictionary> _negated_spreads_detailed_map = new Dictionary>(); /// Returns a null if theo is not valid - private static Triplet _get_spread_negation_detail(string bts_spread_def, double theo) { + private static Triplet _get_spread_negation_detail(string bts_spread_def, double theo, Venue venue) { Triplet rv = null; if (_is_theo_valid(theo)) { lock (_negated_spreads_detailed_map) { if (!_negated_spreads_detailed_map.TryGetValue(bts_spread_def, out rv)) { rv = new Triplet(theo < 0, String.Empty, String.Empty); rv.second = rv.first ? SingleSpreadLeg.negate(bts_spread_def) : bts_spread_def; - SpreadInterpreter.interpret(rv.second, out rv.third); + SpreadInterpreter.interpret(rv.second, out rv.third, venue); _negated_spreads_detailed_map[bts_spread_def] = rv; } } @@ -184,7 +184,7 @@ namespace BCG { double bid, UInt32 bid_size, double ask, UInt32 ask_size, out double normalized_theo, out double normalized_delta, out double normalized_gamma, out double normalized_vega, out double normalized_theta, out double normalized_bid, out UInt32 normalized_bid_size, out double normalized_ask, out UInt32 normalized_ask_size) { - Triplet spread_negation_detail = _get_spread_negation_detail(bts_spread_def, theo); + Triplet spread_negation_detail = _get_spread_negation_detail(bts_spread_def, theo, Venue.Cboe); if (spread_negation_detail != null && spread_negation_detail.first) { /// theos/greeks normalized_theo = -1.0 * theo; normalized_delta = -1.0 * delta; normalized_gamma = -1.0 * gamma; normalized_vega = -1.0 * vega; normalized_theta = -1.0 * theta; @@ -206,7 +206,7 @@ namespace BCG { public static bool normalize_cboe_spread_trade(string bts_spread_def, string spread_detail, double theo, double delta, double trade_price, out string normalized_bts_desc, out string normalized_spread_detail, out double normalized_theo, out double normalized_delta, out double normalized_trade_price) { - Triplet spread_negation_detail = _get_spread_negation_detail(bts_spread_def, theo); + Triplet spread_negation_detail = _get_spread_negation_detail(bts_spread_def, theo, Venue.Cboe); if (spread_negation_detail != null && spread_negation_detail.first) { /// spread desc normalized_bts_desc = spread_negation_detail.second;