From 4aceea19dff9fcb5c44cab20fe8feafdc04e8a52 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 13 Sep 2017 14:49:13 -0400 Subject: [PATCH] Ladder Title --- .../SecuritySelectorDialog.xaml | 2 +- src/client/spark_api/security/Security.cs | 8 +++- .../spark_api/security/SecurityFormatter.cs | 37 ++++++++++++++++--- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/client/spark/mspark/SecurityBrowser/SecuritySelectorDialog.xaml b/src/client/spark/mspark/SecurityBrowser/SecuritySelectorDialog.xaml index a2aa096b6..bce5ed5d9 100644 --- a/src/client/spark/mspark/SecurityBrowser/SecuritySelectorDialog.xaml +++ b/src/client/spark/mspark/SecurityBrowser/SecuritySelectorDialog.xaml @@ -13,7 +13,7 @@ - + diff --git a/src/client/spark_api/security/Security.cs b/src/client/spark_api/security/Security.cs index 62f84486c..5b555b97d 100644 --- a/src/client/spark_api/security/Security.cs +++ b/src/client/spark_api/security/Security.cs @@ -133,7 +133,13 @@ namespace bts.api { return spec; } - private static readonly PartFormattingTuple[] _standard_format = new[] { new PartFormattingTuple(ContractParts.Quantity), new PartFormattingTuple(ContractParts.Symbol, "."), new PartFormattingTuple(ContractParts.MappedExp, "c") }; + private static readonly PartFormattingTuple[] _standard_format = new[] { + new PartFormattingTuple(ContractParts.Name, "!"), + new PartFormattingTuple(ContractParts.Quantity), + new PartFormattingTuple(ContractParts.Symbol, "."), + new PartFormattingTuple(ContractParts.MappedExp, "c") + }; + public string ToString(string format, IFormatProvider formatProvider=null) { return Format(this, string.IsNullOrEmpty(format) ? _standard_format : Parse(format)); } diff --git a/src/client/spark_api/security/SecurityFormatter.cs b/src/client/spark_api/security/SecurityFormatter.cs index 714364f98..b268c1b19 100644 --- a/src/client/spark_api/security/SecurityFormatter.cs +++ b/src/client/spark_api/security/SecurityFormatter.cs @@ -20,11 +20,16 @@ namespace bts.api var part_formatters = parts.Select(p => PartFormatterFactory.get_formatter(p)).ToList(); switch(s.ContractCase) { case Security.ContractOneofCase.Future: return _format_future(s, part_formatters); - default: return string.Join("", SecurityHelper.get_flat_future_legs(s).Select(flt => _format_future_leg(flt, part_formatters))); + default: + if (part_formatters.Count > 0 && part_formatters[0].separator == "!") { + if (part_formatters[0].add_part(s, out string result)) return result; + } + return string.Join("", SecurityHelper.get_flat_future_legs(s).Select(flt => _format_future_leg(flt, part_formatters))); } } - public enum ContractParts { Exchange, Symbol, Quantity, MappedExp, RawExp } + public enum ContractParts { Name, Exchange, Symbol, Quantity, MappedExp, RawExp } + public class PartFormattingTuple { public PartFormattingTuple(ContractParts part, string argument = null) { Part = part; @@ -37,8 +42,9 @@ namespace bts.api #region Private Members private static ContractParts _get_part(char c) { switch(c) { + case 'n': return ContractParts.Name; case 'e': return ContractParts.Exchange; - case 'n': return ContractParts.Symbol; + case 's': return ContractParts.Symbol; case 'r': return ContractParts.RawExp; case 'm': return ContractParts.MappedExp; case 'q': return ContractParts.Quantity; @@ -78,6 +84,7 @@ namespace bts.api { public static IPartFormatter get_formatter(PartFormattingTuple pft) { switch (pft.Part) { + case ContractParts.Name: return new NameFormatter(pft.Argument); case ContractParts.Exchange: return new Formatter(s => s.Exchange, fl => fl.Item1, pft.Argument); case ContractParts.Symbol: return new SymbolFormatter(pft.Argument); case ContractParts.MappedExp: { @@ -106,13 +113,31 @@ namespace bts.api } } } + private class NameFormatter : IPartFormatter { + public NameFormatter(string separator) { + this.separator = separator; + } + public string separator { get; } + public bool add_part(FutureLeg fl, out string result) { + result = null; + return false; + } + public bool add_part(Security s, out string result) { + if (s.ContractCase == Security.ContractOneofCase.Synthetic) { + result = s.Synthetic.Name; + return true; + } else { + result = null; + return false; + } + } + } private class QuantityFormatter : IPartFormatter { public QuantityFormatter(string separator) { - _separator = separator; + this.separator = separator; } private bool _first_leg = true; - private readonly string _separator; - public string separator => _separator ?? string.Empty; + public string separator { get; } public bool add_part(FutureLeg fl, out string result) { if (_first_leg) { if (fl.Item3 > 0) result = fl.Item3 == 1 ? string.Empty : fl.Item3.ToString();