/// <inheritdoc /> /// <summary> /// Update current limit order /// </summary> /// <param name="ticket"></param> public override void Update(UpdateOrderTicket ticket) { //Regular updates base.Update(ticket); //Set new limit price if (ticket.LimitPrice.HasValue) { LimitPrice = ticket.LimitPrice.Value; } }
/// <summary> /// Set data based on order update /// </summary> /// <param name="ticket"></param> public override void Update(UpdateOrderTicket ticket) { //Regular updates base.Update(ticket); //Set new values if (ticket.StopPrice.HasValue) { StopPrice = ticket.StopPrice.Value; } }
/// <summary> /// Update current order /// </summary> /// <param name="ticket"></param> public virtual void Update(UpdateOrderTicket ticket) { //Check if we have the correct order to update if (ticket.OrderId != InternalId) { throw new ArgumentException("Invalid order for update"); } //Check size adjustments if (ticket.Quantity.HasValue) { Quantity = ticket.Quantity.Value; } //Check comment if (!string.IsNullOrWhiteSpace(ticket.Comment)) { Comment = ticket.Comment; } }
/// <summary> /// Processes the update ticket. /// </summary> /// <param name="ticket">The ticket.</param> /// <param name="quantfund">Ticket associated quant fund</param> /// <returns></returns> private OrderTicket ProcessUpdateTicket(UpdateOrderTicket ticket, IQuantFund quantfund) { //Try and get current order ticket if (!OrderTracker.TryGetOrder(ticket.OrderId, out PendingOrder pendingorder)) { ticket.SetResponse(OrderTicketResponse.Error(ticket.OrderId, OrderTicketResponseErrorCode.UnableToFindOrder)); return(ticket); } try { //Try and process cancel ticket if (pendingorder.OrderState.IsDone()) { _log.Error($"Order is already of state {pendingorder.OrderState} while trying to update this order"); ticket.SetResponse(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.InvalidOrderStatus)); } else if (quantfund != null && quantfund.IsBackfilling) { ticket.SetResponse(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.QuantFundBackfilling)); } else { // send the request to be processed ticket.SetResponse(OrderTicketResponse.Processed(ticket.OrderId), OrderTicketState.Processing); _orderTicketQueue.Add(ticket); } } catch (Exception exc) { _log.Error(exc); ticket.SetResponse(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.ProcessingError, exc.Message)); } //Return what we have return(ticket); }
/// <summary> /// Submit update order /// </summary> /// <param name="ticket"></param> protected virtual OrderTicketResponse UpdateOrder(UpdateOrderTicket ticket) { //Get current pending order if (!OrderTracker.TryGetOrder(ticket.OrderId, out PendingOrder pendingorder)) { _log.Error($"Unable to retrieve order with id {ticket.OrderId} could not proceed"); return(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.UnableToFindOrder, $"Current order with id {pendingorder.OrderId} cannot be found")); } //Get the order var order = pendingorder.Order as OrderImpl; //Check if we can update this order if (!CanUpdateOrder(order)) { return(OrderTicketResponse.Error(order.InternalId, OrderTicketResponseErrorCode.InvalidOrderStatus, $"Unable to update order with id {order.InternalId} and current state {order.State}")); } //Check if we can process this order try { if (!Portfolio.BrokerModel.CanUpdateOrder(order, out string message)) { //Notify we cannot update this order order.State = OrderState.Invalid; var response = OrderTicketResponse.Error(order.InternalId, OrderTicketResponseErrorCode.BrokerageModelRefusedToUpdateOrder, $"Cannot update order {order.InternalId}: {message}"); Portfolio.Log(LogLevel.Error, response.ErrorMessage); HandleOrderTicketEvent(OrderTicketEvent.Error(order.InternalId, response.ErrorMessage)); return(response); } } catch (Exception exc) { _log.Error(exc, $"Could not run CanUpdateOrder on order with id {order.InternalId}, please check the implemented logic"); order.State = OrderState.Invalid; return(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.ProcessingError, $"Current order with id {pendingorder.OrderId} cannot be processed due to error")); } //Check order quantity and pricing in case this is out of range RoundLotSize(order); RoundOrderPrices(order); //Try and update this order bool orderupdatesucceeded = false; try { orderupdatesucceeded = BrokerConnection.UpdateOrder(pendingorder); } catch (Exception exc) { _log.Error(exc); } //Process a failed order update event if (!orderupdatesucceeded) { var errormessage = $"Broker connection failed to update order with id {order.InternalId} with connection type {BrokerConnection.BrokerType}"; Portfolio.Log(LogLevel.Error, errormessage); HandleOrderTicketEvent(OrderTicketEvent.Error(order.InternalId, "Failed to update order")); return(OrderTicketResponse.Error(order.InternalId, OrderTicketResponseErrorCode.BrokerageFailedToUpdateOrder, errormessage)); } else { //Apply updates to order order.Update(ticket); pendingorder.UpdateOrder(order); } return(OrderTicketResponse.Processed(order.InternalId)); }