Ladder Title
This commit is contained in:
1 parent
cd15a70b87
commit
4aceea19df
3 files changed
+39
-8
No files matched your search
@@ -13,7 +13,7 @@
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml" />
|
||||
<ResourceDictionary Source="/view/Controls/SecuritySelectorControl/SecuritySelectorControl.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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<Venue>(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();
|
||||
|
||||
Reference in new issue
Block a user