private void OnPositionOpened(BitmexPositionData pos) { if (PositionState.GetStateName() != "Position") { ChangeStopLoss(pos.Symbol, pos.PositionSide, pos.PositionSize.Value, pos.AvgEntryPrice.Value); } }
private void SetPositionCost(BitmexPositionData pos) { if (pos.PosCost.HasValue) { this.Value = String.Format("{0} XBT", BitmexMargin.ToBtc(Math.Abs(pos.PosCost.Value), 5).ToString("0.00000")); } }
private void SetMargin(BitmexPositionData pos) { if (pos.PosMargin.HasValue) { this.PositionMargin = BitmexMargin.ToBtc(pos.PosMargin.Value, 5).ToString("0.00000") + " XBT"; } }
private void SetTimestamp(BitmexPositionData pos) { if (pos.Timestamp.HasValue) { this.Time = pos.Timestamp.Value.ToLocalTime().ToLongTimeString(); } }
private void SetLiquidationPrice(BitmexPositionData pos, MainWindowController ctrl) { if (pos.MarkPrice.HasValue && pos.LiquidationPrice.HasValue) { var diff = ToPrice(Math.Abs(pos.MarkPrice.Value - pos.LiquidationPrice.Value), ctrl); this.LiqPrice = String.Format("(+{0}) {1}", diff, ToPrice(pos.LiquidationPrice.Value, ctrl)); } }
private void SetSize(BitmexPositionData pos) { if (pos.PositionSize.HasValue) { _size = Math.Abs(pos.PositionSize.Value); this.Size = _size.Value.ToString(); } }
private void SetSide(BitmexPositionData pos) { if (pos.IsOpen.HasValue && pos.IsOpen.Value) { this.Side = pos.PositionSide; this.IsOpen = pos.IsOpen.Value; } }
private void SetProfit(BitmexPositionData pos) { if (pos.RealisedPnl.HasValue) { var value = BitmexMargin.ToBtc(pos.RealisedPnl.Value); this.RealisedProfit = String.Format("{0} XBT", value.ToString("0.00000000")); } }
public void Add(BitmexPositionData pos, string instrument, MainWindowController wndCtrl) { var model = PositionModel.ToModel(pos, wndCtrl); _posModel[instrument] = model; Changed(this, new PositionControllerEventArgs(model)); }
private void OnPositionClosed(BitmexPositionData pos) { if (!pos.Leverage.HasValue) { ResetState(); Controller.CancelAllOrders(pos.Symbol); } _stopObj = null; }
public static PositionModel ToModel(BitmexPositionData pos, MainWindowController wndCtrl) { var model = new PositionModel { Symbol = pos.Symbol }; model.InitModel(pos, wndCtrl); return(model); }
private void SetCommission(BitmexPositionData pos) { if (pos.Commission.HasValue) { this.Commision = pos.Commission.Value; if (pos.PositionSize.HasValue) { this.FeePaid = Math.Round(pos.Commission.Value * pos.PositionSize.Value, 8); } } }
public void InitModel(BitmexPositionData pos, MainWindowController wndCtrl) { SetSide(pos); SetSize(pos); SetPositionCost(pos); SetLiquidationPrice(pos, wndCtrl); SetPrices(pos, wndCtrl); SetMargin(pos); SetProfit(pos); SetTimestamp(pos); SetCommission(pos); }
private void SetPrices(BitmexPositionData pos, MainWindowController ctrl) { if (pos.AvgEntryPrice.HasValue) { this.EntryPrice = ctrl.ToStringPrice(pos.AvgEntryPrice.Value, this.Symbol); this.AvgEntryPrice = pos.AvgEntryPrice.Value; } if (pos.MarkPrice.HasValue) { this.MarkPrice = ToPrice(pos.MarkPrice.Value, ctrl); } if (pos.LastPrice.HasValue) { this.LastPrice = pos.LastPrice.Value; } }
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)); } } }