/// <summary> /// Initializes a new instance of the <see cref="OpenOrderEventArgs"/> class /// </summary> public OpenOrderEventArgs(int orderId, Contract contract, Order order, OrderState orderState) { OrderId = orderId; Contract = contract; Order = order; OrderState = orderState; }
public OrderStatusMessage(int orderId, Contract contract, IBApi.Order order, OrderState orderstate) { MessageType = MessageType.OrderStatus; OrderId = orderId; Contract = contract; Order = order; OrderState = orderstate; }
public OpenOrderMessage(int orderId, Contract contract, Order order, OrderState orderState) { Type = MessageType.OpenOrder; OrderId = orderId; Contract = contract; Order = order; OrderState = orderState; }
public EOrderDecoder(EDecoder eDecoder, Contract contract, Order order, OrderState orderState, int msgVersion, int serverVersion) { this.eDecoder = eDecoder; this.contract = contract; this.order = order; this.orderState = orderState; this.msgVersion = msgVersion; this.serverVersion = serverVersion; }
//! [orderstatus] //! [openorder] public virtual void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { // Console.WriteLine("OpenOrder. ID: "+orderId+", "+contract.Symbol+", "+contract.SecType + " @ "+contract.Strike+": "+order.Action+", "+order.OrderType+" "+order.TotalQuantity+", "+orderState.Status); // if (contract.Strike == 0) // Console.WriteLine("Order Details. " + orderId + " Symbol: " + contract.Symbol + ", Leg: " + contract.ComboLegsDescription + ", Action: " + order.Action + ", order type: " + order.OrderType + ", total: " + order.TotalQuantity + ", status: " + orderState.Status); if (order.WhatIf) // if (currOrderId == orderId) { Console.WriteLine("What-If. ID: " + orderId + ", InitMarginBefore: " + Util.formatDoubleString(orderState.InitMarginBefore) + ", MaintMarginBefore: " + Util.formatDoubleString(orderState.MaintMarginBefore) + " EquityWithLoanBefore: " + Util.formatDoubleString(orderState.EquityWithLoanBefore) + ", InitMarginChange: " + Util.formatDoubleString(orderState.InitMarginChange) + ", MaintMarginChange: " + Util.formatDoubleString(orderState.MaintMarginChange) + " EquityWithLoanChange: " + Util.formatDoubleString(orderState.EquityWithLoanChange) + ", InitMarginAfter: " + Util.formatDoubleString(orderState.InitMarginAfter) + ", MaintMarginAfter: " + Util.formatDoubleString(orderState.MaintMarginAfter) + " EquityWithLoanAfter: " + Util.formatDoubleString(orderState.EquityWithLoanAfter)); InitMarginChange = Convert.ToDouble(orderState.InitMarginChange); MaintMarginChange = Convert.ToDouble(orderState.MaintMarginChange); } }
public override bool Equals(Object other) { if (this == other) { return(true); } if (other == null) { return(false); } OrderState state = (OrderState)other; if (commission != state.commission || minCommission != state.minCommission || maxCommission != state.maxCommission) { return(false); } if (Util.StringCompare(status, state.status) != 0 || Util.StringCompare(initMarginBefore, state.initMarginBefore) != 0 || Util.StringCompare(maintMarginBefore, state.maintMarginBefore) != 0 || Util.StringCompare(equityWithLoanBefore, state.equityWithLoanBefore) != 0 || Util.StringCompare(initMarginChange, state.initMarginChange) != 0 || Util.StringCompare(maintMarginChange, state.maintMarginChange) != 0 || Util.StringCompare(equityWithLoanChange, state.equityWithLoanChange) != 0 || Util.StringCompare(initMarginAfter, state.initMarginAfter) != 0 || Util.StringCompare(maintMarginAfter, state.maintMarginAfter) != 0 || Util.StringCompare(equityWithLoanAfter, state.equityWithLoanAfter) != 0 || Util.StringCompare(commissionCurrency, state.commissionCurrency) != 0 || Util.StringCompare(completedTime, state.completedTime) != 0 || Util.StringCompare(completedStatus, state.completedStatus) != 0) { return(false); } return(true); }
public override bool Equals(object other) { if (this == other) { return(true); } OrderState state = other as OrderState; if (state == null) { return(false); } if (Commission != state.Commission || MinCommission != state.MinCommission || MaxCommission != state.MaxCommission) { return(false); } if (Util.StringCompare(Status, state.Status) != 0 || Util.StringCompare(InitMarginBefore, state.InitMarginBefore) != 0 || Util.StringCompare(MaintMarginBefore, state.MaintMarginBefore) != 0 || Util.StringCompare(EquityWithLoanBefore, state.EquityWithLoanBefore) != 0 || Util.StringCompare(InitMarginChange, state.InitMarginChange) != 0 || Util.StringCompare(MaintMarginChange, state.MaintMarginChange) != 0 || Util.StringCompare(EquityWithLoanChange, state.EquityWithLoanChange) != 0 || Util.StringCompare(InitMarginAfter, state.InitMarginAfter) != 0 || Util.StringCompare(MaintMarginAfter, state.MaintMarginAfter) != 0 || Util.StringCompare(EquityWithLoanAfter, state.EquityWithLoanAfter) != 0 || Util.StringCompare(CommissionCurrency, state.CommissionCurrency) != 0 || Util.StringCompare(CompletedTime, state.CompletedTime) != 0 || Util.StringCompare(CompletedStatus, state.CompletedStatus) != 0) { return(false); } return(true); }
public virtual void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { }
public virtual void completedOrder(Contract contract, Order order, OrderState orderState) { }
public void openOrder(int orderId, Contract contract, IBApi.Order order, OrderState orderState) { //1. Add to open order queue OpenOrderMessage ooM = new OpenOrderMessage(); ooM.Order = order; ooM.Contract = contract; ooM.OrderId = orderId; ooM.MessageType = MessageType.OpenOrder; ooM.OrderState = orderState; MessageHandler.messageBox.Enqueue(ooM); }
public virtual void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { Console.WriteLine("OpenOrder. ID: "+orderId+", "+contract.Symbol+", "+contract.SecType+" @ "+contract.Exchange+": "+order.Action+", "+order.OrderType+" "+order.TotalQuantity+", "+orderState.Status+"\n"); //clientSocket.reqMktData(2, contract, "", false); contract.ConId = 0; clientSocket.placeOrder(nextOrderId, contract, order); }
public void UpdateMarginInformation(OrderState state) { FillAndDisplay(state); this.ShowDialog(); }
// This function is called to feed in open orders. // // It is also fired after reconnecting to TWS if the client has any open orders. public virtual void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { String str; str = "Open order @ " + DateTime.Now.ToShortTimeString() + ": OrderId = " + orderId.ToString() + ", contract symbol = " + contract.Symbol + "order = " + order.OrderId.ToString() + "client = " + order.ClientId.ToString() + " order state = " + orderState.Status.ToString(); AddTextToResponseListWindow(str); }
private void OpenOrderEvent() { int msgVersion = ReadInt(); // read order id Order order = new Order(); order.OrderId = ReadInt(); // read contract fields Contract contract = new Contract(); if (msgVersion >= 17) { contract.ConId = ReadInt(); } contract.Symbol = ReadString(); contract.SecType = ReadString(); contract.Expiry = ReadString(); contract.Strike = ReadDouble(); contract.Right = ReadString(); if (msgVersion >= 32) { contract.Multiplier = ReadString(); } contract.Exchange = ReadString(); contract.Currency = ReadString(); if (msgVersion >= 2) { contract.LocalSymbol = ReadString(); } if (msgVersion >= 32) { contract.TradingClass = ReadString(); } // read order fields order.Action = ReadString(); order.TotalQuantity = ReadInt(); order.OrderType = ReadString(); if (msgVersion < 29) { order.LmtPrice = ReadDouble(); } else { order.LmtPrice = ReadDoubleMax(); } if (msgVersion < 30) { order.AuxPrice = ReadDouble(); } else { order.AuxPrice = ReadDoubleMax(); } order.Tif = ReadString(); order.OcaGroup = ReadString(); order.Account = ReadString(); order.OpenClose = ReadString(); order.Origin = ReadInt(); order.OrderRef = ReadString(); if (msgVersion >= 3) { order.ClientId = ReadInt(); } if (msgVersion >= 4) { order.PermId = ReadInt(); if (msgVersion < 18) { // will never happen /* order.ignoreRth = */ ReadBoolFromInt(); } else { order.OutsideRth = ReadBoolFromInt(); } order.Hidden = ReadInt() == 1; order.DiscretionaryAmt = ReadDouble(); } if (msgVersion >= 5) { order.GoodAfterTime = ReadString(); } if (msgVersion >= 6) { // skip deprecated sharesAllocation field ReadString(); } if (msgVersion >= 7) { order.FaGroup = ReadString(); order.FaMethod = ReadString(); order.FaPercentage = ReadString(); order.FaProfile = ReadString(); } if (msgVersion >= 8) { order.GoodTillDate = ReadString(); } if (msgVersion >= 9) { order.Rule80A = ReadString(); order.PercentOffset = ReadDoubleMax(); order.SettlingFirm = ReadString(); order.ShortSaleSlot = ReadInt(); order.DesignatedLocation = ReadString(); if (parent.ServerVersion == 51) { ReadInt(); // exemptCode } else if (msgVersion >= 23) { order.ExemptCode = ReadInt(); } order.AuctionStrategy = ReadInt(); order.StartingPrice = ReadDoubleMax(); order.StockRefPrice = ReadDoubleMax(); order.Delta = ReadDoubleMax(); order.StockRangeLower = ReadDoubleMax(); order.StockRangeUpper = ReadDoubleMax(); order.DisplaySize = ReadInt(); if (msgVersion < 18) { // will never happen /* order.rthOnly = */ ReadBoolFromInt(); } order.BlockOrder = ReadBoolFromInt(); order.SweepToFill = ReadBoolFromInt(); order.AllOrNone = ReadBoolFromInt(); order.MinQty = ReadIntMax(); order.OcaType = ReadInt(); order.ETradeOnly = ReadBoolFromInt(); order.FirmQuoteOnly = ReadBoolFromInt(); order.NbboPriceCap = ReadDoubleMax(); } if (msgVersion >= 10) { order.ParentId = ReadInt(); order.TriggerMethod = ReadInt(); } if (msgVersion >= 11) { order.Volatility = ReadDoubleMax(); order.VolatilityType = ReadInt(); if (msgVersion == 11) { int receivedInt = ReadInt(); order.DeltaNeutralOrderType = ((receivedInt == 0) ? "NONE" : "MKT"); } else { // msgVersion 12 and up order.DeltaNeutralOrderType = ReadString(); order.DeltaNeutralAuxPrice = ReadDoubleMax(); if (msgVersion >= 27 && !Util.StringIsEmpty(order.DeltaNeutralOrderType)) { order.DeltaNeutralConId = ReadInt(); order.DeltaNeutralSettlingFirm = ReadString(); order.DeltaNeutralClearingAccount = ReadString(); order.DeltaNeutralClearingIntent = ReadString(); } if (msgVersion >= 31 && !Util.StringIsEmpty(order.DeltaNeutralOrderType)) { order.DeltaNeutralOpenClose = ReadString(); order.DeltaNeutralShortSale = ReadBoolFromInt(); order.DeltaNeutralShortSaleSlot = ReadInt(); order.DeltaNeutralDesignatedLocation = ReadString(); } } order.ContinuousUpdate = ReadInt(); if (parent.ServerVersion == 26) { order.StockRangeLower = ReadDouble(); order.StockRangeUpper = ReadDouble(); } order.ReferencePriceType = ReadInt(); } if (msgVersion >= 13) { order.TrailStopPrice = ReadDoubleMax(); } if (msgVersion >= 30) { order.TrailingPercent = ReadDoubleMax(); } if (msgVersion >= 14) { order.BasisPoints = ReadDoubleMax(); order.BasisPointsType = ReadIntMax(); contract.ComboLegsDescription = ReadString(); } if (msgVersion >= 29) { int comboLegsCount = ReadInt(); if (comboLegsCount > 0) { contract.ComboLegs = new List <ComboLeg>(comboLegsCount); for (int i = 0; i < comboLegsCount; ++i) { int conId = ReadInt(); int ratio = ReadInt(); String action = ReadString(); String exchange = ReadString(); int openClose = ReadInt(); int shortSaleSlot = ReadInt(); String designatedLocation = ReadString(); int exemptCode = ReadInt(); ComboLeg comboLeg = new ComboLeg(conId, ratio, action, exchange, openClose, shortSaleSlot, designatedLocation, exemptCode); contract.ComboLegs.Add(comboLeg); } } int orderComboLegsCount = ReadInt(); if (orderComboLegsCount > 0) { order.OrderComboLegs = new List <OrderComboLeg>(orderComboLegsCount); for (int i = 0; i < orderComboLegsCount; ++i) { double price = ReadDoubleMax(); OrderComboLeg orderComboLeg = new OrderComboLeg(price); order.OrderComboLegs.Add(orderComboLeg); } } } if (msgVersion >= 26) { int smartComboRoutingParamsCount = ReadInt(); if (smartComboRoutingParamsCount > 0) { order.SmartComboRoutingParams = new List <TagValue>(smartComboRoutingParamsCount); for (int i = 0; i < smartComboRoutingParamsCount; ++i) { TagValue tagValue = new TagValue(); tagValue.tag = ReadString(); tagValue.value = ReadString(); order.SmartComboRoutingParams.Add(tagValue); } } } if (msgVersion >= 15) { if (msgVersion >= 20) { order.ScaleInitLevelSize = ReadIntMax(); order.ScaleSubsLevelSize = ReadIntMax(); } else { /* int notSuppScaleNumComponents = */ ReadIntMax(); order.ScaleInitLevelSize = ReadIntMax(); } order.ScalePriceIncrement = ReadDoubleMax(); } if (msgVersion >= 28 && order.ScalePriceIncrement > 0.0 && order.ScalePriceIncrement != Double.MaxValue) { order.ScalePriceAdjustValue = ReadDoubleMax(); order.ScalePriceAdjustInterval = ReadIntMax(); order.ScaleProfitOffset = ReadDoubleMax(); order.ScaleAutoReset = ReadBoolFromInt(); order.ScaleInitPosition = ReadIntMax(); order.ScaleInitFillQty = ReadIntMax(); order.ScaleRandomPercent = ReadBoolFromInt(); } if (msgVersion >= 24) { order.HedgeType = ReadString(); if (!Util.StringIsEmpty(order.HedgeType)) { order.HedgeParam = ReadString(); } } if (msgVersion >= 25) { order.OptOutSmartRouting = ReadBoolFromInt(); } if (msgVersion >= 19) { order.ClearingAccount = ReadString(); order.ClearingIntent = ReadString(); } if (msgVersion >= 22) { order.NotHeld = ReadBoolFromInt(); } if (msgVersion >= 20) { if (ReadBoolFromInt()) { UnderComp underComp = new UnderComp(); underComp.ConId = ReadInt(); underComp.Delta = ReadDouble(); underComp.Price = ReadDouble(); contract.UnderComp = underComp; } } if (msgVersion >= 21) { order.AlgoStrategy = ReadString(); if (!Util.StringIsEmpty(order.AlgoStrategy)) { int algoParamsCount = ReadInt(); if (algoParamsCount > 0) { order.AlgoParams = new List <TagValue>(algoParamsCount); for (int i = 0; i < algoParamsCount; ++i) { TagValue tagValue = new TagValue(); tagValue.tag = ReadString(); tagValue.value = ReadString(); order.AlgoParams.Add(tagValue); } } } } OrderState orderState = new OrderState(); if (msgVersion >= 16) { order.WhatIf = ReadBoolFromInt(); orderState.Status = ReadString(); orderState.InitMargin = ReadString(); orderState.MaintMargin = ReadString(); orderState.EquityWithLoan = ReadString(); orderState.Commission = ReadDoubleMax(); orderState.MinCommission = ReadDoubleMax(); orderState.MaxCommission = ReadDoubleMax(); orderState.CommissionCurrency = ReadString(); orderState.WarningText = ReadString(); } parent.Wrapper.openOrder(order.OrderId, contract, order, orderState); }
/// <summary> /// This callback feeds in open orders. /// </summary> /// <param name="orderId">The order Id assigned by TWS. Used to cancel or update the order.</param> /// <param name="contract">The Contract class attributes describe the contract.</param> /// <param name="order">The Order class attributes define the details of the order.</param> /// <param name="orderState">The orderState attributes include margin and commissions fields for both pre and post trade data.</param> public void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { OnOpenOrder(new OpenOrderEventArgs(orderId, contract, order, orderState)); }
private void OpenOrderEvent() { int msgVersion = ReadInt(); // read order id Order order = new Order(); order.OrderId = ReadInt(); // read contract fields Contract contract = new Contract(); if (msgVersion >= 17) { contract.ConId = ReadInt(); } contract.Symbol = ReadString(); contract.SecType = ReadString(); contract.Expiry = ReadString(); contract.Strike = ReadDouble(); contract.Right = ReadString(); if (msgVersion >= 32) { contract.Multiplier = ReadString(); } contract.Exchange = ReadString(); contract.Currency = ReadString(); if (msgVersion >= 2) { contract.LocalSymbol = ReadString(); } if (msgVersion >= 32) { contract.TradingClass = ReadString(); } // read order fields order.Action = ReadString(); order.TotalQuantity = ReadInt(); order.OrderType = ReadString(); if (msgVersion < 29) { order.LmtPrice = ReadDouble(); } else { order.LmtPrice = ReadDoubleMax(); } if (msgVersion < 30) { order.AuxPrice = ReadDouble(); } else { order.AuxPrice = ReadDoubleMax(); } order.Tif = ReadString(); order.OcaGroup = ReadString(); order.Account = ReadString(); order.OpenClose = ReadString(); order.Origin = ReadInt(); order.OrderRef = ReadString(); if (msgVersion >= 3) { order.ClientId = ReadInt(); } if (msgVersion >= 4) { order.PermId = ReadInt(); if (msgVersion < 18) { // will never happen /* order.ignoreRth = */ ReadBoolFromInt(); } else { order.OutsideRth = ReadBoolFromInt(); } order.Hidden = ReadInt() == 1; order.DiscretionaryAmt = ReadDouble(); } if (msgVersion >= 5) { order.GoodAfterTime = ReadString(); } if (msgVersion >= 6) { // skip deprecated sharesAllocation field ReadString(); } if (msgVersion >= 7) { order.FaGroup = ReadString(); order.FaMethod = ReadString(); order.FaPercentage = ReadString(); order.FaProfile = ReadString(); } if (msgVersion >= 8) { order.GoodTillDate = ReadString(); } if (msgVersion >= 9) { order.Rule80A = ReadString(); order.PercentOffset = ReadDoubleMax(); order.SettlingFirm = ReadString(); order.ShortSaleSlot = ReadInt(); order.DesignatedLocation = ReadString(); if (parent.ServerVersion == 51) { ReadInt(); // exemptCode } else if (msgVersion >= 23) { order.ExemptCode = ReadInt(); } order.AuctionStrategy = ReadInt(); order.StartingPrice = ReadDoubleMax(); order.StockRefPrice = ReadDoubleMax(); order.Delta = ReadDoubleMax(); order.StockRangeLower = ReadDoubleMax(); order.StockRangeUpper = ReadDoubleMax(); order.DisplaySize = ReadInt(); if (msgVersion < 18) { // will never happen /* order.rthOnly = */ ReadBoolFromInt(); } order.BlockOrder = ReadBoolFromInt(); order.SweepToFill = ReadBoolFromInt(); order.AllOrNone = ReadBoolFromInt(); order.MinQty = ReadIntMax(); order.OcaType = ReadInt(); order.ETradeOnly = ReadBoolFromInt(); order.FirmQuoteOnly = ReadBoolFromInt(); order.NbboPriceCap = ReadDoubleMax(); } if (msgVersion >= 10) { order.ParentId = ReadInt(); order.TriggerMethod = ReadInt(); } if (msgVersion >= 11) { order.Volatility = ReadDoubleMax(); order.VolatilityType = ReadInt(); if (msgVersion == 11) { int receivedInt = ReadInt(); order.DeltaNeutralOrderType = ((receivedInt == 0) ? "NONE" : "MKT"); } else { // msgVersion 12 and up order.DeltaNeutralOrderType = ReadString(); order.DeltaNeutralAuxPrice = ReadDoubleMax(); if (msgVersion >= 27 && !Util.StringIsEmpty(order.DeltaNeutralOrderType)) { order.DeltaNeutralConId = ReadInt(); order.DeltaNeutralSettlingFirm = ReadString(); order.DeltaNeutralClearingAccount = ReadString(); order.DeltaNeutralClearingIntent = ReadString(); } if (msgVersion >= 31 && !Util.StringIsEmpty(order.DeltaNeutralOrderType)) { order.DeltaNeutralOpenClose = ReadString(); order.DeltaNeutralShortSale = ReadBoolFromInt(); order.DeltaNeutralShortSaleSlot = ReadInt(); order.DeltaNeutralDesignatedLocation = ReadString(); } } order.ContinuousUpdate = ReadInt(); if (parent.ServerVersion == 26) { order.StockRangeLower = ReadDouble(); order.StockRangeUpper = ReadDouble(); } order.ReferencePriceType = ReadInt(); } if (msgVersion >= 13) { order.TrailStopPrice = ReadDoubleMax(); } if (msgVersion >= 30) { order.TrailingPercent = ReadDoubleMax(); } if (msgVersion >= 14) { order.BasisPoints = ReadDoubleMax(); order.BasisPointsType = ReadIntMax(); contract.ComboLegsDescription = ReadString(); } if (msgVersion >= 29) { int comboLegsCount = ReadInt(); if (comboLegsCount > 0) { contract.ComboLegs = new List<ComboLeg>(comboLegsCount); for (int i = 0; i < comboLegsCount; ++i) { int conId = ReadInt(); int ratio = ReadInt(); String action = ReadString(); String exchange = ReadString(); int openClose = ReadInt(); int shortSaleSlot = ReadInt(); String designatedLocation = ReadString(); int exemptCode = ReadInt(); ComboLeg comboLeg = new ComboLeg(conId, ratio, action, exchange, openClose, shortSaleSlot, designatedLocation, exemptCode); contract.ComboLegs.Add(comboLeg); } } int orderComboLegsCount = ReadInt(); if (orderComboLegsCount > 0) { order.OrderComboLegs = new List<OrderComboLeg>(orderComboLegsCount); for (int i = 0; i < orderComboLegsCount; ++i) { double price = ReadDoubleMax(); OrderComboLeg orderComboLeg = new OrderComboLeg(price); order.OrderComboLegs.Add(orderComboLeg); } } } if (msgVersion >= 26) { int smartComboRoutingParamsCount = ReadInt(); if (smartComboRoutingParamsCount > 0) { order.SmartComboRoutingParams = new List<TagValue>(smartComboRoutingParamsCount); for (int i = 0; i < smartComboRoutingParamsCount; ++i) { TagValue tagValue = new TagValue(); tagValue.tag = ReadString(); tagValue.value = ReadString(); order.SmartComboRoutingParams.Add(tagValue); } } } if (msgVersion >= 15) { if (msgVersion >= 20) { order.ScaleInitLevelSize = ReadIntMax(); order.ScaleSubsLevelSize = ReadIntMax(); } else { /* int notSuppScaleNumComponents = */ ReadIntMax(); order.ScaleInitLevelSize = ReadIntMax(); } order.ScalePriceIncrement = ReadDoubleMax(); } if (msgVersion >= 28 && order.ScalePriceIncrement > 0.0 && order.ScalePriceIncrement != Double.MaxValue) { order.ScalePriceAdjustValue = ReadDoubleMax(); order.ScalePriceAdjustInterval = ReadIntMax(); order.ScaleProfitOffset = ReadDoubleMax(); order.ScaleAutoReset = ReadBoolFromInt(); order.ScaleInitPosition = ReadIntMax(); order.ScaleInitFillQty = ReadIntMax(); order.ScaleRandomPercent = ReadBoolFromInt(); } if (msgVersion >= 24) { order.HedgeType = ReadString(); if (!Util.StringIsEmpty(order.HedgeType)) { order.HedgeParam = ReadString(); } } if (msgVersion >= 25) { order.OptOutSmartRouting = ReadBoolFromInt(); } if (msgVersion >= 19) { order.ClearingAccount = ReadString(); order.ClearingIntent = ReadString(); } if (msgVersion >= 22) { order.NotHeld = ReadBoolFromInt(); } if (msgVersion >= 20) { if (ReadBoolFromInt()) { UnderComp underComp = new UnderComp(); underComp.ConId = ReadInt(); underComp.Delta = ReadDouble(); underComp.Price = ReadDouble(); contract.UnderComp = underComp; } } if (msgVersion >= 21) { order.AlgoStrategy = ReadString(); if (!Util.StringIsEmpty(order.AlgoStrategy)) { int algoParamsCount = ReadInt(); if (algoParamsCount > 0) { order.AlgoParams = new List<TagValue>(algoParamsCount); for (int i = 0; i < algoParamsCount; ++i) { TagValue tagValue = new TagValue(); tagValue.tag = ReadString(); tagValue.value = ReadString(); order.AlgoParams.Add(tagValue); } } } } OrderState orderState = new OrderState(); if (msgVersion >= 16) { order.WhatIf = ReadBoolFromInt(); orderState.Status = ReadString(); orderState.InitMargin = ReadString(); orderState.MaintMargin = ReadString(); orderState.EquityWithLoan = ReadString(); orderState.Commission = ReadDoubleMax(); orderState.MinCommission = ReadDoubleMax(); orderState.MaxCommission = ReadDoubleMax(); orderState.CommissionCurrency = ReadString(); orderState.WarningText = ReadString(); } parent.Wrapper.openOrder(order.OrderId, contract, order, orderState); }
public virtual void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { parentUI.HandleMessage(new OpenOrderMessage(orderId, contract, order, orderState)); }
public void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { throw new NotImplementedException(); }
public virtual void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { MyLogger.Instance.CreateEntry("OpenOrder. ID: " + orderId + ", " + contract.Symbol + ", " + contract.SecType + " @ " + contract.Exchange + ": " + order.Action + ", " + order.OrderType + " " + order.TotalQuantity + ", " + orderState.Status + "\n"); Console.WriteLine("OpenOrder. ID: " + orderId + ", " + contract.Symbol + ", " + contract.SecType + " @ " + contract.Exchange + ": " + order.Action + ", " + order.OrderType + " " + order.TotalQuantity + ", " + orderState.Status + "\n"); }
public void FillAndDisplay(OrderState state) { this.equityWithLoanResult.Text = state.EquityWithLoan.ToString(); this.initialMarginResult.Text = state.InitMargin.ToString(); this.maintenanceMarginResult.Text = state.MaintMargin.ToString(); }
// "Feeds in currently open orders." We can subscribe to all the current OrdersInfo. For MOC orders for example, before PlaceOrder() we should check that if there is already an MOC order then we Modify that (or Cancel&Recreate) public virtual void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { Utils.Logger.Info("OpenOrder. ID: " + orderId + ", " + contract.Symbol + ", " + contract.SecType + " @ " + contract.Exchange + ": " + order.Action + ", " + order.OrderType + " " + order.TotalQuantity + ", " + orderState.Status); }
// orderStatus, openOrderEnd, EClientSocket::placeOrder, EClientSocket::reqAllOpenOrders, EClientSocket::reqAutoOpenOrders public virtual void openOrder(int orderId, Contract contract, IBApi.Order order, OrderState orderState) { // log warning if (!String.IsNullOrEmpty(orderState.WarningText)) OnDebug(orderState.WarningText); if (orderState.Status != "Submitted" && orderState.Status != "Filled" && orderState.Status != "PreSubmitted") { // igore other states return; } Order o = new Order(); o.OrderStatus = (OrderStatus)EnumDescConverter.GetEnumValue(typeof(OrderStatus), orderState.Status); if (_iborderIdToOrderInfo.ContainsKey(orderId)) { if (_iborderIdToOrderInfo[orderId].IsAcknowledged) return; // already acknowledged _iborderIdToOrderInfo[orderId].IsAcknowledged = true; // update account as it might not have been set explicitly // account is used for cancelling order _iborderIdToOrderInfo[orderId].Account = order.Account; } else // the order was placed directly in Tws { long soId = (long)orderId; _iborderIdToOrderInfo.Add(orderId, new OrderInfo(soId, order.Account, true)); OnDebug("Got order not from strategy. Id = " + orderId + ", " + "symbol = " + contract.Symbol); } o.Id = _iborderIdToOrderInfo[orderId].StrategyOrderId; // strategy Order Id o.Account = order.Account; o.OrderSize = Math.Abs(order.TotalQuantity) * ((order.Action == "BUY") ? 1 : -1); // Order full symbol includes localsymbol, exchange, multiplier, sectype // o.LocalSymbol = contract.LocalSymbol; // o.Exchange = contract.Exchange; // o.Security = (SecurityType)EnumDescConverter.GetEnumValue(typeof(SecurityType), contract.SecType); o.FullSymbol = ContractToSecurityFullName(contract); o.TrailPrice = ((order.OrderType == "TRAIL") || (order.OrderType == "TRAIL LIMIT")) ? (decimal)order.AuxPrice : 0m; o.StopPrice = ((order.OrderType == "STP") || (order.OrderType == "STP LMT")) ? (decimal)order.AuxPrice : 0m; o.LimitPrice = ((order.OrderType == "LMT") || (order.OrderType == "TRAIL LIMIT") || (order.OrderType == "STP LMT")) ? (decimal)order.LmtPrice : 0m; o.Currency = contract.Currency; // o.Currency = (CurrencyType)EnumDescConverter.GetEnumValue(typeof(CurrencyType), contract.Currency); // o.TIF = order.Tif; // Todo: add Tif o.OrderDate = Util.ToIntDate(DateTime.Now); o.OrderTime = Util.ToIntTime(DateTime.Now); if (contract.SecType != "BAG") { OnGotOrder(o); // send deferred fills if any // iterate backwards for possible removal for (int i = _duplicateIBIdToDeferredTrade.Count - 1; i > -1; i--) { if (_duplicateIBIdToDeferredTrade[i].Key == orderId) { Trade trade = _duplicateIBIdToDeferredTrade[i].Value; trade.Id = o.Id; // strategy id _duplicateIBIdToDeferredTrade.RemoveAt(i); OnGotFill(trade); } } } }