using System; using System.Collections.ObjectModel; namespace Krs.Ats.IBNet { /// /// Order class passed to Interactive Brokers to place an order. /// [Serializable()] public class Order { #region Private Variables // main order fields private ActionSide action; private bool allOrNone; private AuctionStrategy auctionStrategy; // 1=AUCTION_MATCH, 2=AUCTION_IMPROVEMENT, 3=AUCTION_TRANSPARENT private decimal auxPrice; private decimal basisPoints; // EFP orders only private int basisPointsType; // EFP orders only // extended order fields private bool blockOrder; private int clientId; private int continuousUpdate; private double delta; private double deltaNeutralAuxPrice; private OrderType deltaNeutralOrderType; private String designatedLocation; // set when slot=2 only. private int deltaNeutralConId; private string deltaNeutralSettlingFirm; private string deltaNeutralClearingAccount; private string deltaNeutralClearingIntent; // HEDGE ORDERS ONLY private string hedgeType; // 'D' - delta, 'B' - beta, 'F' - FX, 'P' - pair private string hedgeParam; // beta value for beta hedge, ratio for pair hedge // SMART routing only private decimal discretionaryAmt; private int displaySize; private bool eTradeOnly; private bool optOutSmartRouting; // Financial advisors only private String faGroup; private FinancialAdvisorAllocationMethod faMethod; private String faPercentage; private String faProfile; private bool firmQuoteOnly; private String goodAfterTime; // FORMAT: 20060505 08:00:00 {time zone} private String goodTillDate; // FORMAT: 20060505 08:00:00 {time zone} private bool hidden; private bool? outsideRth; private decimal limitPrice; private int minQty; private decimal nbboPriceCap; private String ocaGroup; // one cancels all group name private OcaType ocaType; // 1 = CANCEL_WITH_BLOCK, 2 = REDUCE_WITH_BLOCK, 3 = REDUCE_NON_BLOCK // Institutional orders only private String openClose; // O=Open, C=Close private int orderId; private String orderRef; private OrderType orderType; private OrderOrigin origin; // 0=Customer, 1=Firm private bool overridePercentageConstraints; private int parentId; // Parent order Id, to associate Auto STP or TRAIL orders with the original order. private double percentOffset; // REL orders only private int permId; private int referencePriceType; // 1=Average, 2 = BidOrAsk private AgentDescription rule80A; // Individual = 'I', Agency = 'A', AgentOtherMember = 'W', IndividualPTIA = 'J', AgencyPTIA = 'U', AgentOtherMemberPTIA = 'M', IndividualPT = 'K', AgencyPT = 'Y', AgentOtherMemberPT = 'N' private ShortSaleSlot shortSaleSlot; // 1 if you hold the shares, 2 if they will be delivered from elsewhere. Only for Action="SSHORT private int exemptCode; //Code for short sale exemption orders // BOX ORDERS ONLY private decimal startingPrice; // pegged to stock or VOL orders private double stockRangeLower; private double stockRangeUpper; private double stockRefPrice; private bool sweepToFill; private TimeInForce tif; // "Time in Force" - DAY, GTC, etc. private int totalQuantity; private decimal trailStopPrice; // for TRAILLIMIT orders only private bool transmit; // if false, order will be created but not transmited private TriggerMethod triggerMethod; // 0=Default, 1=Double_Bid_Ask, 2=Last, 3=Double_Last, 4=Bid_Ask, 7=Last_or_Bid_Ask, 8=Mid-point // VOLATILITY ORDERS ONLY private double volatility; private VolatilityType volatilityType; // 1=daily, 2=annual // SCALE ORDERS ONLY private int scaleInitLevelSize; private int scaleSubsLevelSize; private decimal scalePriceIncrement; // Clearing info private string account; // IB account private string settlingFirm; private string clearingAccount; // True beneficiary of the order private string clearingIntent; // "" (Default), "IB", "Away", "PTA" (PostTrade) // ALGO ORDERS ONLY private string algoStrategy; private Collection algoParams; // What-if private bool whatIf; // Not Held private bool notHeld; // Smart combo routing params private Collection smartComboRoutingParams; #endregion #region Constructor /// /// Default Constructor /// public Order() { openClose = "O"; origin = OrderOrigin.Customer; transmit = true; tif = TimeInForce.Day; designatedLocation = ""; minQty = Int32.MaxValue; percentOffset = Double.MaxValue; nbboPriceCap = decimal.MaxValue; startingPrice = decimal.MaxValue; stockRefPrice = Double.MaxValue; delta = Double.MaxValue; stockRangeLower = Double.MaxValue; stockRangeUpper = Double.MaxValue; volatility = Double.MaxValue; volatilityType = VolatilityType.Undefined; deltaNeutralOrderType = OrderType.Empty; deltaNeutralAuxPrice = Double.MaxValue; referencePriceType = Int32.MaxValue; trailStopPrice = decimal.MaxValue; basisPoints = decimal.MaxValue; basisPointsType = Int32.MaxValue; scaleInitLevelSize = Int32.MaxValue; scaleSubsLevelSize = Int32.MaxValue; scalePriceIncrement = decimal.MaxValue; faMethod = FinancialAdvisorAllocationMethod.None; notHeld = false; exemptCode = -1; optOutSmartRouting = false; deltaNeutralConId = 0; deltaNeutralOrderType = OrderType.Empty; deltaNeutralSettlingFirm = string.Empty; deltaNeutralClearingAccount = string.Empty; deltaNeutralClearingIntent = string.Empty; } #endregion #region Properties /// /// The id for this order. /// public int OrderId { get { return orderId; } set { orderId = value; } } /// /// The id of the client that placed this order. /// public int ClientId { get { return clientId; } set { clientId = value; } } /// /// The TWS id used to identify orders, remains the same over TWS sessions. /// public int PermId { get { return permId; } set { permId = value; } } /// /// Identifies the side. Valid values are: BUY, SELL, SSHORT /// public ActionSide Action { get { return action; } set { action = value; } } /// /// The order quantity. /// public int TotalQuantity { get { return totalQuantity; } set { totalQuantity = value; } } /// /// The order type. /// /// public OrderType OrderType { get { return orderType; } set { orderType = value; } } /// /// This is the LIMIT price, used for limit, stop-limit and relative orders. /// In all other cases specify zero. For relative orders with no limit price, /// also specify zero. /// public decimal LimitPrice { get { return limitPrice; } set { limitPrice = value; } } /// /// This is the STOP price for stop-limit orders, and the offset amount for /// relative orders. In all other cases, specify zero. /// public decimal AuxPrice { get { return auxPrice; } set { auxPrice = value; } } /// /// The time in force. /// /// Valid values are: DAY, GTC, IOC, GTD. /// public TimeInForce Tif { get { return tif; } set { tif = value; } } /// /// Identifies an OCA (one cancels all) group. /// public string OcaGroup { get { return ocaGroup; } set { ocaGroup = value; } } /// /// Tells how to handle remaining orders in an OCA group when one order or part of an order executes. /// /// /// Valid values include: /// /// 1 = Cancel all remaining orders with block. /// 2 = Remaining orders are proportionately reduced in size with block. /// 3 = Remaining orders are proportionately reduced in size with no block. /// /// If you use a value "with block"gives your order has overfill protection. This means that only one order in the group will be routed at a time to remove the possibility of an overfill. /// /// public OcaType OcaType { get { return ocaType; } set { ocaType = value; } } /// /// The order reference. For institutional customers only. /// public string OrderRef { get { return orderRef; } set { orderRef = value; } } /// /// Specifies whether the order will be transmitted by TWS. /// If set to false, the order will be created at TWS but will not be sent. /// public bool Transmit { get { return transmit; } set { transmit = value; } } /// /// The order ID of the parent order, used for bracket and auto trailing stop orders. /// public int ParentId { get { return parentId; } set { parentId = value; } } /// /// If set to true, specifies that the order is an ISE Block order. /// public bool BlockOrder { get { return blockOrder; } set { blockOrder = value; } } /// /// If set to true, specifies that the order is a Sweep-to-Fill order. /// public bool SweepToFill { get { return sweepToFill; } set { sweepToFill = value; } } /// /// The publicly disclosed order size, used when placing Iceberg orders. /// public int DisplaySize { get { return displaySize; } set { displaySize = value; } } /// /// Specifies how Simulated Stop, Stop-Limit and Trailing Stop orders are triggered. /// /// /// Valid values are: /// /// 0 - the default value. The "double bid/ask" method will be used for orders for OTC stocks and US options. All other orders will used the "last" method. /// 1 - use "double bid/ask" method, where stop orders are triggered based on two consecutive bid or ask prices. /// 2 - "last" method, where stop orders are triggered based on the last price. /// 3 - double last method. /// 4 - bid/ask method. /// 7 - last or bid/ask method. /// 8 - mid-point method. /// /// /// public TriggerMethod TriggerMethod { get { return triggerMethod; } set { triggerMethod = value; } } /// /// If set to true, allows triggering of orders outside of regular trading hours. /// public bool? OutsideRth { get { return outsideRth; } set { outsideRth = value; } } /// /// If set to true, the order will not be visible when viewing the market depth. /// This option only applies to orders routed to the ISLAND exchange. /// public bool Hidden { get { return hidden; } set { hidden = value; } } /// /// The trade's "Good After Time" /// /// format "YYYYMMDD hh:mm:ss (optional time zone)" /// Use an empty String if not applicable. public string GoodAfterTime { get { return goodAfterTime; } set { goodAfterTime = value; } } /// /// You must enter a Time in Force value of Good Till Date. /// /// The trade's "Good Till Date," format is: /// YYYYMMDD hh:mm:ss (optional time zone) /// Use an empty String if not applicable. public string GoodTillDate { get { return goodTillDate; } set { goodTillDate = value; } } /// /// If set, allows you to override TWS order price percentage constraints set to /// reject orders that deviate too far from the NBBO. This precaution was created /// to avoid transmitting orders with an incorrect price. /// public bool OverridePercentageConstraints { get { return overridePercentageConstraints; } set { overridePercentageConstraints = value; } } /// /// This identifies what type of trader you are. /// /// Rule80A required you to identify which type of trader you are. /// public AgentDescription Rule80A { get { return rule80A; } set { rule80A = value; } } /// /// yes=1, no=0 /// public bool AllOrNone { get { return allOrNone; } set { allOrNone = value; } } /// /// Identifies a minimum quantity order type. /// public int MinQty { get { return minQty; } set { minQty = value; } } /// /// The percent offset amount for relative orders. /// public double PercentOffset { get { return percentOffset; } set { percentOffset = value; } } /// /// For TRAILLIMIT orders only /// public decimal TrailStopPrice { get { return trailStopPrice; } set { trailStopPrice = value; } } /// /// The Financial Advisor group the trade will be allocated to -- use an empty String if not applicable. /// public string FAGroup { get { return faGroup; } set { faGroup = value; } } /// /// The Financial Advisor allocation profile the trade will be allocated to -- use an empty String if not applicable. /// public string FAProfile { get { return faProfile; } set { faProfile = value; } } /// /// The Financial Advisor allocation method the trade will be allocated with -- use an empty String if not applicable. /// public FinancialAdvisorAllocationMethod FAMethod { get { return faMethod; } set { faMethod = value; } } /// /// The Financial Advisor percentage concerning the trade's allocation -- use an empty String if not applicable. /// public string FAPercentage { get { return faPercentage; } set { faPercentage = value; } } /// /// Specifies whether the order is an open or close order. /// For institutional customers only. Valid values are O, C. /// public string OpenClose { get { return openClose; } set { openClose = value; } } /// /// The order origin. /// /// For institutional customers only. public OrderOrigin Origin { get { return origin; } set { origin = value; } } /// /// ShortSaleSlot of Third Party requires DesignatedLocation to be specified. Non-empty DesignatedLocation values for all other cases will cause orders to be rejected. /// public ShortSaleSlot ShortSaleSlot { get { return shortSaleSlot; } set { shortSaleSlot = value; } } /// /// Use only when shortSaleSlot value = 2. /// public string DesignatedLocation { get { return designatedLocation; } set { designatedLocation = value; } } /// /// The amount off the limit price allowed for discretionary orders. /// public decimal DiscretionaryAmt { get { return discretionaryAmt; } set { discretionaryAmt = value; } } /// /// Trade with electronic quotes. /// public bool ETradeOnly { get { return eTradeOnly; } set { eTradeOnly = value; } } /// /// Trade with firm quotes. /// public bool FirmQuoteOnly { get { return firmQuoteOnly; } set { firmQuoteOnly = value; } } /// /// The maximum Smart order distance from the NBBO. /// public decimal NbboPriceCap { get { return nbboPriceCap; } set { nbboPriceCap = value; } } /// /// The auction strategy. /// /// For BOX exchange only. /// public AuctionStrategy AuctionStrategy { get { return auctionStrategy; } set { auctionStrategy = value; } } /// /// The starting price. /// /// Valid on BOX orders only. public decimal StartingPrice { get { return startingPrice; } set { startingPrice = value; } } /// /// The stock reference price. /// /// The reference price is used for VOL orders /// to compute the limit price sent to an exchange (whether or not Continuous /// Update is selected), and for price range monitoring. public double StockRefPrice { get { return stockRefPrice; } set { stockRefPrice = value; } } /// /// The stock delta. /// /// Valid on BOX orders only. public double Delta { get { return delta; } set { delta = value; } } /// /// The lower value for the acceptable underlying stock price range. /// /// For price improvement option orders on BOX and VOL orders with dynamic management. public double StockRangeLower { get { return stockRangeLower; } set { stockRangeLower = value; } } /// /// The upper value for the acceptable underlying stock price range. /// /// For price improvement option orders on BOX and VOL orders with dynamic management. public double StockRangeUpper { get { return stockRangeUpper; } set { stockRangeUpper = value; } } /// /// What the price is, computed via TWS's Options Analytics. /// /// For VOL orders, the limit price sent to an exchange is not editable, /// as it is the output of a function. Volatility is expressed as a percentage. public double Volatility { get { return volatility; } set { volatility = value; } } /// /// How the volatility is calculated. /// /// public VolatilityType VolatilityType { get { return volatilityType; } set { volatilityType = value; } } /// /// Used for dynamic management of volatility orders. /// /// Determines whether TWS is /// supposed to update the order price as the underlying moves. If selected, /// the limit price sent to an exchange is modified by TWS if the computed price /// of the option changes enough to warrant doing so. This is very helpful in /// keeping the limit price sent to the exchange up to date as the underlying price changes. public int ContinuousUpdate { get { return continuousUpdate; } set { continuousUpdate = value; } } /// /// Used for dynamic management of volatility orders. Set to /// 1 = Average of National Best Bid or Ask, or set to /// 2 = National Best Bid when buying a call or selling a put; and National Best Ask when selling a call or buying a put. /// public int ReferencePriceType { get { return referencePriceType; } set { referencePriceType = value; } } /// /// VOL orders only. Enter an order type to instruct TWS to submit a /// delta neutral trade on full or partial execution of the VOL order. /// For no hedge delta order to be sent, specify NONE. /// public OrderType DeltaNeutralOrderType { get { return deltaNeutralOrderType; } set { deltaNeutralOrderType = value; } } /// /// VOL orders only. Use this field to enter a value if the value in the /// deltaNeutralOrderType field is an order type that requires an Aux price, such as a REL order. /// public double DeltaNeutralAuxPrice { get { return deltaNeutralAuxPrice; } set { deltaNeutralAuxPrice = value; } } /// /// For EFP orders only /// public decimal BasisPoints { get { return basisPoints; } set { basisPoints = value; } } /// /// For EFP orders only /// public int BasisPointsType { get { return basisPointsType; } set { basisPointsType = value; } } /// /// split order into X buckets /// public int ScaleInitLevelSize { get { return scaleInitLevelSize; } set { scaleInitLevelSize = value; } } /// /// split order so each bucket is of the size X /// public int ScaleSubsLevelSize { get { return scaleSubsLevelSize; } set { scaleSubsLevelSize = value; } } /// /// price increment per bucket /// public decimal ScalePriceIncrement { get { return scalePriceIncrement; } set { scalePriceIncrement = value; } } /// /// The account. For institutional customers only. /// public string Account { get { return account; } set { account = value; } } /// /// Institutional only. /// public string SettlingFirm { get { return settlingFirm; } set { settlingFirm = value; } } /// /// Unknown - assume institutional only. /// public string ClearingAccount { get { return clearingAccount; } set { clearingAccount = value; } } /// /// Unknown - assume institutional only. /// public string ClearingIntent { get { return clearingIntent; } set { clearingIntent = value; } } /// /// Algorithm Strategy /// public string AlgoStrategy { get { return algoStrategy; } set { algoStrategy = value; } } /// /// List of Algorithm Parameters /// public Collection AlgoParams { get { return algoParams; } set { algoParams = value; } } /// /// When this value is set to true, margin and commission data is /// received back via a new OrderState() object for the openOrder() callback. /// public bool WhatIf { get { return whatIf; } set { whatIf = value; } } /// /// Not Held /// public bool NotHeld { get { return notHeld; } set { notHeld = value; } } /// /// Exempt Code for Short Sale Exemption Orders /// public int ExemptCode { get { return exemptCode; } set { exemptCode = value; } } /// /// Opt out of smart routing for directly routed ASX orders /// public bool OptOutSmartRouting { get { return optOutSmartRouting; } set { optOutSmartRouting = value; } } public int DeltaNeutralConId { get { return deltaNeutralConId; } set { deltaNeutralConId = value; } } public string DeltaNeutralSettlingFirm { get { return deltaNeutralSettlingFirm; } set { deltaNeutralSettlingFirm = value; } } public string DeltaNeutralClearingAccount { get { return deltaNeutralClearingAccount; } set { deltaNeutralClearingAccount = value; } } public string DeltaNeutralClearingIntent { get { return deltaNeutralClearingIntent; } set { deltaNeutralClearingIntent = value; } } public string HedgeType { get { return hedgeType; } set { hedgeType = value; } } public string HedgeParam { get { return hedgeParam; } set { hedgeParam = value; } } public Collection SmartComboRoutingParams { get { return smartComboRoutingParams; } set { smartComboRoutingParams = value; } } #endregion } }