public TradeTaskViewModel(SymbolInformation si, string exchangeName) { Model = new TradeTask(); Model.Id = Guid.NewGuid(); Model.Symbol = si.Symbol; Model.Exchange = exchangeName; SymbolInformation = si; QuoteBalance = si.QuoteAssetBalance.Free; QuoteBalancePercent = 0.05; Buy = new OrderTaskViewModel(this) { Price = si.PriceTicker.Ask.GetValueOrDefault() }; StopLoss = new OrderTaskViewModel(this) { Price = si.ClampPrice(Buy.Price * 0.95m) }; TakeProfit = new ObservableCollection <TakeProfitViewModel>(); var DEF_TAKE_PRCNTS = new double[] { 0.6, 0.4 }; for (int ind = 1; ind <= 2; ++ind) { var tp = new TakeProfitViewModel(this, DEF_TAKE_PRCNTS[ind - 1], ind > 1 ? TakeProfit[ind - 2] : null) { Price = Math.Round(Buy.Price * (1.05m + 0.05m * ind), si.PriceDecimals), Caption = $"Тейк {ind}" }; TakeProfit.Add(tp); } LastPrice = Buy.Price; AddTakeProfitCommand = ReactiveCommand.Create <object>(AddTakeProfitExecute); SubmitCommand = ReactiveCommand.CreateFromTask <string, bool>(SubmitImpl); ConnectTrades(edit: true); }
public TakeProfitViewModel(TradeTaskViewModel tt, OrderTask model, TakeProfitViewModel prev = null) : base(tt, model) { Previous = prev; if (Previous != null) { qtyPercentStart = Previous.QuantityPercentEnd; } qtyPercentEnd = qtyPercentStart + model.QuantityPercent; ConnectProperties(); }
private void AddTakeProfitExecute(object param) { int ind = TakeProfit.Count + 1; var tpQuantityPercent = TakeProfit.Sum(x => x.QuantityPercent); var tp = new TakeProfitViewModel(this, 1.00 - tpQuantityPercent, ind > 1 ? TakeProfit[ind - 2] : null) { Price = Math.Round(Buy.Price * (1.0m + 0.05m * ind), SymbolInformation.PriceDecimals), Caption = $"Тейк {ind}" }; TakeProfit.Add(tp); }
public TakeProfitViewModel(TradeTaskViewModel tt, double initialQtyPrcnt, TakeProfitViewModel prev = null) : base(tt) { Previous = prev; if (Previous != null) { QuantityPercentStart = Previous.QuantityPercentEnd; this.ObservableForProperty(x => x.Previous.QuantityPercentEnd).Subscribe(x => QuantityPercentStart = x.Value); } QuantityPercentEnd = QuantityPercentStart + initialQtyPrcnt; ConnectProperties(); }
public TradeTaskViewModel(SymbolInformation si, TradeTask model) { SymbolInformation = si; Model = model; Buy = new OrderTaskViewModel(this, model.Buy); StopLoss = new OrderTaskViewModel(this, model.StopLoss); TakeProfit = new ObservableCollection <TakeProfitViewModel>(); for (int ind = 1; ind <= model.TakeProfit.Count(); ++ind) { var tp = new TakeProfitViewModel(this, model.TakeProfit[ind - 1], ind > 1 ? TakeProfit[ind - 2] : null); TakeProfit.Add(tp); } LastPrice = si.PriceTicker.LastPrice.GetValueOrDefault(); ConnectTrades(); }