Order Commands and Placing an Order

Dec 30 2018
  • Order Commands and Placing an Order

  • NewSingleOrderRequestMessage class provides different static methods to create an order command to submit to a exchange gateway.

  • Market Order

  • private IVObject _iv = new IVObject("Instrument",
                                        "Tradable Instrument",
                                        true,
                                        InstrumentType.Futures | InstrumentType.Options,
                                        MarketDataType.All,
                                        OrderEventType.All);
    ..................
    int orderQty = 10;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateMarketOrder(-iv,
                                                                                                        OrderSide.Sell,
                                                                                                        TimeInForce.GFD,
                                                                                                        orderQty);
     
  • Limit Order
  • double limitPrice = 125.35;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateLimitOrder(_iv,
                                                                                                       OrderSide.Buy,
                                                                                                       TimeInForce.GFD,
                                                                                                       orderQty,
                                                                                                       limitPrice);
     
  • Stop Order
  • double stopPrice = 125.35;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateStopOrder(_iv,
                                                                                                      OrderSide.Buy,
                                                                                                      TimeInForce.GFD,
                                                                                                      orderQty,
                                                                                                      stopPrice);
     
  • Stop Limit Order
  • double limitPrice = 125.30;
    double stopPrice = 125.35;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateStopLimitOrder(_iv,
                                                                                                           OrderSide.Buy,
                                                                                                           TimeInForce.GFD,
                                                                                                           orderQty,
                                                                                                           limitPrice,
                                                                                                           stopPrice);
  • Sending New Order
  • Call SendNewOrder method passing your order command to place an order in a market. There is important property AppOrderID of class NewSingleOrderRequestMessage to retrieve a reference client order id which is used to refer to cancel or modify the order.

  • uint appOrderID = newSingleOrderRequest.AppOrderID;
    string errorString = string.Empty;
    if (!base.SendNewOrder(newSingleOrderRequest, out errorString))
    {
        base.TraceLogInfo("SendOrder failed." + " Reason : " + errorString);
    }
    else
    {
        base.TraceLogInfo ("SendOrder succeeded.");
    }
     
  • Sending Multi-Leg New Order
  • Most exchanges support native multi-leg order that allow trader to buy and sell number of different instrument with same underline simultaneously without placing a separate orders. Multi-legged orders is used in variety of trading strategies such as straddle trading, strangle trading, ratio spread and butterfly spread etc.

  • NewMultiLegOrderRequestMessage multilegRequest = new NewMultiLegOrderRequestMessage();
    multilegRequest.AddLeg(NewSingleOrderRequestMessage.CreateLimitOrder(
                                _ivObjectOptionOTMLeg,
                                OrderSide.Buy,
                                TimeInForce.IOC,
                                1,
                                otmOrderLimitPrice));
    multilegRequest.AddLeg(NewSingleOrderRequestMessage.CreateLimitOrder(
                                _ivObjectOptionATMLeg,
                                OrderSide.Sell,
                                TimeInForce.IOC,
                                2,
                                atmOrderLimitPrice));
    multilegRequest.AddLeg(NewSingleOrderRequestMessage.CreateLimitOrder(
                                _ivObjectOptionITMLeg,
                                OrderSide.Buy,
                                TimeInForce.IOC,
                                1,
                                itmOrderLimitPrice));
     string errorString = string.Empty;
     uint currentMultilegAppOrderID = multilegRequest.AppOrderID;
    if (!base.SendNewOrder(multilegRequest, out errorString))
    {
        currentMultilegAppOrderID = 0;
        base.TraceLogWarning("Multileg Order Request Failed. Reason:" + errorString);
    }
     
  • Sending Native Spread New Order
  • A spread is defined as the sale of one or more futures contracts and the purchase of one or more offsetting futures contracts. A spread tracks the difference between the price of whatever it is you are long and whatever it is you are short. Therefore the risk changes from that of price fluctuation to that of the difference between the two sides of the spread. Most exchanges support native spread contract that allow trader to buy and sell two contracts at differene of their price simultaneously without placing a separate orders

  • if (_ivInstrument.Instrument.InstrumentType == InstrumentType.Spread)
    {
        NewSpreadOrderRequestMessage newSpreadOrderRequestMessage = null;
        switch (orderType)
        {
            case OrderType.Market:
                newSpreadOrderRequestMessage =
                           NewSpreadOrderRequestMessage.CreateMarketOrder(_ivObject, orderSide, orderQty);
                break;
             case OrderType.Limit:
                 newSpreadOrderRequestMessage =
                           NewSpreadOrderRequestMessage.CreateLimitOrder(_ivObject, orderSide, orderQty, orderPrice);
                 break;
              case OrderType.Stop:
              case OrderType.StopLimit:
                  TraceLogError("OrderType is not spported for Spread Order.");
                   break;
           }
           if (newSpreadOrderRequestMessage != null)
           {
               string errorString = string.Empty;
               if (!SendNewOrder(newSpreadOrderRequestMessage, out errorString))
               {
                                TraceLogWarning("Order Sending Failed. Reason : " + errorString);
                       }
                       else
                       {
                           TraceLogInfo("Order Send. AppOrderID : " + newSpreadOrderRequestMessage.AppOrderID);
                        }
                   }
                }
     
  • Cancelling Pending Order
  • Create a CancelOrderRequestMessage command which takes client order id and exchange order id. Exchange order ID is identifier assigned by exchange on the acceptance of the order. Cancel can only be applied to accepted order. Call SendOrderCancellation method passing your cancel order command to cancel pending order from a market.

  • uint appOrderID = GetAppOrderID();
    string exchangeOrderID = GetExchangeOrderID();
    CancelOrderRequestMessage cancelRequest =
    CancelOrderRequestMessage.Create(_iv, appOrderID, exchangeOrderID);
    string errorString = string.Empty;
    if (!SendOrderCancellation(cancelRequest, out errorString))
    {
        base.TraceLogInfo("Cancel order failed." + " Reason : " + errorString);
    }
    else
    {
        base.TraceLogInfo ("Cancel order command routed.");
    }
     
  • Modify Open Order
  • To modify the attributes of pending order like target price, quantity or order type you need to create OrderModificationRequestMessage object and call a proper method on it to set the modifiable attributes.

  • uint appOrderID = GetAppOrderID();
    string exchangeOrderID = GetExchangeOrderID();
    OrderModificationRequestMessage modifyOrder = OrderModificationRequestMessage.Create(iv, appOrderID, exchangeOrderID);
    // Modify limit order price
    modifyOrder.SetPrice(limitOrderPrice);
    string errorString = string.Empty;
    if (!SendOrderModification(modifyOrder, out errorString))
    {
        base.TraceLogInfo("Order modification failed." + " Reason : " + errorString);
    }
    else
    {
        base.TraceLogInfo ("Order modification command routed.");
    }
    //Following is available method to change the specific attribute of the order:
    public void SetOrderType(OrderType orderType)
    public void SetQuantity(uint quantity)
    public void SetDisclosedQuantity(uint quantity)
    public void SetMinimumQuantity(uint quantity)
    public void SetPrice(double limitPrice)
    public void SetStopPrice(double stopPrice)
    public void SetOrderValidity(TimeInForce timeInForce)
    public void SetOrderValidity(DateTime orderExpiryDate)
     
 
  • Order Commands and Placing an Order

  • NewSingleOrderRequestMessage class provides different static methods to create an order command to submit to a exchange gateway.

  • Market Order

  • private IVObject _iv = new IVObject("Instrument",
                                        "Tradable Instrument",
                                        true,
                                        InstrumentType.Futures | InstrumentType.Options,
                                        MarketDataType.All,
                                        OrderEventType.All);
    ..................
    int orderQty = 10;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateMarketOrder(-iv,
                                                                                                        OrderSide.Sell,
                                                                                                        TimeInForce.GFD,
                                                                                                        orderQty);

     

  • Limit Order
  • double limitPrice = 125.35;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateLimitOrder(_iv,
                                                                                                       OrderSide.Buy,
                                                                                                       TimeInForce.GFD,
                                                                                                       orderQty,
                                                                                                       limitPrice);

     

  • Stop Order
  • double stopPrice = 125.35;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateStopOrder(_iv,
                                                                                                      OrderSide.Buy,
                                                                                                      TimeInForce.GFD,
                                                                                                      orderQty,
                                                                                                      stopPrice);

     

  • Stop Limit Order
  • double limitPrice = 125.30;
    double stopPrice = 125.35;
    NewSingleOrderRequestMessage newSingleOrderRequest = NewSingleOrderRequestMessage.CreateStopLimitOrder(_iv,
                                                                                                           OrderSide.Buy,
                                                                                                           TimeInForce.GFD,
                                                                                                           orderQty,
                                                                                                           limitPrice,
                                                                                                           stopPrice);
  • Sending New Order
  • Call SendNewOrder method passing your order command to place an order in a market. There is important property AppOrderID of class NewSingleOrderRequestMessage to retrieve a reference client order id which is used to refer to cancel or modify the order.

  • uint appOrderID = newSingleOrderRequest.AppOrderID;
    string errorString = string.Empty;
    if (!base.SendNewOrder(newSingleOrderRequest, out errorString))
    {
        base.TraceLogInfo("SendOrder failed." + " Reason : " + errorString);
    }
    else
    {
        base.TraceLogInfo ("SendOrder succeeded.");
    }

     

  • Sending Multi-Leg New Order
  • Most exchanges support native multi-leg order that allow trader to buy and sell number of different instrument with same underline simultaneously without placing a separate orders. Multi-legged orders is used in variety of trading strategies such as straddle trading, strangle trading, ratio spread and butterfly spread etc.

  • NewMultiLegOrderRequestMessage multilegRequest = new NewMultiLegOrderRequestMessage();
    multilegRequest.AddLeg(NewSingleOrderRequestMessage.CreateLimitOrder(
                                _ivObjectOptionOTMLeg,
                                OrderSide.Buy,
                                TimeInForce.IOC,
                                1,
                                otmOrderLimitPrice));
    multilegRequest.AddLeg(NewSingleOrderRequestMessage.CreateLimitOrder(
                                _ivObjectOptionATMLeg,
                                OrderSide.Sell,
                                TimeInForce.IOC,
                                2,
                                atmOrderLimitPrice));
    multilegRequest.AddLeg(NewSingleOrderRequestMessage.CreateLimitOrder(
                                _ivObjectOptionITMLeg,
                                OrderSide.Buy,
                                TimeInForce.IOC,
                                1,
                                itmOrderLimitPrice));
     string errorString = string.Empty;
     uint currentMultilegAppOrderID = multilegRequest.AppOrderID;
    if (!base.SendNewOrder(multilegRequest, out errorString))
    {
        currentMultilegAppOrderID = 0;
        base.TraceLogWarning("Multileg Order Request Failed. Reason:" + errorString);
    }

     

  • Sending Native Spread New Order
  • A spread is defined as the sale of one or more futures contracts and the purchase of one or more offsetting futures contracts. A spread tracks the difference between the price of whatever it is you are long and whatever it is you are short. Therefore the risk changes from that of price fluctuation to that of the difference between the two sides of the spread. Most exchanges support native spread contract that allow trader to buy and sell two contracts at differene of their price simultaneously without placing a separate orders

  • if (_ivInstrument.Instrument.InstrumentType == InstrumentType.Spread)
    {
        NewSpreadOrderRequestMessage newSpreadOrderRequestMessage = null;
        switch (orderType)
        {
            case OrderType.Market:
                newSpreadOrderRequestMessage =
                           NewSpreadOrderRequestMessage.CreateMarketOrder(_ivObject, orderSide, orderQty);
                break;
             case OrderType.Limit:
                 newSpreadOrderRequestMessage =
                           NewSpreadOrderRequestMessage.CreateLimitOrder(_ivObject, orderSide, orderQty, orderPrice);
                 break;
              case OrderType.Stop:
              case OrderType.StopLimit:
                  TraceLogError("OrderType is not spported for Spread Order.");
                   break;
           }
           if (newSpreadOrderRequestMessage != null)
           {
               string errorString = string.Empty;
               if (!SendNewOrder(newSpreadOrderRequestMessage, out errorString))
               {
                                TraceLogWarning("Order Sending Failed. Reason : " + errorString);
                       }
                       else
                       {
                           TraceLogInfo("Order Send. AppOrderID : " + newSpreadOrderRequestMessage.AppOrderID);
                        }
                   }
                }

     

  • Cancelling Pending Order
  • Create a CancelOrderRequestMessage command which takes client order id and exchange order id. Exchange order ID is identifier assigned by exchange on the acceptance of the order. Cancel can only be applied to accepted order. Call SendOrderCancellation method passing your cancel order command to cancel pending order from a market.

  • uint appOrderID = GetAppOrderID();
    string exchangeOrderID = GetExchangeOrderID();
    CancelOrderRequestMessage cancelRequest =
    CancelOrderRequestMessage.Create(_iv, appOrderID, exchangeOrderID);
    string errorString = string.Empty;
    if (!SendOrderCancellation(cancelRequest, out errorString))
    {
        base.TraceLogInfo("Cancel order failed." + " Reason : " + errorString);
    }
    else
    {
        base.TraceLogInfo ("Cancel order command routed.");
    }

     

  • Modify Open Order
  • To modify the attributes of pending order like target price, quantity or order type you need to create OrderModificationRequestMessage object and call a proper method on it to set the modifiable attributes.

  • uint appOrderID = GetAppOrderID();
    string exchangeOrderID = GetExchangeOrderID();
    OrderModificationRequestMessage modifyOrder = OrderModificationRequestMessage.Create(iv, appOrderID, exchangeOrderID);
    // Modify limit order price
    modifyOrder.SetPrice(limitOrderPrice);
    string errorString = string.Empty;
    if (!SendOrderModification(modifyOrder, out errorString))
    {
        base.TraceLogInfo("Order modification failed." + " Reason : " + errorString);
    }
    else
    {
        base.TraceLogInfo ("Order modification command routed.");
    }
    //Following is available method to change the specific attribute of the order:
    public void SetOrderType(OrderType orderType)
    public void SetQuantity(uint quantity)
    public void SetDisclosedQuantity(uint quantity)
    public void SetMinimumQuantity(uint quantity)
    public void SetPrice(double limitPrice)
    public void SetStopPrice(double stopPrice)
    public void SetOrderValidity(TimeInForce timeInForce)
    public void SetOrderValidity(DateTime orderExpiryDate)

     

Contact US

Let us help you to achieve your goals!

     

     

     

     

     

    By providing Symphony with your contact information Symphony will process your personal data for the purpose of providing you with the information you have requested. For more information regarding Symphony's processing of your personal data, please read Symphony's Privacy Notice here.


    • Get latest updates from Us