示例#1
0
        private void OnCloseMarketPositionClick(object sender, RoutedEventArgs e)
        {
            var pos  = _posController.GetPosition(_instrument);
            var qty  = Convert.ToInt64(pos.Size);
            var side = pos.Side == "Buy" ? "Sell" : "Buy";

            tbCloseSlip.Background = Brushes.White;

            MainWnd.HandleActionWithMetrics(btnCloseMarket, () => MainWnd.Controller.CreateCloseMarketOrder(_instrument, side, qty), "NEW ORD");
        }
示例#2
0
        private void OnCloseLimitPositionClick(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(tbCloseSlip.Text))
            {
                Warning("Slippage value is undefinfed."); return;
            }

            var pos       = _posController.GetPosition(_instrument);
            var side      = pos.Side == "Buy" ? "Sell" : "Buy";
            var qty       = Convert.ToInt64(pos.Size);
            var closeSlip = Convert.ToDouble(tbCloseSlip.Text) * _instrumentObj.TickSize;

            tbCloseSlip.Background = Brushes.White;

            MainWnd.HandleActionWithMetrics(btnCloseLimit, () => _posWatcher.BeginClosePosition(_instrument, side, qty, closeSlip), "NEW ORD");
        }
示例#3
0
        private void CreateStopLimitOrder(Button btn, string side)
        {
            double stopPx = 0;

            if (String.IsNullOrEmpty(tbPositionSize.Text))
            {
                Warning("Empty position size."); return;
            }
            if (String.IsNullOrEmpty(tbStopLimitPrice.Text))
            {
                Warning("Empty stop limit price."); return;
            }
            if (String.IsNullOrEmpty(tbStopPriceDelta.Text))
            {
                Warning("Empty trigger value"); return;
            }

            var    triggerDelta = ToPrice(tbStopPriceDelta.Text);
            var    price        = ToPrice(tbStopLimitPrice.Text);
            var    size         = Convert.ToInt32(tbPositionSize.Text);
            var    ctrl         = MainWnd.Controller;
            string text         = null;

            if (side == "Buy")
            {
                if (ctrl.GetBidPrice(_instrument) > price)
                {
                    Warning("Stop price is less than market for the buy."); return;
                }
                stopPx = price - triggerDelta;
            }
            else
            {
                if (price > ctrl.GetAskPrice(_instrument))
                {
                    Warning("Stop price is more than market for the sell."); return;
                }
                stopPx = price + triggerDelta;
            }
            if (!_posController.PositionOpened(_instrument))
            {
                text = "OPN";
            }
            MainWnd.HandleActionWithMetrics(btn, () => ctrl.CreateStopLimitOrder(_instrument, side, size, price, stopPx, false, text), "NEW STOP");
        }
示例#4
0
        private void CreateWatchingOrder(Button btn, string side)
        {
            if (PositionSize == 0)
            {
                Warning("Empty position size"); return;
            }

            var stopLoss = GetAlignedStopLoss(Convert.ToDouble(lblBidPrice.Content)); // stopLossPcnt.Value * Convert.ToDouble(lblBidPrice.Content) / 100;

            if (!stopLoss.HasValue)
            {
                return;
            }

            var priceSlip = ConvertValueFromString(tbPriceSlip.Text) * _instrumentObj.TickSize;
            var stopSlip  = StopSlip;

            MainWnd.HandleActionWithMetrics(btn, () => _posWatcher.BeginOpenPosition(_instrument, side, PositionSize, stopLoss.Value, priceSlip, stopSlip), "NEW ORD");
        }
示例#5
0
        private void CreateMarketOrder(Button btn, string side)
        {
            if (!_posController.PositionOpened(_instrument))
            {
                Error("This action shouldn't create a position."); return;
            }
            if (String.IsNullOrEmpty(tbPositionSize.Text))
            {
                Error("Empty position size."); return;
            }

            var    size = Convert.ToInt32(tbPositionSize.Text);
            string text = null;

            if (!_posController.PositionOpened(_instrument))
            {
                text = "OPN";
            }

            MainWnd.HandleActionWithMetrics(btn, () => MainWnd.Controller.CreateMarketOrder(_instrument, side, size, text), "NEW MARKET");
        }
示例#6
0
        private void CreateLimitOrder(Button btn, string side)
        {
            if (String.IsNullOrEmpty(tbPositionSize.Text))
            {
                Warning("Empty position size."); return;
            }
            if (String.IsNullOrEmpty(tbLimitPrice.Text))
            {
                Warning("Empty limit price."); return;
            }

            var    limitPrice = ToPrice(tbLimitPrice.Text);
            var    size       = Convert.ToInt32(tbPositionSize.Text);
            string text       = null;

            if (!_posController.PositionOpened(_instrument))
            {
                text = "OPN";
            }

            MainWnd.HandleActionWithMetrics(btn, () => MainWnd.Controller.CreateLimitOrder(_instrument, side, size, limitPrice, false, text), "NEW LIMIT");
        }
示例#7
0
        private void OnCreateTrailClick(object sender, RoutedEventArgs e)
        {
            string side = "Buy";

            if (String.IsNullOrEmpty(tbTrailValue.Text))
            {
                Warning("Empty trailing stop value"); return;
            }

            var trailValue = Convert.ToDouble(tbTrailValue.Text);
            var exchTrail  = cbExchTrail.IsChecked.Value;
            var qty        = CalcPositionSize(100);

            MainWnd.HandleActionWithMetrics((Button)sender, () =>
            {
                if (exchTrail)
                {
                    if (PositionSide == "Buy")
                    {
                        trailValue *= -1;
                        side        = "Sell";
                    }
                    var ordData     = MainWnd.Controller.Client.CreateTrailingStopOrder(_instrument, side, qty, trailValue);
                    _trailingStopId = ordData.OrderId;
                }
                else
                {
                    _posWatcher.PositionPriceChanged(trailValue);
                }
            },
                                            "TRAIL");

            if (exchTrail)
            {
                btnCancelTrail.IsEnabled = true;
            }
        }