Spark-340 Return of MDConsumerHandle
This commit is contained in:
1 parent
bdf15fb383
commit
82cdc9fc32
8 files changed
+16
-52
No files matched your search
@@ -9,9 +9,9 @@ using System.Threading.Tasks;
|
||||
namespace mbts.spark {
|
||||
struct SecurityMD : IEquatable<SecurityMD> {
|
||||
public SecurityImmutable security { get; }
|
||||
public IMDHandle md { get; }
|
||||
public MDConsumerHandle md { get; }
|
||||
|
||||
public SecurityMD(SecurityImmutable security, IMDHandle md) {
|
||||
public SecurityMD(SecurityImmutable security, MDConsumerHandle md) {
|
||||
this.security = security;
|
||||
this.md = md;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace mbts.spark {
|
||||
public enum CancelType { All, Bids, Asks }
|
||||
|
||||
public SecurityImmutable security { get; }
|
||||
public IMDHandle md { get; }
|
||||
public MDConsumerHandle md { get; }
|
||||
public OrdersModel order_gateway => _order_gateway;
|
||||
|
||||
public async Task<(OrderRecordImmutable def, bool success, string error)[]> cancel_orders(CancelType ct) {
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace mbts.spark {
|
||||
public event Action on_tick;
|
||||
|
||||
public SecurityImmutable security => _model.security;
|
||||
public IMDHandle md => _model.md;
|
||||
public MDConsumerHandle md => _model.md;
|
||||
public bool is_synthetic => _model.security.ContractCase == Security.ContractOneofCase.Synthetic;
|
||||
public CalculatorLogic calculator { get; }
|
||||
public LogViewerMessageCollection log_messages { get; } = new LogViewerMessageCollection();
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace mbts.spark {
|
||||
Interval = TimeSpan.FromSeconds(1)
|
||||
};
|
||||
SecurityImmutable? _security;
|
||||
IMDHandle _handle;
|
||||
MDConsumerHandle _handle;
|
||||
LadderSettings _settings;
|
||||
DateTime _last_recenter = DateTime.MaxValue;
|
||||
double _last_mid = 0.0;
|
||||
|
||||
@@ -39,12 +39,12 @@ namespace mbts.spark.utilities
|
||||
public SecurityMDPump(IObservable<uint> security, IBus bus) : this(security, SparkUtils.DefaultPollInterval, bus) { }
|
||||
public SecurityMDPump(IObservable<uint> security, TimeSpan poll_interval, IBus bus) : this(security, Observable.Interval(poll_interval), bus) { }
|
||||
public SecurityMDPump(IObservable<uint> security, IObservable<long> poll, IBus bus) : this(security.CombineLatest(bus.subscribe(SparkTags.SecuritiesTag), (s, m) => m.GetValueOrDefault(s).md).Where(md => md != null), poll) { }
|
||||
public SecurityMDPump(IMDHandle md) : this(Observable.Return(md)) { }
|
||||
public SecurityMDPump(IMDHandle md, TimeSpan poll_interval) : this(Observable.Return(md), poll_interval) { }
|
||||
public SecurityMDPump(IMDHandle md, IObservable<long> poll) : this(Observable.Return(md), poll) { }
|
||||
public SecurityMDPump(IObservable<IMDHandle> md_source) : this(md_source, SparkUtils.DefaultPollInterval) { }
|
||||
public SecurityMDPump(IObservable<IMDHandle> md_source, TimeSpan poll_interval) : this(md_source, Observable.Interval(poll_interval)) { }
|
||||
public SecurityMDPump(IObservable<IMDHandle> md_source, IObservable<long> poll) {
|
||||
public SecurityMDPump(MDConsumerHandle md) : this(Observable.Return(md)) { }
|
||||
public SecurityMDPump(MDConsumerHandle md, TimeSpan poll_interval) : this(Observable.Return(md), poll_interval) { }
|
||||
public SecurityMDPump(MDConsumerHandle md, IObservable<long> poll) : this(Observable.Return(md), poll) { }
|
||||
public SecurityMDPump(IObservable<MDConsumerHandle> md_source) : this(md_source, SparkUtils.DefaultPollInterval) { }
|
||||
public SecurityMDPump(IObservable<MDConsumerHandle> md_source, TimeSpan poll_interval) : this(md_source, Observable.Interval(poll_interval)) { }
|
||||
public SecurityMDPump(IObservable<MDConsumerHandle> md_source, IObservable<long> poll) {
|
||||
_root_pump = poll.CombineLatest(md_source, (_, md) => md);
|
||||
_bbo_pump = _root_pump.Select(_refresh_bbo).Where(r => r).Publish();
|
||||
_last_pump = _root_pump.Select(_refresh_last).Where(r => r).Publish();
|
||||
@@ -52,7 +52,7 @@ namespace mbts.spark.utilities
|
||||
_connections.Add(_last_pump.Connect());
|
||||
}
|
||||
|
||||
private readonly IObservable<IMDHandle> _root_pump;
|
||||
private readonly IObservable<MDConsumerHandle> _root_pump;
|
||||
private readonly IConnectableObservable<bool> _bbo_pump;
|
||||
private readonly IConnectableObservable<bool> _last_pump;
|
||||
private readonly IList<IDisposable> _connections= new List<IDisposable>();
|
||||
@@ -63,7 +63,7 @@ namespace mbts.spark.utilities
|
||||
private ulong _volume;
|
||||
private DateTime _last_time;
|
||||
|
||||
private bool _refresh_bbo(IMDHandle md) {
|
||||
private bool _refresh_bbo(MDConsumerHandle md) {
|
||||
if (md.get_bbo(ref _bbo_ref, out NativePriceSize b, out NativePriceSize a)) {
|
||||
_bid_price = b.price;
|
||||
_bid_size = b.size;
|
||||
@@ -74,7 +74,7 @@ namespace mbts.spark.utilities
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool _refresh_last(IMDHandle md) {
|
||||
private bool _refresh_last(MDConsumerHandle md) {
|
||||
if (md.get_last_trade(ref _last_ref, out NativePriceSize ps, out DateTime ts, out ulong v)) {
|
||||
_last_price = ps.price;
|
||||
_last_size = ps.size;
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.co2 {
|
||||
static class MDHandleExtensions {
|
||||
public static double mid(this IMDHandle handle) {
|
||||
public static double mid(this MDConsumerHandle handle) {
|
||||
ulong unused = 0;
|
||||
handle.get_bbo(ref unused, out NativePriceSize bid, out NativePriceSize ask);
|
||||
if (bid == NativePriceSize.no_market) return ask.price;
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using bts.co2;
|
||||
|
||||
namespace mbts.co2 {
|
||||
interface IMDHandle {
|
||||
DateTime close_date { get; }
|
||||
double close_price { get; }
|
||||
bool has_depth { get; }
|
||||
bool is_heart_beating { get; }
|
||||
uint key { get; }
|
||||
ulong market_timestamp { get; }
|
||||
ulong misc_timestamp { get; }
|
||||
ulong numeric_id { get; }
|
||||
DateTime open_date { get; }
|
||||
double open_interest { get; }
|
||||
double open_price { get; }
|
||||
DateTime previous_settlement_date { get; }
|
||||
double previous_settlement_price { get; }
|
||||
double session_high { get; }
|
||||
double session_high_bid { get; }
|
||||
double session_low { get; }
|
||||
double session_low_offer { get; }
|
||||
DateTime settlement_date { get; }
|
||||
double settlement_price { get; }
|
||||
//CoconutSecurityStatus.type status { get; }
|
||||
ulong total_volume { get; }
|
||||
ulong trade_timestamp { get; }
|
||||
|
||||
bool get_bbo(ref ulong time, out NativePriceSize bid, out NativePriceSize ask);
|
||||
bool get_depth(ref ulong time, ref NativePriceSize[] bids, ref NativePriceSize[] asks);
|
||||
void get_depth(ref NativePriceSize[] bids, ref NativePriceSize[] asks);
|
||||
bool get_last_trade(ref ulong time, out NativePriceSize ps, out DateTime timestamp, out ulong total_volume);
|
||||
MiscMessage get_misc();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using bts.api;
|
||||
|
||||
namespace mbts.co2
|
||||
{
|
||||
unsafe class MDConsumerHandle : IMDHandle {
|
||||
unsafe class MDConsumerHandle {
|
||||
|
||||
// Once is_initialized goes true it never goes false
|
||||
public bool is_heart_beating { get { return Co2NativeMethods.md_consumer_is_heart_beating(_header); } }
|
||||
|
||||
Reference in new issue
Block a user