From 357bc5ad4413583b88efdd796c41cedda9032abb Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 22 Jan 2023 23:56:32 -0500 Subject: [PATCH] fix (ui): Format perp futs 'Perp' suffix (not bogus exp) --- .../Core/Settings/SecurityExpiration.cs | 2 +- .../spark/Risk/Combo/ComboReportOptionsGrid.cs | 4 ++-- .../spark/Risk/Slide/SlideGreekUnitKey.cs | 10 ++++------ .../SpreadDescription/SpreadInterpreter.cs | 3 ++- src/client/spark/SpreadBox/SpreadUtilities.cs | 2 +- .../view/Converters/ExpirationTextConverter.cs | 17 ++++++----------- src/client/spark_api/security/DateFormatter.cs | 7 ------- src/client/spark_api/security/Security.cs | 3 +++ .../spark_api/security/SecurityFormatter.cs | 11 ++++++++--- 9 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/client/spark/Analytics/Core/Settings/SecurityExpiration.cs b/src/client/spark/Analytics/Core/Settings/SecurityExpiration.cs index aeb39aa86..fb94d9521 100644 --- a/src/client/spark/Analytics/Core/Settings/SecurityExpiration.cs +++ b/src/client/spark/Analytics/Core/Settings/SecurityExpiration.cs @@ -145,7 +145,7 @@ namespace mbts { !(x == y); public override string ToString() => - $"{security_tuple} {expiration.ToShortDateString()}"; + $"{security_tuple} {SecurityFormatter.format_expiration(expiration)}"; } [ProtoContract] diff --git a/src/client/spark/Risk/Combo/ComboReportOptionsGrid.cs b/src/client/spark/Risk/Combo/ComboReportOptionsGrid.cs index ef169aa46..fda85f83d 100644 --- a/src/client/spark/Risk/Combo/ComboReportOptionsGrid.cs +++ b/src/client/spark/Risk/Combo/ComboReportOptionsGrid.cs @@ -136,7 +136,7 @@ namespace mbts.analytics { IEnumerable all_exps) { var exps = all_exps.Where(vse => vse.symbol.is_null_or_empty()).ToArray(); var exp_header_cells = exps - .Select(vse => DateFormatter.Format(vse.expiration, DateFormat.DayMonthAbvDiff2000)) + .Select(vse => SecurityFormatter.format_expiration(vse.expiration)) .ToArray(); return (exps, exp_header_cells); } @@ -145,7 +145,7 @@ namespace mbts.analytics { IEnumerable all_exps) { var exps = all_exps.ToArray(); var exp_header_cells = exps.Select(vse => string.IsNullOrEmpty(vse.symbol) ? - DateFormatter.Format(vse.expiration, DateFormat.DayMonthAbvDiff2000) : vse.symbol) + SecurityFormatter.format_expiration(vse.expiration) : vse.symbol) .ToArray(); return (exps, exp_header_cells); } diff --git a/src/client/spark/Risk/Slide/SlideGreekUnitKey.cs b/src/client/spark/Risk/Slide/SlideGreekUnitKey.cs index ed29dcf72..f256d9d1a 100644 --- a/src/client/spark/Risk/Slide/SlideGreekUnitKey.cs +++ b/src/client/spark/Risk/Slide/SlideGreekUnitKey.cs @@ -1,5 +1,7 @@ #nullable enable namespace mbts.analytics { + using bts.api; + using System; using System.Diagnostics.Contracts; @@ -17,13 +19,9 @@ namespace mbts.analytics { symbol = null; } - private static string _format_exp(DateTime exp) { - return mbts.ui.utility.ExpirationFormatter.DateFormatter.format_day_month_year(exp); - } - SlideGreekUnitKey(DateTime exp_date) { exp = exp_date; - _unique_name = _format_exp(exp_date); + _unique_name = SecurityFormatter.format_expiration(exp_date); type = GroupType.Exp; symbol = null; } @@ -31,7 +29,7 @@ namespace mbts.analytics { SlideGreekUnitKey(DateTime exp_date, string symbol) { exp = exp_date; this.symbol = symbol; - _unique_name = $"{_format_exp(exp_date)}:{symbol}"; + _unique_name = $"{SecurityFormatter.format_expiration(exp_date)}:{symbol}"; type = GroupType.SymExp; } diff --git a/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs b/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs index 448ad289b..c5a92fa67 100644 --- a/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs +++ b/src/client/spark/SpreadBox/SpreadDescription/SpreadInterpreter.cs @@ -71,7 +71,8 @@ namespace BCG { foreach (string sym in temp.Keys) { SortedList temp2 = temp[sym]; foreach (KeyValuePair kvp in temp2) { - string datecode = bts.api.DateFormatter.Format(kvp.Key, bts.api.DateFormat.MonthCodeLastDigitYear); + string datecode = bts.api.SecurityFormatter.format_expiration( + kvp.Key, date_format: bts.api.DateFormat.MonthCodeLastDigitYear); string explegs = (temp.Keys.Count > 1) ? string.Concat(sym, datecode, "_", kvp.Value) : string.Concat(datecode, "_", kvp.Value); diff --git a/src/client/spark/SpreadBox/SpreadUtilities.cs b/src/client/spark/SpreadBox/SpreadUtilities.cs index 94c814fd1..7e798163c 100644 --- a/src/client/spark/SpreadBox/SpreadUtilities.cs +++ b/src/client/spark/SpreadBox/SpreadUtilities.cs @@ -61,7 +61,7 @@ namespace BCG { string rv = String.Empty; foreach (SingleSpreadLeg l in legs) rv += (rv == String.Empty ? "" : "/") + l.symbol + //BCG.Utilities.Dates.DateCode.getMonthSymbol(l.exp) + (l.exp.Year - 2000); - bts.api.DateFormatter.Format(l.exp, bts.api.DateFormat.DayMonthAbvDiff2000); + SecurityFormatter.format_expiration(l.exp); return rv; } diff --git a/src/client/spark/view/Converters/ExpirationTextConverter.cs b/src/client/spark/view/Converters/ExpirationTextConverter.cs index 60fcd8aae..b38f50837 100644 --- a/src/client/spark/view/Converters/ExpirationTextConverter.cs +++ b/src/client/spark/view/Converters/ExpirationTextConverter.cs @@ -22,16 +22,11 @@ namespace mbts.ui.converters { object value, Type target_type, object parameter, CultureInfo culture) => throw new NotImplementedException(); - public string convert(SecurityExpiration exp) { - var sb = new StringBuilder(); - if (ShowType) { - sb.Append($"[{SecurityFormatter.format_security_type(exp.security_type)}] "); - } - if (ShowSymbol) { - sb.Append(exp.symbol); - } - sb.Append(DateFormatter.Format(exp.expiration, DateFormat)); - return sb.ToString(); - } + public string convert(SecurityExpiration exp) => + SecurityFormatter.format_expiration( + exp.expiration, + ShowSymbol ? exp.symbol : null, + ShowType ? exp.security_type.contract_case() : null, + DateFormat); } } diff --git a/src/client/spark_api/security/DateFormatter.cs b/src/client/spark_api/security/DateFormatter.cs index 354e78ed5..6be48ae79 100644 --- a/src/client/spark_api/security/DateFormatter.cs +++ b/src/client/spark_api/security/DateFormatter.cs @@ -33,13 +33,6 @@ public static string Format(DateTime date, DateFormat format) => Format(date.Year, date.Month, date.Day, format); - /// - /// Returns a concise string representation of a date (using single-letter month codes) - /// appropriate for UIs (e.g. March 22, 2019: 22 Mar 19, or 22 H19). - /// - public static string Format(uint year, uint month, uint day, DateFormat format) => - Format((int)year, (int)month, (int)day, format); - /// /// Returns a concise string representation of a date (using single-letter month codes) /// appropriate for UIs (e.g. March 22, 2019: 22 Mar 19, or 22 H19). diff --git a/src/client/spark_api/security/Security.cs b/src/client/spark_api/security/Security.cs index baf4f1c52..de976aa51 100644 --- a/src/client/spark_api/security/Security.cs +++ b/src/client/spark_api/security/Security.cs @@ -10,6 +10,9 @@ namespace bts.api { public partial class Security { public static security_key key(Security s) { return s.Id; } + public static bool is_perpetual_exp(DateTime exp) => + exp.Year < 2000 || exp.Year > 2999; + public static class Defaults { public static ContractSpecification ContractSpecification => new() { diff --git a/src/client/spark_api/security/SecurityFormatter.cs b/src/client/spark_api/security/SecurityFormatter.cs index b82e10ba6..4c0842278 100644 --- a/src/client/spark_api/security/SecurityFormatter.cs +++ b/src/client/spark_api/security/SecurityFormatter.cs @@ -21,7 +21,7 @@ format_future(symbol, (uint)exp.Year, (uint)exp.Month, (uint)exp.Day); public static string format_future(string symbol, uint exp_year, uint exp_month, uint exp_day) => - $"{symbol}{DateFormatter.Format(exp_year, exp_month, exp_day, DateFormat.DayMonthAbvDiff2000)}"; + $"{symbol}{format_expiration(new((int)exp_year, (int)exp_month, (int)exp_day))}"; public static string format_future(string symbol, FutureContractImmutable future) => format_future(symbol, future.ExpirationYear, future.ExpirationMonth, future.ExpirationDay); @@ -108,12 +108,17 @@ string? symbol = null, Security.ContractOneofCase? type = null, DateFormat date_format = DateFormat.DayMonthAbvDiff2000) { - var result = DateFormatter.Format(exp_date, date_format); + var result = Security.is_perpetual_exp(exp_date) ? + "Perp" : DateFormatter.Format(exp_date, date_format); if (symbol is not null) { result = symbol + " " + result; } if (type.HasValue) { - result = format_security_type(type.Value) + " " + result; + if (result.Length == 0) { + result = format_security_type(type.Value); + } else { + result = $"[{format_security_type(type.Value)}] {result}"; + } } return result; }