Add price/quantity display config to SecurityMD
This commit is contained in:
1 parent
7dcfa709d5
commit
ca4ec7025c
4 files changed
+117
-4
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
namespace bts {
|
||||
using bts.api;
|
||||
using bts.api.domain;
|
||||
using bts.api.synthetic;
|
||||
using bts.md;
|
||||
using bts.spark;
|
||||
@@ -28,6 +29,7 @@ namespace bts {
|
||||
readonly Lazy<AuthTokenImmutable> _token;
|
||||
readonly Lazy<SyntheticSecurityService> _ss;
|
||||
readonly Lazy<MDSource> _md_source_backing;
|
||||
readonly SecurityMetadataCollection _security_metadata;
|
||||
readonly TimeSpan _relay_throttle;
|
||||
readonly TimeSpan _output_throttle;
|
||||
readonly List<IDisposable> _resources = new(2);
|
||||
@@ -43,6 +45,7 @@ namespace bts {
|
||||
token,
|
||||
ss,
|
||||
user,
|
||||
Configuration.get<SecurityMetadataCollection>(),
|
||||
TimeSpan.FromMilliseconds(Configuration.get<RelayOptions>().naggle_ms),
|
||||
TimeSpan.FromSeconds(1)) { }
|
||||
|
||||
@@ -51,6 +54,7 @@ namespace bts {
|
||||
Lazy<AuthTokenImmutable> token,
|
||||
Lazy<SyntheticSecurityService> ss,
|
||||
Lazy<UserTuple> user,
|
||||
SecurityMetadataCollection security_metadata,
|
||||
TimeSpan relay_throttle,
|
||||
TimeSpan output_throttle
|
||||
) {
|
||||
@@ -60,6 +64,7 @@ namespace bts {
|
||||
_ss = ss;
|
||||
_relay_throttle = relay_throttle;
|
||||
_output_throttle = output_throttle;
|
||||
_security_metadata = security_metadata;
|
||||
_md_source_backing = new(() => new(_user.Value, _relay_throttle, _output_throttle));
|
||||
}
|
||||
|
||||
@@ -120,11 +125,43 @@ namespace bts {
|
||||
deleted_synth_cache[id] = deleted;
|
||||
}
|
||||
}
|
||||
|
||||
_resolve_metadata_names(_security_metadata, exch_secs.Values.Select(s => s.security));
|
||||
|
||||
// set 'unit quantity' for each sec
|
||||
foreach (var smd in exch_secs.Values) {
|
||||
if (_security_metadata.Items.TryGetFirst(
|
||||
item => item.Scope.to_criteria().includes(smd.security), out var item)) {
|
||||
exch_secs[smd.id] = new(
|
||||
smd.security,
|
||||
smd.md,
|
||||
new(item.Value.PriceDisplay),
|
||||
new(item.Value.QuantityDisplay));
|
||||
}
|
||||
}
|
||||
_bus.post(SparkTags.ServerSecuritiesTag, exch_secs);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(_resources);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to convert security names (<see cref="SecurityCriteriaClause.Names"/>) to ids for
|
||||
/// faster lookups in a security map
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When a name is resolved, it is removed from <see cref="SecurityCriteriaClause.Names"/>,
|
||||
/// and its corresponding id is added to <see cref="SecurityCriteriaClause.Keys"/>
|
||||
/// </remarks>
|
||||
static void _resolve_metadata_names(
|
||||
SecurityMetadataCollection security_metadata, IEnumerable<SecurityImmutable> securities) {
|
||||
foreach (var item in security_metadata.Items) {
|
||||
foreach (var clause in item.Scope.Clauses) {
|
||||
clause.resolve_names(sec_name => securities
|
||||
.TryGetFirst(s => s.ToString().iequals(sec_name), out var s) ? s.Id : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
namespace mbts.spark {
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
@@ -306,6 +306,52 @@ namespace mbts.spark {
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to convert security names (<see cref="SecurityCriteriaClause.Names"/>) to ids for
|
||||
/// faster lookups in a security map
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When a name is resolved, it is removed from <see cref="SecurityCriteriaClause.Names"/>,
|
||||
/// and its corresponding id added to <see cref="SecurityCriteriaClause.Keys"/>
|
||||
/// </remarks>
|
||||
/// <returns>The number of names that were resolved</returns>
|
||||
public static int resolve_names(
|
||||
this bts.api.domain.SecurityCriteriaClause api_clause, Func<string, uint?> try_resolve) {
|
||||
var orig_num_names = api_clause.Names.Count;
|
||||
for (var i = 0; i < api_clause.Names.Count;) {
|
||||
var name = api_clause.Names[i];
|
||||
var id = try_resolve(name);
|
||||
if (id.HasValue) {
|
||||
api_clause.Names.RemoveAt(i);
|
||||
api_clause.Keys.Add(id.Value);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
var n_resolved = api_clause.Names.Count - orig_num_names;
|
||||
return n_resolved;
|
||||
}
|
||||
|
||||
public static SecurityCriteriaClause to_clause(
|
||||
this bts.api.domain.SecurityCriteriaClause api_clause) =>
|
||||
api_clause.to_clause(null);
|
||||
|
||||
public static SecurityCriteriaClause to_clause(
|
||||
this bts.api.domain.SecurityCriteriaClause api_clause, Func<string, uint?>? try_resolve) {
|
||||
if (try_resolve is not null) {
|
||||
api_clause.resolve_names(try_resolve);
|
||||
}
|
||||
return new(
|
||||
api_clause.Exchanges.WrapSelectorRO(v => v.to_venue()).ToArray(),
|
||||
api_clause.SecurityTypes.WrapSelectorRO(t => t.to_security_type()).ToArray(),
|
||||
api_clause.Symbols.ToArray(),
|
||||
api_clause.Keys.ToArray());
|
||||
}
|
||||
|
||||
public static SecurityCriteria to_criteria(
|
||||
this bts.api.domain.SecurityCriteria api_criteria) =>
|
||||
new(api_criteria.Clauses.Select(to_clause));
|
||||
|
||||
static IEnumerable<Func<SecurityImmutable, bool>> _to_predicates(
|
||||
SecurityCriteriaClause clause) {
|
||||
if (clause.exchanges is not null && clause.exchanges.Length > 0) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
namespace mbts {
|
||||
using bts.api;
|
||||
using bts.api.domain;
|
||||
|
||||
using mbts.co2;
|
||||
|
||||
@@ -10,14 +11,23 @@ namespace mbts {
|
||||
public static readonly Func<SecurityMD, uint> key_fn = smd => smd.security.Id;
|
||||
|
||||
public SecurityMD(
|
||||
SecurityImmutable security, IMDConsumerHandle md) {
|
||||
SecurityImmutable security,
|
||||
IMDConsumerHandle md,
|
||||
TickDisplaySettingsImmutable? price_display = null,
|
||||
TickDisplaySettingsImmutable? quantity_display = null) {
|
||||
this.security = security;
|
||||
this.md = md;
|
||||
this.price_display = price_display ?? new(new());
|
||||
this.quantity_display = quantity_display ?? new(new());
|
||||
unit_quantity = 1;
|
||||
}
|
||||
|
||||
public SecurityImmutable security { get; }
|
||||
public uint id => security.Id;
|
||||
public IMDConsumerHandle md { get; }
|
||||
public double unit_quantity { get; }
|
||||
public TickDisplaySettingsImmutable price_display { get; }
|
||||
public TickDisplaySettingsImmutable quantity_display { get; }
|
||||
|
||||
public override int GetHashCode() =>
|
||||
(int)security.Id;
|
||||
|
||||
@@ -104,6 +104,26 @@ namespace bts.api {
|
||||
_ => side,
|
||||
};
|
||||
|
||||
public static SecurityType to_security_type(this domain.SecurityType api_security_type) =>
|
||||
api_security_type switch {
|
||||
domain.SecurityType.Spot => SecurityType.Stock,
|
||||
domain.SecurityType.Future => SecurityType.Future,
|
||||
domain.SecurityType.Option => SecurityType.Option,
|
||||
domain.SecurityType.Spread => SecurityType.Spread,
|
||||
domain.SecurityType.Unset => SecurityType.Unset,
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
|
||||
public static Venue to_venue(this domain.Venue api_venue) =>
|
||||
api_venue switch {
|
||||
domain.Venue.Bts => Venue.Bts,
|
||||
domain.Venue.Sim => Venue.Sim,
|
||||
domain.Venue.Deribit => Venue.Deribit,
|
||||
domain.Venue.Glbx => Venue.Glbx,
|
||||
domain.Venue.None => Venue.Unset,
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
|
||||
// ICE specific properties
|
||||
public static string market_description(this SecurityImmutable security) => security.HasIce ? security.Ice.MarketDescription : string.Empty;
|
||||
public static string product_name(this SecurityImmutable security) => security.HasIce ? security.Ice.ProductName : string.Empty;
|
||||
|
||||
Reference in new issue
Block a user