Synthetic Management description lists legs, not name
This commit is contained in:
1 parent
9ef66991af
commit
c04c9bbd44
1 file changed
+38
-11
@@ -7,9 +7,9 @@ using FutureLeg = System.Tuple<bts.api.Venue, string, bts.api.FutureContractImmu
|
||||
|
||||
namespace bts.api
|
||||
{
|
||||
internal static class SecurityFormatter
|
||||
{
|
||||
private static ConcurrentDictionary<uint, string> _formatted_name_cache = new ConcurrentDictionary<uint, string>();
|
||||
static class SecurityFormatter {
|
||||
static readonly ConcurrentDictionary<SecurityFormattingKey, string> _formatted_name_cache =
|
||||
new ConcurrentDictionary<SecurityFormattingKey, string>();
|
||||
|
||||
public static IEnumerable<PartFormattingTuple> Parse(string str) {
|
||||
return str.Split('/').Select(a => {
|
||||
@@ -20,8 +20,9 @@ namespace bts.api
|
||||
}
|
||||
|
||||
public static string Format(SecurityImmutable s, IEnumerable<PartFormattingTuple> parts) {
|
||||
var key = new SecurityFormattingKey(s.Id, parts);
|
||||
string formatted_security_name = string.Empty;
|
||||
if (_formatted_name_cache.TryGetValue(s.Id, out formatted_security_name)) return formatted_security_name;
|
||||
if (_formatted_name_cache.TryGetValue(key, out formatted_security_name)) return formatted_security_name;
|
||||
else {
|
||||
var part_formatters = parts.Select(p => PartFormatterFactory.get_formatter(p)).ToList();
|
||||
switch (s.ContractCase) {
|
||||
@@ -39,9 +40,6 @@ namespace bts.api
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
case Security.ContractOneofCase.Synthetic:
|
||||
formatted_security_name = s.Synthetic.Name;
|
||||
break;
|
||||
default:
|
||||
if (part_formatters.Count > 0 && part_formatters[0].separator == "!") {
|
||||
if (part_formatters[0].add_part(s, out formatted_security_name)) { break; }
|
||||
@@ -49,20 +47,49 @@ namespace bts.api
|
||||
formatted_security_name = string.Join("", SecurityHelper.get_flat_future_legs(s).Select(flt => _format_future_leg(flt, part_formatters)));
|
||||
break;
|
||||
}
|
||||
_formatted_name_cache.TryAdd(s.Id, formatted_security_name);
|
||||
_formatted_name_cache.TryAdd(key, formatted_security_name);
|
||||
return formatted_security_name;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ContractParts { Name, Exchange, Symbol, Quantity, MappedExp, RawExp }
|
||||
|
||||
public class PartFormattingTuple {
|
||||
class SecurityFormattingKey : IEquatable<SecurityFormattingKey> {
|
||||
readonly uint _security;
|
||||
readonly PartFormattingTuple[] _parts;
|
||||
|
||||
public SecurityFormattingKey(uint security, IEnumerable<PartFormattingTuple> parts) {
|
||||
_security = security;
|
||||
_parts = parts.ToList().ToArray();
|
||||
}
|
||||
|
||||
public bool Equals(SecurityFormattingKey other) =>
|
||||
other != null && other._security == _security && other._parts.SequenceEqual(_parts);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as SecurityFormattingKey);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
_security.GetHashCode() ^ _parts.GetHashCode();
|
||||
}
|
||||
|
||||
public class PartFormattingTuple : IEquatable<PartFormattingTuple> {
|
||||
public readonly ContractParts Part;
|
||||
public readonly string Argument;
|
||||
|
||||
public PartFormattingTuple(ContractParts part, string argument = null) {
|
||||
Part = part;
|
||||
Argument = argument;
|
||||
}
|
||||
public readonly ContractParts Part;
|
||||
public readonly string Argument;
|
||||
|
||||
public bool Equals(PartFormattingTuple other) =>
|
||||
other != null && other.Part == Part && other.Argument == Argument;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as PartFormattingTuple);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
Argument == null ? Part.GetHashCode() : Part.GetHashCode() ^ Argument.GetHashCode();
|
||||
}
|
||||
|
||||
#region Private Members
|
||||
|
||||
Reference in new issue
Block a user