spark-185 move Symbol to top level of Security
This commit is contained in:
1 parent
3fbacd9120
commit
f8cb0b468d
11 files changed
+31
-87
No files matched your search
@@ -35,7 +35,7 @@ namespace mbts.spark
|
||||
|
||||
public void set_securities(IEnumerable<Security> securities) {
|
||||
foreach (var r in _channels.Keys.Except(securities).ToList()) _channels.Remove(r);
|
||||
foreach (var a in securities.Except(_channels.Keys).ToList()) _channels.Add(a, Co2RelayControl.instance.consumer.get_channel(a.symbol, get_type(a.ContractCase), get_exchange(a.Exchange)));
|
||||
foreach (var a in securities.Except(_channels.Keys).ToList()) _channels.Add(a, Co2RelayControl.instance.consumer.get_channel(a.Symbol, get_type(a.ContractCase), get_exchange(a.Exchange)));
|
||||
}
|
||||
|
||||
public void Dispose() { _work_loop.Dispose(); }
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace mbts.ui.spark
|
||||
public static string get_display_name(Security s) { return s.ContractCase == ContractOneofCase.Synthetic ? "{0} ({1:q/n:./m:c})".fmt(s.Synthetic.Name, s) : s.ToString("q/n:./m:c"); }
|
||||
private static string _get_symbol(Security s) {
|
||||
if (s.ContractCase == ContractOneofCase.Synthetic) return _get_symbol(s.Synthetic.Legs.First().Security);
|
||||
else return s.symbol;
|
||||
else return s.Symbol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ namespace bts.api
|
||||
#region Extensions
|
||||
public static string SecurityName(this Security security) {
|
||||
switch (security.ContractCase) {
|
||||
case Security.ContractOneofCase.Future: return security.Future.Symbol;
|
||||
case Security.ContractOneofCase.Spread: return security.Spread.Legs.Count > 0 ? SecurityName(security.Spread.Legs[0].Security) : string.Empty;
|
||||
case Security.ContractOneofCase.Future:
|
||||
case Security.ContractOneofCase.Spread: return security.Symbol;
|
||||
case Security.ContractOneofCase.Synthetic: return security.Synthetic.Legs.Count > 0 ? SecurityName(security.Synthetic.Legs[0].Security) : string.Empty;
|
||||
case Security.ContractOneofCase.None: return "N/A";
|
||||
default: return "Unknown";
|
||||
|
||||
@@ -7,7 +7,7 @@ using static bts.api.Security;
|
||||
using O2Security=bts.security_model.OldSecurity;
|
||||
|
||||
namespace bts.api {
|
||||
public partial class Security : IComparable<Security>, IComparable, IFormattable {
|
||||
public partial class Security : IFormattable {
|
||||
|
||||
internal Security(O2Security other) {
|
||||
// Logger.assert(other != null);
|
||||
@@ -33,8 +33,8 @@ namespace bts.api {
|
||||
ExpirationDay = other.future.expiration_day,
|
||||
ExpirationMonth = other.future.expiration_month,
|
||||
ExpirationYear = other.future.expiration_year,
|
||||
Symbol = other.future.symbol
|
||||
};
|
||||
Symbol = other.future.symbol;
|
||||
break;
|
||||
case security_model.SecurityType.type.SPREAD:
|
||||
Spread = new SpreadContract();
|
||||
@@ -54,22 +54,6 @@ namespace bts.api {
|
||||
}
|
||||
}
|
||||
|
||||
public string symbol {
|
||||
get {
|
||||
switch (ContractCase) {
|
||||
case ContractOneofCase.Future:
|
||||
return Future.Symbol;
|
||||
case ContractOneofCase.Spread:
|
||||
return Spread.Legs.First().Security.symbol;
|
||||
case ContractOneofCase.Synthetic:
|
||||
return Synthetic.Name;
|
||||
default:
|
||||
case ContractOneofCase.None:
|
||||
return "Invalid";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BuySell ofSide(security_model.Side.type side) {
|
||||
switch (side) {
|
||||
case security_model.Side.type.BUY: return BuySell.Buy;
|
||||
@@ -169,10 +153,6 @@ namespace bts.api {
|
||||
get_base_exchange_securities (leg.Security, resolve_side (side, leg.Side), leg.Quantity * mult, ref legs);
|
||||
}
|
||||
|
||||
public int CompareTo(Security other) { return SecurityComparer.Compare(this, other); }
|
||||
|
||||
public int CompareTo(object obj) { return CompareTo(obj as Security); }
|
||||
|
||||
public static readonly Security Empty = new Security {
|
||||
Exchange = Venue.Bts,
|
||||
ContractSpec = new ContractSpecification { CashPerPoint = double.NaN, HighTick = double.NaN, LowTick = double.NaN, PriceBreak = double.NaN, PriceMultiplier = double.NaN }
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using static bts.api.Security;
|
||||
|
||||
namespace bts.api
|
||||
{
|
||||
public static class SecurityComparer
|
||||
{
|
||||
public static int Compare(Security x, Security y) {
|
||||
if (x == null) return y == null ? 0 : -1;
|
||||
if (y == null) return 1;
|
||||
if (x.ContractCase == ContractOneofCase.Future) return y.ContractCase == ContractOneofCase.Future ? Compare(x.Future, y.Future) : -1;
|
||||
if (y.ContractCase == ContractOneofCase.Future) return 1;
|
||||
var xlegs = SecurityHelper.get_flat_future_legs(x).ToArray();
|
||||
var ylegs = SecurityHelper.get_flat_future_legs(y).ToArray();
|
||||
int max = Math.Min(xlegs.Length, ylegs.Length);
|
||||
for(int i = 0; i < max; i++) {
|
||||
int rv = Compare(xlegs[i].Item2, ylegs[i].Item2);
|
||||
if (rv != 0) return rv;
|
||||
}
|
||||
for (int i = 0; i < max; i++) {
|
||||
int rv = xlegs[i].Item3.CompareTo(ylegs[i].Item3);
|
||||
if (rv != 0) return rv;
|
||||
}
|
||||
for (int i = 0; i < max; i++) {
|
||||
int rv = xlegs[i].Item1.CompareTo(ylegs[i].Item1);
|
||||
if (rv != 0) return rv;
|
||||
}
|
||||
return xlegs.Length.CompareTo(ylegs.Length);
|
||||
}
|
||||
|
||||
public static int Compare(FutureContract x, FutureContract y) {
|
||||
int sym_comp = x.Symbol.CompareTo(y.Symbol);
|
||||
return sym_comp == 0 ? x.RawExpDate().CompareTo(y.RawExpDate()) : sym_comp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ namespace bts.api
|
||||
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)));
|
||||
return string.Join("", SecurityHelper.get_flat_future_legs(s).Select(flt => _format_future_leg(flt, s.Symbol, part_formatters)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,18 +52,18 @@ namespace bts.api
|
||||
}
|
||||
}
|
||||
|
||||
private static string _format_future(Security s, IEnumerable<IPartFormatter> part_formatters) { return _format(s, part_formatters, _add_future); }
|
||||
private static string _format_future_leg(FutureLeg l, IEnumerable<IPartFormatter> part_formatters) { return _format(l, part_formatters, _add_future_leg); }
|
||||
private static string _format_future(Security s, IEnumerable<IPartFormatter> part_formatters) { return _format(s, s.Symbol, part_formatters, _add_future); }
|
||||
private static string _format_future_leg(FutureLeg l, string symbol, IEnumerable<IPartFormatter> part_formatters) { return _format(l, symbol, part_formatters, _add_future_leg); }
|
||||
|
||||
private delegate bool AddPart<T>(T t, IPartFormatter part_formatter, out string result);
|
||||
private static bool _add_future(Security s, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(s, out result); }
|
||||
private static bool _add_future_leg(FutureLeg l, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(l, out result); }
|
||||
private delegate bool AddPart<T>(string symbol, T t, IPartFormatter part_formatter, out string result);
|
||||
private static bool _add_future(string symbol, Security s, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(s, out result); }
|
||||
private static bool _add_future_leg(string symbol, FutureLeg l, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(l, symbol, out result); }
|
||||
|
||||
private static string _format<T>(T t, IEnumerable<IPartFormatter> part_formatters, AddPart<T> add_part) {
|
||||
private static string _format<T>(T t, string symbol, IEnumerable<IPartFormatter> part_formatters, AddPart<T> add_part) {
|
||||
var adds = new List<Tuple<string, IPartFormatter>>();
|
||||
foreach (var pf in part_formatters) {
|
||||
string p;
|
||||
if(add_part(t, pf, out p)) adds.Add(Tuple.Create(p, pf));
|
||||
if(add_part(symbol, t, pf, out p)) adds.Add(Tuple.Create(p, pf));
|
||||
}
|
||||
string result = string.Empty;
|
||||
if (adds.Count > 0) {
|
||||
@@ -76,7 +76,7 @@ namespace bts.api
|
||||
private interface IPartFormatter
|
||||
{
|
||||
string separator { get; }
|
||||
bool add_part(FutureLeg fl, out string result);
|
||||
bool add_part(FutureLeg fl, string symbol, out string result);
|
||||
bool add_part(Security s, out string result);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace bts.api
|
||||
this.separator = separator;
|
||||
}
|
||||
public string separator { get; }
|
||||
public bool add_part(FutureLeg fl, out string result) {
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) {
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ namespace bts.api
|
||||
}
|
||||
private bool _first_leg = true;
|
||||
public string separator { get; }
|
||||
public bool add_part(FutureLeg fl, out string result) {
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) {
|
||||
if (_first_leg) {
|
||||
if (fl.Item3 > 0) result = fl.Item3 == 1 ? string.Empty : fl.Item3.ToString();
|
||||
else result = fl.Item3 == -1 ? "-" : fl.Item3.ToString("-0");
|
||||
@@ -160,8 +160,8 @@ namespace bts.api
|
||||
this.separator = separator;
|
||||
}
|
||||
public string separator { get; }
|
||||
public bool add_part(FutureLeg fl, out string result) { result = fl.Item2.Symbol; return true; }
|
||||
public bool add_part(Security s, out string result) { result = s.Future.Symbol; return true; }
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) { result = symbol; return true; }
|
||||
public bool add_part(Security s, out string result) { result = s.Symbol; return true; }
|
||||
}
|
||||
private class Formatter<T> : IPartFormatter {
|
||||
public Formatter(Func<Security, T> get_sec_value, Func<FutureLeg, T> get_leg_value, string separator) : this(get_sec_value, get_leg_value, t => t.ToString(), separator) { }
|
||||
@@ -188,7 +188,7 @@ namespace bts.api
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool add_part(FutureLeg fl, out string result) {
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) {
|
||||
T val = _get_leg_value(fl);
|
||||
if (!val.Equals(_last_val)) {
|
||||
result = _format(_last_val = val);
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace mbts.co2.tests
|
||||
//Assert.That(s.security.numeric_id == s.handle.numeric_id);
|
||||
}
|
||||
Assert.That(securities.Count() == 24);
|
||||
var dict = securities.Select(s => s.security).GroupBy(s => s.symbol).ToDictionary(group => group.Key, group => group.ToList());
|
||||
var dict = securities.Select(s => s.security).GroupBy(s => s.Symbol).ToDictionary(group => group.Key, group => group.ToList());
|
||||
Assert.That(dict.Count == 2);
|
||||
Assert.That(dict.All(kvp => kvp.Value.Count == 12));
|
||||
}
|
||||
@@ -200,8 +200,8 @@ namespace mbts.co2.tests
|
||||
consumer.scan_securities();
|
||||
System.Threading.Thread.Sleep(100);
|
||||
Assert.AreEqual(24, securities.Count);
|
||||
Assert.That(securities.Find(s => s.symbol == "FOOM") != null);
|
||||
Assert.That(securities.Find(s => s.symbol == "FOOXM") != null);
|
||||
Assert.That(securities.Find(s => s.Symbol == "FOOM") != null);
|
||||
Assert.That(securities.Find(s => s.Symbol == "FOOXM") != null);
|
||||
|
||||
foreach (var sec in securities) {
|
||||
var handle = consumer.try_get_handle(sec.Id);
|
||||
|
||||
@@ -53,7 +53,6 @@ message ICEExchangeData {
|
||||
}
|
||||
|
||||
message FutureContract {
|
||||
string symbol = 10;
|
||||
uint32 expiration_year = 20;
|
||||
uint32 expiration_month = 30;
|
||||
uint32 expiration_day = 40;
|
||||
@@ -85,6 +84,7 @@ message ContractSpecification {
|
||||
|
||||
message Security {
|
||||
uint32 id = 10 [(bts.api.key)=true];
|
||||
string symbol = 11;
|
||||
Venue exchange = 20;
|
||||
ContractSpecification contract_spec = 30;
|
||||
Currency currency = 40;
|
||||
|
||||
@@ -33,7 +33,8 @@ public:
|
||||
CoconutSecurityStatus::type status() const;
|
||||
uint16_t sequence() const;
|
||||
bool has_depth() const { return _cheader && _cheader->has_depth; }
|
||||
security_key key() const { return _cdata ? _cdata->security.key : invalid_security_key; }
|
||||
// security_key key() const { return _cdata ? _cdata->security.key : invalid_security_key; }
|
||||
security_key key() const { return has_depth() ? hotd()->key : hot()->key; }
|
||||
OldSecurity get_normalized_security() const { bts_assert(is_initialized()); return convert_security(_cdata->security); }
|
||||
|
||||
|
||||
|
||||
@@ -360,9 +360,10 @@ void convert_security(const OldSecurity& source, Security& dest) {
|
||||
dest.mutable_future()->set_expiration_day(source.future().expiration_day());
|
||||
dest.mutable_future()->set_expiration_month(source.future().expiration_month());
|
||||
dest.mutable_future()->set_expiration_year(source.future().expiration_year());
|
||||
dest.mutable_future()->set_symbol(source.future().symbol());
|
||||
dest.set_symbol(source.future().symbol());
|
||||
break;
|
||||
case security_model::SecurityType::SPREAD: {
|
||||
dest.set_symbol(source.spread().symbol());
|
||||
for(const auto& oleg : source.spread().legs()) {
|
||||
auto* nleg = dest.mutable_spread()->add_legs();
|
||||
nleg->set_quantity(oleg.leg_quantity());
|
||||
|
||||
@@ -49,16 +49,15 @@ struct ALIGNED_(32) HotEntry {
|
||||
const uint32_t COCONUT_MAX_DEPTH = 10;
|
||||
struct ALIGNED_(CACHE_LINE) HotDepthEntry {
|
||||
HotDepthEntry() :
|
||||
timestamp(), sequence(0), status(CoconutSecurityStatus::OK), book(), key(invalid_security_key)
|
||||
timestamp(), key(invalid_security_key), status(CoconutSecurityStatus::OK), book(), sequence(0)
|
||||
{ }
|
||||
uint32_t size() const { return sizeof(HotDepthEntry); }
|
||||
TimeStamp timestamp; // 8
|
||||
uint16_t sequence; // 2
|
||||
//md::CoconutSecurityStatus::type status; // 4
|
||||
security_key key; // NOTE: key is at a different offset than it is in HotEntry
|
||||
uint8_t status; // 1
|
||||
// Interleave bid/ask values so the top of book is always on the first line
|
||||
SingleWriterPriceSizeStore book[COCONUT_MAX_DEPTH*2];
|
||||
security_key key; // NOTE: key is at a different offset than it is in HotEntry
|
||||
uint16_t sequence; // 2
|
||||
|
||||
SingleWriterPriceSizeStore& bid(uint32_t depth) { return book[depth*2]; }
|
||||
const SingleWriterPriceSizeStore& bid(uint32_t depth) const { return book[depth*2]; }
|
||||
|
||||
Reference in new issue
Block a user