public void Set(OrderPreview order) { this.OrderPrice.Note = Model.OrderSides.PriceKind(order.Side); this.OrderPrice.Value = order.OrderPrice?.ToString(); this.OrderPrice.Unit = order.BaseCurrency; this.StopLoss.Note = Model.OrderSides.PriceKind(Model.OrderSides.Inv(order.Side)); this.StopLoss.Value = order.StopLoss?.ToString(); this.StopLoss.Unit = order.BaseCurrency; this.TakeProfit.Note = Model.OrderSides.PriceKind(Model.OrderSides.Inv(order.Side)); this.TakeProfit.Value = order.TakeProfit?.ToString(); this.TakeProfit.Unit = order.BaseCurrency; this.StopLossWidth.Value = order.StopLossWidth?.ToString(); this.StopLossWidth.Unit = order.BaseCurrency; this.TakeProfitWidth.Value = order.TakeProfitWidth?.ToString(); this.TakeProfitWidth.Unit = order.BaseCurrency; this.RiskRewardRatio.Value = order.RiskRewardRatio?.ToString("0.0000"); this.RiskRatio.Note = order.RiskType.Name; this.RiskRatio.Value = order.RiskValue.ToString("G29"); this.RiskRatio.Unit = order.RiskType.Unit(order.Account); this.RiskAtAccountCurrency.Value = (order.RiskType == Model.RiskType.Fixed) ? "" : order.OrderRiskAccountCurrency?.ToString("0.0000"); this.RiskAtAccountCurrency.Unit = (order.RiskType == Model.RiskType.Fixed) ? "" : order.Account?.accountCurrency; this.RiskAtBaseCurrency.Value = (order.Account?.accountCurrency == order.BaseCurrency) ? "" : order.OrderRiskBaseCurrency?.ToString("0.0000"); this.RiskAtBaseCurrency.Unit = (order.Account?.accountCurrency == order.BaseCurrency) ? "" : order.BaseCurrency; this.OrderSize.Value = order.OrderSize.ToString(); this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); }
private void UpdateOrderPreview() { logger.Trace("update order preview"); var name = this.selectedInstrument.Value; var lines = (name == null) ? null : this.lines[name]; var instrument = (name == null) ? null : this.service.Instruments[name]; var price = instrument?.Price.Value; var account = this.service.Account.Value; this.buyOrder = new OrderPreview { Instrument = name, BaseCurrency = instrument?.BaseCurrency, Side = Model.OrderSide.Buy, OrderPrice = price?.ask, Mt4Price = lines?.Current?.Ask, Mt4StopLoss = lines?.StopLossBuy?.Bid, Mt4TakeProfit = lines?.TakeProfitBuy?.Bid, Account = account, RiskType = this.riskSetting.Type, RiskValue = this.riskSetting.Value, CurrencyRate = this.service.Transrate(1, account?.accountCurrency, instrument?.BaseCurrency), }; this.sellOrder = new OrderPreview { Instrument = name, BaseCurrency = instrument?.BaseCurrency, Side = Model.OrderSide.Sell, OrderPrice = price?.bid, Mt4Price = lines?.Current?.Bid, Mt4StopLoss = lines?.StopLossSell?.Ask, Mt4TakeProfit = lines?.TakeProfitSell?.Ask, Account = account, RiskType = this.riskSetting.Type, RiskValue = this.riskSetting.Value, CurrencyRate = this.service.Transrate(1, account?.accountCurrency, instrument?.BaseCurrency), }; Dispatcher.Invoke(() => { this.buyPreview.Set(this.buyOrder); this.sellPreview.Set(this.sellOrder); this.button_Buy.IsEnabled = this.buyOrder.OrderSize > 0; this.button_Sell.IsEnabled = this.sellOrder.OrderSize > 0; }); }