public bool TakePosition(Symbol s, double price, Position.PositionSide side, double size, DateTime date) { //Check if we can take the position, based on margin requirement //If there's a position open for s, adjust position accordingly _positions.Add(s, new Position(s, price, size, side, date)); return true; }
public void PlaceMarketOrder(Symbol sym, int size, Position.PositionSide side, double stopPips = double.NaN, double LimitPips = double.NaN) { if (!currentOffers.ContainsKey(sym)) return; double orderPrice = side.Equals(Position.PositionSide.Long) ? currentOffers[sym].AskClose : currentOffers[sym].BidClose; //------------------------------------ // Take the position. //------------------------------------ _portfolio.TakePosition(sym, orderPrice, side, size, currentOffers[sym].Time); //------------------------------------ // Place Stop/Limits if defined //------------------------------------ if (!stopPips.Equals(double.NaN)) { StopOrder stopOrder = new StopOrder(sym, side, ((side.Equals(Position.PositionSide.Long)) ? orderPrice - stopPips : orderPrice + stopPips)); PlaceStopOrder(stopOrder); } if (!LimitPips.Equals(double.NaN)) { LimitOrder limitOrder = new LimitOrder(sym, side, ((side.Equals(Position.PositionSide.Long)) ? orderPrice + LimitPips : orderPrice - LimitPips)); PlaceLimitOrder(limitOrder); } //------------------------------------ // Flags for visualization purposes //------------------------------------ _flags.Add(new HighstockFlag( (side == Position.PositionSide.Long) ? "B" : "S", ((side == Position.PositionSide.Long) ? "Bought " : "Sold ") + size + " on " + side + " at " + orderPrice + " on " + currentOffers[sym].Time.ToString(), currentOffers[sym].Time )); //Console.WriteLine(order.OrderDate.ToString() + "ORDER--------"); }
public void PlaceMarketOrder(Symbol sym, int size, Position.PositionSide side, double stopPips, double LimitPips) { OrderPlacementEngine.OrderObject orderObject = _opEngine.prepareParamsFromLoginRules(sym.SymbolString); _opEngine.CreateTrueMarketOrder(orderObject.AccountID, orderObject.OfferID, size, (side.Equals(Position.PositionSide.Long)) ? "Buy" : "Sell"); }