public void Add(BitmexPositionData pos, string instrument, MainWindowController wndCtrl) { var model = PositionModel.ToModel(pos, wndCtrl); _posModel[instrument] = model; Changed(this, new PositionControllerEventArgs(model)); }
internal void OnPositionChanged(BitmexPositionData pos) { if (pos.Leverage.HasValue) { ChangeControl(() => lblLeverage.Content = (int)pos.Leverage.Value + "x"); } if (pos.IsOpen.HasValue) { ChangeControl(() => gridClosePosition.IsEnabled = pos.IsOpen.Value); var posCtrl = _posController; var ctrl = MainWnd.Controller; if (pos.IsOpen.Value) { ctrl.Exchange.XbtPriceChanged += OnPriceChangedWhenPositionOpened; ctrl.Exchange.EthPriceChanged += OnPriceChangedWhenPositionOpened; ctrl.Exchange.LtcPriceChanged += OnPriceChangedWhenPositionOpened; ctrl.Exchange.EosPriceChanged += OnPriceChangedWhenPositionOpened; ctrl.Exchange.XrpPriceChanged += OnPriceChangedWhenPositionOpened; ctrl.Exchange.AdaPriceChanged += OnPriceChangedWhenPositionOpened; ctrl.Exchange.TrxPriceChanged += OnPriceChangedWhenPositionOpened; ctrl.Exchange.BchPriceChanged += OnPriceChangedWhenPositionOpened; ActualPositionSize = pos.PositionSize.Value; PositionSide = pos.PositionSide; posCtrl.Add(pos, pos.Symbol, ctrl); ChangeControl(() => { LogPositionEvent("OPENED " + pos.Symbol); tabPosition.SelectedIndex = 1; cbProfitPcnt1.SelectedIndex = 1; }); } else { ctrl.Exchange.XbtPriceChanged -= OnPriceChangedWhenPositionOpened; ctrl.Exchange.EthPriceChanged -= OnPriceChangedWhenPositionOpened; ctrl.Exchange.LtcPriceChanged -= OnPriceChangedWhenPositionOpened; ctrl.Exchange.EosPriceChanged -= OnPriceChangedWhenPositionOpened; ctrl.Exchange.XrpPriceChanged -= OnPriceChangedWhenPositionOpened; ctrl.Exchange.AdaPriceChanged -= OnPriceChangedWhenPositionOpened; ctrl.Exchange.TrxPriceChanged -= OnPriceChangedWhenPositionOpened; ctrl.Exchange.BchPriceChanged -= OnPriceChangedWhenPositionOpened; ChangeControl(() => { lblPriceStop.Content = "0.00"; tbTrailValue.Text = tbProfit1.Text = tbProfit2.Text = tbProfit3.Text = tbPositionSize.Text = String.Empty; cbProfitPcnt1.SelectedIndex = cbProfitPcnt2.SelectedIndex = cbProfitPcnt3.SelectedIndex = 0; tabPosition.SelectedIndex = 0; rbOrdTypeAuto.IsChecked = true; OpenPositionFee = null; if (_instrument != null && posCtrl.PositionOpened(_instrument)) { posCtrl.Remove(_instrument); LogPositionEvent("CLOSED " + pos.Symbol); } }); } } else { long?newSize = null; UpdateModel(pos.Symbol, model => { var posModel = PositionModel.ToModel(pos, MainWnd.Controller); newSize = model.Update(posModel, msg => { ChangeControl(() => { pos.Message = "Update " + msg; LogPositionEvent(pos.Message); }); }, () => { }); }); if (newSize.HasValue) { ActualPositionSize = newSize.Value; PositionSizeChanged(this, new PosWatcherEventArgs(ActualPositionSize)); } } }