NinjaScript > Language Reference > Strategy >

IOrder

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
Represents a read only interface that exposes information regarding an order.

 

An IOrder object returned from calling an order method is dynamic in that its properties will always reflect the current state of an order
The property <IOrder>.OrderId is NOT a unique value since it can change throughout an order's lifetime
The property <IOrder>.Token is NOT a unique value since it will change as the strategy transitions from historical to real-time
The property <IOrder>.Oco WILL be appended with a suffix when the strategy transitions from historical to real-time to ensure the OCO id is unique across multiple strategies for live orders
To check for equality you can compare IOrder objects directly

 

Methods and Properties

OrderAction

Possible values are:
 

OrderAction.Buy

OrderAction.BuyToCover

OrderAction.Sell

OrderAction.SellShort

AvgFillPrice

A double value representing the average fill price of an order

Error

Possible values are:

 

ErrorCode.BrokerOrderError

ErrorCode.InvalidInstrument

ErrorCode.LoginFailed

ErrorCode.NoError

ErrorCode.NotConnected

ErrorCode.NotSupported

ErrorCode.OrderRejected

ErrorCode.Panic

ErrorCode.ServerConnectionIsBroken

ErrorCode.UnableToCancelOrder

ErrorCode.UnableToChangeOrder

ErrorCode.UnableToSubmitOrder

ErrorCode.UserAbort

Filled

An int value representing the filled amount of an order

FromEntrySignal

A string representing the user defined fromEntrySignal parameter on an order

Instrument

An Instrument value representing the instrument of an order

LimitPrice

A double value representing the limit price of an order

LiveUntilCancelled

*A bool value representing if the order is live until cancelled by the user

Name

A string representing the name of an order which can be provided by the entry or exit signal name

NativeError

A string representing the error message provided directly from the broker

Oco

A string representing the OCO (one cancels other) id of an order

OrderId

A string representing the broker issued order id value (this value can change)

OrderState

See table below

OrderType

Possible values are:
 

OrderType.Limit

OrderType.Market

OrderType.Stop

OrderType.StopLimit

OverFill

**A bool value representing if the order is an overfill. For use when using Unmanaged orders and IgnoreOverFill

Quantity

An int value representing the quantity of an order

StopPrice

A double value representing the stop price of an order

Time

A DateTime structure representing the last time the order changed state

TimeInForce

Possible values are:
 

TimeInForce.Day

TimeInForce.Gtc

Token

A string representing the unique id of an order

ToString()

A string representation of an order

 

OrderState Values

OrderState.Accepted

Order has been acknowledged by the broker

OrderState.Cancelled

Order has been cancelled

OrderState.Filled

Order has been filled

OrderState.PartFilled

Order has been part filled

OrderState.PendingCancel

An order cancellation request has been submitted

OrderState.PendingChange

An order change request has been submitted

OrderState.PendingSubmit

An order has been submitted

OrderState.Rejected

An order has been rejected

OrderState.Working

An order is working at the exchange

OrderState.Unknown

An unknown order state

* In a historical backtest, orders will always reach a "Working" state. In real-time, some stop orders may only reach "Accepted" state if they are simulated/held on a brokers server
 
** An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation. The cancel request could have been induced by an explicit CancelOrder() call, from more implicit cancellations like those that occur when another order sharing the same OCO ID is filled, or from things like order expirations.

 

Examples

private IOrder entryOrder = null;

protected override void OnBarUpdate()
{
    if (entryOrder == null && Close[0] > Open[0])
         entryOrder = EnterLong();
}

 

protected override void OnOrderUpdate(IOrder order)
{
    if (entryOrder != null && entryOrder == order)
    {
         Print(order.ToString());
        if (order.OrderState == OrderState.Filled)
              entryOrder = null;
    }
}