159 lines
8.3 KiB
C#
159 lines
8.3 KiB
C#
using mbts.ui.shell;
|
|
using mbts.ui.spark;
|
|
using mbts.utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reactive.Subjects;
|
|
using System.Windows;
|
|
|
|
namespace mbts.spark {
|
|
partial class SyntheticEditorVM {
|
|
internal interface IRowModel {
|
|
string display_name { get; }
|
|
string help_text { get; }
|
|
bool read_only { get; }
|
|
ParameterSection[] section_path { get; }
|
|
bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups);
|
|
object get_value(LegSpreaderParamsTuple leg_tup);
|
|
void set_value(LegSpreaderParamsTuple leg_tup, object value);
|
|
void override_value(LegSpreaderParamsTuple leg_tup, object value);
|
|
void set_enabled(LegSpreaderParamsTuple leg_tup, bool enabled);
|
|
ICell create_cell(LegSpreaderParamsTuple leg_tup);
|
|
IObservable<object> observe_override_value(LegSpreaderParamsTuple leg_tup);
|
|
IObservable<bool> observe_enabled(LegSpreaderParamsTuple leg_tup);
|
|
}
|
|
|
|
internal interface IRowModel<T> : IRowModel {
|
|
new T get_value(LegSpreaderParamsTuple leg_tup);
|
|
void set_value(LegSpreaderParamsTuple leg_tup, T value);
|
|
void override_value(LegSpreaderParamsTuple leg_tup, T value);
|
|
new IObservable<T> observe_override_value(LegSpreaderParamsTuple leg_tup);
|
|
}
|
|
|
|
internal interface ICell {
|
|
event Action value_changed;
|
|
IRowModel row { get; }
|
|
Type data_type { get; }
|
|
bool enabled { get; }
|
|
}
|
|
|
|
internal interface IHaveFontParams {
|
|
FontWeight font_weight { get; }
|
|
}
|
|
|
|
internal abstract class RowModelBase<T> : ViewModelBase, IRowModel {
|
|
readonly Dictionary<LegSpreaderParamsTuple, ReplaySubject<bool>> _enabled_store = new Dictionary<LegSpreaderParamsTuple, ReplaySubject<bool>>();
|
|
readonly Dictionary<LegSpreaderParamsTuple, Subject<T>> _override_value_store = new Dictionary<LegSpreaderParamsTuple, Subject<T>>();
|
|
|
|
protected RowModelBase() { }
|
|
|
|
public abstract string display_name { get; }
|
|
public abstract string help_text { get; }
|
|
public abstract string man_page { get; }
|
|
public virtual bool read_only { get; } = false;
|
|
public virtual ParameterSection[] section_path { get; } = new ParameterSection[0];
|
|
public virtual bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups) => false;
|
|
|
|
public abstract T get_value(LegSpreaderParamsTuple leg_tup);
|
|
public abstract void set_value(LegSpreaderParamsTuple leg_tup, T value);
|
|
public virtual ICell create_cell(LegSpreaderParamsTuple leg_tup) => new Cell<T>(this, leg_tup);
|
|
|
|
public void set_enabled(LegSpreaderParamsTuple leg_tup, bool enabled) =>
|
|
_enabled_store.GetOrAdd(leg_tup, sec => new ReplaySubject<bool>(1)).OnNext(enabled);
|
|
|
|
public void override_value(LegSpreaderParamsTuple leg_tup, T value) {
|
|
if (_override_value_store.TryGetValue(leg_tup, out Subject<T> subject))
|
|
subject.OnNext(value);
|
|
}
|
|
|
|
public IObservable<bool> observe_enabled(LegSpreaderParamsTuple leg_tup) =>
|
|
_enabled_store.GetOrAdd(leg_tup, sec => {
|
|
var rs = new ReplaySubject<bool>(1);
|
|
rs.OnNext(_get_enabled(leg_tup));
|
|
return rs;
|
|
});
|
|
|
|
public IObservable<T> observe_override_value(LegSpreaderParamsTuple leg_tup) =>
|
|
_override_value_store.GetOrAdd(leg_tup, sec => new Subject<T>());
|
|
|
|
protected virtual bool _get_enabled(LegSpreaderParamsTuple leg_tup) => true;
|
|
#region IRowModel (explicit)
|
|
object IRowModel.get_value(LegSpreaderParamsTuple leg_tup) => get_value(leg_tup);
|
|
void IRowModel.set_value(LegSpreaderParamsTuple leg_tup, object value) {
|
|
T tval = ExceptionAssert.Argument.Is<T>(value, nameof(value));
|
|
set_value(leg_tup, tval);
|
|
}
|
|
void IRowModel.override_value(LegSpreaderParamsTuple leg_tup, object value) {
|
|
T tval = ExceptionAssert.Argument.Is<T>(value, nameof(value));
|
|
override_value(leg_tup, tval);
|
|
}
|
|
IObservable<object> IRowModel.observe_override_value(LegSpreaderParamsTuple leg_tup) =>
|
|
(IObservable<object>)observe_override_value(leg_tup);
|
|
#endregion
|
|
}
|
|
|
|
private static class Sections {
|
|
public static ParameterSection Quote => new ParameterSection("Quote");
|
|
public static ParameterSection PreHedge => new ParameterSection("Pre-Hedge");
|
|
public static ParameterSection PostHedge => new ParameterSection("Post-Hedge");
|
|
}
|
|
|
|
private static class Subsections {
|
|
public static ParameterSection ShowQuantity =>
|
|
new ParameterSection("Show Quantity", true,
|
|
"The quantity shown when the order is placed.");
|
|
|
|
public static ParameterSection Throttle =>
|
|
new ParameterSection("Throttle", true,
|
|
"Reduces re-quoting updates by defining a region on either side " +
|
|
"of the working quoting order, inside which quote updates will not be sent.");
|
|
|
|
public static ParameterSection Conditional =>
|
|
new ParameterSection("Conditional", true,
|
|
"Reduces re-quoting updates by only quoting if N ticks away from the opposite " +
|
|
"inside market. Quotes are cancelled when it gets further away. 'Price Type' " +
|
|
"dictates if this logic applies to the quoting market or to the synthetic spread " +
|
|
"market");
|
|
|
|
public static ParameterSection InsideMarketDistance =>
|
|
new ParameterSection("Inside Market Distance", true,
|
|
"Reduces re-quoting by throttling quotes that are moving toward the inside market " +
|
|
"but are more than 'Toward Distance' away from the inside market");
|
|
|
|
public static ParameterSection InsideMarketThrottleThresholds =>
|
|
new ParameterSection("Inside Market Throttle Thresholds", true,
|
|
"Reduces re-quoting for quotes that are moving toward the inside market. " +
|
|
"Orders moving toward the inside market are not re-quoted if:\n\n" +
|
|
"i. New order is more than 'Ticks' away from the inside market or\n" +
|
|
"ii. New order has not moved 'Min Move' away from the current price");
|
|
|
|
public static ParameterSection Payless =>
|
|
new ParameterSection("Pay Less", true,
|
|
"When the quantity at the level of the calculated hedge price is more than " +
|
|
"'Threshold,' the hedge order is paid less by 'Payless Ticks.'");
|
|
|
|
public static ParameterSection Payup =>
|
|
new ParameterSection("Pay Up", true,
|
|
"When the quantity at the level of the calculated hedge price is less than " +
|
|
"'Threshold,' then the hedge order is paid up by 'Payup Ticks.'");
|
|
|
|
public static ParameterSection TicksAwayCross =>
|
|
new ParameterSection("Ticks Away Cross", true,
|
|
"Forces legged hedging orders to automatically cross the market if they get too " +
|
|
"far away from the opposite inside market.If a legged hedge order's price gets 'Ticks' away " +
|
|
"from the opposite inside market, it is re-priced to cross the opposite inside market by 'Cross Ticks.'");
|
|
|
|
public static ParameterSection TimeBasedCross =>
|
|
new ParameterSection("Time Based Cross", true,
|
|
"Forces legged hedge orders to automatically cross the market, if they are still " +
|
|
"working beyond a certain time period.If a hedge order is legged for 'Time(ms)', " +
|
|
"it is re-priced to cross the opposite inside market by 'Cross Ticks.'");
|
|
|
|
public static ParameterSection OppositeMarketVolumeBasedCross =>
|
|
new ParameterSection("Size Based Cross", true,
|
|
"Forces legged hedging orders to automatically cross the market if the volume " +
|
|
"of the opposite inside market drops below the threhold. If opposite inside market volume drops below 'Threshold,' " +
|
|
"it is re-priced to cross the opposite inside market by 'Cross Ticks.'");
|
|
}
|
|
}
|
|
} |