I'm having a hard time submitting an order to my IB Gateway. The TWS logs don't tell me much as to what I am doing wrong: 06:51:30:519 <- 3-42-0-0-IVE-STK--0---ARCA--USD-IVE-----0--0-0-----0--0-0-0-0-0-0-0-0--0-------0--0-0---0-0-0-0-0-0-0-0-0-0-0-0-0-0-0--0-0-0-0-0-0-0-0-----0---0-0--0-- 06:51:30:535 -> 4-2-0-321-Error validating request.-'bN' : cause - Invalid order type was entered- I am just trying to submit a MKT order to flatten my position of 100 shares. Here is the order object I'm sending to the gateway: I: May-21 08:20:09.497991 | service.go | ib.placeOrder | sent order: {OrderID:1 ClientID:0 PermID:0 Action:SELL TotalQty:100 OrderType:MKT LimitPrice:1.7976931348623157e+308 AuxPrice:1.7976931348623157e+308 TIF: ActiveStartTime: ActiveStopTime: OCAGroup: OCAType:0 OrderRef:Closing position Transmit:true ParentID:0 BlockOrder:false SweepToFill:false DisplaySize:0 TriggerMethod:0 OutsideRTH:false Hidden:false GoodAfterTime: GoodTillDate: OverridePercentageConstraints:false Rule80A: AllOrNone:false MinQty:9223372036854775807 PercentOffset:1.7976931348623157e+308 TrailStopPrice:1.7976931348623157e+308 TrailingPercent:1.7976931348623157e+308 FAGroup: FAProfile: FAMethod: FAPercentage: OpenClose:O Origin:0 ShortSaleSlot:0 DesignatedLocation: ExemptCode:-1 DiscretionaryAmount:0 ETradeOnly:0 FirmQuoteOnly:false NBBOPriceCap:1.7976931348623157e+308 OptOutSmartRouting:false AuctionStrategy:0 StartingPrice:1.7976931348623157e+308 StockRefPrice:1.7976931348623157e+308 Delta:1.7976931348623157e+308 StockRangeLower:1.7976931348623157e+308 StockRangeUpper:1.7976931348623157e+308 Volatility:1.7976931348623157e+308 VolatilityType:9223372036854775807 ContinuousUpdate:0 ReferencePriceType:9223372036854775807 DeltaNeutralOrderType: DeltaNeutralAuxPrice:1.7976931348623157e+308 DeltaNeutral:{ContractID:0 SettlingFirm: ClearingAccount: ClearingIntent: OpenClose: ShortSale:false ShortSaleSlot:0 DesignatedLocation:} BasisPoints:1.7976931348623157e+308 BasisPointsType:9223372036854775807 ScaleInitLevelSize:9223372036854775807 ScaleSubsLevelSize:9223372036854775807 ScalePriceIncrement:1.7976931348623157e+308 ScalePriceAdjustValue:1.7976931348623157e+308 ScalePriceAdjustInterval:9223372036854775807 ScaleProfitOffset:1.7976931348623157e+308 ScaleAutoReset:false ScaleInitPosition:9223372036854775807 ScaleInitFillQty:9223372036854775807 ScaleRandomPercent:false ScaleTable: HedgeType: HedgeParam: AccountU927493 SettlingFirm: ClearingAccount: ClearingIntent: AlgoStrategy: AlgoParams:{Params:[]} WhatIf:false NotHeld:false SmartComboRoutingParams:[] OrderComboLegs:[] OrderMiscOptions:[]}
I assume that you are submitting orders via an API program, not manually via TWS. Does this error happen each and every time you submit an order? Or is this an incidental occasion?
Yes I am submitting this order via the placeOrder API. The error happens every time. Also this is in my paper trading account.
Did you submit this order during active market hours? I see multiple time stamps in your log but don't know the time zone you're in.
I tried submitting the order during mkt hours and outside mkt hours and see the same error. Is there a more detailed explanation of the specific error message? What is the validation logic for a market order? Thanks
In certain cases (e.g. when the market is closed) is it not allowed to place an MKT order. I forgot the exact details about the necessary requirements. What you could do, as analysis step, is to replace the MKT sell order with a LMT order with a low price (e.g. 10% below current market price). Which basically is the same as a market order. Then you can verify whether you have actually used an "invalid order type", which is the error message which was given to you. LMT orders are allowed outside market hours. What you also should do is to print out all details from all three error callbacks.
Ok, thanks for the idea. I did submit the order as a LMT order with a limitPrice 10% below the last close. I see the same error: I: May-22 11:50:09.228447 | service.go | ib.placeOrder | sent order: {OrderID:1 ClientID:0 PermID:0 Action:SELL TotalQty:100 OrderType:LMT LimitPrice:133.443 AuxPrice:1.7976931348623157e+308 TIF: ActiveStartTime: ActiveStopTime: OCAGroup: OCAType:0 OrderRef:ClosingPosition Transmit:true ParentID:0 BlockOrder:false SweepToFill:false DisplaySize:0 TriggerMethod:0 OutsideRTH:false Hidden:false GoodAfterTime: GoodTillDate: OverridePercentageConstraints:false Rule80A: AllOrNone:false MinQty:9223372036854775807 PercentOffset:1.7976931348623157e+308 TrailStopPrice:1.7976931348623157e+308 TrailingPercent:1.7976931348623157e+308 FAGroup: FAProfile: FAMethod: FAPercentage: OpenClose:O Origin:0 ShortSaleSlot:0 DesignatedLocation: ExemptCode:-1 DiscretionaryAmount:0 ETradeOnly:0 FirmQuoteOnly:false NBBOPriceCap:1.7976931348623157e+308 OptOutSmartRouting:false AuctionStrategy:0 StartingPrice:1.7976931348623157e+308 StockRefPrice:1.7976931348623157e+308 Delta:1.7976931348623157e+308 StockRangeLower:1.7976931348623157e+308 StockRangeUpper:1.7976931348623157e+308 Volatility:1.7976931348623157e+308 VolatilityType:9223372036854775807 ContinuousUpdate:0 ReferencePriceType:9223372036854775807 DeltaNeutralOrderType: DeltaNeutralAuxPrice:1.7976931348623157e+308 DeltaNeutral:{ContractID:0 SettlingFirm: ClearingAccount: ClearingIntent: OpenClose: ShortSale:false ShortSaleSlot:0 DesignatedLocation:} BasisPoints:1.7976931348623157e+308 BasisPointsType:9223372036854775807 ScaleInitLevelSize:9223372036854775807 ScaleSubsLevelSize:9223372036854775807 ScalePriceIncrement:1.7976931348623157e+308 ScalePriceAdjustValue:1.7976931348623157e+308 ScalePriceAdjustInterval:9223372036854775807 ScaleProfitOffset:1.7976931348623157e+308 ScaleAutoReset:false ScaleInitPosition:9223372036854775807 ScaleInitFillQty:9223372036854775807 ScaleRandomPercent:false ScaleTable: HedgeType: HedgeParam: AccountU927493 SettlingFirm: ClearingAccount: ClearingIntent: AlgoStrategy: AlgoParams:{Params:[]} WhatIf:false NotHeld:false SmartComboRoutingParams:[] OrderComboLegs:[] OrderMiscOptions:[]} E: May-22 11:50:09.303653 | service.go | ib.engineLoop | error: Error validating request.-'bN' : cause - Invalid order type was entered (0/321), Account: PAPER, Error ID: 0, Code:321, Message: Error validating request.-'bN' : cause - Invalid order type was entered Also, the openOrder, orderStatus callbacks don't get called. I only get this error message on the errorMessage callback. Thanks
In that case you'd better review your code in detail. There might be something wrong in parameter settings and such. Of course not. Your order is not processed by IB, because it is rejected. So there is nothing to report. One more tip: don't fiddle with code about placing orders during the weekend. Wait until the market has re-opened.
Show your order as you entered it, the attributes of the order are helpful. From what I see your TIF is clearly missing. order.tif = 'DAY' (or 'GTC') would be a start.
Well I figured out what I was doing wrong: I did not properly fill the PlaceOrder struct with the order details so the gateway was receiving what I thought I was sending. Thank you everyone for your helpful insights!