¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Incorrect margin in whatif order


 

Your code sets several fields in the order object that do not exist. Most languages would complain about something like that but Python does not:
  • Fields eTradeOnly? and firmQuoteOnly? have been deprecated years ago and have been removed from the Order class entirely in TWS API V9.85 (three years ago)
  • The "whatIf" field in Python is spelled with a lower case "w" but your code has an upper case "W". So you are actually placing orders instead of asking for margin information.

After changing "order.WhatIf" to "order.whatIf" you should get proper margin values ... and no additional orders for APPL.

´³¨¹°ù²µ±ð²Ô


On Fri, Oct 6, 2023 at 08:04 AM, Lipp F. wrote:
The code is like this:
? ? ? ? contract = Contract()
? ? ? ? contract.symbol = "AAPL"
? ? ? ? contract.secType = "STK"
? ? ? ? contract.exchange = "SMART"
? ? ? ? contract.currency = "USD"
?
? ? ? ? order = Order()
? ? ? ? order.orderId = orderId
? ? ? ? order.orderType = "LMT"
? ? ? ? order.lmtPrice = 200
? ? ? ? order.action = "SELL"
? ? ? ? order.totalQuantity = 10
? ? ? ? order.transmit = False
?
? ? ? ? order.eTradeOnly = False
? ? ? ? order.firmQuoteOnly = False
?
? ? ? ? # you need to transmit to get whatif response. In this case, it does NOT transmit the order to the market!
? ? ? ? order.transmit = True
? ? ? ? order.WhatIf = True? ??
?
? ? ? ? self.placeOrder(order.orderId, contract, order)
and it returns Maintenance Margin: 1.7976931348623157E308:
openOrder: 3, contract: 265598,AAPL,STK,,0.0,?,,SMART,,USD,AAPL,NMS,False,,combo:, order: 3,1000,984843980: LMT SELL 10@... DAY, Maintenance Margin: 1.7976931348623157E308
orderStatus. orderId: 3, status:? PreSubmitted, filled: 0.0, remaining: 10.0, avgFillPrice: 0.0, permId: 984843980, parentId: 0, lastFillPrice: 0.0, clientId: 1000, whyHeld: , mktCapPrice: 0.0
openOrder: 3, contract: 265598,AAPL,STK,,0.0,?,,SMART,,USD,AAPL,NMS,False,,combo:, order: 3,1000,984843980: LMT SELL 10@... DAY, Maintenance Margin: 1.7976931348623157E308
orderStatus. orderId: 3, status:? PreSubmitted, filled: 0.0, remaining: 10.0, avgFillPrice: 0.0, permId: 984843980, parentId: 0, lastFillPrice: 0.0, clientId: 1000, whyHeld: , mktCapPrice: 0.0
?

Join [email protected] to automatically receive all group messages.