Merge branch 'master' of bitbucket.org:bluetradesys/spark
This commit is contained in:
commit
fc9cb7e13d
66 files changed
+1312
-1996
No files matched your search
@@ -18,7 +18,6 @@ namespace mbts.spark
|
||||
{ Order.AlgoOrderTypeOneofCase.StopLimitOrder, typeof(orders.StopLimitOrderActor) },
|
||||
{ Order.AlgoOrderTypeOneofCase.StopMarketOrder, typeof(orders.StopMarketOrderActor) },
|
||||
{ Order.AlgoOrderTypeOneofCase.CrossingHedgeOrder, typeof(orders.CrossingHedgeOrderActor) },
|
||||
{ Order.AlgoOrderTypeOneofCase.SimpleHedgeOrder, typeof(orders.SimpleHedgeOrderActor) },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -59,15 +59,10 @@ namespace mbts.spark.orders
|
||||
else
|
||||
bid_or_ask = bbo.Item1;
|
||||
|
||||
if(bid_or_ask.size <= _order.CrossingHedgeOrder.CrossSizeThreshold ||
|
||||
bid_or_ask.size <= _order.CrossingHedgeOrder.CrossRatioThreshold * _order.Size)
|
||||
{
|
||||
_exchange.modify_price(_order.Id, bid_or_ask.price);
|
||||
}
|
||||
|
||||
uint distance = Convert.ToUInt32(Math.Abs(bid_or_ask.price - _status.Order.Price) / compute_tick(_order.Security));
|
||||
if(distance > _order.CrossingHedgeOrder.TicksBetterThreshold)
|
||||
_exchange.modify_price(_order.Id, bid_or_ask.price);
|
||||
double tick = (_order.Side == BuySell.Buy ? 1.0 : -1.0) * compute_tick(_order.Security);
|
||||
if(distance > _order.CrossingHedgeOrder.TicksThreshold)
|
||||
_exchange.modify_price(_order.Id, _status.Order.Price + _order.CrossingHedgeOrder.MarketCrossTicks * tick);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace mbts.spark.orders
|
||||
{
|
||||
foreach(Security sec in _leg_ratios.Keys)
|
||||
{
|
||||
SyntheticLegExecutionParams param;
|
||||
LegSpreaderParams param;
|
||||
_execution_strategy.TryGetValue(sec.Id, out param);
|
||||
if(param.QuoteParams.IsWorking)
|
||||
if(param.IsActiveQuoting)
|
||||
{
|
||||
IOrderHandle current_order = _children.Values
|
||||
.Where(x => x.security.Equals(sec) && !_hedges.Contains(x.order_id)).FirstOrDefault();
|
||||
@@ -66,7 +66,7 @@ namespace mbts.spark.orders
|
||||
}
|
||||
|
||||
void update_existing_order(IOrderHandle current_order, double new_price, uint new_size, BuySell side,
|
||||
IReadOnlyList<PriceSize> this_leg_book, SyntheticLegExecutionParams param, bool bypass_quote_rules)
|
||||
IReadOnlyList<PriceSize> this_leg_book, LegSpreaderParams param, bool bypass_quote_rules)
|
||||
{
|
||||
OrderStatus status;
|
||||
if(_child_status.TryGetValue(current_order.order_id, out status))
|
||||
@@ -85,9 +85,9 @@ namespace mbts.spark.orders
|
||||
{
|
||||
int ticks_from_center = Convert.ToInt32((this_leg_book[0].price - status.Order.Price) / tick);
|
||||
|
||||
var qlevel = param.QuoteParams.TickRangeRequoteRules.TicksAwayToSensitivity
|
||||
.LastOrDefault(x => x.Key <= ticks_from_center);
|
||||
uint sensitivity = Math.Max(qlevel.Value, 1);
|
||||
//var qlevel = param.QuoteParams.TickRangeRequoteRules.TicksAwayToSensitivity
|
||||
// .LastOrDefault(x => x.Key <= ticks_from_center);
|
||||
uint sensitivity = Math.Max(/*qlevel.Value*/1u, 1);
|
||||
if(Math.Abs(price_diff) >= sensitivity)
|
||||
current_order.modify_price(new_price);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace mbts.spark.orders
|
||||
bool hit_myself = false;
|
||||
foreach(Security sec in _leg_ratios.Keys)
|
||||
{
|
||||
SyntheticLegExecutionParams param;
|
||||
LegSpreaderParams param;
|
||||
if(!_execution_strategy.TryGetValue(sec.Id, out param))
|
||||
return false;
|
||||
double quote_size = _leg_ratios[sec] * _order_size;
|
||||
@@ -152,26 +152,23 @@ namespace mbts.spark.orders
|
||||
uint size_counter = looking_for_size;
|
||||
foreach(var level in bid_or_ask_book)
|
||||
{
|
||||
if(param.QuoteParams.PessimisticHedgePricing)
|
||||
if(level.size >= looking_for_size) //pessimistic
|
||||
{
|
||||
if(level.size >= looking_for_size)
|
||||
{
|
||||
leg_price = level.price;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint level_size = Math.Min(level.size, size_counter);
|
||||
leg_price += level.price * level_size / looking_for_size;
|
||||
size_counter -= level_size;
|
||||
if(size_counter == 0)
|
||||
{
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
leg_price = level.price;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// uint level_size = Math.Min(level.size, size_counter);
|
||||
// leg_price += level.price * level_size / looking_for_size;
|
||||
// size_counter -= level_size;
|
||||
// if(size_counter == 0)
|
||||
// {
|
||||
// ok = true;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
if(!ok)
|
||||
return false;
|
||||
|
||||
@@ -22,10 +22,10 @@ namespace mbts.spark.orders
|
||||
base.on_spawn();
|
||||
foreach(var kv in _leg_ratios)
|
||||
{
|
||||
SyntheticLegExecutionParams param;
|
||||
LegSpreaderParams param;
|
||||
if(_execution_strategy.TryGetValue(kv.Key.Id, out param))
|
||||
{
|
||||
if(param.QuoteParams.IsWorking)
|
||||
if(param.IsActiveQuoting)
|
||||
{
|
||||
BuySell side = kv.Value > 0.0 ? BuySell.Buy : BuySell.Sell;
|
||||
uint size = Convert.ToUInt32(Math.Abs(kv.Value * _order.Size));
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace mbts.spark.orders
|
||||
public Security leg;
|
||||
public double price;
|
||||
public double size;
|
||||
public SyntheticLegExecutionParams leg_params;
|
||||
public LegSpreaderParams leg_params;
|
||||
}
|
||||
|
||||
override public void on_spawn()
|
||||
@@ -149,12 +149,13 @@ namespace mbts.spark.orders
|
||||
//}
|
||||
|
||||
double tick = compute_tick(kv.Key);
|
||||
var post = kv.Value.leg_params.HedgeParams.PostHedgeRules;
|
||||
PostHedgePriceBasedForcedCross post = null;
|
||||
if(post.Priority.IsActive)
|
||||
post = kv.Value.leg_params.PostHedgeParams.PriceBasedCross;
|
||||
var cross = new CrossingHedgeOrder
|
||||
{
|
||||
CrossSizeThreshold = post == null ? 0 : post.CrossSizeThreshold,
|
||||
CrossRatioThreshold = post == null ? 1.0 : post.CrossRatioThreshold,
|
||||
TicksBetterThreshold = Convert.ToUInt32(Math.Abs(hedge_price - kv.Value.price) / tick),
|
||||
TicksThreshold = (post == null) ? 1000 : post.TicksThreshold,
|
||||
MarketCrossTicks = (post == null) ? 0 : post.MarketCrossTicks,
|
||||
};
|
||||
|
||||
var hedge = create_order<CrossingHedgeOrder>(kv.Value.leg, hedge_size, hedge_price,
|
||||
@@ -168,58 +169,65 @@ namespace mbts.spark.orders
|
||||
}
|
||||
}
|
||||
|
||||
double compute_hedge_price(Security security, BuySell side, uint size, SyntheticLegExecutionParams param, double base_price)
|
||||
double compute_hedge_price(Security security, BuySell side, uint size, LegSpreaderParams param, double base_price)
|
||||
{
|
||||
if(param.HedgeParams.PaylessHedgeRules.EnablePayless || param.HedgeParams.PayupHedgeRules.EnablePayup)
|
||||
{
|
||||
PriceSize bbo;
|
||||
if(side == BuySell.Buy)
|
||||
bbo = _books[security].Item2.Where(x => Math.Abs(x.price - base_price) < 1e-5).DefaultIfEmpty(PriceSize.no_market).First();
|
||||
else
|
||||
bbo = _books[security].Item1.Where(x => Math.Abs(x.price - base_price) < 1e-5).DefaultIfEmpty(PriceSize.no_market).First();
|
||||
PriceSize bbo;
|
||||
if(side == BuySell.Buy)
|
||||
bbo = _books[security].Item2.Where(x => Math.Abs(x.price - base_price) < 1e-5).DefaultIfEmpty(PriceSize.no_market).First();
|
||||
else
|
||||
bbo = _books[security].Item1.Where(x => Math.Abs(x.price - base_price) < 1e-5).DefaultIfEmpty(PriceSize.no_market).First();
|
||||
|
||||
check_payup(bbo, security, side, size, param, ref base_price);
|
||||
check_payless(bbo, security, side, size, param, ref base_price);
|
||||
}
|
||||
check_payup(bbo, security, side, size, param, ref base_price);
|
||||
check_payless(bbo, security, side, size, param, ref base_price);
|
||||
return base_price;
|
||||
}
|
||||
|
||||
void check_payup(PriceSize bbo, Security security, BuySell side, uint size, SyntheticLegExecutionParams param, ref double price)
|
||||
void check_payup(PriceSize bbo, Security security, BuySell side, uint size, LegSpreaderParams param, ref double price)
|
||||
{
|
||||
var rules = param.HedgeParams.PayupHedgeRules;
|
||||
if(rules.EnablePayup)
|
||||
var rules = param?.PreHedgeParams?.QuantityBasedPayupTicks;
|
||||
var active = rules?.Priority?.IsActive;
|
||||
if(active.HasValue && active.Value)
|
||||
{
|
||||
double tick = compute_tick(security);
|
||||
double ratio = rules.RatioThreshold <= 0.0 ? 1.0 : rules.RatioThreshold;
|
||||
uint thresh = 0u;
|
||||
if(rules.QuantityThreshold.QuantityCase == QuantityMeasure.QuantityOneofCase.Absolute)
|
||||
thresh = rules.QuantityThreshold.Absolute;
|
||||
else
|
||||
thresh = Convert.ToUInt32(rules.QuantityThreshold.Ratio * size);
|
||||
if(side == BuySell.Buy)
|
||||
{
|
||||
if(bbo.size <= rules.SizeThreshold || bbo.size <= ratio * size)
|
||||
if(bbo.size <= thresh )
|
||||
price += tick * rules.PayupTicks;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bbo.size <= rules.SizeThreshold || bbo.size <= ratio * size)
|
||||
if(bbo.size <= thresh)
|
||||
price -= tick * rules.PayupTicks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void check_payless(PriceSize bbo, Security security, BuySell side, uint size, SyntheticLegExecutionParams param, ref double price)
|
||||
void check_payless(PriceSize bbo, Security security, BuySell side, uint size, LegSpreaderParams param, ref double price)
|
||||
{
|
||||
var rules = param.HedgeParams.PaylessHedgeRules;
|
||||
if(rules.EnablePayless)
|
||||
var rules = param?.PreHedgeParams?.QuantityBasedPaylessTicks;
|
||||
var active = rules?.Priority?.IsActive;
|
||||
if(active.HasValue && active.Value)
|
||||
{
|
||||
double tick = compute_tick(security);
|
||||
double ratio = rules.RatioThreshold <= 0.0 ? 1.0 : rules.RatioThreshold;
|
||||
uint thresh = 0u;
|
||||
if(rules.QuantityThreshold.QuantityCase == QuantityMeasure.QuantityOneofCase.Absolute)
|
||||
thresh = rules.QuantityThreshold.Absolute;
|
||||
else
|
||||
thresh = Convert.ToUInt32(rules.QuantityThreshold.Ratio * size);
|
||||
if(side == BuySell.Buy)
|
||||
{
|
||||
if(bbo.size >= rules.SizeThreshold || bbo.size >= ratio * size)
|
||||
price -= tick * rules.PaylessTicks;
|
||||
if(bbo.size <= thresh)
|
||||
price += tick * rules.PaylessTicks;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(bbo.size >= rules.SizeThreshold || bbo.size >= ratio * size)
|
||||
price += tick * rules.PaylessTicks;
|
||||
if(bbo.size <= thresh)
|
||||
price -= tick * rules.PaylessTicks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ namespace mbts.spark.orders
|
||||
throw new NotSupportedException("Limit order doesn't support SecurityType == None");
|
||||
else if(order.Security.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
{
|
||||
var algo = new SimpleSyntheticLimitOrder(fabric, order);
|
||||
//var algo = new SyntheticLimitOrder(fabric, order);
|
||||
var algo = new SyntheticLimitOrder(fabric, order);
|
||||
_impl = algo; _cancel = algo; _modify = algo; _pause = null; _crack = null; _poll = null;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -18,12 +18,12 @@ namespace mbts.spark.orders
|
||||
readonly protected ConcurrentDictionary<OrderID, OrderStatus> _child_status = new ConcurrentDictionary<OrderID, OrderStatus>();
|
||||
|
||||
readonly protected ConcurrentBag<Fill> _child_fills = new ConcurrentBag<Fill>();
|
||||
readonly protected ConcurrentDictionary<uint, SyntheticLegExecutionParams> _execution_strategy = new ConcurrentDictionary<uint, SyntheticLegExecutionParams>();
|
||||
readonly protected ConcurrentDictionary<uint, LegSpreaderParams> _execution_strategy = new ConcurrentDictionary<uint, LegSpreaderParams>();
|
||||
|
||||
protected OrderActorBase(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
if(order.ExecutionStrategy != null && order.ExecutionStrategy.SecurityIdToParams != null)
|
||||
order.ExecutionStrategy.SecurityIdToParams.ForEach(x => _execution_strategy.TryAdd(x.Key, x.Value));
|
||||
if(order.ExecutionStrategy != null && order.ExecutionStrategy.LegParamsMap != null)
|
||||
order.ExecutionStrategy.LegParamsMap.ForEach(x => _execution_strategy.TryAdd(x.Key, x.Value));
|
||||
}
|
||||
|
||||
protected IOrderHandle spawn_limit_order(Security sec, uint size, double price, BuySell side,
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.co2;
|
||||
|
||||
using BBOType = System.Tuple<mbts.co2.PriceSize, mbts.co2.PriceSize>;
|
||||
|
||||
namespace mbts.spark.orders
|
||||
{
|
||||
class SimpleHedgeOrderActor : SimpleOrderBase, ICancelable, IModifiable
|
||||
{
|
||||
readonly IMarketDataSource _md;
|
||||
readonly IExchangeGateway _exchange;
|
||||
readonly IDropCopy _dc;
|
||||
OrderStatus _status;
|
||||
readonly double _tick;
|
||||
public SimpleHedgeOrderActor(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
//TODO Multi exchange
|
||||
fabric.find_wellknown_service<IMarketDataSource>(order.Security.Exchange, out _md);
|
||||
fabric.find_wellknown_service<IExchangeGateway>(order.Security.Exchange, out _exchange);
|
||||
fabric.find_wellknown_service<IDropCopy>(order.Security.Exchange, out _dc);
|
||||
_tick = compute_tick(order.Security);
|
||||
}
|
||||
|
||||
override protected List<OrderStatus.Types.Status> child_status_list()
|
||||
{
|
||||
var stat = new List<OrderStatus.Types.Status>();
|
||||
if(_status != null)
|
||||
stat.Add(_status.Status);
|
||||
return stat;
|
||||
}
|
||||
|
||||
override protected void on_child_status(OrderStatus child_status, ref OrderStatus merged_status)
|
||||
{
|
||||
_status = child_status;
|
||||
if(_status.Order?.Id != null)
|
||||
merged_status.Children.Add(_status.Order.Id);
|
||||
}
|
||||
|
||||
public override void on_spawn()
|
||||
{
|
||||
_disposables.Add(_md.subscribe_bbo(_order.Security).Subscribe(x =>
|
||||
{
|
||||
if(x != null)
|
||||
watch_hedges(x);
|
||||
}));
|
||||
_disposables.Add(_dc.subscribe_fills(new Predicate<Fill>(x => _order.Id.Equals(x.Order.Id))).Subscribe(x =>
|
||||
{
|
||||
compute_fill_internal(x);
|
||||
}));
|
||||
_disposables.Add(_dc.subscribe_status(new Predicate<OrderStatus>(x => _order.Id.Equals(x.Order.Id))).Subscribe(x =>
|
||||
{
|
||||
compute_status_internal(x);
|
||||
}));
|
||||
|
||||
var clone = _order.Clone();
|
||||
clone.LimitOrder = new LimitOrder();
|
||||
_exchange.send_order(clone);
|
||||
}
|
||||
|
||||
void watch_hedges(BBOType bbo)
|
||||
{
|
||||
if(_status != null)
|
||||
{
|
||||
PriceSize inside_market;
|
||||
if(_status.Order.Side == BuySell.Buy)
|
||||
inside_market = bbo.Item2;
|
||||
else
|
||||
inside_market = bbo.Item1;
|
||||
|
||||
evaluate_post_hedge_rules(inside_market);
|
||||
}
|
||||
}
|
||||
|
||||
void evaluate_post_hedge_rules(PriceSize inside_market)
|
||||
{
|
||||
PostHedgePriceBasedForcedCross post = _order.SimpleHedgeOrder.Post;
|
||||
if(post == null || _status == null || post.TicksThreshold == 0 || post.MarketCrossTicks == 0)
|
||||
return;
|
||||
|
||||
if(_status.Order.Side == BuySell.Buy)
|
||||
{
|
||||
uint diff = Convert.ToUInt32((inside_market.price - _status.Order.Price) / _tick);
|
||||
if(diff >= post.TicksThreshold)
|
||||
_exchange.modify_price(_order.Id, _status.Order.Price + _tick * post.MarketCrossTicks);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint diff = Convert.ToUInt32((_status.Order.Price - inside_market.price) / _tick);
|
||||
if(diff >= post.TicksThreshold)
|
||||
_exchange.modify_price(_order.Id, _status.Order.Price - _tick * post.MarketCrossTicks);
|
||||
}
|
||||
}
|
||||
|
||||
bool ICancelable.on_cancel()
|
||||
{
|
||||
_exchange.cancel_order(_order.Id);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_price(double new_price)
|
||||
{
|
||||
_exchange.modify_price(_order.Id, new_price);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_size(uint new_size)
|
||||
{
|
||||
_exchange.modify_size(_order.Id, new_size);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,358 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.co2;
|
||||
|
||||
using BookType = System.Tuple<mbts.co2.PriceSize[], mbts.co2.PriceSize[]>;
|
||||
|
||||
namespace mbts.spark.orders
|
||||
{
|
||||
|
||||
class SpreaderLegOrderInfo
|
||||
{
|
||||
public IOrderHandle handle;
|
||||
public double last_hedge_price;
|
||||
}
|
||||
|
||||
struct SpreaderLeg
|
||||
{
|
||||
public readonly Security security;
|
||||
public readonly SimpleExecutionParams param;
|
||||
public readonly double ratio;
|
||||
public readonly double mult;
|
||||
public readonly double tick;
|
||||
|
||||
public BookType book;
|
||||
public OrderStatus status;
|
||||
public SpreaderLegOrderInfo order_info;
|
||||
public SpreaderLeg(Security sec, SimpleExecutionParams para, double ratio, double mult, double tick)
|
||||
{
|
||||
this.security = sec;
|
||||
this.param = para;
|
||||
this.ratio = ratio;
|
||||
this.mult = mult;
|
||||
this.tick = tick;
|
||||
|
||||
this.book = null;
|
||||
this.status = null;
|
||||
this.order_info = new SpreaderLegOrderInfo();
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleSyntheticLimitOrder : SimpleOrderBase, IActor, ICancelable, IModifiable
|
||||
{
|
||||
readonly IMarketDataSource _md;
|
||||
|
||||
SpreaderLeg _leg1, _leg2;
|
||||
readonly ConcurrentDictionary<OrderID, object> _hedges = new ConcurrentDictionary<OrderID, object>();
|
||||
readonly ConcurrentDictionary<OrderID, OrderStatus> _status = new ConcurrentDictionary<OrderID, OrderStatus>();
|
||||
public SimpleSyntheticLimitOrder(IActorFabric fabric, Order order) : base(fabric, order)
|
||||
{
|
||||
IDictionary<Security, double> leg_ratios;
|
||||
IDictionary<Security, double> price_mults;
|
||||
flatten_synthetic(order, out leg_ratios, out price_mults);
|
||||
foreach(var sec in leg_ratios.Keys)
|
||||
{
|
||||
if(sec.ContractCase == Security.ContractOneofCase.Synthetic)
|
||||
throw new NotSupportedException("Nested Synthetics not supported");
|
||||
fabric.find_wellknown_service<IMarketDataSource>(sec.Exchange, out _md);
|
||||
}
|
||||
if(leg_ratios.Keys.Count != 2)
|
||||
throw new NotSupportedException("Simple Synthetic Only Supports 2 Legs");
|
||||
|
||||
SimpleExecutionStrategy simple = order.SimpleExecutionStrategy;
|
||||
//map the current UI to this new simple mode
|
||||
if(simple == null && order.ExecutionStrategy != null)
|
||||
{
|
||||
var map = order.ExecutionStrategy.SecurityIdToParams;
|
||||
Security sec1 = leg_ratios.Keys.First();
|
||||
Security sec2 = leg_ratios.Keys.Last();
|
||||
|
||||
SyntheticLegExecutionParams old1 = map[sec1.Id], old2 = map[sec2.Id];
|
||||
SimpleExecutionParams s1 = convert_exec_params(sec1, old1), s2 = convert_exec_params(sec2, old2);
|
||||
_leg1 = new SpreaderLeg(sec1, s1, leg_ratios[sec1], price_mults[sec1], compute_tick(sec1));
|
||||
_leg2 = new SpreaderLeg(sec2, s2, leg_ratios[sec2], price_mults[sec2], compute_tick(sec2));
|
||||
}
|
||||
else
|
||||
{
|
||||
Security sec1 = order.SimpleExecutionStrategy.Leg1.Security;
|
||||
Security sec2 = order.SimpleExecutionStrategy.Leg2.Security;
|
||||
_leg1 = new SpreaderLeg(sec1, order.SimpleExecutionStrategy.Leg1, leg_ratios[sec1], price_mults[sec1], compute_tick(sec1));
|
||||
_leg2 = new SpreaderLeg(sec2, order.SimpleExecutionStrategy.Leg2, leg_ratios[sec2], price_mults[sec2], compute_tick(sec2));
|
||||
}
|
||||
}
|
||||
|
||||
SimpleExecutionParams convert_exec_params(Security sec, SyntheticLegExecutionParams old)
|
||||
{
|
||||
uint slop = 0;
|
||||
var ss = old.QuoteParams?.TickRangeRequoteRules?.TicksAwayToSensitivity?.FirstOrDefault();
|
||||
if(ss.HasValue)
|
||||
slop = ss.Value.Value;
|
||||
int payup = 0;
|
||||
var pu = old.HedgeParams?.PayupHedgeRules;
|
||||
if(pu != null && pu.EnablePayup)
|
||||
payup = Convert.ToInt32(pu.PayupTicks);
|
||||
var pl = old.HedgeParams?.PaylessHedgeRules;
|
||||
if(pl != null && pl.EnablePayless)
|
||||
payup = -Convert.ToInt32(pu.PayupTicks);
|
||||
var post = old.HedgeParams?.PostHedgeRules;
|
||||
|
||||
var s = new SimpleExecutionParams()
|
||||
{
|
||||
IsHedging = true,
|
||||
IsWorking = old.QuoteParams.IsWorking,
|
||||
Security = sec,
|
||||
Slop = new QuoteMuteZone { InsideTicks = slop, OutsideTicks = slop },
|
||||
PreHedgePayupTicks = payup,
|
||||
Post = new PostHedgePriceBasedForcedCross
|
||||
{
|
||||
MarketCrossTicks = post == null ? 0 : post.CrossSizeThreshold,
|
||||
TicksThreshold = post == null ? 0 : Convert.ToUInt32(post.CrossRatioThreshold),
|
||||
},
|
||||
};
|
||||
return s;
|
||||
}
|
||||
|
||||
override protected List<OrderStatus.Types.Status> child_status_list()
|
||||
{
|
||||
return _status.Values.Select(x => x.Status).ToList();
|
||||
}
|
||||
override protected void on_child_status(OrderStatus child_status, ref OrderStatus merged_status)
|
||||
{
|
||||
if(child_status.Order.Security.Equals(_leg1.security))
|
||||
_leg1.status = child_status;
|
||||
if(child_status.Order.Security.Equals(_leg2.security))
|
||||
_leg2.status = child_status;
|
||||
|
||||
if(_leg1.order_info.handle != null)
|
||||
merged_status.Children.Add(_leg1.order_info.handle.order_id);
|
||||
if(_leg2.order_info.handle != null)
|
||||
merged_status.Children.Add(_leg2.order_info.handle.order_id);
|
||||
_status[child_status.Order.Id] = child_status;
|
||||
}
|
||||
|
||||
|
||||
override public void on_spawn()
|
||||
{
|
||||
_disposables.Add(_md.subscribe_depth(_leg1.security).Subscribe(x =>
|
||||
{
|
||||
BookType transformed = Tuple.Create(x.Item1.Select(xx => new PriceSize(xx.price * _leg1.mult, xx.size)).ToArray(),
|
||||
x.Item2.Select(xx => new PriceSize(xx.price * _leg1.mult, xx.size)).ToArray());
|
||||
_leg1.book = transformed;
|
||||
requote(_leg2, _leg1);
|
||||
}));
|
||||
|
||||
_disposables.Add(_md.subscribe_depth(_leg2.security).Subscribe(x =>
|
||||
{
|
||||
BookType transformed = Tuple.Create(x.Item1.Select(xx => new PriceSize(xx.price * _leg2.mult, xx.size)).ToArray(),
|
||||
x.Item2.Select(xx => new PriceSize(xx.price * _leg2.mult, xx.size)).ToArray());
|
||||
_leg2.book = transformed;
|
||||
requote(_leg1, _leg2);
|
||||
}));
|
||||
}
|
||||
|
||||
public override void on_destroy()
|
||||
{
|
||||
base.on_destroy();
|
||||
}
|
||||
|
||||
#region Quoting
|
||||
|
||||
//always pessimistic
|
||||
bool walk_book(PriceSize[] book, uint size, out double leg_price)
|
||||
{
|
||||
bool ok = false; leg_price = double.NaN;
|
||||
uint agg = 0;
|
||||
foreach(var level in book)
|
||||
{
|
||||
agg += level.size;
|
||||
if(agg >= size)
|
||||
{
|
||||
leg_price = level.price;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(leg_price == 0.0)
|
||||
leg_price = double.NaN;
|
||||
return ok;
|
||||
}
|
||||
|
||||
void new_quote_order(Security security, uint quote_size, double quote_price, BuySell quote_side, double hedge_price,
|
||||
SpreaderLegOrderInfo order_info)
|
||||
{
|
||||
order_info.handle = create_order<LimitOrder>(security, quote_size, quote_price, quote_side, _order.TimeInForce, new LimitOrder());
|
||||
order_info.last_hedge_price = hedge_price; //cache this for later
|
||||
track_child(order_info.handle);
|
||||
order_info.handle.spawn();
|
||||
}
|
||||
|
||||
void replace_quote_order(SpreaderLeg quote_leg, double hedge_price, ref double quote_price)
|
||||
{
|
||||
if(evaluate_prequote_rules(quote_leg, ref quote_price))
|
||||
{
|
||||
if(double.IsNaN(quote_price))
|
||||
quote_leg.order_info.handle.cancel();
|
||||
else
|
||||
{
|
||||
quote_leg.order_info.handle.modify_price(quote_price);
|
||||
quote_leg.order_info.last_hedge_price = hedge_price; //cache this for later
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void requote_all()
|
||||
{
|
||||
requote(_leg1, _leg2);
|
||||
requote(_leg2, _leg1);
|
||||
}
|
||||
|
||||
//reprice the quote leg in terms of the hedge leg
|
||||
void requote(SpreaderLeg quote_leg, SpreaderLeg hedge_leg)
|
||||
{
|
||||
if(quote_leg.status != null && is_final_state(quote_leg.status.Status))
|
||||
return;
|
||||
if(!quote_leg.param.IsWorking)
|
||||
return;
|
||||
|
||||
double quote_price = _order.Price * -1.0;
|
||||
|
||||
int hedge_size_signed = Convert.ToInt32(_order.Size * hedge_leg.ratio);
|
||||
int hedge_side = (hedge_size_signed < 0 ? -1 : 1);
|
||||
uint hedge_size = Convert.ToUInt32(Math.Abs(hedge_size_signed));
|
||||
|
||||
double hedge_price_at_size = double.NaN;
|
||||
if(hedge_side < 0)
|
||||
walk_book(hedge_leg.book.Item1, hedge_size, out hedge_price_at_size);
|
||||
else
|
||||
walk_book(hedge_leg.book.Item2, hedge_size, out hedge_price_at_size);
|
||||
|
||||
quote_price += hedge_side * hedge_price_at_size * (_order.Side == BuySell.Sell ? -1 : 1);
|
||||
quote_price = Math.Round(Math.Abs(quote_price) / quote_leg.tick, MidpointRounding.AwayFromZero) * quote_leg.tick;
|
||||
|
||||
if(quote_leg.order_info.handle == null && !double.IsNaN(quote_price)) //new order
|
||||
{
|
||||
int quote_size_signed = Convert.ToInt32(_order.Size * quote_leg.ratio);
|
||||
BuySell quote_side = (quote_size_signed < 0 ? BuySell.Sell : BuySell.Buy);
|
||||
uint quote_size = Convert.ToUInt32(Math.Abs(quote_size_signed));
|
||||
new_quote_order(quote_leg.security, quote_size, quote_price, quote_side, hedge_price_at_size, quote_leg.order_info);
|
||||
}
|
||||
else
|
||||
replace_quote_order(quote_leg, hedge_price_at_size, ref quote_price);
|
||||
}
|
||||
|
||||
//one day this could modify size, do a fancy rule chain, etc
|
||||
bool evaluate_prequote_rules(SpreaderLeg quote_leg, ref double quote_price)
|
||||
{
|
||||
SimpleExecutionParams param = quote_leg.param;
|
||||
if(param.Slop != null)
|
||||
{
|
||||
double? orig_price = quote_leg.status?.Order.Price;
|
||||
if(orig_price.HasValue)
|
||||
{
|
||||
int diff = Convert.ToInt32((quote_price - orig_price) / quote_leg.tick);
|
||||
if(diff != 0)
|
||||
{
|
||||
if(quote_leg.status.Order.Side == BuySell.Buy)
|
||||
{
|
||||
if(diff >= param.Slop.InsideTicks || diff <= -param.Slop.OutsideTicks)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(diff <= -param.Slop.InsideTicks || diff >= param.Slop.OutsideTicks)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hedging
|
||||
|
||||
protected override void on_child_fill(Fill child_fill, ref Fill merged_fill)
|
||||
{
|
||||
if(!_hedges.ContainsKey(child_fill.Order.Id))
|
||||
hedge_fill(child_fill);
|
||||
}
|
||||
|
||||
void reduce_working_order(OrderStatus quote_leg_status, SpreaderLegOrderInfo order_info, uint hedge_size)
|
||||
{
|
||||
if(order_info.handle != null && quote_leg_status != null && !is_final_state(quote_leg_status.Status))
|
||||
{
|
||||
if(hedge_size < quote_leg_status.Order.Size)
|
||||
order_info.handle.modify_size(quote_leg_status.Order.Size - hedge_size);
|
||||
else
|
||||
order_info.handle.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void hedge_fill(Fill fill)
|
||||
{
|
||||
SpreaderLeg quote_leg, hedge_leg;
|
||||
if(fill.Order.Security.Equals(_leg1.security))
|
||||
{
|
||||
quote_leg = _leg1;
|
||||
hedge_leg = _leg2;
|
||||
}
|
||||
else
|
||||
{
|
||||
quote_leg = _leg2;
|
||||
hedge_leg = _leg1;
|
||||
}
|
||||
if(!hedge_leg.param.IsHedging)
|
||||
return;
|
||||
|
||||
double hedge_size_signed = hedge_leg.ratio * fill.Size * (fill.Side == BuySell.Buy ? 1.0 : -1.0);
|
||||
var hedge_side = (hedge_size_signed > 0.0) ? BuySell.Buy : BuySell.Sell;
|
||||
uint hedge_size = Convert.ToUInt32(Math.Abs(hedge_size_signed));
|
||||
reduce_working_order(hedge_leg.status, hedge_leg.order_info, hedge_size);
|
||||
double hedge_price = quote_leg.order_info.last_hedge_price + hedge_leg.param.PreHedgePayupTicks * hedge_leg.tick;
|
||||
|
||||
var rules = new SimpleHedgeOrder { Post = hedge_leg.param.Post };
|
||||
var hedge = create_order<SimpleHedgeOrder>(hedge_leg.security, hedge_size, hedge_price,
|
||||
hedge_side, Order.Types.TimeInForce.Day, rules);
|
||||
_hedges[hedge.order_id] = null;
|
||||
track_child(hedge);
|
||||
hedge.spawn();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
bool ICancelable.on_cancel()
|
||||
{
|
||||
if(_leg1.order_info.handle != null)
|
||||
_leg1.order_info.handle.cancel();
|
||||
if(_leg2.order_info.handle != null)
|
||||
_leg2.order_info.handle.cancel();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_price(double new_price)
|
||||
{
|
||||
_order.Price = new_price;
|
||||
requote_all();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IModifiable.on_modify_size(uint new_size)
|
||||
{
|
||||
_order.Size = new_size;
|
||||
_leg1.order_info.handle?.cancel();
|
||||
_leg1.order_info = null;
|
||||
_leg2.order_info.handle?.cancel();
|
||||
_leg2.order_info = null;
|
||||
requote_all();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,6 @@ namespace mbts.spark {
|
||||
case Order.AlgoOrderTypeOneofCase.StopLimitOrder: return order.StopLimitOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.IcebergOrder: return order.IcebergOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.CrossingHedgeOrder: return order.CrossingHedgeOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.SimpleHedgeOrder: return order.SimpleHedgeOrder;
|
||||
case Order.AlgoOrderTypeOneofCase.CustomOrder: return order.CustomOrder;
|
||||
default:
|
||||
throw new MissingFieldException($"No field for: {order.AlgoOrderTypeCase}");
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace mbts.spark
|
||||
}
|
||||
|
||||
private IObservable<Security> _get_current_security_observable() { return _current_cell.Select(_get_security).DistinctUntilChanged(); }
|
||||
private static Security _get_security(DataGridCellInfo cell) { return ((Row)cell.Item).security.value; }
|
||||
private static Security _get_security(DataGridCellInfo cell) { return (cell.Item as Row)?.security.value; }
|
||||
private static Order _create_order(DataGridCellInfo cell) { return _create_order((Row)cell.Item, (Columns)DataGridEx.GetArgument(cell.Column)); }
|
||||
private static Order _create_order(Row row, Columns col) {
|
||||
var order = new Order { Security = row.security.value, MarketOrder = new MarketOrder(), Price = 0, Size = 1 };
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<ResourceDictionary Source="/view/Controls/Algo/QuantityTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/PriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/TimeWindowControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/BTSStopOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/BTSIcebergOrderControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Popup/PopupControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
@@ -141,6 +142,47 @@
|
||||
<c:PopupControl Grid.Row="2" Grid.Column="1" Margin="4,2,0,2" Content="{Binding algo_type.order_details}" PopupPlacement="Right">
|
||||
<c:PopupControl.ContentTemplateSelector>
|
||||
<usp:OrderModificationTemplateSelector>
|
||||
<usp:OrderModificationTemplateSelector.StopLimitOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock FontWeight="SemiBold">Stop Price</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Column="1" Margin="12,0,0,0" Width="80" Value="{Binding StopPrice}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.StopLimitOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.StopMarketOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock FontWeight="SemiBold">Stop Price</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Column="1" Margin="12,0,0,0" Width="80" Value="{Binding StopPrice}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.StopMarketOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.IcebergOrderTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock FontWeight="SemiBold">Show Quantity</TextBlock>
|
||||
<c:TickUpDownUInt Grid.Column="1" Margin="12,0,0,0" Width="80" Value="{Binding ShowQuantity}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.IcebergOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.BTSStopOrderTemplate>
|
||||
<DataTemplate>
|
||||
<uag:BTSStopOrderControl Order="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</usp:OrderModificationTemplateSelector.BTSStopOrderTemplate>
|
||||
<usp:OrderModificationTemplateSelector.BTSIcebergOrderTemplate>
|
||||
<DataTemplate>
|
||||
<uag:BTSIcebergOrderControl Order="{Binding}"/>
|
||||
|
||||
@@ -16,10 +16,18 @@ namespace mbts.ui.spark
|
||||
|
||||
internal class OrderModificationTemplateSelector : DataTemplateSelector
|
||||
{
|
||||
public DataTemplate StopLimitOrderTemplate { get; set; }
|
||||
public DataTemplate StopMarketOrderTemplate { get; set; }
|
||||
public DataTemplate IcebergOrderTemplate { get; set; }
|
||||
public DataTemplate BTSStopOrderTemplate { get; set; }
|
||||
public DataTemplate BTSIcebergOrderTemplate { get; set; }
|
||||
public DataTemplate ReflectionTemplate { get; set; }
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
|
||||
if (item is BTSIcebergOrder) return BTSIcebergOrderTemplate;
|
||||
if (item is StopLimitOrder) return StopLimitOrderTemplate;
|
||||
else if (item is StopMarketOrder) return StopMarketOrderTemplate;
|
||||
else if (item is IcebergOrder) return IcebergOrderTemplate;
|
||||
else if (item is BTSStopOrder) return BTSStopOrderTemplate;
|
||||
else if (item is BTSIcebergOrder) return BTSIcebergOrderTemplate;
|
||||
else return ReflectionTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,8 +125,6 @@ namespace mbts.spark
|
||||
case Order.AlgoOrderTypeOneofCase.IcebergOrder:
|
||||
return new OrderMetadata() { KeyBinding = "I", Color = BTSColors.module_colors[4].rgb_color() };
|
||||
case Order.AlgoOrderTypeOneofCase.CrossingHedgeOrder:
|
||||
case Order.AlgoOrderTypeOneofCase.SimpleHedgeOrder:
|
||||
case Order.AlgoOrderTypeOneofCase.CustomOrder:
|
||||
default:
|
||||
case Order.AlgoOrderTypeOneofCase.None:
|
||||
return default_order_metadata;
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace mbts.spark
|
||||
BTSMessageBox.Show(warn_msg, "Synthetic Strategy", MessageBoxButton.OK, MessageBoxImage.Exclamation, true, false, true);
|
||||
}
|
||||
private void show_synthetic_editor(Security synthetic, ExecutionStrategy strategy) {
|
||||
new SyntheticEditorDialog { DataContext = new SyntheticEditorVM2(_bus, synthetic, strategy) }.Show(-200, -300);
|
||||
var dialog = new SyntheticEditorDialog { DataContext = new SyntheticEditorVM(_bus, synthetic, strategy) }.Show(-200, -300, true);
|
||||
}
|
||||
private string find_unique_synthetic_name() {
|
||||
int i = 1;
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
<UserControl x:Class="mbts.ui.spark.ExecutionStrategyEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls">
|
||||
<UserControl.Resources>
|
||||
<sys:Double x:Key="spacing_x">8.0</sys:Double>
|
||||
<sys:Double x:Key="spacing_y">4.0</sys:Double>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="2*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="Working" IsEnabled="{Binding is_working}" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" Padding="8">
|
||||
<Grid DataContext="{Binding quote_params}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.ColumnSpan="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Hedge Ratio</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Column="2" Value="{Binding lean_quantity_ratio}" HorizontalAlignment="Stretch" Increment="0.05" />
|
||||
</Grid>
|
||||
<CheckBox Grid.Row="2" Grid.ColumnSpan="3" IsChecked="{Binding pessimistic_hedge_pricing}" Content="Pessimistic Hedge Pricing" />
|
||||
<GroupBox Grid.Row="4" Grid.ColumnSpan="3" Header="Tick Range Requote" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" Padding="4" MinWidth="200">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ItemsControl ItemsSource="{Binding tick_range_requote_items}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Margin="0,3,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Style="{StaticResource RoundCloseButton}" Command="{Binding DataContext.remove_tick_range_requote_item, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
|
||||
<TextBlock Grid.Column="1">within</TextBlock>
|
||||
<TextBox Grid.Column="2" Margin="2,0" MinWidth="20" Text="{Binding range, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Column="3">ticks, requote every</TextBlock>
|
||||
<TextBox Grid.Column="4" Margin="2,0" MinWidth="20" Text="{Binding sensitivity, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Column="5">ticks</TextBlock>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Button Grid.Row="1" HorizontalAlignment="Left" Margin="14,6,0,0" Width="60" Command="{Binding add_tick_range_requote_item}">+</Button>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="2" Header="Hedge" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding hedge_params}" Padding="8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<GroupBox Header="Payup" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding payup_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_payup}" />
|
||||
<TextBlock Grid.Row="2">Ticks</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding payup_ticks, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Size</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="6">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="6" Grid.Column="2" Text="{Binding ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="2" Header="Payless" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding payless_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_payless}" />
|
||||
<TextBlock Grid.Row="2">Ticks</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding payless_ticks, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Size</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="6">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="6" Grid.Column="2" Text="{Binding ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Column="4" Header="Post" HeaderTemplate="{StaticResource SemiBoldHeaderTemplate}" DataContext="{Binding post_hedge_rules}" Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.ColumnSpan="3" Content="Enable" IsChecked="{Binding enable_post_hedge}" />
|
||||
<TextBlock Grid.Row="2">Size</TextBlock>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding cross_size_threshold, Converter={StaticResource UIntTextConverter}}" />
|
||||
<TextBlock Grid.Row="4">Ratio</TextBlock>
|
||||
<TextBox Grid.Row="4" Grid.Column="2" Text="{Binding cross_ratio_threshold, Converter={StaticResource DoubleTextConverter}}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ExecutionStrategyEditor.xaml
|
||||
/// </summary>
|
||||
public partial class ExecutionStrategyEditor : UserControl
|
||||
{
|
||||
public ExecutionStrategyEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -1,212 +1,210 @@
|
||||
<Window x:Class="mbts.ui.spark.SyntheticEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:api="clr-namespace:bts.api"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
Title="{Binding title}"
|
||||
Width="648"
|
||||
Height="617"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
u:BoundCommands.New="{Binding legs.AddItemCommand}"
|
||||
Style="{StaticResource BTSDialog}">
|
||||
<Window.Resources>
|
||||
<sys:Double x:Key="spacing_x">8.0</sys:Double>
|
||||
<sys:Double x:Key="spacing_y">4.0</sys:Double>
|
||||
<SolidColorBrush x:Key="GridBorderBrush" Color="#688CAF" />
|
||||
<ControlTemplate x:Key="ChooseSecurityPromptTemplate" TargetType="ComboBox">
|
||||
<TextBlock FontStyle="Italic">None</TextBlock>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="SideComboBox" TargetType="ComboBox">
|
||||
<Setter Property="ItemsSource" Value="{u:EnumBindingSource api:BuySell}" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
<Style x:Key="StrategyToggleSwitch" TargetType="ToggleButton">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="19" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Ellipse x:Name="circle" Fill="White" HorizontalAlignment="Center" Height="19" Stroke="#FF333333" VerticalAlignment="Center" Width="19"/>
|
||||
<Path x:Name="arrow" Data="M1,1.5L4.5,5 8,1.5" HorizontalAlignment="Center" SnapsToDevicePixels="False" Stroke="#FF333333" StrokeThickness="2" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="text" Grid.Column="1" Margin="4,0,0,0" Text="Execution Strategy" FontStyle="Italic" FontWeight="SemiBold" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Data" TargetName="arrow" Value="M1,4.5L4.5,1 8,4.5"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF5593FF"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFF3F9FF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FF3C77DD"/>
|
||||
<Setter Property="StrokeThickness" TargetName="circle" Value="1.5"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFD9ECFF"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Stroke" TargetName="circle" Value="#FFBCBCBC"/>
|
||||
<Setter Property="Fill" TargetName="circle" Value="#FFE6E6E6"/>
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="#FF707070"/>
|
||||
<Setter Property="Foreground" TargetName="text" Value="Gray"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding security}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Key="n" Modifiers="Ctrl" Command="New" />
|
||||
</Window.InputBindings>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="{Binding Source={StaticResource spacing_y}}" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource spacing_x}}" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock>Name</TextBlock>
|
||||
<TextBox Grid.Column="2" IsEnabled="{Binding is_new, Mode=OneTime}" Text="{Binding name}" />
|
||||
<TextBlock Grid.Row="2">Tick</TextBlock>
|
||||
<c:TickUpDownDouble Grid.Row="2" Grid.Column="2" IsEnabled="{Binding is_new, Mode=OneTime}" Value="{Binding tick_size}" Increment="0.05" />
|
||||
</Grid>
|
||||
<Border Grid.Row="1" BorderBrush="{StaticResource GridBorderBrush}" Padding="10">
|
||||
<ScrollViewer VerticalAlignment="Stretch">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<DataGrid Grid.ColumnSpan="2" IsReadOnly="{Binding is_new, Converter={StaticResource NotConverter}, Mode=OneTime}" u:DataGridBehavior.SingleClickEdit="{Binding is_new, Mode=OneTime}"
|
||||
HeadersVisibility="All" CanUserDeleteRows="{Binding is_new, Mode=OneTime}" SelectionUnit="FullRow" ItemsSource="{Binding legs}">
|
||||
<DataGrid.RowHeaderStyle>
|
||||
<Style TargetType="DataGridRowHeader">
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="DataGridRowHeader">
|
||||
<Button Command="{Binding DataContext.legs.RemoveItemCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding}" Style="{StaticResource RoundCloseButton}" VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.RowHeaderStyle>
|
||||
<DataGrid.RowStyle>
|
||||
<Style TargetType="DataGridRow">
|
||||
<Setter Property="DetailsVisibility" Value="Visible"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="DataGridRow">
|
||||
<Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
|
||||
<SelectiveScrollingGrid>
|
||||
<SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<SelectiveScrollingGrid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</SelectiveScrollingGrid.RowDefinitions>
|
||||
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
<Grid Grid.Row="1" Grid.Column="1" Visibility="{Binding show_strategy, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle Fill="Black" Opacity="0.5" Height="1" HorizontalAlignment="Stretch">
|
||||
<Rectangle.Effect>
|
||||
<DropShadowEffect />
|
||||
</Rectangle.Effect>
|
||||
</Rectangle>
|
||||
<DataGridDetailsPresenter Grid.Row="1" Margin="0,3">
|
||||
<SelectiveScrollingGrid.SelectiveScrollingOrientation>
|
||||
<Binding Path="AreRowDetailsFrozen" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
|
||||
<Binding.ConverterParameter>
|
||||
<SelectiveScrollingOrientation>Vertical</SelectiveScrollingOrientation>
|
||||
</Binding.ConverterParameter>
|
||||
</Binding>
|
||||
</SelectiveScrollingGrid.SelectiveScrollingOrientation>
|
||||
</DataGridDetailsPresenter>
|
||||
<Rectangle Visibility="Collapsed" Grid.Row="2" Fill="Black" Opacity="0.5" Height="1" HorizontalAlignment="Stretch">
|
||||
<Rectangle.Effect>
|
||||
<DropShadowEffect Direction="-315" />
|
||||
</Rectangle.Effect>
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
<DataGridRowHeader Grid.RowSpan="2" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
|
||||
<DataGridRowHeader.Visibility>
|
||||
<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
|
||||
<Binding.ConverterParameter>
|
||||
<DataGridHeadersVisibility>Row</DataGridHeadersVisibility>
|
||||
</Binding.ConverterParameter>
|
||||
</Binding>
|
||||
</DataGridRowHeader.Visibility>
|
||||
</DataGridRowHeader>
|
||||
</SelectiveScrollingGrid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.RowDetailsTemplate>
|
||||
<DataTemplate>
|
||||
<usp:ExecutionStrategyEditor />
|
||||
</DataTemplate>
|
||||
</DataGrid.RowDetailsTemplate>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Security" Width="120" IsReadOnly="True" Binding="{Binding security}"/>
|
||||
<DataGridComboBoxColumn Header="Side" Width="60" ElementStyle="{StaticResource SideComboBox}" EditingElementStyle="{StaticResource SideComboBox}" SelectedItemBinding="{Binding side}" />
|
||||
<c:DataGridEditableUIntColumn Header="Qty" Width="60" ValueBinding="{Binding quantity}" />
|
||||
<c:DataGridEditableDoubleColumn Header="Multiplier" Width="60" ValueBinding="{Binding multiplier}"/>
|
||||
<DataGridTemplateColumn Header="Working" Width="60" IsReadOnly="True">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox IsChecked="{Binding is_working, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn IsReadOnly="True" Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ToggleButton IsChecked="{Binding show_strategy, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource StrategyToggleSwitch}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Button Grid.Row="1" VerticalAlignment="Top" Width="60" Command="{Binding legs.AddItemCommand}" ToolTip="Add Leg (Ctrl+n)">+</Button>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<c:DialogSkirtOKCancel Grid.Row="2" IsOkDefault="False" OKCommand="{Binding commit}" />
|
||||
</Grid>
|
||||
</Window>
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/DataGrid.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<usp:RowHeaderGroupIndentConverter x:Key="RowHeaderGroupIndentConverter" Indent="18"/>
|
||||
<usp:RowHeaderGroupIndentConverter x:Key="ReverseRowHeaderGroupIndentConverter" Indent="-18"/>
|
||||
<usp:DataGridParameterCellTemplateConverter x:Key="ParameterCellTemplateConverter">
|
||||
<usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox HorizontalAlignment="Left" IsChecked="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter>
|
||||
<usp:DataGridParameterCellTemplateConverter x:Key="ParameterCellEditingTemplateConverter">
|
||||
<usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox HorizontalAlignment="Left" IsChecked="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownDouble Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownInt Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownUInt Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter>
|
||||
<Style x:Key="ExpanderToggleButton" TargetType="ToggleButton">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Grid IsHitTestVisible="True" Background="Transparent">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="12" />
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Path x:Name="arrow" Data="M0,0L3.5,3.5 0,7" HorizontalAlignment="Center" SnapsToDevicePixels="False" Stroke="#77333333" StrokeThickness="2" VerticalAlignment="Center"/>
|
||||
<ContentPresenter Grid.Column="1" Margin="4,0,0,0" ContentSource="{TemplateBinding Content}"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Data" TargetName="arrow" Value="M0,0L3.5,3.5 7,0"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="#FF707070"/>
|
||||
<Setter Property="Foreground" Value="Gray"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="GroupItemTemplate" TargetType="GroupItem">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<ToggleButton x:Name="ExpanderToggle" IsChecked="True" Style="{StaticResource ExpanderToggleButton}">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
|
||||
</ToggleButton>
|
||||
<ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Margin="18,0,0,0"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Name}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" TargetName="ExpanderToggle" Value="Collapsed"/>
|
||||
<Setter Property="Margin" TargetName="ItemsHost" Value="0"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsChecked, ElementName=ExpanderToggle}" Value="False">
|
||||
<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="GroupItemStyle" TargetType="GroupItem">
|
||||
<Setter Property="Template" Value="{StaticResource GroupItemTemplate}"/>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="DataGridRowTemplate" TargetType="DataGridRow">
|
||||
<Border x:Name="DGR_Border"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Background="{TemplateBinding Background}"
|
||||
SnapsToDevicePixels="True">
|
||||
<SelectiveScrollingGrid Margin="{Binding section_count, Converter={StaticResource ReverseRowHeaderGroupIndentConverter}}">
|
||||
<SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<DataGridRowHeader SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
|
||||
Background="Transparent"
|
||||
Padding="{Binding section_count, Converter={StaticResource RowHeaderGroupIndentConverter}}"
|
||||
Content="{Binding display_name}"
|
||||
Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}">
|
||||
</DataGridRowHeader>
|
||||
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</SelectiveScrollingGrid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="usp:SyntheticEditor.RowHasErrors" Value="True">
|
||||
<Setter Property="BorderBrush" Value="Red"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
|
||||
<Setter Property="BorderThickness" Value="1,0"/>
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="Template" Value="{StaticResource DataGridRowTemplate}"/>
|
||||
<Setter Property="usp:SyntheticEditor.RowHasErrors" Value="{Binding has_errors}"/>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="SyntheticEditorTemplate" TargetType="usp:SyntheticEditor">
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
Width="{TemplateBinding Width}"
|
||||
Height="{TemplateBinding Height}"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="3*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center">Name</TextBlock>
|
||||
<TextBox Grid.Column="1" Margin="6,0,0,0" HorizontalAlignment="Stretch" Text="{Binding SyntheticName, RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
<TextBlock Grid.Column="2" VerticalAlignment="Center" Margin="6,0,0,0">Pricing</TextBlock>
|
||||
<ComboBox Grid.Column="3" Margin="6,0,0,0" ItemsSource="{x:Static usp:SyntheticEditor.PriceCalcItems}" SelectedItem="{Binding PriceCalc, RelativeSource={RelativeSource TemplatedParent}}" ItemTemplate="{StaticResource EnumDescriptionTemplate}"/>
|
||||
<c:HelpButton Grid.Column="4" Margin="3,0,0,0"/>
|
||||
</Grid>
|
||||
<c:DataGridEx x:Name="PART_DataGrid"
|
||||
Grid.Row="1"
|
||||
Margin="0,4,0,0"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="0"
|
||||
GridLinesVisibility="None"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
HeadersVisibility="All"
|
||||
RowHeaderWidth="250"
|
||||
RowStyle="{StaticResource DataGridRowStyle}"
|
||||
ItemsSource="{Binding ParameterRowsView, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<DataGrid.Resources>
|
||||
<Style x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}" TargetType="Button">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Rectangle Fill="{u:BTSColor header}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource GroupItemStyle}"/>
|
||||
</DataGrid.GroupStyle>
|
||||
</c:DataGridEx>
|
||||
</Grid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
<Style TargetType="usp:SyntheticEditor">
|
||||
<Setter Property="ParameterCellTemplateConverter" Value="{StaticResource ParameterCellTemplateConverter}"/>
|
||||
<Setter Property="ParameterCellEditingTemplateConverter" Value="{StaticResource ParameterCellEditingTemplateConverter}"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Template" Value="{StaticResource SyntheticEditorTemplate}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -1,14 +1,176 @@
|
||||
using System.Windows;
|
||||
using bts.api;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SyntheticEditor.xaml
|
||||
/// </summary>
|
||||
public partial class SyntheticEditor : Window
|
||||
///
|
||||
internal partial class SyntheticEditor : Control
|
||||
{
|
||||
public SyntheticEditor() {
|
||||
InitializeComponent();
|
||||
static SyntheticEditor() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(SyntheticEditor), new FrameworkPropertyMetadata(typeof(SyntheticEditor)));
|
||||
}
|
||||
|
||||
public interface IParameterViewMetadata {
|
||||
string[] section_path { get; }
|
||||
bool read_only { get; }
|
||||
}
|
||||
|
||||
#region SyntheticName
|
||||
public static readonly DependencyProperty SyntheticNameProperty = DependencyProperty.Register("SyntheticName", typeof(string), typeof(SyntheticEditor),
|
||||
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
public string SyntheticName { get => GetValue(SyntheticNameProperty) as string; set => SetValue(SyntheticNameProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region PriceCalc
|
||||
public static readonly DependencyProperty PriceCalcProperty = DependencyProperty.Register("PriceCalc", typeof(SyntheticContract.Types.PriceCalc), typeof(SyntheticEditor),
|
||||
new FrameworkPropertyMetadata(SyntheticContract.Types.PriceCalc.Diff, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
public SyntheticContract.Types.PriceCalc PriceCalc { get => (SyntheticContract.Types.PriceCalc)GetValue(PriceCalcProperty); set => SetValue(PriceCalcProperty, value); }
|
||||
|
||||
public static readonly IEnumerable<SyntheticContract.Types.PriceCalc> PriceCalcItems = EnumHelper.get_values<SyntheticContract.Types.PriceCalc>();
|
||||
#endregion
|
||||
|
||||
#region LegTuples
|
||||
public static readonly DependencyProperty LegTuplesProperty = DependencyProperty.Register("LegTuples", typeof(IReadOnlyCollection<LegSpreaderParamsTuple>), typeof(SyntheticEditor),
|
||||
new FrameworkPropertyMetadata(new LegSpreaderParamsTuple[0], FrameworkPropertyMetadataOptions.AffectsMeasure, SyncColumns, CoerceLegTuples));
|
||||
private static object CoerceLegTuples(DependencyObject d, object baseValue) {
|
||||
return baseValue is IReadOnlyCollection<LegSpreaderParamsTuple> ? baseValue : new List<LegSpreaderParamsTuple>();
|
||||
}
|
||||
public IReadOnlyCollection<LegSpreaderParamsTuple> LegTuples { get => GetValue(LegTuplesProperty) as IReadOnlyCollection<LegSpreaderParamsTuple>; set => SetValue(LegTuplesProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterRows
|
||||
public static readonly DependencyProperty ParameterRowsProperty = DependencyProperty.Register("ParameterRows", typeof(IEnumerable<IParameterViewMetadata>), typeof(SyntheticEditor),
|
||||
new PropertyMetadata(Enumerable.Empty<IParameterViewMetadata>(), OnParameterRowsChanged));
|
||||
private static void OnParameterRowsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
var rows = e.NewValue as IEnumerable<IParameterViewMetadata>;
|
||||
if (rows != null) {
|
||||
var prv = CollectionViewSource.GetDefaultView(rows);
|
||||
int n_groups = rows.Max(r => r.section_path.Length);
|
||||
for (int i = 0; i < n_groups; i++) prv.GroupDescriptions.Add(new PropertyGroupDescription($"[{i}]"));
|
||||
d.SetValue(ParameterRowsViewPropertyKey, prv);
|
||||
} else d.SetValue(ParameterRowsViewPropertyKey, null);
|
||||
}
|
||||
public IEnumerable<IParameterViewMetadata> ParameterRows { get => GetValue(ParameterRowsProperty) as IEnumerable<IParameterViewMetadata>; set => SetValue(ParameterRowsProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterRowsView (ReadOnly)
|
||||
private static readonly DependencyPropertyKey ParameterRowsViewPropertyKey = DependencyProperty.RegisterReadOnly("ParameterRowsView", typeof(ICollectionView), typeof(SyntheticEditor),
|
||||
new PropertyMetadata());
|
||||
public static readonly DependencyProperty ParameterRowsViewProperty = ParameterRowsViewPropertyKey.DependencyProperty;
|
||||
public ICollectionView ParameterRowsView { get => GetValue(ParameterRowsViewProperty) as ICollectionView; private set => SetValue(ParameterRowsViewPropertyKey, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterCellTemplateConverter
|
||||
public static readonly DependencyProperty ParameterCellTemplateConverterProperty = DependencyProperty.Register("ParameterCellTemplateConverter", typeof(IValueConverter), typeof(SyntheticEditor),
|
||||
new PropertyMetadata(SyncColumns));
|
||||
public IValueConverter ParameterCellTemplateConverter { get => GetValue(ParameterCellTemplateConverterProperty) as IValueConverter; set => SetValue(ParameterCellTemplateConverterProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterCellEditingTemplateConverter
|
||||
public static readonly DependencyProperty ParameterCellEditingTemplateConverterProperty = DependencyProperty.Register("ParameterCellEditingTemplateConverter", typeof(IValueConverter), typeof(SyntheticEditor),
|
||||
new PropertyMetadata(SyncColumns));
|
||||
public IValueConverter ParameterCellEditingTemplateConverter { get => GetValue(ParameterCellEditingTemplateConverterProperty) as IValueConverter; set => SetValue(ParameterCellEditingTemplateConverterProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region RowHasError
|
||||
public static readonly DependencyProperty RowHasErrorsProperty = DependencyProperty.RegisterAttached("RowHasErrors", typeof(bool), typeof(SyntheticEditor), new PropertyMetadata(false));
|
||||
public static bool GetRowHasErrors(DependencyObject d) { return (bool)d.GetValue(RowHasErrorsProperty); }
|
||||
public static void SetRowHasErrors(DependencyObject d, bool value) { d.SetValue(RowHasErrorsProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region CellDataType
|
||||
public static readonly DependencyProperty CellDataTypeProperty = DependencyProperty.RegisterAttached("CellDataType", typeof(Type), typeof(SyntheticEditor), new PropertyMetadata(null));
|
||||
public static Type GetCellDataType(DependencyObject d) { return d.GetValue(CellDataTypeProperty) as Type; }
|
||||
public static void SetCellDataType(DependencyObject d, Type value) { d.SetValue(CellDataTypeProperty, value); }
|
||||
#endregion
|
||||
|
||||
private static void SyncColumns(DependencyObject d, DependencyPropertyChangedEventArgs e) { ((SyntheticEditor)d)._sync_columns(); }
|
||||
public override void OnApplyTemplate() { _sync_columns(); }
|
||||
|
||||
private SyntheticEditorGridLineAdorner _dg_line_adorner;
|
||||
|
||||
private void _sync_columns() {
|
||||
_dg_line_adorner?.Dispose();
|
||||
var dg = (DataGridEx)GetTemplateChild("PART_DataGrid");
|
||||
if (dg != null) {
|
||||
dg.Columns.SetItems(LegTuples.Select(l => {
|
||||
var col = new DataGridColumnInternal(l.leg.Security, ParameterCellTemplateConverter, ParameterCellEditingTemplateConverter) { Width = 60 };
|
||||
DataGridEx.SetRightBorder(col, new DataGridExVerticalLine(false, true, System.Windows.Media.Colors.DarkGray, 1));
|
||||
return col;
|
||||
}));
|
||||
_dg_line_adorner = new SyntheticEditorGridLineAdorner(dg);
|
||||
}
|
||||
}
|
||||
|
||||
private class DataGridColumnInternal : DataGridDynamicColumn {
|
||||
public DataGridColumnInternal(Security security, IValueConverter cell_template_converter, IValueConverter cell_editing_template_converter) {
|
||||
Header = security.ToString(null);
|
||||
SetValue(DataGridEx.CellKeyProperty, security);
|
||||
_cell_template_converter = cell_template_converter;
|
||||
_cell_editing_template_converter = cell_editing_template_converter;
|
||||
}
|
||||
|
||||
private readonly IValueConverter _cell_template_converter, _cell_editing_template_converter;
|
||||
|
||||
// I decided this was an easy and simple enough solution to justify breaking the mvvm paradigm
|
||||
// The alternative - within strict bounds of the paradigm - is to change the DataGridParameterCellTemplateConverter into an IMultiValueConverter, bound to data_type AND read_only
|
||||
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) {
|
||||
var rm = dataItem as IParameterViewMetadata;
|
||||
return rm != null && rm.read_only ? base.GenerateElement(cell, dataItem) : base.GenerateEditingElement(cell, dataItem);
|
||||
}
|
||||
protected override FrameworkElement generate_element_internal() { return _generate_element(_cell_template_converter); }
|
||||
protected override FrameworkElement generate_editing_element_internal() { return _generate_element(_cell_editing_template_converter); }
|
||||
|
||||
private FrameworkElement _generate_element(IValueConverter cell_template_converter) {
|
||||
var rv = new ContentControl();
|
||||
rv.SetBinding(ContentControl.ContentProperty, new Binding());
|
||||
rv.SetBinding(ContentControl.ContentTemplateProperty, new Binding("data_type") { Converter = cell_template_converter });
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(int), typeof(Thickness))]
|
||||
internal class RowHeaderGroupIndentConverter : IValueConverter {
|
||||
public double Indent { get; set; }
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return new Thickness(((int)value + 1) * Indent, 0, 0, 0);
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(Type), typeof(DataTemplate))]
|
||||
internal class DataGridParameterCellTemplateConverter : IValueConverter {
|
||||
public DataTemplate DoubleTemplate { get; set; }
|
||||
public DataTemplate BooleanTemplate { get; set; }
|
||||
public DataTemplate IntTemplate { get; set; }
|
||||
public DataTemplate UIntTemplate { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
Type t = (Type)value;
|
||||
if (t == typeof(double)) return DoubleTemplate;
|
||||
else if (t == typeof(bool)) return BooleanTemplate;
|
||||
else if (t == typeof(int)) return IntTemplate;
|
||||
else if (t == typeof(uint)) return UIntTemplate;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -4,13 +4,12 @@
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
u:WindowStyle.AllowResize="True"
|
||||
u:WindowStyle.SizeToContent="WidthAndHeight"
|
||||
Style="{StaticResource BTSDialogTitleTemplate}">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/mspark/Shell/Securities/Synthetic2/SyntheticEditor2.xaml"/>
|
||||
<ResourceDictionary Source="/mspark/Shell/Securities/Synthetic/SyntheticEditor.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
@@ -19,7 +18,7 @@
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<usp:SyntheticEditor2 Margin="6" SyntheticName="{Binding name}" PriceCalc="{Binding price_calc}" ParameterRows="{Binding rows}" LegTuples="{Binding leg_tuples}" HorizontalAlignment="Stretch"/>
|
||||
<usp:SyntheticEditor Margin="6" SyntheticName="{Binding name}" PriceCalc="{Binding price_calc}" ParameterRows="{Binding rows}" LegTuples="{Binding leg_tuples}" HorizontalAlignment="Stretch"/>
|
||||
<c:DialogSkirtOKCancel Grid.Row="1" OKCommand="{Binding commit}"/>
|
||||
</Grid>
|
||||
<u:WindowStyle.TitleContentTemplate>
|
||||
File renamed without changes.
@@ -0,0 +1,33 @@
|
||||
using mbts.ui.controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
internal partial class SyntheticEditor : Control {
|
||||
internal class SyntheticEditorGridLineAdorner : DataGridExVerticalLineAdorner
|
||||
{
|
||||
public SyntheticEditorGridLineAdorner(DataGridEx grid) : base(grid) { }
|
||||
|
||||
private ItemsPresenter _items_presenter;
|
||||
|
||||
protected override IEnumerable<IDisposable> get_other_hooks() {
|
||||
_items_presenter = _grid.visual_children_where(el => el is ItemsPresenter).Cast<ItemsPresenter>().FirstOrDefault();
|
||||
if (_items_presenter != null) {
|
||||
_items_presenter.SizeChanged += _items_presenter_SizeChanged;
|
||||
yield return Disposable.Create(() => _items_presenter.SizeChanged -= _items_presenter_SizeChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void _items_presenter_SizeChanged(object sender, SizeChangedEventArgs e) { InvalidateVisual(); }
|
||||
|
||||
protected override void draw_vertical_line(DrawingContext dc, double x, DataGridExVerticalLine line) {
|
||||
if (_items_presenter != null) dc.DrawLine(line.pen.Value, new Point(x - 10, 58), new Point(x - 10, _items_presenter.ActualHeight + 58));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.collections.extensions;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal class SyntheticEditorVM : ViewModelBase
|
||||
{
|
||||
public SyntheticEditorVM(IBus bus, Security security, ExecutionStrategy strategy, bool is_new) {
|
||||
var model = new SyntheticEditorModel(bus);
|
||||
if (this.is_new = is_new) {
|
||||
commit = new DelegateCommand(() => model.save(get_security(), get_strategy()));
|
||||
title = "Create Synthetic";
|
||||
} else {
|
||||
if (strategy == null) throw new ArgumentNullException("strategy");
|
||||
commit = new DelegateCommand(() => model.save(get_security(), get_strategy()));
|
||||
title = "{0} Strategy".fmt(security.Synthetic.Name);
|
||||
}
|
||||
name = security.Synthetic.Name;
|
||||
legs = new ObservableCollection<LegVM>(security.Synthetic.Legs.Select(l => new LegVM(l, strategy?.SecurityIdToParams?.GetValueOrDefault(l.Security.Id))));
|
||||
_tick_size = backing(nameof(tick_size), security.ContractSpec.LowTick);
|
||||
}
|
||||
|
||||
private Security get_security() {
|
||||
var contract = new SyntheticContract { Name = name };
|
||||
foreach (var l in legs) contract.Legs.Add(l.get_contract_leg());
|
||||
return new Security { Synthetic = contract, ContractSpec = new ContractSpecification { HighTick = tick_size, LowTick = tick_size, PriceBreak = double.MinValue } };
|
||||
}
|
||||
private ExecutionStrategy get_strategy() {
|
||||
var rv = new ExecutionStrategy();
|
||||
foreach (var l in legs.Where(l => l.security != null)) rv.SecurityIdToParams[l.security.Id] = l.get_params_obj();
|
||||
return rv;
|
||||
}
|
||||
|
||||
private readonly Property<double> _tick_size;
|
||||
|
||||
public bool is_new { get; }
|
||||
public string title { get; }
|
||||
public string name { get; set; }
|
||||
public double tick_size { get => _tick_size.Value; set => _tick_size.Value = value; }
|
||||
public ObservableCollection<LegVM> legs { get; }
|
||||
public ICommand commit { get; private set; }
|
||||
|
||||
public class LegVM : ViewModelBase {
|
||||
public LegVM(ContractLeg l, SyntheticLegExecutionParams selp) {
|
||||
security = l.Security;
|
||||
side = l.Side;
|
||||
if (selp == null) selp = new SyntheticLegExecutionParams { HedgeParams = _default_hedge_params(), QuoteParams = _default_quote_params() };
|
||||
else _sanitize_execution_params(ref selp);
|
||||
_is_working = backing(nameof(is_working), selp.QuoteParams.IsWorking);
|
||||
_show_strategy = backing(nameof(show_strategy), true);
|
||||
quote_params = new QuoteParamsVM(selp.QuoteParams);
|
||||
hedge_params = new HedgeParamsVM(selp.HedgeParams);
|
||||
}
|
||||
private readonly Property<bool> _is_working, _show_strategy;
|
||||
|
||||
#region Defaults/Sanitization
|
||||
private static QuoteParams _default_quote_params() {
|
||||
var rv = new QuoteParams { LeanQuantityRatio = 1.0, IsWorking = true, PessimisticHedgePricing = true };
|
||||
_sanitize_quote_params(rv);
|
||||
return rv;
|
||||
}
|
||||
private static HedgeParams _default_hedge_params() {
|
||||
var rv = new HedgeParams();
|
||||
_sanitize_hedge_params(rv);
|
||||
return rv;
|
||||
}
|
||||
private static void _sanitize_execution_params(ref SyntheticLegExecutionParams selp) {
|
||||
_sanitize_quote_params(selp.QuoteParams);
|
||||
_sanitize_hedge_params(selp.HedgeParams);
|
||||
}
|
||||
private static void _sanitize_quote_params(QuoteParams quote_parms) {
|
||||
if (quote_parms == null) quote_parms = new QuoteParams { LeanQuantityRatio = 1.0, IsWorking = true, PessimisticHedgePricing = true };
|
||||
if (quote_parms.TickRangeRequoteRules == null) quote_parms.TickRangeRequoteRules = new TickRangeRequoteRules();
|
||||
}
|
||||
private static void _sanitize_hedge_params(HedgeParams hedge_params) {
|
||||
if (hedge_params == null) hedge_params = new HedgeParams();
|
||||
if (hedge_params.PayupHedgeRules == null) hedge_params.PayupHedgeRules = new PayupHedgeRules { RatioThreshold = 1.0, SizeThreshold = 0 };
|
||||
if (hedge_params.PaylessHedgeRules == null) hedge_params.PaylessHedgeRules = new PaylessHedgeRules { RatioThreshold = 1.0, SizeThreshold = 0 };
|
||||
if (hedge_params.PostHedgeRules == null) hedge_params.PostHedgeRules = new PostHedgeRules { CrossRatioThreshold = 1.0, CrossSizeThreshold = 0 };
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Security security { get; }
|
||||
public BuySell side { get; set; }
|
||||
public uint quantity { get; set; } = 1u;
|
||||
public double multiplier { get; set; } = 1.0;
|
||||
public bool is_working { get => _is_working.Value; set => _is_working.Value = value; }
|
||||
public bool show_strategy { get => _show_strategy.Value; set => _show_strategy.Value = value; }
|
||||
public QuoteParamsVM quote_params { get; private set; }
|
||||
public HedgeParamsVM hedge_params { get; private set; }
|
||||
|
||||
public ContractLeg get_contract_leg() { return new ContractLeg { Quantity = quantity, Security = security, Side = side, PriceMultiplier = multiplier }; }
|
||||
public SyntheticLegExecutionParams get_params_obj() { return new SyntheticLegExecutionParams { QuoteParams = quote_params.get_params_obj(is_working), HedgeParams = hedge_params.get_params_obj() }; }
|
||||
|
||||
public class QuoteParamsVM {
|
||||
public QuoteParamsVM(QuoteParams from) {
|
||||
lean_quantity_ratio = from.LeanQuantityRatio;
|
||||
pessimistic_hedge_pricing = from.PessimisticHedgePricing;
|
||||
foreach (var rr in from.TickRangeRequoteRules.TicksAwayToSensitivity) tick_range_requote_items.Add(new TickRangeRequoteVM(rr.Key, rr.Value));
|
||||
remove_tick_range_requote_item = new DelegateCommand<TickRangeRequoteVM>(item => tick_range_requote_items.Remove(item));
|
||||
add_tick_range_requote_item = new DelegateCommand(() => tick_range_requote_items.Add(new TickRangeRequoteVM(tick_range_requote_items.Count == 0 ? 0 : tick_range_requote_items.Select(trr => trr.range).Max(), 1)));
|
||||
}
|
||||
public double lean_quantity_ratio { get; set; }
|
||||
public bool pessimistic_hedge_pricing { get; set; }
|
||||
public ObservableCollection<TickRangeRequoteVM> tick_range_requote_items { get; } = new ObservableCollection<TickRangeRequoteVM>();
|
||||
public ICommand remove_tick_range_requote_item { get; private set; }
|
||||
public ICommand add_tick_range_requote_item { get; private set; }
|
||||
|
||||
public QuoteParams get_params_obj(bool is_working) {
|
||||
var rv = new QuoteParams { PessimisticHedgePricing = pessimistic_hedge_pricing, LeanQuantityRatio = lean_quantity_ratio, IsWorking = is_working, TickRangeRequoteRules = new TickRangeRequoteRules() };
|
||||
foreach (var rr in tick_range_requote_items) rv.TickRangeRequoteRules.TicksAwayToSensitivity[rr.range] = rr.sensitivity;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public class TickRangeRequoteVM {
|
||||
public TickRangeRequoteVM() : this(0, 0) { }
|
||||
public TickRangeRequoteVM(uint range, uint sensitivity) { this.range = range; this.sensitivity = sensitivity; }
|
||||
public uint range { get; set; }
|
||||
public uint sensitivity { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class HedgeParamsVM {
|
||||
public HedgeParamsVM(HedgeParams from) {
|
||||
payup_hedge_rules = new PayupHedgeRulesVM(from.PayupHedgeRules);
|
||||
payless_hedge_rules = new PaylessHedgeRulesVM(from.PaylessHedgeRules);
|
||||
post_hedge_rules = new PostHedgeRulesVM(from.PostHedgeRules);
|
||||
}
|
||||
|
||||
public PayupHedgeRulesVM payup_hedge_rules { get; private set; }
|
||||
public PaylessHedgeRulesVM payless_hedge_rules { get; private set; }
|
||||
public PostHedgeRulesVM post_hedge_rules { get; private set; }
|
||||
|
||||
public HedgeParams get_params_obj() { return new HedgeParams { PayupHedgeRules = payup_hedge_rules.get_params_obj(), PaylessHedgeRules = payless_hedge_rules.get_params_obj() , PostHedgeRules = post_hedge_rules.get_params_obj() }; }
|
||||
|
||||
public class PayupHedgeRulesVM {
|
||||
public PayupHedgeRulesVM(PayupHedgeRules from) {
|
||||
enable_payup = from.EnablePayup;
|
||||
payup_ticks = from.PayupTicks;
|
||||
size_threshold = from.SizeThreshold;
|
||||
ratio_threshold = from.RatioThreshold;
|
||||
}
|
||||
public bool enable_payup { get; set; }
|
||||
public uint payup_ticks { get; set; }
|
||||
public uint size_threshold { get; set; }
|
||||
public double ratio_threshold { get; set; }
|
||||
public PayupHedgeRules get_params_obj() { return new PayupHedgeRules { EnablePayup = enable_payup, PayupTicks = payup_ticks, SizeThreshold = size_threshold, RatioThreshold = ratio_threshold }; }
|
||||
}
|
||||
|
||||
public class PaylessHedgeRulesVM {
|
||||
public PaylessHedgeRulesVM(PaylessHedgeRules from) {
|
||||
enable_payless = from.EnablePayless;
|
||||
payless_ticks = from.PaylessTicks;
|
||||
size_threshold = from.SizeThreshold;
|
||||
ratio_threshold = from.RatioThreshold;
|
||||
}
|
||||
public bool enable_payless { get; set; }
|
||||
public uint payless_ticks { get; set; }
|
||||
public uint size_threshold { get; set; }
|
||||
public double ratio_threshold { get; set; }
|
||||
public PaylessHedgeRules get_params_obj() { return new PaylessHedgeRules { EnablePayless = enable_payless, PaylessTicks = payless_ticks, SizeThreshold = size_threshold, RatioThreshold = ratio_threshold }; }
|
||||
}
|
||||
|
||||
public class PostHedgeRulesVM {
|
||||
public PostHedgeRulesVM(PostHedgeRules from) {
|
||||
enable_post_hedge = from.EnablePostHedge;
|
||||
cross_size_threshold = from.CrossSizeThreshold;
|
||||
cross_ratio_threshold = from.CrossRatioThreshold;
|
||||
}
|
||||
public bool enable_post_hedge { get; set; }
|
||||
public uint cross_size_threshold { get; set; }
|
||||
public double cross_ratio_threshold { get; set; }
|
||||
public PostHedgeRules get_params_obj() { return new PostHedgeRules { EnablePostHedge = enable_post_hedge, CrossSizeThreshold = cross_size_threshold, CrossRatioThreshold = cross_ratio_threshold }; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -4,8 +4,7 @@ using System;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal partial class SyntheticEditorVM2
|
||||
{
|
||||
internal partial class SyntheticEditorVM {
|
||||
internal class Cell<T> : ViewModelBase, ICell {
|
||||
public Cell(RowModelBase<T> model, LegSpreaderParamsTuple leg_tup) {
|
||||
_model = model;
|
||||
+3
-4
@@ -9,9 +9,8 @@ using System.Reactive.Linq;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal partial class SyntheticEditorVM2
|
||||
{
|
||||
internal interface IRowModel : SyntheticEditor2.IParameterViewMetadata {
|
||||
internal partial class SyntheticEditorVM {
|
||||
internal interface IRowModel : SyntheticEditor.IParameterViewMetadata {
|
||||
string display_name { get; }
|
||||
bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups);
|
||||
ICell create_cell(LegSpreaderParamsTuple leg_tup);
|
||||
@@ -38,7 +37,7 @@ namespace mbts.spark
|
||||
Payless = "Pay Less",
|
||||
Payup = "Pay up",
|
||||
OrderType = "Order Type",
|
||||
MarketForcedCross = "Price-Based Mkt Forced Cross",
|
||||
MarketForcedCross = "Price-Based Forced Cross",
|
||||
TimeForcedCross = "Time-Based Forced Cross";
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@ using System.Linq;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
internal partial class SyntheticEditorVM2
|
||||
internal partial class SyntheticEditorVM
|
||||
{
|
||||
internal class RowVM : DataGridExRow<Security>, SyntheticEditor2.IParameterViewMetadata, IDisposable {
|
||||
internal class RowVM : DataGridExRow<Security>, SyntheticEditor.IParameterViewMetadata, IDisposable {
|
||||
public RowVM(IRowModel model, IReadOnlyCollection<LegSpreaderParamsTuple> legs) {
|
||||
display_name = model.display_name;
|
||||
section_path = model.section_path;
|
||||
+7
-2
@@ -2,6 +2,7 @@
|
||||
using bts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
@@ -11,14 +12,14 @@ namespace mbts.spark
|
||||
/// <summary>
|
||||
/// The view model designed to serve as the DataContext for the SyntheticEditor2 control
|
||||
/// </summary>
|
||||
internal partial class SyntheticEditorVM2 {
|
||||
internal partial class SyntheticEditorVM : IDisposable {
|
||||
/// <summary>
|
||||
/// Initializes a new instance of SyntheticEditorVM2 class. The commit command will create a new Synthetic if synthetic's Id is 0, otherwise it will modify the existing synthetic's strategy.
|
||||
/// </summary>
|
||||
/// <param name="bus">The application bus</param>
|
||||
/// <param name="synthetic">The new synthetic security to create, or existing synthetic security who's strategy to modify, on commit</param>
|
||||
/// <param name="strategy">The new strategy to create, or existing strategy to modify, on commit</param>
|
||||
public SyntheticEditorVM2(IBus bus, Security synthetic, ExecutionStrategy strategy) {
|
||||
public SyntheticEditorVM(IBus bus, Security synthetic, ExecutionStrategy strategy) {
|
||||
_synthetic = synthetic;
|
||||
leg_tuples = _synthetic.Synthetic.Legs.Select(l => new LegSpreaderParamsTuple(l, strategy.LegParamsMap[l.Security.Id])).ToList();
|
||||
var payless = new PaylessRowGroup();
|
||||
@@ -57,5 +58,9 @@ namespace mbts.spark
|
||||
public IReadOnlyCollection<LegSpreaderParamsTuple> leg_tuples { get; }
|
||||
public IReadOnlyCollection<RowVM> rows { get; }
|
||||
public ICommand commit { get; }
|
||||
|
||||
public void Dispose() {
|
||||
foreach (var r in rows) r.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Resources/DataGrid.xaml"/>
|
||||
<ResourceDictionary Source="/view/Resources/DataTemplates.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<usp:RowHeaderGroupIndentConverter x:Key="RowHeaderGroupIndentConverter" Indent="18"/>
|
||||
<usp:RowHeaderGroupIndentConverter x:Key="ReverseRowHeaderGroupIndentConverter" Indent="-18"/>
|
||||
<usp:DataGridParameterCellTemplateConverter x:Key="ParameterCellTemplateConverter">
|
||||
<usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox HorizontalAlignment="Left" IsChecked="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter>
|
||||
<usp:DataGridParameterCellTemplateConverter x:Key="ParameterCellEditingTemplateConverter">
|
||||
<usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox HorizontalAlignment="Left" IsChecked="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownDouble Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.DoubleTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownInt Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.IntTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownUInt Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.UIntTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter>
|
||||
<Style x:Key="ExpanderToggleButton" TargetType="ToggleButton">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Grid IsHitTestVisible="True" Background="Transparent">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="12" />
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Path x:Name="arrow" Data="M0,0L3.5,3.5 0,7" HorizontalAlignment="Center" SnapsToDevicePixels="False" Stroke="#77333333" StrokeThickness="2" VerticalAlignment="Center"/>
|
||||
<ContentPresenter Grid.Column="1" Margin="4,0,0,0" ContentSource="{TemplateBinding Content}"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="Data" TargetName="arrow" Value="M0,0L3.5,3.5 7,0"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="Black"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Stroke" TargetName="arrow" Value="#FF707070"/>
|
||||
<Setter Property="Foreground" Value="Gray"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="GroupItemTemplate" TargetType="GroupItem">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<ToggleButton x:Name="ExpanderToggle" IsChecked="True" Style="{StaticResource ExpanderToggleButton}">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="Bold"/>
|
||||
</ToggleButton>
|
||||
<ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Margin="18,0,0,0"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Name}" Value="{x:Null}">
|
||||
<Setter Property="Visibility" TargetName="ExpanderToggle" Value="Collapsed"/>
|
||||
<Setter Property="Margin" TargetName="ItemsHost" Value="0"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsChecked, ElementName=ExpanderToggle}" Value="False">
|
||||
<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="GroupItemStyle" TargetType="GroupItem">
|
||||
<Setter Property="Template" Value="{StaticResource GroupItemTemplate}"/>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="DataGridRowTemplate" TargetType="DataGridRow">
|
||||
<Border x:Name="DGR_Border"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Background="{TemplateBinding Background}"
|
||||
SnapsToDevicePixels="True">
|
||||
<SelectiveScrollingGrid Margin="{Binding section_count, Converter={StaticResource ReverseRowHeaderGroupIndentConverter}}">
|
||||
<SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</SelectiveScrollingGrid.ColumnDefinitions>
|
||||
<DataGridRowHeader SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
|
||||
Background="Transparent"
|
||||
Padding="{Binding section_count, Converter={StaticResource RowHeaderGroupIndentConverter}}"
|
||||
Content="{Binding display_name}"
|
||||
Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}">
|
||||
</DataGridRowHeader>
|
||||
<DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
|
||||
</SelectiveScrollingGrid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="usp:SyntheticEditor2.RowHasErrors" Value="True">
|
||||
<Setter Property="BorderBrush" Value="Red"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
|
||||
<Setter Property="BorderThickness" Value="1,0"/>
|
||||
<Setter Property="BorderBrush" Value="Transparent"/>
|
||||
<Setter Property="Template" Value="{StaticResource DataGridRowTemplate}"/>
|
||||
<Setter Property="usp:SyntheticEditor2.RowHasErrors" Value="{Binding has_errors}"/>
|
||||
</Style>
|
||||
<ControlTemplate x:Key="SyntheticEditor2Template" TargetType="usp:SyntheticEditor2">
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
Width="{TemplateBinding Width}"
|
||||
Height="{TemplateBinding Height}"
|
||||
Padding="{TemplateBinding Padding}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="3*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center">Name</TextBlock>
|
||||
<TextBox Grid.Column="1" Margin="6,0,0,0" HorizontalAlignment="Stretch" Text="{Binding SyntheticName, RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
<TextBlock Grid.Column="2" VerticalAlignment="Center" Margin="6,0,0,0">Pricing</TextBlock>
|
||||
<ComboBox Grid.Column="3" Margin="6,0,0,0" ItemsSource="{x:Static usp:SyntheticEditor2.PriceCalcItems}" SelectedItem="{Binding PriceCalc, RelativeSource={RelativeSource TemplatedParent}}" ItemTemplate="{StaticResource EnumDescriptionTemplate}"/>
|
||||
<c:HelpButton Grid.Column="4" Margin="3,0,0,0"/>
|
||||
</Grid>
|
||||
<DataGrid x:Name="PART_DataGrid"
|
||||
Grid.Row="1"
|
||||
Margin="0,4,0,0"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="0"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
HeadersVisibility="All"
|
||||
RowHeaderWidth="200"
|
||||
RowStyle="{StaticResource DataGridRowStyle}"
|
||||
ItemsSource="{Binding ParameterRowsView, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<DataGrid.Resources>
|
||||
<Style x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}" TargetType="Button">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Rectangle Fill="{u:BTSColor header}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.GroupStyle>
|
||||
<GroupStyle ContainerStyle="{StaticResource GroupItemStyle}"/>
|
||||
</DataGrid.GroupStyle>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
<Style TargetType="usp:SyntheticEditor2">
|
||||
<Setter Property="ParameterCellTemplateConverter" Value="{StaticResource ParameterCellTemplateConverter}"/>
|
||||
<Setter Property="ParameterCellEditingTemplateConverter" Value="{StaticResource ParameterCellEditingTemplateConverter}"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Template" Value="{StaticResource SyntheticEditor2Template}"/>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -1,165 +0,0 @@
|
||||
using bts.api;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SyntheticEditor2.xaml
|
||||
/// </summary>
|
||||
///
|
||||
internal partial class SyntheticEditor2 : Control
|
||||
{
|
||||
static SyntheticEditor2() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(SyntheticEditor2), new FrameworkPropertyMetadata(typeof(SyntheticEditor2)));
|
||||
}
|
||||
|
||||
public interface IParameterViewMetadata {
|
||||
string[] section_path { get; }
|
||||
bool read_only { get; }
|
||||
}
|
||||
|
||||
#region SyntheticName
|
||||
public static readonly DependencyProperty SyntheticNameProperty = DependencyProperty.Register("SyntheticName", typeof(string), typeof(SyntheticEditor2),
|
||||
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
public string SyntheticName { get => GetValue(SyntheticNameProperty) as string; set => SetValue(SyntheticNameProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region PriceCalc
|
||||
public static readonly DependencyProperty PriceCalcProperty = DependencyProperty.Register("PriceCalc", typeof(SyntheticContract.Types.PriceCalc), typeof(SyntheticEditor2),
|
||||
new FrameworkPropertyMetadata(SyntheticContract.Types.PriceCalc.Diff, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
public SyntheticContract.Types.PriceCalc PriceCalc { get => (SyntheticContract.Types.PriceCalc)GetValue(PriceCalcProperty); set => SetValue(PriceCalcProperty, value); }
|
||||
|
||||
public static readonly IEnumerable<SyntheticContract.Types.PriceCalc> PriceCalcItems = EnumHelper.get_values<SyntheticContract.Types.PriceCalc>();
|
||||
#endregion
|
||||
|
||||
#region LegTuples
|
||||
public static readonly DependencyProperty LegTuplesProperty = DependencyProperty.Register("LegTuples", typeof(IReadOnlyCollection<LegSpreaderParamsTuple>), typeof(SyntheticEditor2),
|
||||
new FrameworkPropertyMetadata(new LegSpreaderParamsTuple[0], FrameworkPropertyMetadataOptions.AffectsMeasure, SyncColumns, CoerceLegTuples));
|
||||
private static object CoerceLegTuples(DependencyObject d, object baseValue) {
|
||||
return baseValue is IReadOnlyCollection<LegSpreaderParamsTuple> ? baseValue : new List<LegSpreaderParamsTuple>();
|
||||
}
|
||||
public IReadOnlyCollection<LegSpreaderParamsTuple> LegTuples { get => GetValue(LegTuplesProperty) as IReadOnlyCollection<LegSpreaderParamsTuple>; set => SetValue(LegTuplesProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterRows
|
||||
public static readonly DependencyProperty ParameterRowsProperty = DependencyProperty.Register("ParameterRows", typeof(IEnumerable<IParameterViewMetadata>), typeof(SyntheticEditor2),
|
||||
new PropertyMetadata(Enumerable.Empty<IParameterViewMetadata>(), OnParameterRowsChanged));
|
||||
private static void OnParameterRowsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
var rows = e.NewValue as IEnumerable<IParameterViewMetadata>;
|
||||
if (rows != null) {
|
||||
var prv = CollectionViewSource.GetDefaultView(rows);
|
||||
int n_groups = rows.Max(r => r.section_path.Length);
|
||||
for (int i = 0; i < n_groups; i++) prv.GroupDescriptions.Add(new PropertyGroupDescription($"[{i}]"));
|
||||
d.SetValue(ParameterRowsViewPropertyKey, prv);
|
||||
} else d.SetValue(ParameterRowsViewPropertyKey, null);
|
||||
}
|
||||
public IEnumerable<IParameterViewMetadata> ParameterRows { get => GetValue(ParameterRowsProperty) as IEnumerable<IParameterViewMetadata>; set => SetValue(ParameterRowsProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterRowsView (ReadOnly)
|
||||
private static readonly DependencyPropertyKey ParameterRowsViewPropertyKey = DependencyProperty.RegisterReadOnly("ParameterRowsView", typeof(ICollectionView), typeof(SyntheticEditor2),
|
||||
new PropertyMetadata());
|
||||
public static readonly DependencyProperty ParameterRowsViewProperty = ParameterRowsViewPropertyKey.DependencyProperty;
|
||||
public ICollectionView ParameterRowsView { get => GetValue(ParameterRowsViewProperty) as ICollectionView; private set => SetValue(ParameterRowsViewPropertyKey, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterCellTemplateConverter
|
||||
public static readonly DependencyProperty ParameterCellTemplateConverterProperty = DependencyProperty.Register("ParameterCellTemplateConverter", typeof(IValueConverter), typeof(SyntheticEditor2),
|
||||
new PropertyMetadata(SyncColumns));
|
||||
public IValueConverter ParameterCellTemplateConverter { get => GetValue(ParameterCellTemplateConverterProperty) as IValueConverter; set => SetValue(ParameterCellTemplateConverterProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region ParameterCellEditingTemplateConverter
|
||||
public static readonly DependencyProperty ParameterCellEditingTemplateConverterProperty = DependencyProperty.Register("ParameterCellEditingTemplateConverter", typeof(IValueConverter), typeof(SyntheticEditor2),
|
||||
new PropertyMetadata(SyncColumns));
|
||||
public IValueConverter ParameterCellEditingTemplateConverter { get => GetValue(ParameterCellEditingTemplateConverterProperty) as IValueConverter; set => SetValue(ParameterCellEditingTemplateConverterProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region RowHasError
|
||||
public static readonly DependencyProperty RowHasErrorsProperty = DependencyProperty.RegisterAttached("RowHasErrors", typeof(bool), typeof(SyntheticEditor2), new PropertyMetadata(false));
|
||||
public static bool GetRowHasErrors(DependencyObject d) { return (bool)d.GetValue(RowHasErrorsProperty); }
|
||||
public static void SetRowHasErrors(DependencyObject d, bool value) { d.SetValue(RowHasErrorsProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region CellDataType
|
||||
public static readonly DependencyProperty CellDataTypeProperty = DependencyProperty.RegisterAttached("CellDataType", typeof(Type), typeof(SyntheticEditor2), new PropertyMetadata(null));
|
||||
public static Type GetCellDataType(DependencyObject d) { return d.GetValue(CellDataTypeProperty) as Type; }
|
||||
public static void SetCellDataType(DependencyObject d, Type value) { d.SetValue(CellDataTypeProperty, value); }
|
||||
#endregion
|
||||
|
||||
private static void SyncColumns(DependencyObject d, DependencyPropertyChangedEventArgs e) { ((SyntheticEditor2)d)._sync_columns(); }
|
||||
public override void OnApplyTemplate() { _sync_columns(); }
|
||||
|
||||
private void _sync_columns() {
|
||||
((DataGrid)GetTemplateChild("PART_DataGrid"))?.Columns.SetItems(LegTuples.Select(l => new DataGridColumnInternal(l.leg.Security, ParameterCellTemplateConverter, ParameterCellEditingTemplateConverter) { Width = 60 }));
|
||||
}
|
||||
|
||||
private class DataGridColumnInternal : DataGridDynamicColumn {
|
||||
public DataGridColumnInternal(Security security, IValueConverter cell_template_converter, IValueConverter cell_editing_template_converter) {
|
||||
Header = security.ToString(null);
|
||||
SetValue(DataGridEx.CellKeyProperty, security);
|
||||
_cell_template_converter = cell_template_converter;
|
||||
_cell_editing_template_converter = cell_editing_template_converter;
|
||||
}
|
||||
|
||||
private readonly IValueConverter _cell_template_converter, _cell_editing_template_converter;
|
||||
|
||||
// I decided this was an easy and simple enough solution to justify breaking the mvvm paradigm
|
||||
// The alternative - within strict bounds of the paradigm - is to change the DataGridParameterCellTemplateConverter into an IMultiValueConverter, bound to data_type AND read_only
|
||||
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) {
|
||||
var rm = dataItem as IParameterViewMetadata;
|
||||
return rm != null && rm.read_only ? base.GenerateElement(cell, dataItem) : base.GenerateEditingElement(cell, dataItem);
|
||||
}
|
||||
protected override FrameworkElement generate_element_internal() { return _generate_element(_cell_template_converter); }
|
||||
protected override FrameworkElement generate_editing_element_internal() { return _generate_element(_cell_editing_template_converter); }
|
||||
|
||||
private FrameworkElement _generate_element(IValueConverter cell_template_converter) {
|
||||
var rv = new ContentControl();
|
||||
rv.SetBinding(ContentControl.ContentProperty, new Binding());
|
||||
rv.SetBinding(ContentControl.ContentTemplateProperty, new Binding("data_type") { Converter = cell_template_converter });
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(int), typeof(Thickness))]
|
||||
internal class RowHeaderGroupIndentConverter : IValueConverter {
|
||||
public double Indent { get; set; }
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return new Thickness(((int)value + 1) * Indent, 0, 0, 0);
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[ValueConversion(typeof(Type), typeof(DataTemplate))]
|
||||
internal class DataGridParameterCellTemplateConverter : IValueConverter {
|
||||
public DataTemplate DoubleTemplate { get; set; }
|
||||
public DataTemplate BooleanTemplate { get; set; }
|
||||
public DataTemplate IntTemplate { get; set; }
|
||||
public DataTemplate UIntTemplate { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
Type t = (Type)value;
|
||||
if (t == typeof(double)) return DoubleTemplate;
|
||||
else if (t == typeof(bool)) return BooleanTemplate;
|
||||
else if (t == typeof(int)) return IntTemplate;
|
||||
else if (t == typeof(uint)) return UIntTemplate;
|
||||
else return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,9 +91,10 @@ namespace mbts.ui.spark
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext) {
|
||||
double y_min = _col_header_presenter.TranslatePoint(new Point(0, _col_header_presenter.ActualHeight), this).Y;
|
||||
foreach (var kv in _row_animation_map) {
|
||||
var row = _grid.ItemContainerGenerator.ContainerFromItem(kv.Key) as DataGridRow;
|
||||
if (row != null) {
|
||||
if (row != null && row.TranslatePoint(new Point(0, row.ActualHeight * 0.5), this).Y > y_min) {
|
||||
var cells = row.descendants_of_type<DataGridCell>();
|
||||
var cell_map = _grid.Columns.Select(c => Tuple.Create(c, DataGridEx.GetArgument(c))).Where(t => t.Item2 != null).ToDictionary(t => t.Item2, t => cells.First(c => c.Column.Equals(t.Item1)));
|
||||
foreach (var cell_animations in kv.Value) {
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace mbts.spark.utilities
|
||||
public static OrderTime OrderTime => new OrderTime { Now = true };
|
||||
public static BTSTimedWindowParameters TimeWindow => new BTSTimedWindowParameters { Cancel = true, StartTime = OrderTime, StopTime = new OrderTime() };
|
||||
public static BTSWithATickParameters WithATick => new BTSWithATickParameters { QuantityThreshold = QuantityMeasure };
|
||||
public static BTSStopOrder BTSStopOrder => new BTSStopOrder { LimitOrder = new LimitOrder(), Price = 1, PriceTrigger = PriceTrigger, OptionalTimedParameters = TimeWindow, OptionalWithatickParameters = WithATick };
|
||||
public static BTSIcebergOrder BTSIcebergOrder => new BTSIcebergOrder { DisplayQuantity = QuantityMeasure, MarketOffset = PriceOffset, PriceTrigger = PriceTrigger, TimedWindowParameters = TimeWindow, WithatickParameters = WithATick };
|
||||
|
||||
public static IMessage[] Algos => new IMessage[] {
|
||||
@@ -33,14 +34,8 @@ namespace mbts.spark.utilities
|
||||
new StopMarketOrder(),
|
||||
new StopLimitOrder(),
|
||||
new IcebergOrder(),
|
||||
new BTSStopOrder(),
|
||||
new BTSIcebergOrder {
|
||||
DisplayQuantity = QuantityMeasure,
|
||||
MarketOffset = PriceOffset,
|
||||
PriceTrigger = PriceTrigger,
|
||||
TimedWindowParameters = TimeWindow,
|
||||
WithatickParameters = WithATick
|
||||
}
|
||||
BTSStopOrder,
|
||||
BTSIcebergOrder
|
||||
};
|
||||
|
||||
public static Order Order(Security security) {
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace mbts.spark.utilities
|
||||
else sanitize(data.QuoteMuteZone);
|
||||
if (data.QuoteRepriceThrottle == null) data.QuoteRepriceThrottle = Defaults.QuoteRepriceThrottle;
|
||||
else sanitize(data.QuoteRepriceThrottle);
|
||||
if (data.TickRangeRequoteRules == null) data.TickRangeRequoteRules = Defaults.TickRangeRequoteRules;
|
||||
if (data.QuoteMaxOrderMove == null) data.QuoteMaxOrderMove = Defaults.QuoteMaxOrderMove;
|
||||
}
|
||||
public static void sanitize(QuoteInsideMarketDistance data) {
|
||||
@@ -79,17 +78,7 @@ namespace mbts.spark.utilities
|
||||
PreHedgeParams = PreHedgeParams,
|
||||
PostHedgeParams = PostHedgeParams,
|
||||
};
|
||||
public static PaylessHedgeRules PayLessHedgeRules => new PaylessHedgeRules();
|
||||
public static PayupHedgeRules PayUpHedgeRules => new PayupHedgeRules();
|
||||
public static RulePriority RulePriority => new RulePriority();
|
||||
public static TickRangeRequoteRules TickRangeRequoteRules {
|
||||
get {
|
||||
var rv = new TickRangeRequoteRules();
|
||||
rv.TicksAwayToSensitivity.Add(1, 1);
|
||||
rv.TicksAwayToSensitivity.Add(5, 3);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
#region QuoteParams
|
||||
public static QuoteParams QuoteParams => new QuoteParams {
|
||||
@@ -99,7 +88,6 @@ namespace mbts.spark.utilities
|
||||
QuoteMuteZone = QuoteMuteZone,
|
||||
QuoteRepriceThrottle = QuoteRepriceThrottle,
|
||||
QuoteInsideMarketDistanceWithTravel = QuoteInsideMarketDistanceWithTravel,
|
||||
TickRangeRequoteRules = TickRangeRequoteRules
|
||||
};
|
||||
public static QuoteMaxOrderMove QuoteMaxOrderMove => new QuoteMaxOrderMove {
|
||||
MaxOrderMoveThreshold = 1
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock FontWeight="SemiBold">Display Quantity</TextBlock>
|
||||
<uag:QuantityMeasureControl Grid.Column="2" Grid.ColumnSpan="3" QuantityMeasure="{Binding display_quantity}" HeaderColName="c2"/>
|
||||
<uag:QuantityMeasureControl Grid.Column="2" Grid.ColumnSpan="3" HeaderColName="c2" QuantityMeasure="{Binding display_quantity}"/>
|
||||
<TextBlock Grid.Row="2" FontWeight="SemiBold">Child Order Offset</TextBlock>
|
||||
<Grid Grid.Row="2" Grid.Column="2" HorizontalAlignment="Stretch">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -106,12 +106,12 @@
|
||||
<TextBlock FontWeight="SemiBold">Ticks</TextBlock>
|
||||
<uag:QuantityMeasureControl Grid.Column="2" QuantityMeasure="{Binding withatick_parameters.QuantityThreshold}" HeaderColName="c2"/>
|
||||
<TextBlock Grid.Row="2" FontWeight="SemiBold">Price Trigger</TextBlock>
|
||||
<uag:PriceTriggerControl Grid.Row="2" Grid.Column="2" PriceTrigger="{Binding price_trigger}" HeaderColName="c2"/>
|
||||
<uag:PriceTriggerControl Grid.Row="2" Grid.Column="2" HeaderColName="c2" PriceTrigger="{Binding price_trigger}"/>
|
||||
<TextBlock Grid.Row="4" FontWeight="SemiBold">Time Window</TextBlock>
|
||||
<TextBlock Grid.Row="6" Grid.Column="2" Margin="-56,0,0,0">Start</TextBlock>
|
||||
<uag:OrderTimeControl Grid.Row="6" Grid.Column="2" OrderTime="{Binding start_time}" HeaderColName="c2"/>
|
||||
<uag:OrderTimeControl Grid.Row="6" Grid.Column="2" HeaderColName="c2" OrderTime="{Binding start_time}"/>
|
||||
<TextBlock Grid.Row="8" Grid.Column="2" Margin="-56,0,0,0">Stop</TextBlock>
|
||||
<uag:OrderTimeControl Grid.Row="8" Grid.Column="2" OrderTime="{Binding stop_time}" IsStopTime="True" HeaderColName="c2"/>
|
||||
<uag:OrderTimeControl Grid.Row="8" Grid.Column="2" HeaderColName="c2" OrderTime="{Binding stop_time}" IsStopTime="True"/>
|
||||
</Grid>
|
||||
</Expander>
|
||||
</Grid>
|
||||
|
||||
@@ -52,12 +52,9 @@ namespace mbts.ui.spark.algo
|
||||
}
|
||||
}
|
||||
|
||||
public QuantityMeasure display_quantity => _model.DisplayQuantity;
|
||||
public BTSIcebergOrder.ChildOrderOffsetOneofCase offset_case
|
||||
{
|
||||
public BTSIcebergOrder.ChildOrderOffsetOneofCase offset_case {
|
||||
get => _model.ChildOrderOffsetCase;
|
||||
set
|
||||
{
|
||||
set {
|
||||
if (value != offset_case) {
|
||||
_assign_template();
|
||||
switch (value) {
|
||||
@@ -69,6 +66,8 @@ namespace mbts.ui.spark.algo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public QuantityMeasure display_quantity => _model.DisplayQuantity;
|
||||
public double diff_from_last_fill { get => _model.DiffFromLastFill; set => _model.DiffFromLastFill = value; }
|
||||
public PriceOffset market_offset => _model.MarketOffset;
|
||||
public BTSWithATickParameters withatick_parameters => _model.WithatickParameters;
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:sp="clr-namespace:bts.spark;assembly=spark_core"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:uag="clr-namespace:mbts.ui.spark.algo">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/PriceOffsetControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/QuantityMeasureControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/AbsolutePriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/TrailingPriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/QuantityTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/PriceTriggerControl.xaml"/>
|
||||
<ResourceDictionary Source="/view/Controls/Algo/TimeWindowControl.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="VerticalSpacing">6.0</sys:Double>
|
||||
<sys:Double x:Key="HorizontalSpacing">6.0</sys:Double>
|
||||
<cv:ValueConverterPipe x:Key="PayupVisibilityConverter">
|
||||
<cv:StaticValueEqualsConverter Value="{u:Enum Payup, Type={u:Nested sp:BTSStopOrder.TriggerOrderPriceOneofCase}}"/>
|
||||
<BooleanToVisibilityConverter/>
|
||||
</cv:ValueConverterPipe>
|
||||
<cv:ValueConverterPipe x:Key="PriceVisibilityConverter">
|
||||
<cv:StaticValueEqualsConverter Value="{u:Enum Price, Type={u:Nested sp:BTSStopOrder.TriggerOrderPriceOneofCase}}"/>
|
||||
<BooleanToVisibilityConverter/>
|
||||
</cv:ValueConverterPipe>
|
||||
<uag:ChildOrderOffsetDisplayTextConverter x:Key="ChildOrderOffsetTextConverter"/>
|
||||
<Style TargetType="uag:BTSStopOrderControl">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="uag:BTSStopOrderControl">
|
||||
<Grid DataContext="{TemplateBinding OrderVM}" Grid.IsSharedSizeScope="True">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="6" MaxWidth="6" SharedSizeGroup="c1"/>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c2"/>
|
||||
<ColumnDefinition Width="6" MaxWidth="6" SharedSizeGroup="c3"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock FontWeight="SemiBold">Order Type</TextBlock>
|
||||
<ComboBox Grid.Column="2" Grid.ColumnSpan="3" ItemsSource="{u:EnumBindingSource {u:Nested sp:BTSStopOrder.NativeTriggerOrderTypeOneofCase}, Except=None}" SelectedItem="{Binding order_type}"/>
|
||||
<TextBlock Grid.Row="2" FontWeight="SemiBold">Price</TextBlock>
|
||||
<Grid Grid.Row="2" Grid.Column="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox ItemsSource="{u:EnumBindingSource {u:Nested sp:BTSStopOrder.TriggerOrderPriceOneofCase}, Except=None}" SelectedItem="{Binding price_type}"/>
|
||||
<TextBlock Grid.Column="1" Margin="2,0,0,0">:</TextBlock>
|
||||
</Grid>
|
||||
<uag:PriceOffsetControl Grid.Row="2" Grid.Column="4" PriceOffset="{Binding payup}" Visibility="{Binding price_type, Converter={StaticResource PayupVisibilityConverter}}"/>
|
||||
<c:TickUpDownDouble Grid.Row="2" Grid.Column="4" Value="{Binding price}" Visibility="{Binding price_type, Converter={StaticResource PriceVisibilityConverter}}"/>
|
||||
<TextBlock Grid.Row="4" FontWeight="SemiBold">Price Trigger</TextBlock>
|
||||
<uag:PriceTriggerControl Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="3" HeaderColName="c2" PriceTrigger="{Binding price_trigger}"/>
|
||||
<Expander Grid.Row="6" Grid.ColumnSpan="5" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
|
||||
<Expander.Header>
|
||||
<TextBlock FontStyle="Italic">Optional...</TextBlock>
|
||||
</Expander.Header>
|
||||
<Grid Margin="0,6,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSpacing}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="6" MaxWidth="6" SharedSizeGroup="c1"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock FontWeight="SemiBold">Ticks</TextBlock>
|
||||
<uag:QuantityMeasureControl Grid.Column="2" HeaderColName="c2" QuantityMeasure="{Binding withatick_parameters.QuantityThreshold}"/>
|
||||
<TextBlock Grid.Row="2" FontWeight="SemiBold">Time Window</TextBlock>
|
||||
<TextBlock Grid.Row="4" Grid.Column="2" Margin="-56,0,0,0">Start</TextBlock>
|
||||
<uag:OrderTimeControl Grid.Row="4" Grid.Column="2" HeaderColName="c2" OrderTime="{Binding start_time}"/>
|
||||
<TextBlock Grid.Row="6" Grid.Column="2" Margin="-56,0,0,0">Stop</TextBlock>
|
||||
<uag:OrderTimeControl Grid.Row="6" Grid.Column="2" HeaderColName="c2" OrderTime="{Binding stop_time}" IsStopTime="True"/>
|
||||
</Grid>
|
||||
</Expander>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,88 @@
|
||||
using bts.spark;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.shell;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace mbts.ui.spark.algo
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for BTSStopMarketOrderControl.xaml
|
||||
/// </summary>
|
||||
public class BTSStopOrderControl : Control
|
||||
{
|
||||
static BTSStopOrderControl() {
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(BTSStopOrderControl), new FrameworkPropertyMetadata(typeof(BTSStopOrderControl)));
|
||||
}
|
||||
|
||||
#region Order
|
||||
public static readonly DependencyProperty OrderProperty = DependencyProperty.Register("Order", typeof(BTSStopOrder), typeof(BTSStopOrderControl), new PropertyMetadata(null, OnOrderChanged, CoerceOrder));
|
||||
private static object CoerceOrder(DependencyObject d, object baseValue) { return baseValue is BTSStopOrder ? baseValue : OrderDataHelper.Defaults.BTSStopOrder; }
|
||||
private static void OnOrderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { d.SetValue(OrderVMPropertyKey, new BTSStopOrderVM((BTSStopOrder)e.NewValue)); }
|
||||
public BTSStopOrder Order { get => GetValue(OrderProperty) as BTSStopOrder; set => SetValue(OrderProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region OrderVM (ReadOnly)
|
||||
private static readonly DependencyPropertyKey OrderVMPropertyKey = DependencyProperty.RegisterReadOnly("OrderVM", typeof(BTSStopOrderVM), typeof(BTSStopOrderControl), new PropertyMetadata(null));
|
||||
internal static readonly DependencyProperty OrderVMProperty = OrderVMPropertyKey.DependencyProperty;
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
internal BTSStopOrderVM OrderVM { get => GetValue(OrderVMProperty) as BTSStopOrderVM; private set => SetValue(OrderVMPropertyKey, value); }
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal class BTSStopOrderVM : ViewModelBase
|
||||
{
|
||||
public BTSStopOrderVM(BTSStopOrder model) {
|
||||
_model = model;
|
||||
_assign_template();
|
||||
}
|
||||
|
||||
private readonly BTSStopOrder _model;
|
||||
private double _price;
|
||||
private PriceOffset _payup = OrderDataHelper.Defaults.PriceOffset;
|
||||
|
||||
private void _assign_template() {
|
||||
switch (_model.TriggerOrderPriceCase) {
|
||||
case BTSStopOrder.TriggerOrderPriceOneofCase.Price: _price = _model.Price; break;
|
||||
case BTSStopOrder.TriggerOrderPriceOneofCase.Payup: _payup = _model.Payup; break;
|
||||
}
|
||||
}
|
||||
|
||||
public BTSStopOrder.NativeTriggerOrderTypeOneofCase order_type {
|
||||
get => _model.NativeTriggerOrderTypeCase;
|
||||
set {
|
||||
if (value != order_type) {
|
||||
switch (value) {
|
||||
case BTSStopOrder.NativeTriggerOrderTypeOneofCase.LimitOrder: _model.LimitOrder = new LimitOrder(); break;
|
||||
case BTSStopOrder.NativeTriggerOrderTypeOneofCase.MarketOrder: _model.MarketOrder = new MarketOrder(); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BTSStopOrder.TriggerOrderPriceOneofCase price_type {
|
||||
get => _model.TriggerOrderPriceCase;
|
||||
set {
|
||||
if (value != price_type) {
|
||||
_assign_template();
|
||||
switch (value) {
|
||||
case BTSStopOrder.TriggerOrderPriceOneofCase.Price: _model.Price = _price; break;
|
||||
case BTSStopOrder.TriggerOrderPriceOneofCase.Payup: _model.Payup = new PriceOffset(_payup); break;
|
||||
}
|
||||
RaisePropertyChanged(nameof(price_type), nameof(price), nameof(payup));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PriceTrigger price_trigger => _model.PriceTrigger;
|
||||
public double price { get => _model.Price; set => _model.Price = value; }
|
||||
public PriceOffset payup => _model.Payup;
|
||||
|
||||
// exposing start_time and stop_time properties so the OrderTime [TimeCase]header ComboBox can be in the same ColumnDefinition SharedSizeGroup in the xaml.
|
||||
// In the xaml 2 OrderTimeControls are used instead of 1 TimeWindowControl (with 2 OrderTimeControls inside)...it makes the layout geometry (lining up TextBlock/ComboBox headers) MUCH easier.
|
||||
// public BTSTimedWindowParameters time_window => _model.TimedWindowParameters;
|
||||
public OrderTime start_time => _model.OptionalTimedParameters.StartTime;
|
||||
public OrderTime stop_time => _model.OptionalTimedParameters.StopTime;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
@@ -13,22 +12,24 @@ namespace mbts.ui.controls
|
||||
{
|
||||
public class DataGridExVerticalLineAdorner : Adorner, IDisposable
|
||||
{
|
||||
public DataGridExVerticalLineAdorner(DataGridEx grid)
|
||||
: base(grid) {
|
||||
public DataGridExVerticalLineAdorner(DataGridEx grid) : base(grid) {
|
||||
_grid = grid;
|
||||
if (_grid.IsLoaded) _init();
|
||||
else _grid.Loaded += (s, e) => _init();
|
||||
this.attach();
|
||||
_grid.Loaded += _grid_Loaded;
|
||||
_grid.Unloaded += _grid_Unloaded;
|
||||
}
|
||||
|
||||
private readonly DataGridEx _grid;
|
||||
protected readonly DataGridEx _grid;
|
||||
private IList<IDisposable> _grid_hooks = new List<IDisposable>();
|
||||
private IDictionary<DataGridColumn, IDisposable> _column_hooks = new Dictionary<DataGridColumn, IDisposable>();
|
||||
private ScrollViewer _scroll_viewer;
|
||||
private ScrollBar _h_scroll, _v_scroll;
|
||||
private DataGridColumnHeadersPresenter _col_header_presenter;
|
||||
private IDictionary<DataGridColumn, IList<IDisposable>> _column_hooks = new Dictionary<DataGridColumn, IList<IDisposable>>();
|
||||
protected ScrollViewer _scroll_viewer;
|
||||
protected ScrollBar _h_scroll, _v_scroll;
|
||||
protected DataGridColumnHeadersPresenter _col_header_presenter;
|
||||
private double _horizontal_offset = 0d;
|
||||
|
||||
private void _grid_Loaded(object sender, RoutedEventArgs e) { _init(); }
|
||||
private void _grid_Unloaded(object sender, RoutedEventArgs e) { _dispose_hooks(); this.detach(); }
|
||||
|
||||
private void _init() {
|
||||
_dispose_hooks();
|
||||
_scroll_viewer = _grid.visual_children_where(fe => fe is ScrollViewer).Cast<ScrollViewer>().FirstOrDefault();
|
||||
@@ -37,25 +38,22 @@ namespace mbts.ui.controls
|
||||
_v_scroll = _grid.visual_children_where(fe => fe is ScrollBar).Cast<ScrollBar>().Where(s => s.Orientation == Orientation.Vertical).FirstOrDefault();
|
||||
// do not add hooks if any components are null (prevents null ref exceptions in OnRender)
|
||||
if (_scroll_viewer == null || _col_header_presenter == null || _h_scroll == null || _v_scroll == null) return;
|
||||
_grid_hooks.Add(_get_scrollbar_hook(_h_scroll));
|
||||
_grid_hooks.Add(_get_scrollbar_hook(_v_scroll));
|
||||
_grid_hooks.AddRange(get_scrollbar_hooks(_h_scroll));
|
||||
_grid_hooks.AddRange(get_scrollbar_hooks(_v_scroll));
|
||||
_grid_hooks.Add(_grid.ObserveProperty(DataGridEx.ActualHeightProperty, (s, e) => InvalidateVisual()));
|
||||
foreach (var c in _grid.Columns) _column_hooks.Add(c, _get_col_hook(c));
|
||||
_grid_hooks.AddRange(get_other_hooks());
|
||||
foreach (var c in _grid.Columns) _column_hooks.Add(c, get_col_hooks(c).ToList());
|
||||
_grid_hooks.Add(_grid.Columns.Subscribe(_columns_CollectionChanged));
|
||||
_scroll_viewer.ScrollChanged += _scroll_viewer_ScrollChanged;
|
||||
_grid_hooks.Add(Disposable.Create(() => _scroll_viewer.ScrollChanged -= _scroll_viewer_ScrollChanged));
|
||||
this.attach();
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
private void _columns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
|
||||
switch (e.Action) {
|
||||
case NotifyCollectionChangedAction.Add: foreach (DataGridColumn c in e.NewItems) _column_hooks.Add(c, _get_col_hook(c)); break;
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
foreach (DataGridColumn c in e.OldItems) {
|
||||
IDisposable d;
|
||||
if (_column_hooks.TryGetValue(c, out d)) Disposable.dispose(ref d);
|
||||
}
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Add: foreach (DataGridColumn c in e.NewItems) _column_hooks.Add(c, get_col_hooks(c).ToList()); break;
|
||||
case NotifyCollectionChangedAction.Remove: foreach (DataGridColumn c in e.OldItems) if (_column_hooks.TryGetValue(c, out IList<IDisposable> d)) Disposable.dispose(d); break;
|
||||
}
|
||||
InvalidateVisual();
|
||||
}
|
||||
@@ -67,29 +65,27 @@ namespace mbts.ui.controls
|
||||
_horizontal_offset = tt.X;
|
||||
}
|
||||
|
||||
private IDisposable _get_col_hook(DataGridColumn col) {
|
||||
return Disposable.Create(
|
||||
col.ObserveProperty(DataGridColumn.WidthProperty, (s, e) => InvalidateVisual()),
|
||||
col.ObserveProperty(DataGridColumn.VisibilityProperty, (s, e) => InvalidateVisual()),
|
||||
col.ObserveProperty(DataGridEx.LeftBorderProperty, (s, e) => InvalidateVisual()),
|
||||
col.ObserveProperty(DataGridEx.RightBorderProperty, (s, e) => InvalidateVisual())
|
||||
);
|
||||
}
|
||||
|
||||
private IDisposable _get_scrollbar_hook(ScrollBar sb) {
|
||||
return Disposable.Create(
|
||||
sb.ObserveProperty(ScrollBar.VisibilityProperty, (s, e) => InvalidateVisual()),
|
||||
sb.ObserveProperty(ScrollBar.ActualWidthProperty, (s, e) => InvalidateVisual()),
|
||||
sb.ObserveProperty(ScrollBar.ActualHeightProperty, (s, e) => InvalidateVisual())
|
||||
);
|
||||
}
|
||||
|
||||
private void _dispose_hooks() {
|
||||
Disposable.dispose(_grid_hooks);
|
||||
foreach (var hook in _column_hooks.Values) hook.Dispose();
|
||||
foreach (var hook in _column_hooks.Values) Disposable.dispose(hook);
|
||||
_column_hooks.Clear();
|
||||
}
|
||||
|
||||
protected virtual IEnumerable<IDisposable> get_col_hooks(DataGridColumn col) {
|
||||
yield return col.ObserveProperty(DataGridColumn.WidthProperty, (s, e) => InvalidateVisual());
|
||||
yield return col.ObserveProperty(DataGridColumn.VisibilityProperty, (s, e) => InvalidateVisual());
|
||||
yield return col.ObserveProperty(DataGridEx.LeftBorderProperty, (s, e) => InvalidateVisual());
|
||||
yield return col.ObserveProperty(DataGridEx.RightBorderProperty, (s, e) => InvalidateVisual());
|
||||
}
|
||||
|
||||
protected virtual IEnumerable<IDisposable> get_scrollbar_hooks(ScrollBar sb) {
|
||||
yield return sb.ObserveProperty(ScrollBar.VisibilityProperty, (s, e) => InvalidateVisual());
|
||||
yield return sb.ObserveProperty(ScrollBar.ActualWidthProperty, (s, e) => InvalidateVisual());
|
||||
yield return sb.ObserveProperty(ScrollBar.ActualHeightProperty, (s, e) => InvalidateVisual());
|
||||
}
|
||||
|
||||
protected virtual IEnumerable<IDisposable> get_other_hooks() { return Enumerable.Empty<IDisposable>(); }
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext) {
|
||||
double x = _grid.Columns.Take(_grid.FrozenColumnCount).Where(c => c.Visibility == Visibility.Visible).Select(c => c.ActualWidth).Sum();
|
||||
DataGridHeadersVisibility header_vis = _grid.HeadersVisibility;
|
||||
@@ -99,30 +95,25 @@ namespace mbts.ui.controls
|
||||
}
|
||||
foreach (var c in _grid.Columns.Skip(_grid.FrozenColumnCount).Where(c => c.Visibility == Visibility.Visible)) {
|
||||
var lb = DataGridEx.GetLeftBorder(c);
|
||||
if (lb != null) _draw_vertical_line(drawingContext, x, lb);
|
||||
if (lb != null) draw_vertical_line(drawingContext, x, lb);
|
||||
x += c.ActualWidth;
|
||||
var rb = DataGridEx.GetRightBorder(c);
|
||||
if (rb != null) _draw_vertical_line(drawingContext, x, rb);
|
||||
if (rb != null) draw_vertical_line(drawingContext, x, rb);
|
||||
}
|
||||
if (!(RenderTransform is TranslateTransform)) RenderTransform = new TranslateTransform(_horizontal_offset, 0d);
|
||||
}
|
||||
|
||||
//draw 1 continuous line if possible to help performance
|
||||
private void _draw_vertical_line(DrawingContext dc, double x, DataGridExVerticalLine line) {
|
||||
protected virtual void draw_vertical_line(DrawingContext dc, double x, DataGridExVerticalLine line) {
|
||||
if (line.through_colum_header) {
|
||||
if (line.through_cells)
|
||||
dc.DrawLine(line.pen.Value, new Point(x, 0), new Point(x, _grid.ActualHeight - _h_scroll.ActualHeight));
|
||||
else
|
||||
dc.DrawLine(line.pen.Value, new Point(x, 0), new Point(x, _grid.super_header_height + _col_header_presenter.ActualHeight));
|
||||
} else if (line.through_cells)
|
||||
_draw_through_cells(dc, x, line.pen.Value);
|
||||
dc.DrawLine(line.pen.Value, new Point(x, _grid.super_header_height + _col_header_presenter.ActualHeight), new Point(x, _grid.ActualHeight));
|
||||
}
|
||||
|
||||
private void _draw_through_cells(DrawingContext dc, double x, Pen pen) { dc.DrawLine(pen, new Point(x, _grid.super_header_height + _col_header_presenter.ActualHeight), new Point(x, _grid.ActualHeight - _h_scroll.ActualHeight)); }
|
||||
|
||||
public void Dispose() {
|
||||
_dispose_hooks();
|
||||
this.detach();
|
||||
}
|
||||
public void Dispose() { _dispose_hooks(); this.detach(); }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using bts.api;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using static bts.api.Security;
|
||||
|
||||
|
||||
@@ -126,10 +126,13 @@ message NativeOrderState {
|
||||
|
||||
// Mutable, always available
|
||||
orderman.ManualOrderIndicator manual_order_indicator = 11;
|
||||
double price = 17;
|
||||
uint32 order_quantity = 13;
|
||||
|
||||
uint32 filled_quantity=16;
|
||||
double last_price = 12;
|
||||
double avg_price = 15;
|
||||
uint32 order_quantity = 13;
|
||||
uint32 filled_quantity=16;
|
||||
|
||||
OrderStatus order_status= 14;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,39 +40,12 @@ message Order {
|
||||
BTSStopOrder bts_stop_order = 400;
|
||||
|
||||
CrossingHedgeOrder crossing_hedge_order = 50000;
|
||||
SimpleHedgeOrder simple_hedge_order = 51000;
|
||||
CustomOrder custom_order = 1000000;
|
||||
}
|
||||
ExecutionStrategy execution_strategy = 2000;
|
||||
SimpleExecutionStrategy simple_execution_strategy = 2100;
|
||||
}
|
||||
|
||||
/***************************************Algo Order Support Data**********************************/
|
||||
|
||||
/********************* SIMPLE *********************************/
|
||||
message SimpleExecutionStrategy
|
||||
{
|
||||
SimpleExecutionParams leg1 = 10;
|
||||
SimpleExecutionParams leg2 = 20;
|
||||
}
|
||||
message SimpleExecutionParams
|
||||
{
|
||||
bts.api.Security security = 10;
|
||||
|
||||
int32 pre_hedge_payup_ticks = 100;
|
||||
bool is_working = 110;
|
||||
bool is_hedging = 120;
|
||||
|
||||
QuoteMuteZone slop = 200;
|
||||
PostHedgePriceBasedForcedCross post = 300;
|
||||
}
|
||||
message SimpleHedgeOrder
|
||||
{
|
||||
PostHedgePriceBasedForcedCross post = 10;
|
||||
}
|
||||
|
||||
/********************* END SIMPLE *********************************/
|
||||
|
||||
/********** Fundamental Data **********/
|
||||
|
||||
message PriceType
|
||||
@@ -414,6 +387,20 @@ message LegSpreaderParams
|
||||
******************************************Quote**************************************************
|
||||
*************************************************************************************************/
|
||||
|
||||
message QuoteParams
|
||||
{
|
||||
// Defines how much volume required to price off of a hedge leg level, as a ratio of working leg size.
|
||||
// e.g. If you are working N lots of 2 (leg_1) by 3 spread, you will work leg_1 at a price determined by
|
||||
// the price level at which you can sell N*3*lean_quantity_ratio.
|
||||
double lean_quantity_ratio = 20;
|
||||
|
||||
QuoteMuteZone quote_mute_zone = 1000;
|
||||
QuoteRepriceThrottle quote_reprice_throttle = 1010;
|
||||
QuoteInsideMarketDistance quote_inside_market_distance = 1020;
|
||||
QuoteInsideMarketDistanceWithTravel quote_inside_market_distance_with_travel = 1030;
|
||||
QuoteMaxOrderMove quote_max_order_move = 1040;
|
||||
}
|
||||
|
||||
/*************************************Quote MuteZone***********************************
|
||||
(TT Basic Slop)
|
||||
This rule sets a band above and below the quoting order inside of which any price changes will be
|
||||
@@ -436,9 +423,9 @@ THEN
|
||||
*/
|
||||
message QuoteMuteZone
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
uint32 outside_ticks = 10;
|
||||
uint32 inside_ticks = 20;
|
||||
RulePriority priority = 30;
|
||||
uint32 inside_ticks = 20;
|
||||
}
|
||||
|
||||
/*************************************Quote RepriceThrottle*******************************
|
||||
@@ -450,8 +437,8 @@ f(new_price, curr_price, market_bid, market_ask) -> new_price
|
||||
*/
|
||||
message QuoteRepriceThrottle
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
map<uint32, uint32> ticks_away_to_sensitivity = 10;
|
||||
RulePriority priority = 20;
|
||||
}
|
||||
|
||||
|
||||
@@ -482,8 +469,8 @@ THEN
|
||||
|
||||
message QuoteInsideMarketDistance
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
uint32 ticks_from_inside = 10;
|
||||
RulePriority priority = 20;
|
||||
}
|
||||
|
||||
/******************************Quote InsideMarketDistanceWithTravel******************************
|
||||
@@ -516,9 +503,9 @@ THEN
|
||||
|
||||
message QuoteInsideMarketDistanceWithTravel
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
uint32 ticks_from_inside = 10;
|
||||
uint32 limit = 20;
|
||||
RulePriority priority = 30;
|
||||
}
|
||||
|
||||
/*************************************Quote MaxOrderMove*****************************************
|
||||
@@ -539,6 +526,7 @@ rememberred in order to put it back in
|
||||
|
||||
message QuoteMaxOrderMove
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
uint32 max_order_move_threshold = 10;
|
||||
}
|
||||
|
||||
@@ -576,6 +564,7 @@ THEN calculated_hedge_price = market_bid_price - tick_size * hedge_tick_limit
|
||||
|
||||
message PreHedgeMaxPriceFromInsideMarket
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
uint32 hedge_tick_limit = 10;
|
||||
}
|
||||
|
||||
@@ -615,6 +604,7 @@ IF (TRUE)
|
||||
|
||||
message PreHedgeSendHedgeAsMarketOrder
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
bool send_hedge_as_market_order = 10;
|
||||
}
|
||||
|
||||
@@ -635,6 +625,7 @@ if (quantity_at_price (calculated_hedge_order_price) < quantity_threshold)
|
||||
|
||||
message PreHedgeQuantityBasedPayupTicks
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
QuantityMeasure quantity_threshold = 10;
|
||||
uint32 payup_ticks = 20;
|
||||
}
|
||||
@@ -656,6 +647,7 @@ if (quantity_at_price (calculated_hedge_order_price) > quantity_threshold)
|
||||
|
||||
message PreHedgeQuantityBasedPayLessTicks
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
QuantityMeasure quantity_threshold = 10;
|
||||
uint32 payless_ticks = 20;
|
||||
}
|
||||
@@ -692,6 +684,7 @@ THEN hedge_order_price = market_buy - tick_size * market_cross_ticks
|
||||
|
||||
message PostHedgeTimeBasedForcedCross
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
uint32 time_in_ms_threshold = 10;
|
||||
uint32 market_cross_ticks = 20;
|
||||
}
|
||||
@@ -716,6 +709,7 @@ IF (hedge_order_price > market_bid + tick_size * ticks_threshold)
|
||||
|
||||
message PostHedgePriceBasedForcedCross
|
||||
{
|
||||
RulePriority priority = 1;
|
||||
uint32 ticks_threshold = 10;
|
||||
uint32 market_cross_ticks = 20;
|
||||
}
|
||||
@@ -787,114 +781,20 @@ message IcebergOrder {
|
||||
uint32 show_quantity = 20;
|
||||
}
|
||||
//This is the order type used to encapsulate (and localize) the post hedge rules; it should be called 'With A Tick'
|
||||
message CrossingHedgeOrder {
|
||||
uint32 ticks_better_threshold = 5;
|
||||
uint32 cross_size_threshold = 10;
|
||||
double cross_ratio_threshold = 20;
|
||||
}
|
||||
|
||||
//Nice place to use the server API
|
||||
message CustomOrder {
|
||||
string order_impl_type = 20;
|
||||
map<string, string> custom_parameters = 30;
|
||||
message CrossingHedgeOrder
|
||||
{
|
||||
uint32 ticks_threshold = 10;
|
||||
uint32 market_cross_ticks = 20;
|
||||
}
|
||||
|
||||
message ExecutionStrategy
|
||||
{
|
||||
map<uint32, SyntheticLegExecutionParams> security_id_to_params = 10;
|
||||
map<uint32, LegSpreaderParams> leg_params_map = 20;
|
||||
}
|
||||
|
||||
message SyntheticLegExecutionParams
|
||||
message SyntheticExecutionStrategy
|
||||
{
|
||||
QuoteParams quote_params = 10;
|
||||
HedgeParams hedge_params = 20;
|
||||
}
|
||||
|
||||
message QuoteParams
|
||||
{
|
||||
// If it's working, an order is sent immediatly. Else the order is sent based on a fill of the other leg
|
||||
// TODO:retire since its available in LegSpreaderParams
|
||||
bool is_working = 10;
|
||||
// Defines how much volume required to price off of a hedge leg level, as a ratio of working leg size.
|
||||
// e.g. If you are working N lots of 2 (leg_1) by 3 spread, you will work leg_1 at a price determined by
|
||||
// the price level at which you can sell N*3*lean_quantity_ratio.
|
||||
double lean_quantity_ratio = 20;
|
||||
// This tells whether to use the volume weighted average price or the worst price for the other legs,
|
||||
// when computing the price of this active quoting leg
|
||||
bool pessimistic_hedge_pricing = 30;
|
||||
// TODO:retire since its a Parameter
|
||||
oneof quote_rules
|
||||
{
|
||||
TickRangeRequoteRules tick_range_requote_rules = 60;
|
||||
CustomRequoteRules custom_requote_rules = 100;
|
||||
}
|
||||
QuoteMuteZone quote_mute_zone = 1000;
|
||||
QuoteRepriceThrottle quote_reprice_throttle = 1010;
|
||||
QuoteInsideMarketDistance quote_inside_market_distance = 1020;
|
||||
QuoteInsideMarketDistanceWithTravel quote_inside_market_distance_with_travel = 1030;
|
||||
QuoteMaxOrderMove quote_max_order_move = 1040;
|
||||
}
|
||||
|
||||
message TickRangeRequoteRules
|
||||
{
|
||||
//From zero to map[0].key ticks to inside market requote the working leg every map[0].value
|
||||
//From map[0].key to map[1].key distance to inside market requote the working leg every map[1].value
|
||||
map<uint32, uint32> ticks_away_to_sensitivity = 10;
|
||||
}
|
||||
|
||||
message CustomRequoteRules
|
||||
{
|
||||
string requote_rule_type = 10;
|
||||
map<string, string> custom_parameters = 20;
|
||||
}
|
||||
|
||||
message HedgeParams {
|
||||
PayupHedgeRules payup_hedge_rules = 10;
|
||||
PaylessHedgeRules payless_hedge_rules = 20;
|
||||
PostHedgeRules post_hedge_rules = 30;
|
||||
CustomHedgeRules custom_hedge_rules = 100;
|
||||
}
|
||||
|
||||
message PayupHedgeRules {
|
||||
//To 'pay up' means to buy payup_ticks through the target hedge price or sell for payup_ticks lower than the target hedge price
|
||||
//Paying up is conditional on the size at the target hedge price level.
|
||||
//The condition is satisfied if either the target size is <= size_threshold
|
||||
//or the target size is <= ratio_threshold*hedge_order_size
|
||||
//(Note that setting the size threshold to a very large number would make the payup virtually unconditional)
|
||||
bool enable_payup = 5;
|
||||
uint32 payup_ticks = 10;
|
||||
uint32 size_threshold = 20;
|
||||
double ratio_threshold = 30;
|
||||
}
|
||||
message PaylessHedgeRules {
|
||||
//To 'pay less' means to buy or sell payless_ticks better than the target hedge price, thereby 'working' all
|
||||
//or part of the hedge order.
|
||||
//Paying less is conditional on the size at the target hedge price level.
|
||||
//The condition is satisfied if either the target size is >= size_threshold
|
||||
//or the target size is >= ratio_threshold*hedge_order_size
|
||||
//(Note that setting the size threshold to a very small, nonzero number would make the payless virtually unconditional)
|
||||
bool enable_payless = 5;
|
||||
uint32 payless_ticks = 10;
|
||||
uint32 size_threshold = 20;
|
||||
double ratio_threshold = 30;
|
||||
}
|
||||
message PostHedgeRules {
|
||||
//The post hedger watches all working hedges (arising through a deliberate payless or getting legged).
|
||||
//If the the opposite inside market size meets the threshold, the hedge is amended to cross the bid / offer spread.
|
||||
//For instance, we'd amend the hedge if the inside market size is <= size_threshold or
|
||||
//the inside market size is <= ratio_threshold*the size of the hedge order (ignoring zero)
|
||||
//This algorithm is implemented at the hedge site through the submission of a CrossingHedgeOrder
|
||||
bool enable_post_hedge = 5;
|
||||
uint32 cross_size_threshold = 10;
|
||||
double cross_ratio_threshold = 20;
|
||||
}
|
||||
message CustomHedgeRules {
|
||||
string hedge_rule_type = 10;
|
||||
map<string, string> custom_parameters = 20;
|
||||
}
|
||||
|
||||
message SyntheticExecutionStrategy {
|
||||
bts.api.Security security = 10;
|
||||
ExecutionStrategy execution_strategy = 20;
|
||||
}
|
||||
|
||||
@@ -22,18 +22,6 @@ namespace cmd {
|
||||
|
||||
using namespace orderman;
|
||||
|
||||
template <class T>
|
||||
inline void print_buffer(const char*label,T const&array)
|
||||
{
|
||||
const char * p = (const char*) &array;
|
||||
|
||||
std::cout << label << ": " ;
|
||||
for (size_t i = 0; i < sizeof(array); i++) {
|
||||
std::cout << (int) p[i] << ",";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
|
||||
api::orderman::CreateOrderRequest make_create_request(SecurityKey sec, api::BuySell side, Price price, Quantity quantity)
|
||||
{
|
||||
@@ -77,68 +65,69 @@ api::orderman::CancelOrderRequest make_cancel_request(OrderKey k)
|
||||
|
||||
int TestOrderman::execute(std::vector<std::string> const &)
|
||||
{
|
||||
using Node = event_grid::EventNode<event::GatewayBeginReplay, event_grid::event::Init> ;
|
||||
Node::Msg msg;
|
||||
auto ev = event::GatewayBeginReplay { GatewayName ("hello") };
|
||||
print_buffer("ev",ev);
|
||||
new (&msg.payload[0]) event::GatewayBeginReplay (ev);
|
||||
print_buffer("pl",msg.payload);
|
||||
auto ptr = *(event::GatewayBeginReplay*) (&msg.payload[0]);
|
||||
print_buffer("*ptr",ptr);
|
||||
std::cout << ptr.name.value() << "\n";
|
||||
return 0;
|
||||
// OrderKey current_order (null_order_key());
|
||||
// api::ServiceContext ctx;
|
||||
// OrderServiceServer server(ctx);
|
||||
// api::orderman::OrderService client(ctx.locate<api::orderman::OrderService> ());
|
||||
OrderKey current_order (null_order_key());
|
||||
api::ServiceContext ctx;
|
||||
OrderServiceServer server(ctx);
|
||||
api::orderman::OrderService client(ctx.locate<api::orderman::OrderService> ());
|
||||
|
||||
// while (true) {
|
||||
// std::cout << "create order: c sec_key b/s price quantity\nupdate order: u price quantity\ncancel order: x\nchange current order: o order_key\n";
|
||||
// char choice;
|
||||
// std::cin >> choice;
|
||||
// switch (choice) {
|
||||
// case 'c': {
|
||||
// uint32_t sec_key;char side; double price; int quantity;
|
||||
// std::cin >> sec_key >> side >> price >> quantity;
|
||||
// auto resp = client.create_order(make_create_request(SecurityKey(sec_key),
|
||||
// side == 'b' ? api::BUY : api::SELL,
|
||||
// Price(price),
|
||||
// Quantity(quantity)));
|
||||
// if (resp.success()) {
|
||||
// current_order = OrderKey(resp.result()->order_key());
|
||||
// std::cout << utils::pb::to_string(*resp.result()) << "\n";
|
||||
// }
|
||||
// else
|
||||
// std::cout << resp.error_message() << "\n";
|
||||
// break;
|
||||
// }
|
||||
// case 'u': {
|
||||
// double price; int quantity;
|
||||
// std::cin >> price >> quantity;
|
||||
// auto resp = client.update_order(make_update_request(current_order,
|
||||
// Price(price),
|
||||
// Quantity(quantity)));
|
||||
// if (resp.success())
|
||||
// std::cout << utils::pb::to_string(*resp.result()) << "\n";
|
||||
// else
|
||||
// std::cout << resp.error_message() << "\n";
|
||||
// break;
|
||||
// }
|
||||
// case 'x': {
|
||||
// auto resp = client.cancel_order(make_cancel_request(current_order));
|
||||
// if (resp.success())
|
||||
// std::cout << utils::pb::to_string(*resp.result()) << "\n";
|
||||
// else
|
||||
// std::cout << resp.error_message() << "\n";
|
||||
// break;
|
||||
// }
|
||||
// case 'o': {
|
||||
// std::cin >> current_order.value();
|
||||
// std::cout << "Current order: " << current_order.value() << "\n";
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
client.subscribe_orders().subscribe([](const api::orderman::OrdersUpdate &update) {
|
||||
for (auto const &os : update.added())
|
||||
std::cout << utils::pb::to_string(*os);
|
||||
for (auto const &os : update.removed())
|
||||
std::cout << "Removed: " << os->order_key() << "\n";
|
||||
});
|
||||
|
||||
while (true) {
|
||||
std::cout <<
|
||||
"create order: c sec_key b/s price quantity\n"
|
||||
"update order: u price quantity\n"
|
||||
"cancel order: x\nchange current order: o order_key\n";
|
||||
|
||||
char choice;
|
||||
std::cin >> choice;
|
||||
switch (choice) {
|
||||
case 'c': {
|
||||
uint32_t sec_key;char side; double price; int quantity;
|
||||
std::cin >> sec_key >> side >> price >> quantity;
|
||||
auto resp = client.create_order(make_create_request(SecurityKey(sec_key),
|
||||
side == 'b' ? api::BUY : api::SELL,
|
||||
Price(price),
|
||||
Quantity(quantity)));
|
||||
if (resp.success()) {
|
||||
current_order = OrderKey(resp.result()->order_key());
|
||||
std::cout << utils::pb::to_string(*resp.result()) << "\n";
|
||||
}
|
||||
else
|
||||
std::cout << resp.error_message() << "\n";
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
double price; int quantity;
|
||||
std::cin >> price >> quantity;
|
||||
auto resp = client.update_order(make_update_request(current_order,
|
||||
Price(price),
|
||||
Quantity(quantity)));
|
||||
if (resp.success())
|
||||
std::cout << utils::pb::to_string(*resp.result()) << "\n";
|
||||
else
|
||||
std::cout << resp.error_message() << "\n";
|
||||
break;
|
||||
}
|
||||
case 'x': {
|
||||
auto resp = client.cancel_order(make_cancel_request(current_order));
|
||||
if (resp.success())
|
||||
std::cout << utils::pb::to_string(*resp.result()) << "\n";
|
||||
else
|
||||
std::cout << resp.error_message() << "\n";
|
||||
break;
|
||||
}
|
||||
case 'o': {
|
||||
std::cin >> current_order.value();
|
||||
std::cout << "Current order: " << current_order.value() << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string TestOrderman::help ()
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace event_grid {
|
||||
|
||||
template <typename... Events> struct Consumes
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename... Events> struct Produces {};
|
||||
|
||||
template <typename Implementer,
|
||||
typename Consumes,
|
||||
typename Produces>
|
||||
class Component
|
||||
{
|
||||
template <class EN>
|
||||
void set_node(EN &en) {
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -1,50 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/meta_programming.h"
|
||||
#include "server/sparkd/event_grid/events/Init.h"
|
||||
|
||||
#include "server/sparkd/event_grid/HeterogeneousQueue.h"
|
||||
|
||||
#include <memory>
|
||||
#include <moodycamel/concurrentqueue.h>
|
||||
|
||||
|
||||
namespace bts {
|
||||
namespace event_grid {
|
||||
|
||||
|
||||
|
||||
|
||||
template <class E,size_t MaxObs=10>
|
||||
class EventRecord
|
||||
{
|
||||
public:
|
||||
EventRecord() :_n_observers(0),_observers() {}
|
||||
|
||||
|
||||
using Event = E;
|
||||
using Observer = std::function<void(const E&, bool)>;
|
||||
using NoFwdObserver = std::function<void(const E&)>;
|
||||
|
||||
|
||||
void observe(Observer const &o) {
|
||||
bts_assert(_n_observers < MaxObs);
|
||||
_observers[_n_observers++] = o;
|
||||
}
|
||||
|
||||
|
||||
void signal(const E&e, bool fwd)
|
||||
{
|
||||
for (size_t i = 0;i < _n_observers;i++)
|
||||
_observers[i](e,fwd);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
uint8_t _n_observers;
|
||||
std::array<Observer,MaxObs> _observers;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template <int N,typename HandlerArray,typename EventRecordTuple, typename Payload>
|
||||
struct HandlerInit {
|
||||
static void init(HandlerArray &handlers,EventRecordTuple &event_records)
|
||||
{
|
||||
using Event = typename std::tuple_element<N, EventRecordTuple>::type::Event;
|
||||
handlers[N] = [&event_records] (Payload const&pl, bool fwd) {
|
||||
std::get<N>(event_records).signal(*(Event*) (&pl[0]),fwd);
|
||||
auto &ev = *(Event*) &pl;
|
||||
std::get<N>(event_records).signal(ev,fwd);
|
||||
ev.~Event();
|
||||
};
|
||||
HandlerInit<N-1,HandlerArray,EventRecordTuple,Payload>::init(handlers,event_records);
|
||||
}
|
||||
@@ -54,9 +56,9 @@ struct HandlerInit<-1,HandlerArray,EventRecordTuple,Payload>
|
||||
{
|
||||
static void init(HandlerArray &,EventRecordTuple &) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename... Events>
|
||||
class EventNode {
|
||||
public:
|
||||
@@ -66,18 +68,23 @@ public:
|
||||
using EventRecordTuple = std::tuple<EventRecord<Events>...> ;
|
||||
using EventHandler = std::function<void(const Payload &, bool fwd)> ;
|
||||
using HandlerArray = std::array<EventHandler,NumberEvents> ;
|
||||
|
||||
struct MsgHeader {
|
||||
uint8_t handler_idx;
|
||||
uint8_t forwarded;
|
||||
};
|
||||
|
||||
EventNode() : _queue(),
|
||||
_handlers(),
|
||||
_events()
|
||||
{
|
||||
HandlerInit<NumberEvents-1,HandlerArray,EventRecordTuple,Payload>::init (_handlers,_events);
|
||||
// send(event::Init());
|
||||
send<event::Init>();
|
||||
}
|
||||
|
||||
template <class Event>
|
||||
void send(Event const&ev) {send(ev,false);}
|
||||
|
||||
|
||||
template <class Event,typename... Args>
|
||||
void send(Args&&... args)
|
||||
{send<Event>(false,std::forward<Args>(args)...);}
|
||||
|
||||
template <class Event>
|
||||
void observe(typename EventRecord<Event>::Observer const&o)
|
||||
{
|
||||
@@ -85,7 +92,7 @@ public:
|
||||
std::get<meta::GetTypeIdxInTuple<EventRecord<Event>,EventRecordTuple>::value> (_events);
|
||||
ev_record.observe(o);
|
||||
}
|
||||
|
||||
|
||||
template <class Event>
|
||||
void observe(typename EventRecord<Event>::NoFwdObserver const&o)
|
||||
{
|
||||
@@ -93,51 +100,47 @@ public:
|
||||
std::get<meta::GetTypeIdxInTuple<EventRecord<Event>,EventRecordTuple>::value> (_events);
|
||||
ev_record.observe([o](auto const&ev,bool) {o(ev);});
|
||||
}
|
||||
|
||||
|
||||
bool do_work()
|
||||
{
|
||||
Msg m;
|
||||
if (_queue.try_dequeue(m)) {
|
||||
_handlers[m.handler_idx](m.payload,m.forwarded);
|
||||
auto raw_msg = _queue.pop();
|
||||
if (raw_msg) {
|
||||
auto const &header = raw_msg->header;
|
||||
_handlers[header.handler_idx](raw_msg->payload,header.forwarded);
|
||||
_queue.release(raw_msg);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template <class Event, class N1, class N2>
|
||||
friend void forward(N1 &from, N2& to);
|
||||
|
||||
|
||||
public:
|
||||
struct Msg {
|
||||
uint8_t handler_idx;
|
||||
uint8_t forwarded;
|
||||
Payload payload;
|
||||
};
|
||||
|
||||
template <class Event>
|
||||
void send(Event const&ev,bool fwd)
|
||||
|
||||
|
||||
template <class Event,typename... Args>
|
||||
void send(bool fwd,Args&&... args)
|
||||
{
|
||||
Msg m;
|
||||
m.handler_idx = meta::GetTypeIdxInTuple<EventRecord<Event>,EventRecordTuple>::value;
|
||||
m.forwarded = fwd;
|
||||
|
||||
new (&m.payload[0]) Event (ev);
|
||||
_queue.enqueue(m);
|
||||
_queue.template inplace_push<Event> (
|
||||
MsgHeader {meta::GetTypeIdxInTuple<EventRecord<Event>,EventRecordTuple>::value,fwd},
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
moodycamel::ConcurrentQueue<Msg> _queue;
|
||||
|
||||
HeterogenousQueue<MsgHeader,MaxMsgSize> _queue;
|
||||
std::array<EventHandler,NumberEvents> _handlers;
|
||||
EventRecordTuple _events;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class Event, class N1, class N2>
|
||||
void forward(N1 &from, N2& to)
|
||||
{
|
||||
from.template observe<Event>([&to](Event const&ev, bool fwded) {
|
||||
if (!fwded)
|
||||
to.send(ev,true);
|
||||
to.template send<Event>(true,ev);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include <boost/lockfree/queue.hpp>
|
||||
#include <boost/lockfree/stack.hpp>
|
||||
|
||||
namespace bts {
|
||||
namespace event_grid {
|
||||
|
||||
template<class Header,
|
||||
size_t PayloadSize,
|
||||
size_t BlockSize = 1024,
|
||||
size_t InitialCapacity=1024>
|
||||
class HeterogenousQueue
|
||||
{
|
||||
public:
|
||||
struct Item {
|
||||
Header header;
|
||||
std::array<uint8_t,PayloadSize> payload;
|
||||
};
|
||||
|
||||
HeterogenousQueue() : _queue(BlockSize),_free(InitialCapacity),_storage()
|
||||
{alloc_block();}
|
||||
|
||||
template<class T,typename... Args>
|
||||
void inplace_push(Header const &header,Args&&... args)
|
||||
{
|
||||
static_assert(sizeof(T) <= PayloadSize,"Type is too large for this queue");
|
||||
|
||||
auto free_item = get_free_item();
|
||||
free_item->header = header;
|
||||
new (&free_item->payload) T{std::forward<Args>(args)...};
|
||||
|
||||
_queue.push(free_item);
|
||||
}
|
||||
|
||||
Item* pop()
|
||||
{
|
||||
Item*result=nullptr;
|
||||
_queue.pop(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void release(Item*item)
|
||||
{
|
||||
_free.push(item);
|
||||
}
|
||||
|
||||
private:
|
||||
using Block = std::array<Item,BlockSize>;
|
||||
using BlockPtr = std::unique_ptr<Block>;
|
||||
using Queue = boost::lockfree::queue<Item*>;
|
||||
using FreeList = boost::lockfree::stack<Item*>;
|
||||
|
||||
Item* get_free_item()
|
||||
{
|
||||
Item *result;
|
||||
for(;;) {
|
||||
if (_free.pop(result))
|
||||
return result;
|
||||
else
|
||||
alloc_block();
|
||||
}
|
||||
}
|
||||
|
||||
void alloc_block()
|
||||
{
|
||||
auto block = std::make_unique<Block>();
|
||||
for (auto &item : *block)
|
||||
_free.push(&item);
|
||||
|
||||
std::lock_guard<std::mutex> l (_storage_lock);
|
||||
_storage.push_back(std::move(block));
|
||||
}
|
||||
|
||||
Queue _queue;
|
||||
FreeList _free;
|
||||
std::vector<BlockPtr> _storage;
|
||||
std::mutex _storage_lock;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include <boost/lockfree/queue.hpp>
|
||||
#include <boost/lockfree/stack.hpp>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
template<class Header,
|
||||
size_t PayloadSize,
|
||||
size_t BlockSize = 1024>
|
||||
class HeterogenousQueue
|
||||
{
|
||||
public:
|
||||
struct Item {
|
||||
Header header;
|
||||
std::array<uint8_t,PayloadSize> payload;
|
||||
};
|
||||
|
||||
HeterogenousQueue() : _queue(),_free(),_storage()
|
||||
{alloc_block();}
|
||||
|
||||
template<class T,typename... Args>
|
||||
void create_and_push(Header const &header,Args&&... args)
|
||||
{
|
||||
static_assert(sizeof(header) <= PayloadSize,"Type is too large for this queue");
|
||||
|
||||
auto free_item = get_free_item();
|
||||
free_item->header = header;
|
||||
new (&free_item->payload) T(std::forward<Args>(args)...);
|
||||
|
||||
_queue.push(free_item);
|
||||
}
|
||||
|
||||
Item* pop()
|
||||
{
|
||||
Item*result=nullptr;
|
||||
_queue.pop(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void release(Item*item)
|
||||
{
|
||||
((T*) (&item->payload))->~T();
|
||||
_free.push(item);
|
||||
}
|
||||
|
||||
private:
|
||||
using Block = std::array<Item,BlockSize>;
|
||||
using BlockPtr = std::unique_ptr<Block>;
|
||||
using Queue = boost::lockfree::queue<Item*>;
|
||||
using FreeList = boost::lockfree::stack<Item*>;
|
||||
|
||||
Item* get_free_item()
|
||||
{
|
||||
Item *result;
|
||||
for(;;) {
|
||||
if (_free.pop(result))
|
||||
return result;
|
||||
else
|
||||
alloc_block();
|
||||
}
|
||||
}
|
||||
|
||||
void alloc_block()
|
||||
{
|
||||
auto block = std::make_unique<Block>();
|
||||
for (auto &item : block)
|
||||
_free.push(&item);
|
||||
|
||||
std::lock_guard<std::mutex> l (_storage_lock);
|
||||
_storage.push_back(block);
|
||||
}
|
||||
|
||||
Queue _queue;
|
||||
FreeList _free;
|
||||
std::vector<BlockPtr> _storage;
|
||||
std::mutex _storage_lock;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -30,12 +30,15 @@ FillRecorder::~FillRecorder () {}
|
||||
|
||||
void FillRecorder::on(event::ExecutionReport const&er)
|
||||
{
|
||||
auto pb = event::to_pb(*er.data);
|
||||
me->store.store(pb);
|
||||
LOG(OrderMan,Info,"Storing fill: {} ",utils::pb::to_string(pb));
|
||||
if (er.data->exec_type == api::orderman::ET_PARTIAL_FILL ||
|
||||
er.data->exec_type == api::orderman::ET_FILL) {
|
||||
auto pb = event::to_pb(*er.data);
|
||||
LOG(OrderMan,Info,"Storing fill: {} ",utils::pb::to_string(pb));
|
||||
me->store.store(pb);
|
||||
|
||||
std::vector<api::orderman::NativeFill> v {pb};
|
||||
native_fill_signal(event::NativeFills {v});
|
||||
std::vector<api::orderman::NativeFill> v {pb};
|
||||
native_fill_signal(event::NativeFills {v});
|
||||
}
|
||||
}
|
||||
|
||||
void FillRecorder::on(event_grid::event::Init const&)
|
||||
|
||||
@@ -28,3 +28,4 @@ private:
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -61,12 +61,19 @@ Gateway::Gateway(config::JetFIX::Connection const&c, securities::SecurityDB &db)
|
||||
api::orderman::OrderStatus(msg.get<fix::OrdStatus>()),
|
||||
msg.get<fix::ManualOrderIndicator>() ? api::orderman::MOI_YES: api::orderman::MOI_NO,
|
||||
to<ExchangeOrderID>(msg.get<fix::OrderID>()),
|
||||
Price (msg.get<fix::Price>()),
|
||||
securities::decode_exchange_price(*sec,Price (msg.get<fix::Price>())),
|
||||
Quantity(msg.get<fix::OrderQty>()),
|
||||
Quantity(msg.get<fix::CumQty>()),
|
||||
Quantity(msg.get<fix::LastShares>()),
|
||||
securities::decode_exchange_price(*sec,Price(msg.get<fix::LastPx>())),
|
||||
securities::decode_exchange_price(*sec,Price(msg.get<fix::AvgPx>())),
|
||||
|
||||
msg.has<fix::LastShares>()?
|
||||
Quantity(msg.get<fix::LastShares>()):Quantity(0),
|
||||
|
||||
msg.has<fix::LastPx>()?
|
||||
securities::decode_exchange_price(*sec,Price(msg.get<fix::LastPx>())) : Price(0),
|
||||
|
||||
msg.has<fix::AvgPx>()?
|
||||
securities::decode_exchange_price(*sec,Price(msg.get<fix::AvgPx>())) : Price(0),
|
||||
|
||||
to<ExchangeFillID>(msg.get<fix::ExecID>()),
|
||||
to<OrderTimeStamp>(msg.get<fix::TransactTimeStr>()),
|
||||
reject_msg
|
||||
|
||||
@@ -113,7 +113,7 @@ void NativeOrderMan::on(event::CreateNativeOrder const&create)
|
||||
LOG(OrderMan,Error,
|
||||
"Someone tried to create a native order "
|
||||
"using existing id {}. Order was for security: {}"
|
||||
" This is a dangerous bug" ,
|
||||
" This is a dangerous bug, please report it to development" ,
|
||||
k.value(), securities::descriptor(*order._header.security));
|
||||
return;
|
||||
}
|
||||
@@ -139,17 +139,31 @@ void NativeOrderMan::on(event::CreateNativeOrder const&create)
|
||||
void NativeOrderMan::on(event::UpdateNativeOrder const&update)
|
||||
{
|
||||
auto &order = const_cast<NativeOrder&> (*update.order);
|
||||
|
||||
LOG(OrderMan,Diag, "NativeOrderMan UpdateNativeOrder {}",order.key().value());
|
||||
if (order.can_be_udpated()) {
|
||||
auto buffer = get_fix_bufer();
|
||||
order.encode_update(me->latest_timestamp,update.price,update.quantity,&buffer->fix[0]);
|
||||
out_gateway_msg_signal(event::OutGatewayMsg {buffer});
|
||||
}
|
||||
else {
|
||||
LOG(OrderMan,Warn, "Attempt to update in flight order {}. Request will be ignored",order.key().value());
|
||||
order.set_reject_msg("Order has not yet been aknowledged by the exchange and cannot be updated");
|
||||
|
||||
switch (me->state) {
|
||||
case State::REPLAY:
|
||||
bts_assert(false);
|
||||
break;
|
||||
case State::DISCONNECTED:
|
||||
LOG(OrderMan,Warn,
|
||||
"Unable to update order {} because gateway connection is down. "
|
||||
"Update request will be ignored",order.key().value());
|
||||
order.set_reject_msg("Order gateway is not ready");
|
||||
native_order_state_change_signal(event::NativeOrderStateChange {&order,&order.header(),order.state()});
|
||||
return;
|
||||
case State::CONNECTED:
|
||||
if (order.can_be_udpated()) {
|
||||
auto buffer = get_fix_bufer();
|
||||
order.encode_update(me->latest_timestamp,update.price,update.quantity,&buffer->fix[0]);
|
||||
out_gateway_msg_signal(event::OutGatewayMsg {buffer});
|
||||
}
|
||||
else {
|
||||
LOG(OrderMan,Warn, "Attempt to update in flight order {}. Request will be ignored",order.key().value());
|
||||
order.set_reject_msg("Order cannot be updated until it is aknowledged by the order gateway");
|
||||
native_order_state_change_signal(event::NativeOrderStateChange {&order,&order.header(),order.state()});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,15 +173,29 @@ void NativeOrderMan::on(event::CancelNativeOrder const&cancel)
|
||||
|
||||
LOG(OrderMan,Diag, "NativeOrderMan CancelNativeOrder {}",order.key().value());
|
||||
|
||||
if (order.can_be_canceled()) {
|
||||
auto buffer = get_fix_bufer();
|
||||
order.encode_cancel(me->latest_timestamp,&buffer->fix[0]);
|
||||
out_gateway_msg_signal(event::OutGatewayMsg {buffer});
|
||||
}
|
||||
else {
|
||||
LOG(OrderMan,Warn, "Attempt to cancel in flight order {}. Request will be ignored",order.key().value());
|
||||
order.set_reject_msg("Order has not yet been aknowledged by the exchange and cannot be canceled");
|
||||
switch (me->state) {
|
||||
case State::REPLAY:
|
||||
bts_assert(false);
|
||||
break;
|
||||
case State::DISCONNECTED:
|
||||
LOG(OrderMan,Warn,
|
||||
"Unable to cancel order {} because gateway connection is down. "
|
||||
"Cancel request will be ignored",order.key().value());
|
||||
order.set_reject_msg("Order gateway is not ready");
|
||||
native_order_state_change_signal(event::NativeOrderStateChange {&order,&order.header(),order.state()});
|
||||
return;
|
||||
case State::CONNECTED:
|
||||
if (order.can_be_canceled()) {
|
||||
auto buffer = get_fix_bufer();
|
||||
order.encode_cancel(me->latest_timestamp,&buffer->fix[0]);
|
||||
out_gateway_msg_signal(event::OutGatewayMsg {buffer});
|
||||
}
|
||||
else {
|
||||
LOG(OrderMan,Warn, "Attempt to cancel in flight order {}. Request will be ignored",order.key().value());
|
||||
order.set_reject_msg("Order cannot be canceled until it is aknowledged by the order gateway");
|
||||
native_order_state_change_signal(event::NativeOrderStateChange {&order,&order.header(),order.state()});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,9 +255,9 @@ void NativeOrderMan::on(event::ExecutionReport const&er)
|
||||
else {
|
||||
LOG(OrderMan,Error,
|
||||
"Received an execution report for an unknown order with key {} "
|
||||
". Order state will be recovered from this report but fields "
|
||||
"CustomerOrFirm, CTI code and parent/child relationship cannot be recovered and will be set "
|
||||
"to default values", k.value());
|
||||
". Order state will be reconstructed from this report but some information "
|
||||
" cannot be recovered, including fix fields CustomerOrFirm and CTI code"
|
||||
" and the parent order id (if any)", k.value());
|
||||
|
||||
api::orderman::NativeOrderState recovered;
|
||||
recovered.set_account_name(to_str(er.data->account_name));
|
||||
@@ -271,7 +299,7 @@ void NativeOrderMan::on(event::CancelReject const&cr)
|
||||
else
|
||||
LOG(OrderMan,Error,
|
||||
"Received a cancel reject for an unknown order with key {} "
|
||||
"This should not happen and should be investigated", k.value());
|
||||
". This should not happen. Please investigate", k.value());
|
||||
}
|
||||
|
||||
void NativeOrderMan::on(event::TimeChange const&new_time)
|
||||
@@ -313,6 +341,7 @@ void NativeOrderMan::transition(State new_state)
|
||||
{
|
||||
LOG(OrderMan,Info,"Transitioning NativeOrderMan from {} to {}",
|
||||
state_name(me->state),state_name(new_state));
|
||||
me->state = new_state;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -30,8 +30,8 @@ OrderRecorder::~OrderRecorder () {}
|
||||
void OrderRecorder::on(event::NativeOrderStateChange const&ch)
|
||||
{
|
||||
auto pb = event::to_pb(*ch.header,ch.current_state);
|
||||
me->store.store(pb);
|
||||
LOG(OrderMan,Info,"Storing order: {} ",utils::pb::to_string(pb));
|
||||
me->store.store(pb);
|
||||
|
||||
std::vector<api::orderman::OrderState> v {pb};
|
||||
order_state_change_signal(event::OrderStateChange {v});
|
||||
|
||||
@@ -12,10 +12,10 @@ class TimeSource
|
||||
{
|
||||
public:
|
||||
|
||||
TimeSource() : time_update_signal([](auto){}),_last() {}
|
||||
TimeSource() : time_change_signal([](auto){}),_last() {}
|
||||
|
||||
// out
|
||||
std::function<void(event::TimeChange const&)> time_update_signal;
|
||||
std::function<void(event::TimeChange const&)> time_change_signal;
|
||||
|
||||
void do_work() {
|
||||
auto now = Timer::now();
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
Timer::now(),
|
||||
to<OrderTimeStamp> (datetime::FIX_timestamp(datetime::now()))
|
||||
};
|
||||
time_update_signal(change);
|
||||
time_change_signal(change);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -279,4 +279,59 @@ CheckSum = 151 10=151
|
||||
- need to get a handle on transact time
|
||||
- probably best design is to flatten order, making copies cheaper
|
||||
- consider including restatement reason
|
||||
- Compile newer cgdb
|
||||
- Add all source paths to gdb init
|
||||
- Publish gdb init
|
||||
- see if handling of cancel rejects is any good
|
||||
- batch handling of orders, batch handling of fills
|
||||
- better event_grid
|
||||
- simpler wiring
|
||||
- less indirection in dispatch
|
||||
- consider passing lambdas around
|
||||
* Notes on "A guide to spread trading futures"
|
||||
- Spread trading exploits correlations between securities and mean
|
||||
reversion
|
||||
- Correlations are discovered by traders
|
||||
- Types of spreads
|
||||
- Calendar: same security, different maturities
|
||||
- Nearer month ditacts naming of spread: long on near month ==
|
||||
long on spread
|
||||
- Butterfly (fly): two calendar spreads
|
||||
- 3 maturity dates
|
||||
- body: -2
|
||||
- Wings: +1, +1
|
||||
- Long if long wings, short if short wings
|
||||
- Condor
|
||||
- 4 Maturity dates
|
||||
- Like a flat butterfly:
|
||||
- 1, -1, -1, 1
|
||||
- Intra-market spreads
|
||||
- Different securities
|
||||
- Examples:
|
||||
- Crack Spread (crude oil and an oil by-product)
|
||||
- Spark Spread (natural gas and electricity)
|
||||
- Crush Spread (soybeans and a byproduct)
|
||||
- Exchange Listed Spreads are not cross product spreads
|
||||
- Spread Matrix:
|
||||
- Display Exchange in a tabular form for every month pair
|
||||
- Factors to consider when determining hedge ratios
|
||||
- Tick Value.
|
||||
- Different products might have different tick values
|
||||
- To be hedged you make sure that for a 1 tick move the price
|
||||
movements of both contracts are the same
|
||||
- Currency of contract
|
||||
- Relative movement of contract
|
||||
- Trader preferance
|
||||
- Exchange that contract is listed on
|
||||
- Trading hours will vary
|
||||
- Trade Ratio/Price Ratio
|
||||
- Integrate the relative movement and tick ratios to determine the
|
||||
final ratio
|
||||
- Strategies
|
||||
- Mean Reversion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
|
||||
namespace api { namespace orderman { class CreateOrderRequest;}}
|
||||
|
||||
namespace orderman {
|
||||
namespace event {
|
||||
|
||||
class CreateOrder
|
||||
{
|
||||
public:
|
||||
api::orderman::CreateOrderRequest request;
|
||||
std::function<void(bts::api::orderman::CreateOrderResponse const&) response_handler;
|
||||
};
|
||||
|
||||
}}}
|
||||
@@ -44,6 +44,7 @@ api::orderman::OrderState to_pb(NativeOrderHeader const&header,NativeOrderState
|
||||
result.set_reject_msg(std::string(current_state.reject_msg));
|
||||
|
||||
native.set_manual_order_indicator(header.manual_order_indicator);
|
||||
native.set_price(current_state.price.value());
|
||||
native.set_last_price(current_state.last_price.value());
|
||||
native.set_avg_price(current_state.avg_price.value());
|
||||
native.set_order_quantity(current_state.order_quantity.value());
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
static auto const PriceFieldSz=20;
|
||||
static auto const SizeFieldSz=6;
|
||||
|
||||
void NativeOrder::init_update_fix()
|
||||
{
|
||||
auto &encoding = _fix_data.update_encoding;
|
||||
@@ -15,8 +12,8 @@ void NativeOrder::init_update_fix()
|
||||
using namespace jetfix;
|
||||
|
||||
// price, quantity, transact time will all be changing on every order update
|
||||
_fix_data.update_price_bm = encoding.add<fix::Price> (0,PriceFieldSz);
|
||||
_fix_data.update_quantity_bm = encoding.add<fix::OrderQty> (0,SizeFieldSz);
|
||||
_fix_data.update_price_bm = encoding.add<fix::Price> (0,price_sz());
|
||||
_fix_data.update_quantity_bm = encoding.add<fix::OrderQty> (0,quantity_sz());
|
||||
_fix_data.update_transact_time_bm =
|
||||
encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
|
||||
|
||||
@@ -25,6 +22,7 @@ void NativeOrder::init_update_fix()
|
||||
encoding.add<fix::Side> (_header.side);
|
||||
encoding.add<fix::TimeInForce> (_header.time_in_force);
|
||||
encoding.add<fix::OrdType> (_header.order_type);
|
||||
encoding.add<fix::ManualOrderIndicator> (_header.manual_order_indicator);
|
||||
encoding.add<fix::CustomerOrFirm> (_header.customer_or_firm);
|
||||
encoding.add<fix::CtiCode> (_header.cti_code);
|
||||
encoding.add<fix::SecurityDesc> (_header.security->glbx().security_desc());
|
||||
@@ -34,22 +32,17 @@ void NativeOrder::init_update_fix()
|
||||
encoding.add<fix::ClOrdID> (clordid);
|
||||
encoding.add<fix::OrigClOrdID> (clordid);
|
||||
encoding.add<fix::CorrelationClOrdID> (clordid);
|
||||
|
||||
// if we have an exchange order id use it, otherwise we will
|
||||
// do it when get our first execution report
|
||||
if (_state.exchange_order_id)
|
||||
update_exchange_order_id(*_state.exchange_order_id);
|
||||
}
|
||||
|
||||
void NativeOrder::init_create_fix()
|
||||
{
|
||||
auto &encoding = _fix_data.update_encoding;
|
||||
auto &encoding = _fix_data.create_encoding;
|
||||
|
||||
using namespace jetfix;
|
||||
|
||||
// price, quantity, transact time will all be changing on every order update
|
||||
_fix_data.create_price_bm = encoding.add<fix::Price> (0,PriceFieldSz);
|
||||
_fix_data.create_quantity_bm = encoding.add<fix::OrderQty> (0,SizeFieldSz);
|
||||
_fix_data.create_price_bm = encoding.add<fix::Price> (0,price_sz());
|
||||
_fix_data.create_quantity_bm = encoding.add<fix::OrderQty> (0,quantity_sz());
|
||||
_fix_data.create_transact_time_bm =
|
||||
encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
|
||||
|
||||
@@ -58,6 +51,7 @@ void NativeOrder::init_create_fix()
|
||||
encoding.add<fix::Side> (_header.side);
|
||||
encoding.add<fix::TimeInForce> (_header.time_in_force);
|
||||
encoding.add<fix::OrdType> (_header.order_type);
|
||||
encoding.add<fix::ManualOrderIndicator> (_header.manual_order_indicator);
|
||||
encoding.add<fix::CustomerOrFirm> (_header.customer_or_firm);
|
||||
encoding.add<fix::CtiCode> (_header.cti_code);
|
||||
encoding.add<fix::SecurityDesc> (_header.security->glbx().security_desc());
|
||||
@@ -69,7 +63,7 @@ void NativeOrder::init_create_fix()
|
||||
|
||||
void NativeOrder::init_cancel_fix()
|
||||
{
|
||||
auto &encoding = _fix_data.update_encoding;
|
||||
auto &encoding = _fix_data.cancel_encoding;
|
||||
|
||||
using namespace jetfix;
|
||||
|
||||
@@ -81,18 +75,14 @@ void NativeOrder::init_cancel_fix()
|
||||
encoding.add<fix::Side> (_header.side);
|
||||
encoding.add<fix::TimeInForce> (_header.time_in_force);
|
||||
encoding.add<fix::OrdType> (_header.order_type);
|
||||
encoding.add<fix::CustomerOrFirm> (_header.customer_or_firm);
|
||||
encoding.add<fix::CtiCode> (_header.cti_code);
|
||||
encoding.add<fix::ManualOrderIndicator> (_header.manual_order_indicator);
|
||||
encoding.add<fix::SecurityDesc> (_header.security->glbx().security_desc());
|
||||
|
||||
std::string clordid(clordid_sz(),' ');
|
||||
encode_clorid(_header.order_key,SecurityKey(_header.security->id()),&clordid);
|
||||
encoding.add<fix::ClOrdID> (clordid);
|
||||
|
||||
// if we have an exchange order id use it, otherwise we will
|
||||
// do it when get our first execution report
|
||||
if (_state.exchange_order_id)
|
||||
update_exchange_order_id(*_state.exchange_order_id);
|
||||
encoding.add<fix::OrigClOrdID> (clordid);
|
||||
encoding.add<fix::CorrelationClOrdID> (clordid);
|
||||
}
|
||||
|
||||
void NativeOrder::init_fix()
|
||||
|
||||
@@ -50,24 +50,25 @@ public:
|
||||
};
|
||||
|
||||
_state = NativeOrderState {
|
||||
Price(pb.price()),
|
||||
Quantity(pb.order_quantity()),
|
||||
Price(pb.last_price()),
|
||||
Price(pb.avg_price()),
|
||||
Quantity(pb.order_quantity()),
|
||||
Quantity(pb.filled_quantity()),
|
||||
pb.order_status(),
|
||||
&_exchange_order_id,
|
||||
nullptr,
|
||||
nullptr
|
||||
};
|
||||
|
||||
if (reject_msg)
|
||||
set_reject_msg(*reject_msg);
|
||||
|
||||
init_fix();
|
||||
|
||||
if (pb.exchange_order_id().size())
|
||||
update_exchange_order_id(to<ExchangeOrderID>(pb.exchange_order_id()));
|
||||
else
|
||||
_state.exchange_order_id = nullptr;
|
||||
|
||||
init_fix();
|
||||
}
|
||||
|
||||
NativeOrder(NativeOrderHeader const&header) :
|
||||
@@ -77,8 +78,8 @@ public:
|
||||
_exchange_order_id(),
|
||||
_keep_alive_rej()
|
||||
{
|
||||
_state.exchange_order_id = nullptr;
|
||||
init_fix();
|
||||
_state.exchange_order_id = nullptr;
|
||||
}
|
||||
|
||||
void mark_rejected_by_spark(std::string const&msg)
|
||||
@@ -107,9 +108,10 @@ public:
|
||||
// no ops
|
||||
return false;
|
||||
default: {
|
||||
_state.price = er.data->price;
|
||||
_state.order_quantity = er.data->order_quantity;
|
||||
_state.last_price = er.data->last_price;
|
||||
_state.avg_price = er.data->avg_price;
|
||||
_state.order_quantity = er.data->order_quantity;
|
||||
_state.filled_quantity = er.data->filled_quantity;
|
||||
_state.order_status = er.data->order_status;
|
||||
if (er.data->reject_msg.size())
|
||||
@@ -148,6 +150,7 @@ public:
|
||||
|
||||
auto &f = stream->new_msg(jetfix::MessageTypes::NewOrderSingle);
|
||||
f.append(_fix_data.create_encoding);
|
||||
stream->close();
|
||||
}
|
||||
|
||||
void encode_update(OrderTimeStamp const&ts,Price p,Quantity q, jetfix::FIXEncodingStream *stream)
|
||||
@@ -175,6 +178,7 @@ public:
|
||||
|
||||
auto &f = stream->new_msg(jetfix::MessageTypes::CancelReplace);
|
||||
f.append(_fix_data.update_encoding);
|
||||
stream->close();
|
||||
}
|
||||
|
||||
void encode_cancel(OrderTimeStamp const&ts,jetfix::FIXEncodingStream *stream)
|
||||
@@ -188,8 +192,9 @@ public:
|
||||
encoding.overwrite(_fix_data.cancel_transact_time_bm,
|
||||
&ts.value()[0],ts.value().size());
|
||||
|
||||
auto &f = stream->new_msg(jetfix::MessageTypes::CancelReplace);
|
||||
auto &f = stream->new_msg(jetfix::MessageTypes::Cancel);
|
||||
f.append(_fix_data.cancel_encoding);
|
||||
stream->close();
|
||||
}
|
||||
|
||||
OrderKey key() const {return _header.order_key;}
|
||||
|
||||
@@ -11,9 +11,10 @@ namespace orderman {
|
||||
class NativeOrderState
|
||||
{
|
||||
public:
|
||||
Price price;
|
||||
Quantity order_quantity;
|
||||
Price last_price;
|
||||
Price avg_price;
|
||||
Quantity order_quantity;
|
||||
Quantity filled_quantity;
|
||||
api::orderman::OrderStatus order_status;
|
||||
ExchangeOrderID const *exchange_order_id;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "lib/api/public/ServiceContext.h"
|
||||
#include "server/sparkd/event_grid/events/Init.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
@@ -101,18 +102,18 @@ struct FastExecutor {
|
||||
// in
|
||||
node.observe<event::OutGatewayMsg> ([this] (const auto &ev) { gw.on(ev);});
|
||||
// out
|
||||
gw.execution_report_signal = [this] (auto const &ev) {node.send(ev);};
|
||||
gw.cancel_reject_signal = [this] (auto const &ev) {node.send(ev);};
|
||||
gw.gateway_status_change_signal = [this] (auto const &ev) {node.send(ev);};
|
||||
gw.gateway_begin_replay_signal = [this] (auto const &ev) {node.send(ev);};
|
||||
gw.gateway_end_replay_signal = [this] (auto const &ev) {node.send(ev);};
|
||||
gw.execution_report_signal = [this] (auto const &ev) {node.send<event::ExecutionReport>(ev);};
|
||||
gw.cancel_reject_signal = [this] (auto const &ev) {node.send<event::CancelReject>(ev);};
|
||||
gw.gateway_status_change_signal = [this] (auto const &ev) {node.send<event::GatewayStatusChange>(ev);};
|
||||
gw.gateway_begin_replay_signal = [this] (auto const &ev) {node.send<event::GatewayBeginReplay>(ev);};
|
||||
gw.gateway_end_replay_signal = [this] (auto const &ev) {node.send<event::GatewayEndReplay>(ev);};
|
||||
|
||||
|
||||
// wiring up md
|
||||
// in
|
||||
node.observe<event::MDSubscription> ([this] (const auto &ev) {md.on(ev);});
|
||||
// out
|
||||
md.book_update_signal = [this] (auto const&ev) {node.send(ev);};
|
||||
md.book_update_signal = [this] (auto const&ev) {node.send<event::BookUpdate>(ev);};
|
||||
|
||||
// wiring up order_man
|
||||
// in
|
||||
@@ -128,8 +129,8 @@ struct FastExecutor {
|
||||
node.observe<event::TimeChange> ([this] (const auto &ev) {order_man.on(ev);});
|
||||
|
||||
// out
|
||||
order_man.out_gateway_msg_signal = [this] (auto const &ev) {node.send(ev);};
|
||||
order_man.native_order_state_change_signal = [this] (auto const &ev) {node.send(ev);};
|
||||
order_man.out_gateway_msg_signal = [this] (auto const &ev) {node.send<event::OutGatewayMsg>(ev);};
|
||||
order_man.native_order_state_change_signal = [this] (auto const &ev) {node.send<event::NativeOrderStateChange>(ev);};
|
||||
}
|
||||
|
||||
~FastExecutor()
|
||||
@@ -175,15 +176,20 @@ struct SlowExecutor {
|
||||
worker()
|
||||
{
|
||||
// time source
|
||||
time_source.time_update_signal = [this] (const auto &ev) { node.send(ev);};
|
||||
time_source.time_change_signal = [this] (const auto &ev) { node.send<event::TimeChange>(ev);};
|
||||
|
||||
// fill storage
|
||||
node.observe<event::ExecutionReport> ([this] (const auto &ev) {fill_recorder.on(ev);});
|
||||
node.observe<event_grid::event::Init> ([this] (const auto &ev) {fill_recorder.on(ev);});
|
||||
|
||||
// order storage
|
||||
// order storage
|
||||
node.observe<event::NativeOrderStateChange> ([this] (const auto &ev) {order_recorder.on(ev);});
|
||||
node.observe<event_grid::event::Init> ([this] (const auto &ev) {order_recorder.on(ev);});
|
||||
|
||||
// order PB publication
|
||||
order_recorder.order_state_change_signal = [this] (const auto &ev) { node.send<event::OrderStateChange>(ev);};
|
||||
// fill PB publication
|
||||
fill_recorder.native_fill_signal = [this] (const auto &ev) { node.send<event::NativeFills>(ev);};
|
||||
}
|
||||
|
||||
~SlowExecutor()
|
||||
@@ -266,6 +272,7 @@ OrderServiceServer::OrderServiceServer (bts::api::ServiceContext& ctx)
|
||||
|
||||
me->slow.node.observe<event::OrderStateChange> ([&ctx,this] (auto const&os) {
|
||||
ctx.post([this,os] () {
|
||||
LOG(OrderMan,Info,"Post Received order update for publishing");
|
||||
this->on_order_updates(os);
|
||||
});
|
||||
});
|
||||
@@ -311,6 +318,7 @@ void OrderServiceServer::on_fills(event::NativeFills const&f)
|
||||
|
||||
void OrderServiceServer::on_order_updates(event::OrderStateChange const&os)
|
||||
{
|
||||
LOG(OrderMan,Info,"Received order update for publishing");
|
||||
std::vector<api::orderman::OrderState> created;
|
||||
created.reserve(os.state.size());
|
||||
std::vector<api::orderman::OrderState> updated;
|
||||
@@ -411,7 +419,7 @@ void OrderServiceServer::create_order(const api::orderman::CreateOrderRequest& r
|
||||
new NativeOrder(header)
|
||||
};
|
||||
|
||||
me->fast.node.send(ev);
|
||||
me->fast.node.send<event::CreateNativeOrder>(ev);
|
||||
|
||||
resp.set_order_key(header.order_key.value());
|
||||
resp.set_error_code(api::orderman::OE_OK);
|
||||
@@ -445,7 +453,7 @@ void OrderServiceServer::cancel_order(const api::orderman::CancelOrderRequest& c
|
||||
|
||||
|
||||
auto ev = event::CancelNativeOrder {it->second};
|
||||
me->fast.node.send(ev);
|
||||
me->fast.node.send<event::CancelNativeOrder>(ev);
|
||||
resp.set_error_code(api::orderman::OE_OK);
|
||||
on_reply(resp);
|
||||
}
|
||||
@@ -484,7 +492,7 @@ void OrderServiceServer::update_order(const api::orderman::UpdateOrderRequest& u
|
||||
}
|
||||
|
||||
auto ev = event::UpdateNativeOrder {Price(native.price()),Quantity(native.quantity()),it->second};
|
||||
me->fast.node.send(ev);
|
||||
me->fast.node.send<event::UpdateNativeOrder>(ev);
|
||||
resp.set_error_code(api::orderman::OE_OK);
|
||||
on_reply(resp);
|
||||
}
|
||||
|
||||
@@ -118,9 +118,9 @@ SqliteStore::Data SqliteStore::retrieve_all() {
|
||||
|
||||
int sqlite_result;
|
||||
do {
|
||||
sqlite3_stmt* pq = query.get();
|
||||
auto pq = query.get();
|
||||
sqlite_result = sqlite3_step(pq);
|
||||
if (sqlite_result == SQLITE_ROW || sqlite_result == SQLITE_DONE) {
|
||||
if (sqlite_result == SQLITE_ROW ) {
|
||||
std::string ns((char*)sqlite3_column_text(pq, 0), sqlite3_column_bytes(pq, 0));
|
||||
std::string key((char*)sqlite3_column_text(pq, 1), sqlite3_column_bytes(pq, 1));
|
||||
std::string val((char*)sqlite3_column_blob(pq, 2), sqlite3_column_bytes(pq, 2));
|
||||
@@ -134,23 +134,20 @@ SqliteStore::Data SqliteStore::retrieve_all() {
|
||||
|
||||
std::pair<bool,std::string> SqliteStore::retrieve_one(std::string const&ns, std::string const&k)
|
||||
{
|
||||
auto query_str = fmt::format ("select ns,key,value from store where ns='{}' and k='{}'", ns,k);
|
||||
auto query_str = fmt::format ("select ns,key,value from store where ns='{}' and key='{}'", ns,k);
|
||||
sqlite3_stmt_ptr query = utils::prepare_query(me->conn,query_str.c_str());
|
||||
|
||||
std::pair<bool,std::string> result {false,""};
|
||||
|
||||
int sqlite_result;
|
||||
do {
|
||||
sqlite3_stmt* pq = query.get();
|
||||
sqlite_result = sqlite3_step(pq);
|
||||
if (sqlite_result == SQLITE_ROW || sqlite_result == SQLITE_DONE) {
|
||||
std::string ns((char*)sqlite3_column_text(pq, 0), sqlite3_column_bytes(pq, 0));
|
||||
std::string key((char*)sqlite3_column_text(pq, 1), sqlite3_column_bytes(pq, 1));
|
||||
std::string val((char*)sqlite3_column_blob(pq, 2), sqlite3_column_bytes(pq, 2));
|
||||
result.first = true;
|
||||
result.second = std::move(val);
|
||||
}
|
||||
} while(sqlite_result == SQLITE_ROW);
|
||||
auto pq = query.get();
|
||||
auto sqlite_result = sqlite3_step(pq);
|
||||
if (sqlite_result == SQLITE_ROW ) {
|
||||
std::string ns((char*)sqlite3_column_text(pq, 0), sqlite3_column_bytes(pq, 0));
|
||||
std::string key((char*)sqlite3_column_text(pq, 1), sqlite3_column_bytes(pq, 1));
|
||||
std::string val((char*)sqlite3_column_blob(pq, 2), sqlite3_column_bytes(pq, 2));
|
||||
result.first = true;
|
||||
result.second = std::move(val);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace spreader
|
||||
SimpleSpreader();
|
||||
virtual ~SimpleSpreader();
|
||||
|
||||
SpreaderSubscriptions init(orderman::OrderKey my_key, const SpreaderCreate&);
|
||||
SpreaderSubscriptions init(orderman::OrderKey my_key, const SpreaderCreate&) override;
|
||||
void on_connect() override;
|
||||
void on_disconnect() override;
|
||||
void on_md(const orderman::Book&) override;
|
||||
@@ -82,4 +82,4 @@ namespace spreader
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,17 +7,17 @@ namespace bts {
|
||||
namespace spreader {
|
||||
|
||||
SingleFillHedger::SingleFillHedger(ISpreaderManager& spreader_manager,
|
||||
size_t leg_index,
|
||||
size_t, //leg_index,
|
||||
const OrderTemplate& order_template,
|
||||
const LegPropertyData& leg_property_data,
|
||||
const LegPropertyData&, //leg_property_data,
|
||||
bts::Price hedge_price,
|
||||
bts::Quantity hedge_quantity,
|
||||
api::BuySell hedge_side)
|
||||
:
|
||||
_spreader_manager(spreader_manager),
|
||||
_leg_index (leg_index),
|
||||
// _leg_index (leg_index),
|
||||
_order_template (order_template),
|
||||
_leg_property_data (leg_property_data),
|
||||
// _leg_property_data (leg_property_data),
|
||||
_price_quantity_state(hedge_price, hedge_quantity, hedge_side),
|
||||
_state(HedgerState::START)
|
||||
{
|
||||
|
||||
@@ -110,9 +110,9 @@ class SingleFillHedger
|
||||
|
||||
private:
|
||||
ISpreaderManager& _spreader_manager;
|
||||
const size_t _leg_index;
|
||||
//const size_t _leg_index;
|
||||
const OrderTemplate& _order_template;
|
||||
const LegPropertyData& _leg_property_data;
|
||||
// const LegPropertyData& _leg_property_data;
|
||||
HedgePriceQuantityState _price_quantity_state;
|
||||
HedgerState _state;
|
||||
bts::orderman::OrderKey _order_key;
|
||||
|
||||
@@ -407,7 +407,6 @@ void SingleLegQuoter::_compute_price_quantity(Price& price, Quantity& quantity)
|
||||
if (_aux_comp_data.at(min_quoter_leg_quantity_index).quoter_leg_quantity.value() <= quoter_leg_quantity.value())
|
||||
min_quoter_leg_quantity_index = idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
quantity = _aux_comp_data.at(min_quoter_leg_quantity_index).quoter_leg_quantity;
|
||||
price = _compute_leg_price(_aux_comp_data);
|
||||
@@ -436,4 +435,4 @@ double SingleLegQuoter::_get_equivelant_quantity(size_t leg_index, Quantity quan
|
||||
return static_cast<double> (quantity.value() * this_leg_data.leg_contract.quantity() / leg_data.leg_contract.quantity());
|
||||
}
|
||||
|
||||
}}
|
||||
}}
|
||||
@@ -0,0 +1,7 @@
|
||||
@setlocal
|
||||
@echo off
|
||||
cd %~dp0\..
|
||||
@call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" > nul
|
||||
cd %~dp0\..
|
||||
msbuild /m /p:platform=x64 /clp:verbosity=minimal /clp:summary spark_server.sln
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
cd %~dp0\..
|
||||
Reference in new issue
Block a user