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); }
/// <summary> /// Generate a stop order for a position, at a specified per-share/contract price /// </summary> /// <param name="p">your position</param> /// <param name="offset">how far away stop is</param> /// <param name="percent">what percent of position to close</param> /// <param name="normalizesize">whether to normalize size to even-lots</param> /// <param name="MINSIZE">size of an even lot</param> /// <returns></returns> public static Order PositionStop(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 * -1); int size = percent == 0 ? 0 : (!normalizesize ? (int)(p.FlatSize * percent) : Calc.Norm2Min(p.FlatSize * percent, MINSIZE)); o = new StopOrder(p.FullSymbol, p.isLong ? -size : size, price); return o; }