/// <summary> /// Send an exercise order to the transaction handler /// </summary> /// <param name="optionSymbol">String symbol for the option position</param> /// <param name="quantity">Quantity of options contracts</param> /// <param name="asynchronous">Send the order asynchrously (false). Otherwise we'll block until it fills</param> /// <param name="tag">String tag for the order (optional)</param> public OrderTicket ExerciseOption(Symbol optionSymbol, int quantity, bool asynchronous = false, string tag = "") { var option = (Option)Securities[optionSymbol]; var request = CreateSubmitOrderRequest(OrderType.OptionExercise, option, quantity, tag, DefaultOrderProperties?.Clone()); // If warming up, do not submit if (IsWarmingUp) { return OrderTicket.InvalidWarmingUp(Transactions, request); } //Initialize the exercise order parameters var preOrderCheckResponse = PreOrderChecks(request); if (preOrderCheckResponse.IsError) { return OrderTicket.InvalidSubmitRequest(Transactions, request, preOrderCheckResponse); } //Add the order and create a new order Id. var ticket = Transactions.AddOrder(request); // Wait for the order event to process, only if the exchange is open if (!asynchronous) { Transactions.WaitForOrder(ticket.OrderId); } return ticket; }
/// <summary> /// Market on close order implementation: Send a market order when the exchange closes /// </summary> /// <param name="symbol">The symbol to be ordered</param> /// <param name="quantity">The number of shares to required</param> /// <param name="tag">Place a custom order property or tag (e.g. indicator data).</param> /// <returns>The order ID</returns> public OrderTicket MarketOnCloseOrder(Symbol symbol, decimal quantity, string tag = "") { var security = Securities[symbol]; var request = CreateSubmitOrderRequest(OrderType.MarketOnClose, security, quantity, tag, DefaultOrderProperties?.Clone()); var response = PreOrderChecks(request); if (response.IsError) { return OrderTicket.InvalidSubmitRequest(Transactions, request, response); } return Transactions.AddOrder(request); }
/// <summary> /// Send a stop limit order to the transaction handler: /// </summary> /// <param name="symbol">String symbol for the asset</param> /// <param name="quantity">Quantity of shares for limit order</param> /// <param name="stopPrice">Stop price for this order</param> /// <param name="limitPrice">Limit price to fill this order</param> /// <param name="tag">String tag for the order (optional)</param> /// <returns>Order id</returns> public OrderTicket StopLimitOrder(Symbol symbol, decimal quantity, decimal stopPrice, decimal limitPrice, string tag = "") { var security = Securities[symbol]; var request = CreateSubmitOrderRequest(OrderType.StopLimit, security, quantity, tag, stopPrice: stopPrice, limitPrice: limitPrice, properties: DefaultOrderProperties?.Clone()); var response = PreOrderChecks(request); if (response.IsError) { return OrderTicket.InvalidSubmitRequest(Transactions, request, response); } //Add the order and create a new order Id. return Transactions.AddOrder(request); }
/// <summary> /// Market order implementation: Send a market order and wait for it to be filled. /// </summary> /// <param name="symbol">Symbol of the MarketType Required.</param> /// <param name="quantity">Number of shares to request.</param> /// <param name="asynchronous">Send the order asynchrously (false). Otherwise we'll block until it fills</param> /// <param name="tag">Place a custom order property or tag (e.g. indicator data).</param> /// <returns>int Order id</returns> public OrderTicket MarketOrder(Symbol symbol, decimal quantity, bool asynchronous = false, string tag = "") { var security = Securities[symbol]; // check the exchange is open before sending a market order, if it's not open // then convert it into a market on open order if (!security.Exchange.ExchangeOpen) { var mooTicket = MarketOnOpenOrder(security.Symbol, quantity, tag); if (!_isMarketOnOpenOrderWarningSent) { var anyNonDailySubscriptions = security.Subscriptions.Any(x => x.Resolution != Resolution.Daily); if (mooTicket.SubmitRequest.Response.IsSuccess && !anyNonDailySubscriptions) { Debug("Warning: all market orders sent using daily data, or market orders sent after hours are automatically converted into MarketOnOpen orders."); _isMarketOnOpenOrderWarningSent = true; } } return mooTicket; } var request = CreateSubmitOrderRequest(OrderType.Market, security, quantity, tag, DefaultOrderProperties?.Clone()); // If warming up, do not submit if (IsWarmingUp) { return OrderTicket.InvalidWarmingUp(Transactions, request); } //Initialize the Market order parameters: var preOrderCheckResponse = PreOrderChecks(request); if (preOrderCheckResponse.IsError) { return OrderTicket.InvalidSubmitRequest(Transactions, request, preOrderCheckResponse); } //Add the order and create a new order Id. var ticket = Transactions.AddOrder(request); // Wait for the order event to process, only if the exchange is open if (!asynchronous) { Transactions.WaitForOrder(ticket.OrderId); } return ticket; }