Ladder - add\implement market-break-line settings
This commit is contained in:
1 parent
d739d19a42
commit
8c4a7ae0f0
7 files changed
+349
-71
No files matched your search
@@ -22,10 +22,28 @@ namespace bts.shell {
|
||||
[ImportingConstructor]
|
||||
public TradingShellModule(IBus bus, IWindowManager wm, UserSettingsHub settings_hub, OrdersModel orders_model, PAndLModel pandl_model) {
|
||||
_lwf = new LadderWindowFactory(this, bus, wm,
|
||||
new WindowSettingsManagerFactory<LadderSettings>(settings_hub, us => us.ladder, (us, v) => us.with(v)), orders_model);
|
||||
new WindowSettingsManagerFactory<LadderSettings>(
|
||||
settings_hub,
|
||||
us => sanitize_ladder_settings(us.ladder),
|
||||
(us, v) => us.with(sanitize_ladder_settings(v))),
|
||||
orders_model);
|
||||
_obwf = new OrderBookWindowFactory(this, bus, orders_model);
|
||||
_fwf = new FillsWindowFactory(this, bus, orders_model);
|
||||
_plwf = new PAndLWindowFactory(this, bus, pandl_model);
|
||||
|
||||
// if there are new props, make sure they are not null, invalid, etc.
|
||||
LadderSettings sanitize_ladder_settings(LadderSettings s) {
|
||||
// these MarketBreakLines are new settings props, ensure they are not null, and "show" is true for at least 1 of them
|
||||
if (s.bid_break_line == null)
|
||||
s.bid_break_line = LadderSettings.Default.bid_break_line;
|
||||
if (s.ask_break_line == null)
|
||||
s.ask_break_line = LadderSettings.Default.ask_break_line;
|
||||
if (s.mid_break_line == null)
|
||||
s.mid_break_line = LadderSettings.Default.mid_break_line;
|
||||
if (!s.bid_break_line.show && !s.ask_break_line.show && !s.mid_break_line.show)
|
||||
s.bid_break_line.show = true;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public ImageSource icon => Icons.Trades;
|
||||
@@ -58,5 +76,4 @@ namespace bts.shell {
|
||||
if (i != null) i.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -146,15 +146,6 @@ namespace mbts.spark {
|
||||
return raw_mid - (raw_mid % tick_size);
|
||||
}
|
||||
|
||||
public static double atm_tick(ContractSpecificationImmutable spec, double bid, double ask, MarketBreakType atm_line) {
|
||||
switch (atm_line) {
|
||||
case MarketBreakType.Bid: return double.IsNaN(bid) ? ask : bid;
|
||||
case MarketBreakType.Ask: return double.IsNaN(ask) ? bid : ask;
|
||||
case MarketBreakType.Mid:
|
||||
default: return mid_tick(spec, bid, ask);
|
||||
}
|
||||
}
|
||||
|
||||
public static IReadOnlyList<TickFactors> all_present_ticks() =>
|
||||
_ticks_cache.Values.ToReadOnlyList();
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ namespace mbts.spark {
|
||||
readonly VisualHost _visualHost = new VisualHost();
|
||||
readonly LadderOrdersHost _ordershost;
|
||||
readonly DrawingVisual
|
||||
_midvis = new DrawingVisual(),
|
||||
_mid_mkt_break_vis = new DrawingVisual(),
|
||||
_bid_mkt_break_vis = new DrawingVisual(),
|
||||
_ask_mkt_break_vis = new DrawingVisual(),
|
||||
_gridvis = new DrawingVisual();
|
||||
readonly VisualGlyphTuple
|
||||
_bid_vis_tup = new VisualGlyphTuple(),
|
||||
@@ -42,12 +44,14 @@ namespace mbts.spark {
|
||||
bool _price_dirty = false;
|
||||
double[] _price_list = null;
|
||||
IComparer<double> _price_comparer;
|
||||
double _last_market_break;
|
||||
double _last_origin_price;
|
||||
MarketBreakLines _mkt_break_lines;
|
||||
NativePriceSize _last_trade;
|
||||
|
||||
public LadderGridHost() {
|
||||
AllowDrop = true;
|
||||
UseLayoutRounding = true;
|
||||
_mkt_break_lines = new MarketBreakLines(this);
|
||||
_ordershost = new LadderOrdersHost(this) { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Stretch };
|
||||
var scrollViewerFactory = new FrameworkElementFactory(typeof(ScrollViewer));
|
||||
scrollViewerFactory.SetValue(FocusableProperty, false);
|
||||
@@ -309,7 +313,7 @@ namespace mbts.spark {
|
||||
case ColumnType.Ask: render_market_col(_asks); break;
|
||||
}
|
||||
void render_market_col(NativePriceSize[] depth) {
|
||||
var mid = LadderRender.index_of(_price_list, _last_market_break, _price_comparer);
|
||||
var mid = LadderRender.index_of(_price_list, _last_origin_price, _price_comparer);
|
||||
LadderRender.render_sizes(column.visual_tup.visual, column.visual_tup.glyph_context, mid, _price_list, depth, _settings.row_height, security.ContractSpec, column.settings);
|
||||
}
|
||||
}
|
||||
@@ -344,8 +348,8 @@ namespace mbts.spark {
|
||||
|
||||
void _scroll_to_center() {
|
||||
if (_scrollViewer != null && _settings != null) {
|
||||
int index = _price_list != null && !double.IsNaN(_last_market_break) ?
|
||||
LadderRender.index_of(_price_list, _last_market_break, _price_comparer) :
|
||||
int index = _price_list != null && !double.IsNaN(_last_origin_price) ?
|
||||
LadderRender.index_of(_price_list, _last_origin_price, _price_comparer) :
|
||||
_row_count / 2;
|
||||
double target_position = index * _settings.row_height - (ActualHeight / 2);
|
||||
if (_settings.animate_recenter) {
|
||||
@@ -372,22 +376,23 @@ namespace mbts.spark {
|
||||
ulong unused = 0;
|
||||
_vm.md.get_last_trade(ref unused, out NativePriceSize last, out DateTime _, out ulong __);
|
||||
bool depth_changed = _vm.md.get_depth(ref _prices_updated, ref _bids, ref _asks);
|
||||
double market_break = _get_market_break();
|
||||
//
|
||||
_mkt_break_lines.refresh();
|
||||
bool update_prices =
|
||||
_price_dirty ||
|
||||
(double.IsNaN(_last_market_break) && !double.IsNaN(market_break)) ||
|
||||
(market_break >= _price_list[0] || market_break <= _price_list[_price_list.Length - 1]);
|
||||
(double.IsNaN(_last_origin_price) && !double.IsNaN(_mkt_break_lines.origin)) ||
|
||||
_mkt_break_lines.origin >= _price_list[0] || _mkt_break_lines.origin <= _price_list[_price_list.Length - 1];
|
||||
if (!update_prices && _prices_out_of_range(out double low, out double high)) {
|
||||
// The market can be wider than the 1001 rows (ticks) we [initially] allot.
|
||||
// Rendering prices is expensive, and will lock up the ui if done continuously.
|
||||
// Therefore, ensure a minimum time interval has elapsed before rendering prices again.
|
||||
var now = DateTime.Now;
|
||||
if ((now - _last_price_range_calc_time) > _price_out_of_range_render_interval) {
|
||||
SparkUtils.lazy_warn(!double.IsNaN(market_break) && market_break >= low && market_break <= high,
|
||||
() => fmt_log_msg($"market break ({market_break}) is unacceptable for the market range ({low} - {high})"));
|
||||
SparkUtils.lazy_warn(!double.IsNaN(_mkt_break_lines.origin) && _mkt_break_lines.origin >= low && _mkt_break_lines.origin <= high,
|
||||
() => fmt_log_msg($"market break ({_mkt_break_lines.origin}) is unacceptable for the market range ({low} - {high})"));
|
||||
int prev_row_count = _row_count;
|
||||
int n_ticks_to_low = TickUtils.normalized_tick_diff(security.ContractSpec, market_break, low);
|
||||
int n_ticks_to_high = TickUtils.normalized_tick_diff(security.ContractSpec, high, market_break);
|
||||
int n_ticks_to_low = TickUtils.normalized_tick_diff(security.ContractSpec, _mkt_break_lines.origin, low);
|
||||
int n_ticks_to_high = TickUtils.normalized_tick_diff(security.ContractSpec, high, _mkt_break_lines.origin);
|
||||
int desired_row_count = Math.Max(n_ticks_to_low, n_ticks_to_high) * 2 + 1;
|
||||
_row_count = Math.Min(_max_row_count, desired_row_count);
|
||||
if (_row_count != prev_row_count) {
|
||||
@@ -401,7 +406,7 @@ namespace mbts.spark {
|
||||
_ordershost.Height = height;
|
||||
_render_grid_lines();
|
||||
} else {
|
||||
update_prices = market_break != _last_market_break;
|
||||
update_prices = _mkt_break_lines.origin != _last_origin_price;
|
||||
}
|
||||
_last_price_range_calc_time = now;
|
||||
//
|
||||
@@ -411,7 +416,7 @@ namespace mbts.spark {
|
||||
}
|
||||
if (update_prices) {
|
||||
var prev_price_list = _price_list;
|
||||
_price_list = LadderRender.render_prices(_price_vis_tup.visual, _price_vis_tup.glyph_context, market_break, _row_count, _settings.row_height, _settings.price_column, security.ContractSpec);
|
||||
_price_list = LadderRender.render_prices(_price_vis_tup.visual, _price_vis_tup.glyph_context, _mkt_break_lines.origin, _row_count, _settings.row_height, _settings.price_column, security.ContractSpec);
|
||||
_ordershost.update_settings(_price_list, _price_comparer, _settings.row_height, _settings.orders_column);
|
||||
if (prev_price_list != null) {
|
||||
// maintain previous visible price range if possible
|
||||
@@ -428,11 +433,14 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
}
|
||||
int market_break_index = LadderRender.index_of(_price_list, market_break, _price_comparer);
|
||||
if (update_prices || market_break != _last_market_break) {
|
||||
_last_market_break = market_break;
|
||||
LadderRender.render_mid(_midvis, market_break_index, _settings.row_height);
|
||||
}
|
||||
// render market breaks
|
||||
if (update_prices || _mkt_break_lines.bid_dirty)
|
||||
render_mkt_break(_bid_mkt_break_vis, _mkt_break_lines.bid, _settings.bid_break_line.color);
|
||||
if (update_prices || _mkt_break_lines.ask_dirty)
|
||||
render_mkt_break(_ask_mkt_break_vis, _mkt_break_lines.ask, _settings.ask_break_line.color);
|
||||
if (update_prices || _mkt_break_lines.mid_dirty)
|
||||
render_mkt_break(_mid_mkt_break_vis, _mkt_break_lines.mid, _settings.mid_break_line.color);
|
||||
//
|
||||
if (update_prices || _last_trade != last) {
|
||||
_last_trade = last;
|
||||
var last_index = LadderRender.index_of(_price_list, last.price, _price_comparer);
|
||||
@@ -442,36 +450,50 @@ namespace mbts.spark {
|
||||
}
|
||||
if (update_prices || depth_changed) {
|
||||
Logger.assert_d(_price_list != null);
|
||||
LadderRender.render_sizes(_bid_vis_tup.visual, _bid_vis_tup.glyph_context, market_break_index, _price_list, _bids, _settings.row_height, security.ContractSpec, _settings.bid_column);
|
||||
LadderRender.render_sizes(_ask_vis_tup.visual, _ask_vis_tup.glyph_context, market_break_index, _price_list, _asks, _settings.row_height, security.ContractSpec, _settings.ask_column);
|
||||
int origin_index = LadderRender.index_of(_price_list, _mkt_break_lines.origin, _price_comparer);
|
||||
LadderRender.render_sizes(_bid_vis_tup.visual, _bid_vis_tup.glyph_context, origin_index, _price_list, _bids, _settings.row_height, security.ContractSpec, _settings.bid_column);
|
||||
LadderRender.render_sizes(_ask_vis_tup.visual, _ask_vis_tup.glyph_context, origin_index, _price_list, _asks, _settings.row_height, security.ContractSpec, _settings.ask_column);
|
||||
}
|
||||
_last_origin_price = _mkt_break_lines.origin;
|
||||
_price_dirty = false;
|
||||
//
|
||||
void render_mkt_break(DrawingVisual vis, double price, uint color) {
|
||||
int index = LadderRender.index_of(_price_list, price, _price_comparer);
|
||||
LadderRender.render_mkt_break(vis, index, _settings.row_height, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double _get_market_break() {
|
||||
#region Market Break Utils
|
||||
double _get_bid_market_break() {
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
switch (_settings.market_break_type) {
|
||||
case MarketBreakType.Bid:
|
||||
return double.IsNaN(best_bid) ?
|
||||
double.IsNaN(best_ask) ? _vm.low : security.ContractSpec.tickdown(best_ask) :
|
||||
best_bid;
|
||||
case MarketBreakType.Ask:
|
||||
return double.IsNaN(best_ask) ?
|
||||
double.IsNaN(best_bid) ? security.ContractSpec.tickdown(_vm.high) : best_bid :
|
||||
security.ContractSpec.tickdown(best_ask);
|
||||
case MarketBreakType.Mid:
|
||||
return double.IsNaN(best_bid) ?
|
||||
double.IsNaN(best_ask) ? 0.5 * (_vm.low + _vm.high) : security.ContractSpec.tickdown(best_ask) :
|
||||
double.IsNaN(best_ask) ? best_bid : TickUtils.mid_tick(security.ContractSpec, best_bid, best_ask);
|
||||
default: throw new NotImplementedException($"Unknown MarketBreakType ({_settings.market_break_type})");
|
||||
}
|
||||
double _get_top_price(NativePriceSize[] prices) =>
|
||||
prices != null && prices.Length > 0 ? prices[0].price : double.NaN;
|
||||
return double.IsNaN(best_bid) ?
|
||||
double.IsNaN(best_ask) ? _vm.low : security.ContractSpec.tickdown(best_ask) :
|
||||
best_bid;
|
||||
}
|
||||
|
||||
void _settings_updated(LadderSettings s) {
|
||||
double _get_ask_market_break() {
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
return double.IsNaN(best_ask) ?
|
||||
double.IsNaN(best_bid) ? security.ContractSpec.tickdown(_vm.high) : best_bid :
|
||||
security.ContractSpec.tickdown(best_ask);
|
||||
}
|
||||
|
||||
double _get_mid_market_break() {
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
return double.IsNaN(best_bid) ?
|
||||
double.IsNaN(best_ask) ? 0.5 * (_vm.low + _vm.high) : security.ContractSpec.tickdown(best_ask) :
|
||||
double.IsNaN(best_ask) ? best_bid : TickUtils.mid_tick(security.ContractSpec, best_bid, best_ask);
|
||||
}
|
||||
|
||||
static double _get_top_price(NativePriceSize[] prices) =>
|
||||
prices != null && prices.Length > 0 ? prices[0].price : double.NaN;
|
||||
#endregion
|
||||
|
||||
void _settings_updated(LadderSettings s) {
|
||||
_settings = s;
|
||||
_bid_vis_tup.glyph_context = glyph_context(s.bid_column);
|
||||
_ask_vis_tup.glyph_context = glyph_context(s.ask_column);
|
||||
@@ -504,7 +526,9 @@ namespace mbts.spark {
|
||||
}
|
||||
// Renders the grid lines
|
||||
_visualHost.AddVisualChild(_gridvis);
|
||||
_visualHost.AddVisualChild(_midvis);
|
||||
_visualHost.AddVisualChild(_mid_mkt_break_vis);
|
||||
_visualHost.AddVisualChild(_ask_mkt_break_vis);
|
||||
_visualHost.AddVisualChild(_bid_mkt_break_vis);
|
||||
_init_tactile_adorner();
|
||||
// this effectively sets the background of the "Last" column
|
||||
if (_scrollViewer != null)
|
||||
@@ -569,5 +593,46 @@ namespace mbts.spark {
|
||||
public static bool operator !=(Column x, Column y) =>
|
||||
!(x == y);
|
||||
}
|
||||
|
||||
class MarketBreakLines {
|
||||
readonly LadderGridHost _owner;
|
||||
|
||||
public MarketBreakLines(LadderGridHost owner) =>
|
||||
_owner = owner;
|
||||
|
||||
public bool bid_dirty { get; private set; }
|
||||
public bool ask_dirty { get; private set; }
|
||||
public bool mid_dirty { get; private set; }
|
||||
public bool origin_dirty { get; private set; }
|
||||
|
||||
public double bid { get; private set; }
|
||||
public double ask { get; private set; }
|
||||
public double mid { get; private set; }
|
||||
public double origin { get; private set; }
|
||||
|
||||
public void refresh() {
|
||||
double new_bid = _owner._settings.bid_break_line.show ? _owner._get_bid_market_break() : double.NaN;
|
||||
double new_ask = _owner._settings.ask_break_line.show ? _owner._get_ask_market_break() : double.NaN;
|
||||
double new_mid = _owner._settings.mid_break_line.show ? _owner._get_mid_market_break() : double.NaN;
|
||||
//
|
||||
if ((bid_dirty = !new_bid.Equals(bid)))
|
||||
bid = new_bid;
|
||||
if ((ask_dirty = !new_ask.Equals(ask)))
|
||||
ask = new_ask;
|
||||
if ((mid_dirty = !new_mid.Equals(mid)))
|
||||
mid = new_mid;
|
||||
//
|
||||
double new_origin;
|
||||
if (!double.IsNaN(bid))
|
||||
new_origin = bid;
|
||||
else if (!double.IsNaN(ask))
|
||||
new_origin = ask;
|
||||
else new_origin = mid;
|
||||
if (double.IsNaN(new_origin))
|
||||
new_origin = _owner._get_bid_market_break();
|
||||
if ((origin_dirty = !new_origin.Equals(origin)))
|
||||
origin = new_origin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace mbts.spark {
|
||||
public enum MarketBreakType { Bid, Ask, Mid }
|
||||
|
||||
// IMPORTANT: BE SURE TO ADD ANY NEW PROPERTIES TO THE EQUALS FUNCTION!
|
||||
// 1 important reason at this time:
|
||||
// From the settings dialog, default settings will only be persisted when they are NOT EQUAL to the current default settings.
|
||||
@@ -75,6 +73,26 @@ namespace mbts.spark {
|
||||
public static bool operator !=(LadderColumnSettings x, LadderColumnSettings y) => !(x == y);
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public class LadderMarketBreakLine : IEquatable<LadderMarketBreakLine> {
|
||||
[ProtoMember(1)]
|
||||
public bool show { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public uint color { get; set; }
|
||||
|
||||
public bool Equals(LadderMarketBreakLine other) =>
|
||||
other != null &&
|
||||
other.show == show &&
|
||||
other.color == color;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as LadderMarketBreakLine);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
show.GetHashCode() +
|
||||
(int)color;
|
||||
}
|
||||
|
||||
// IMPORTANT: BE SURE TO ADD ANY NEW PROPERTIES TO THE EQUALS FUNCTION!
|
||||
// 1 important reason at this time:
|
||||
// From the settings dialog, default settings will only be persisted when they are NOT EQUAL to the current default settings.
|
||||
@@ -99,7 +117,6 @@ namespace mbts.spark {
|
||||
return new LadderSettings {
|
||||
row_height = 20,
|
||||
grid_line_color = 0x535353,
|
||||
market_break_type = MarketBreakType.Bid,
|
||||
orders_column = orders_column,
|
||||
bid_column = bid_column,
|
||||
ask_column = ask_column,
|
||||
@@ -111,7 +128,10 @@ namespace mbts.spark {
|
||||
seconds_to_recenter = 300,
|
||||
default_order_type = CustomOrderDefinition.CustomOneofCase.Limit,
|
||||
default_time_in_force = TimeInForce.Day,
|
||||
animate_recenter = true
|
||||
animate_recenter = true,
|
||||
bid_break_line = new LadderMarketBreakLine { color = 0, show = true },
|
||||
ask_break_line = new LadderMarketBreakLine { color = 0, show = false },
|
||||
mid_break_line = new LadderMarketBreakLine { color = 0, show = false }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -122,8 +142,8 @@ namespace mbts.spark {
|
||||
public double row_height { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public uint grid_line_color { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public MarketBreakType market_break_type { get; set; }
|
||||
//[ProtoMember(3)]
|
||||
//public MarketBreakType market_break_type { get; set; }
|
||||
|
||||
// Column settings
|
||||
[ProtoMember(4)]
|
||||
@@ -156,11 +176,17 @@ namespace mbts.spark {
|
||||
[ProtoMember(17)]
|
||||
public BadgeStyle badge_style { get; set; }
|
||||
|
||||
[ProtoMember(18)]
|
||||
public LadderMarketBreakLine bid_break_line { get; set; }
|
||||
[ProtoMember(19)]
|
||||
public LadderMarketBreakLine ask_break_line { get; set; }
|
||||
[ProtoMember(20)]
|
||||
public LadderMarketBreakLine mid_break_line { get; set; }
|
||||
|
||||
public bool Equals(LadderSettings other) =>
|
||||
other != null &&
|
||||
other.row_height == row_height &&
|
||||
other.grid_line_color == grid_line_color &&
|
||||
other.market_break_type == market_break_type &&
|
||||
other.orders_column.safe_equals(orders_column) &&
|
||||
other.bid_column.safe_equals(bid_column) &&
|
||||
other.ask_column.safe_equals(ask_column) &&
|
||||
@@ -173,14 +199,16 @@ namespace mbts.spark {
|
||||
other.default_time_in_force == default_time_in_force &&
|
||||
other.seconds_to_recenter == size &&
|
||||
other.animate_recenter == animate_recenter &&
|
||||
other.badge_style == badge_style;
|
||||
other.badge_style == badge_style &&
|
||||
other.bid_break_line.safe_equals(bid_break_line) &&
|
||||
other.ask_break_line.safe_equals(ask_break_line) &&
|
||||
other.mid_break_line.safe_equals(mid_break_line);
|
||||
|
||||
public override bool Equals(object obj) => Equals(obj as LadderSettings);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
row_height.GetHashCode() +
|
||||
grid_line_color.GetHashCode() +
|
||||
market_break_type.GetHashCode() +
|
||||
orders_column.GetHashCode() +
|
||||
bid_column.GetHashCode() +
|
||||
ask_column.GetHashCode() +
|
||||
@@ -193,6 +221,9 @@ namespace mbts.spark {
|
||||
default_order_type.GetHashCode() +
|
||||
default_time_in_force.GetHashCode() +
|
||||
seconds_to_recenter.GetHashCode() +
|
||||
animate_recenter.GetHashCode();
|
||||
animate_recenter.GetHashCode() +
|
||||
bid_break_line.GetHashCode() +
|
||||
ask_break_line.GetHashCode() +
|
||||
mid_break_line.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ namespace mbts.spark {
|
||||
_price = new LadderColumnSettingsVM("Price"),
|
||||
_ask = new LadderColumnSettingsVM("Ask"),
|
||||
_last = new LadderColumnSettingsVM("Last");
|
||||
LadderMarketBreakLineVM
|
||||
_bid_mkt_line = new LadderMarketBreakLineVM("Bid"),
|
||||
_ask_mkt_line = new LadderMarketBreakLineVM("Ask"),
|
||||
_mid_mkt_line = new LadderMarketBreakLineVM("Mid");
|
||||
|
||||
public LadderSettingsVM() =>
|
||||
_badge_style = backing<LadderSettings.BadgeStyle>(nameof(badge_style));
|
||||
@@ -38,6 +42,20 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public LadderColumnSettingsVM orders_column => _orders;
|
||||
public LadderColumnSettingsVM bid_column => _bid;
|
||||
public LadderColumnSettingsVM price_column => _price;
|
||||
public LadderColumnSettingsVM ask_column => _ask;
|
||||
public LadderColumnSettingsVM last_column => _last;
|
||||
|
||||
public IEnumerable<LadderMarketBreakLineVM> mkt_break_items {
|
||||
get {
|
||||
yield return _bid_mkt_line;
|
||||
yield return _ask_mkt_line;
|
||||
yield return _mid_mkt_line;
|
||||
}
|
||||
}
|
||||
|
||||
public void load(LadderSettings settings) {
|
||||
_current = settings;
|
||||
badge_style = settings.badge_style;
|
||||
@@ -46,6 +64,9 @@ namespace mbts.spark {
|
||||
_ask.assign_from(_current.ask_column);
|
||||
_price.assign_from(_current.price_column);
|
||||
_last.assign_from(_current.last_column);
|
||||
_bid_mkt_line.assign_from(_current.bid_break_line);
|
||||
_ask_mkt_line.assign_from(_current.ask_break_line);
|
||||
_mid_mkt_line.assign_from(_current.mid_break_line);
|
||||
}
|
||||
|
||||
public LadderSettings get_result() {
|
||||
@@ -56,9 +77,12 @@ namespace mbts.spark {
|
||||
clone.price_column = _price.get_settings();
|
||||
clone.ask_column = _ask.get_settings();
|
||||
clone.last_column = _last.get_settings();
|
||||
clone.bid_break_line = _bid_mkt_line.get_settings();
|
||||
clone.ask_break_line = _ask_mkt_line.get_settings();
|
||||
clone.mid_break_line = _mid_mkt_line.get_settings();
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
public class LadderColumnSettingsVM : ViewModelBase {
|
||||
readonly Property<double> _font_size;
|
||||
readonly Property<Color> _foreground, _background;
|
||||
@@ -122,5 +146,33 @@ namespace mbts.spark {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class LadderMarketBreakLineVM : ViewModelBase {
|
||||
readonly Property<Color> _color;
|
||||
readonly Property<bool> _show;
|
||||
|
||||
public LadderMarketBreakLineVM(string name) {
|
||||
this.name = name;
|
||||
palettes = new ObservableCollection<ColorPaletteVM>(ColorPalette.all_presets().Select(p => new ColorPaletteVM(p)));
|
||||
_color = backing(nameof(color), Colors.Black);
|
||||
_show = backing(nameof(show), false);
|
||||
}
|
||||
|
||||
public string name { get; }
|
||||
public Color color { get => _color.Value; set => _color.Value = value; }
|
||||
public bool show { get => _show.Value; set => _show.Value = value; }
|
||||
public ObservableCollection<ColorPaletteVM> palettes { get; }
|
||||
|
||||
public void assign_from(LadderMarketBreakLine settings) {
|
||||
color = settings.color.rgb_color();
|
||||
show = settings.show;
|
||||
}
|
||||
|
||||
public LadderMarketBreakLine get_settings() =>
|
||||
new LadderMarketBreakLine {
|
||||
color = new BTSColor(color).ToUint(),
|
||||
show = show
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,12 @@
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
TextElement.FontSize="{x:Static u:FontSizes.Small}"
|
||||
>
|
||||
<Grid>
|
||||
<Grid Grid.IsSharedSizeScope="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
@@ -20,7 +22,7 @@
|
||||
<TextBlock VerticalAlignment="Center" Margin="8,0,0,0">Order Badge Style</TextBlock>
|
||||
<ComboBox Grid.Column="1" Margin="8,0,24,0" ItemsSource="{u:EnumBindingSource {u:Nested sp:LadderSettings.BadgeStyle}}" SelectedItem="{Binding badge_style}"/>
|
||||
<GroupBox Grid.Row="1" Grid.ColumnSpan="2" Margin="0,6,0,0" Padding="8" Header="Fonts and Colors">
|
||||
<Grid Grid.IsSharedSizeScope="True">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="27"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -99,5 +101,124 @@
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="2" Grid.ColumnSpan="2" Margin="0,6,0,0" Padding="8" Header="Market Break Lines">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="27"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid TextElement.Foreground="{u:BTSColor header_text}" Background="{u:BTSColor header}" Margin="8,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition SharedSizeGroup="c1"/>
|
||||
<ColumnDefinition SharedSizeGroup="c2"/>
|
||||
<ColumnDefinition SharedSizeGroup="c3"/>
|
||||
<ColumnDefinition SharedSizeGroup="c4"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="1" HorizontalAlignment="Center" Margin="6,0" Text="Show" VerticalAlignment="Center"/>
|
||||
<TextBlock Grid.Column="2" HorizontalAlignment="Center" Margin="6,0" Text="Color" VerticalAlignment="Center"/>
|
||||
<TextBlock Grid.Column="3" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="6,0" Text="Sample" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<ItemsControl Grid.Row="1" ItemsSource="{Binding mkt_break_items}" Margin="8,0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Height="27">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition SharedSizeGroup="c1"/>
|
||||
<ColumnDefinition SharedSizeGroup="c2"/>
|
||||
<ColumnDefinition SharedSizeGroup="c3"/>
|
||||
<ColumnDefinition SharedSizeGroup="c4"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border Grid.Column="0" Background="{u:BTSColor header}" Padding="6,3">
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding name}" Foreground="{u:BTSColor header_text}"/>
|
||||
</Border>
|
||||
<CheckBox Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding show}"/>
|
||||
<c:ColorPickerPopup
|
||||
Grid.Column="2"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="0"
|
||||
PopupPlacement="Left"
|
||||
Palettes="{Binding palettes}"
|
||||
SelectedColor="{Binding color}"
|
||||
/>
|
||||
<Grid Grid.Column="3" Grid.ColumnSpan="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="2"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle Grid.Column="0" Grid.RowSpan="3" Panel.ZIndex="1" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="1" Fill="Black"/>
|
||||
<!--<Rectangle Grid.Column="4" Grid.RowSpan="3" Panel.ZIndex="1" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="1" Fill="Black"/>-->
|
||||
<Rectangle
|
||||
Grid.Column="0"
|
||||
Grid.RowSpan="3"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Fill="{Binding DataContext.orders_column.background, RelativeSource={RelativeSource AncestorType=usp:LadderSettingsView}, Converter={StaticResource ColorToBrushConverter}}"
|
||||
/>
|
||||
<Rectangle
|
||||
Grid.Column="1"
|
||||
Grid.RowSpan="3"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Fill="{Binding DataContext.bid_column.background, RelativeSource={RelativeSource AncestorType=usp:LadderSettingsView}, Converter={StaticResource ColorToBrushConverter}}"
|
||||
/>
|
||||
<Rectangle
|
||||
Grid.Column="2"
|
||||
Grid.RowSpan="3"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Fill="{Binding DataContext.price_column.background, RelativeSource={RelativeSource AncestorType=usp:LadderSettingsView}, Converter={StaticResource ColorToBrushConverter}}"
|
||||
/>
|
||||
<Rectangle
|
||||
Grid.Column="3"
|
||||
Grid.RowSpan="3"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Fill="{Binding DataContext.ask_column.background, RelativeSource={RelativeSource AncestorType=usp:LadderSettingsView}, Converter={StaticResource ColorToBrushConverter}}"
|
||||
/>
|
||||
<Rectangle
|
||||
Grid.Column="4" Grid.RowSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
Fill="{Binding DataContext.last_column.background, RelativeSource={RelativeSource AncestorType=usp:LadderSettingsView}, Converter={StaticResource ColorToBrushConverter}}"
|
||||
/>
|
||||
<Rectangle Grid.Row="1" Grid.ColumnSpan="5" Fill="{Binding color, Converter={StaticResource ColorToBrushConverter}}">
|
||||
<Rectangle.Style>
|
||||
<Style TargetType="Rectangle">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding show}" Value="{u:False}">
|
||||
<Setter Property="Fill" Value="Transparent"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Rectangle.Style>
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
<Rectangle Grid.Column="1" Grid.ColumnSpan="5" Fill="DimGray" Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<!--<GroupBox Grid.Row="2" Grid.ColumnSpan="2" Header="Market Break Lines">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="8"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox IsChecked="{Binding show_bid_break_line}">Bid</CheckBox>
|
||||
<CheckBox IsChecked="{Binding show_ask_break_line}">Ask</CheckBox>
|
||||
<CheckBox IsChecked="{Binding show_mid_break_line}">Mid</CheckBox>
|
||||
</Grid>
|
||||
</GroupBox>-->
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -74,7 +74,7 @@ namespace mbts.spark {
|
||||
public static void render_sizes(
|
||||
DrawingVisual dv,
|
||||
GlyphContext glyph_context,
|
||||
int market_break_index,
|
||||
int origin_index,
|
||||
double[] prices,
|
||||
NativePriceSize[] rungs,
|
||||
double row_height,
|
||||
@@ -85,10 +85,10 @@ namespace mbts.spark {
|
||||
using (var dc = dv.RenderOpen())
|
||||
using (_draw_with_clip(dc, settings, row_height, prices.Length)) {
|
||||
dc.DrawRectangle(background, null, new Rect(0, 0, settings.width, prices.Length * row_height));
|
||||
if (!prices.within_range(market_break_index) || rungs.is_null_or_empty())
|
||||
if (!prices.within_range(origin_index) || rungs.is_null_or_empty())
|
||||
return;
|
||||
var foreground = new SolidColorBrush(settings.foreground.rgb_color());
|
||||
int curr_index = market_break_index;
|
||||
int curr_index = origin_index;
|
||||
double curr_price = prices[curr_index];
|
||||
foreach (var nps in rungs) {
|
||||
if (nps.is_nan) break;
|
||||
@@ -114,9 +114,10 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public static void render_mid(DrawingVisual dv, int midIndex, double row_height) {
|
||||
public static void render_mkt_break(DrawingVisual dv, int index, double row_height, uint color) {
|
||||
using (var dc = dv.RenderOpen()) {
|
||||
dc.DrawRectangle(Brushes.Black, null, new Rect(0, midIndex * row_height - 1, SystemParameters.FullPrimaryScreenWidth, 3));
|
||||
if (index >= 0)
|
||||
dc.DrawRectangle(color.rgb_brush(), null, new Rect(0, index * row_height - 1, SystemParameters.FullPrimaryScreenWidth, 3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user