private void OnPlaceOrder(object obj) 
        {
            Order _workingorder = null;

            switch (_selectedordertype)
            {
                case 0:
                    _workingorder = new MarketOrder(_fullsymbol, _selectedbuysell == 0 ? _size : -_size, _globalIdService.GetNextOrderId());
                    //_workingorder.StopPrice = 0;
                    //_workingorder.LimitPrice = 0;
                    break;
                case 1:
                    _workingorder = new LimitOrder(_fullsymbol, _selectedbuysell == 0 ? _size : -_size, _price, _globalIdService.GetNextOrderId());
                    //_workingorder.StopPrice = 0;
                    //_workingorder.LimitPrice = _price;
                    break;
                case 2:
                    _workingorder = new StopOrder(_fullsymbol, _selectedbuysell == 0 ? _size : -_size, _price, _globalIdService.GetNextOrderId());
                    //_workingorder.StopPrice = _price;
                    //_workingorder.LimitPrice = 0;
                    break;
                case 3:
                    _workingorder = new StopLimitOrder(_fullsymbol, _selectedbuysell == 0 ? _size : -_size, _price, _auxprice,_globalIdService.GetNextOrderId());
                    break;
                case 4:
                    _workingorder = new TrailingStopOrder(_fullsymbol, _selectedbuysell == 0 ? _size : -_size, _auxprice, _globalIdService.GetNextOrderId());
                    break;
                case 5:
                    _workingorder = new TrailingStopLimitOrder(_fullsymbol, _selectedbuysell == 0 ? _size : -_size, _price, _auxprice, _globalIdService.GetNextOrderId());
                    break;
            }

            _workingorder.OrderStatus = OrderStatus.PendingSubmit;
            _eventaggregator.GetEvent<SendOrderEvent>().Publish(_workingorder);
        }
Example #2
0
 /// <summary>
 /// Generates profit taking order for a given position, at a specified per-share profit target.  
 /// </summary>
 /// <param name="p">your position</param>
 /// <param name="offset">target price, per share/contract</param>
 /// <param name="percent">percent of the position to close with this order</param>
 /// <param name="normalizesize">whether to normalize order to be an even-lot trade</param>
 /// <param name="MINSIZE">size of an even lot</param>
 /// <returns></returns>
 public static Order PositionProfit(Position p, decimal offset, decimal percent, bool normalizesize, int MINSIZE)
 {
     Order o = new Order();
     if (!p.isValid || p.isFlat) return o;
     decimal price = Calc.OffsetPrice(p, offset);
     int size = percent == 0 ? 0 : (!normalizesize ? (int)(p.FlatSize * percent) : Calc.Norm2Min(p.FlatSize * percent, MINSIZE));
     o = new LimitOrder(p.FullSymbol, p.isLong ? -size : size, price);
     return o;
 }