"You must enter a valid price" - API vs TWS

Discussion in 'Interactive Brokers' started by nooby_mcnoob, May 7, 2020.

  1. Anyone ever had this issue where the API doesn't accept an order but TWS does, and only has an issue in the live account?

    Through the API, I put in an order for USDCAD:

    Code:
      contract = Contract()
      contract.symbol="USD"
      contract.secType="CASH"
      contract.currency="CAD"
      contract.exchange="IDEALPRO"
      order = Order()
      order.action="SELL"
      order.orderType="LMT"
      order.totalQuantity=50000
      minTick = 5e-05
      order.lmtPrice=1.41675
      self.placeOrder(orderId,contract,order)
    
    I get the message

    I put in the same exact order in TWS manually, no problems. Order goes through. I put the same order in the paper account through the API and it's fine, no problems. It's only live trading where I have the problem, and even then, only through the API.

    Any ideas?

    Thanks!
     
    Last edited: May 7, 2020
  2. kmiklas

    kmiklas

    Where do you assign the value of orderId
     
  3. That's not the issue, just assume it's 80085.
     
  4. sprstpd

    sprstpd

    Totally idiotic brainstorming ideas:

    1. Try writing out minTick = 0.00005
    2. Maybe it is a floating point issue where the value IB sees is not what you think it is (like 1.41674999 for the lmtPrice)

    Good luck!
     
  5. That was an excellent guess and I actually removed minTick from the equation. You are correct that the price cannot be exactly represented as floating point but that doesn't explain why we don't have a problem in paper trading vs live trading.

    Surely someone here trades FX through the API!
     
  6. sprstpd

    sprstpd

    What I am saying is that maybe when you enter the price in TWS, it is handling the floating point issue properly but when you use the API (I'm assuming you are using Python), there is something going on with how Python interprets the 1.41675 so that when it passes it to IB, IB sees it as 1.41674999 or whatever. Have you checked the logs to see if it shows you what price IB is seeing from your API order? Maybe the logs don't show this.
     
  7. Another excellent guess. I went through the log and it looks like IB relies on Python to round it properly when converting it to a string for the message. The actual message looks something like this. Notice the price is exactly as input.

    3\026\00\0USD\0CASH\0\00.0\0\0\0IDEALPRO\0\0CAD\0\0\0\0\0SELL\050000\0LMT\01.41675\0\0\0\0\0\00\0\01\00\00\00\00\00\00\00\0\00\0\0\0\0\0\0\0\00\0\0-1\00\0\0\00\0\0\01\01\0\00\0\0\0\0\0\00\0\0\0\0\00\0\0\0\0\0\0\0\0\0\0\00\0\0\00\00\0\0\00\0\00\00\00\00\0\01.7976931348623157e+308\01.7976931348623157e+308\01.7976931348623157e+308\01.7976931348623157e+308\01.7976931348623157e+308\00\0\0\0\01.7976931348623157e+308\0\0\0\0\00\00\00\0\0

    Edit: and here is the IB side from their logs (again, shows correctly):

    9:27:58:381 <- 3-27-0-USD-CASH--0.0---IDEALPRO--CAD-----SELL-50000-LMT-1.41675------0--1-0-0-0-0-0-0-0--0--------0---1-0---0---1-1--0------0-----0-----------0---0-0---0--0-0-0-0--1.7976931348623157e+308-1.7976931348623157e+308-1.7976931348623157e+308-1.7976931348623157e+308-1.7976931348623157e+308-0----1.7976931348623157e+308-----0-0-0--
    09:27:58:398 -> ---)4-2-27-463-You must enter a valid price.-
     
  8. Even upgrading to latest TWS didn't help. Ugh.
     
  9. sprstpd

    sprstpd

    Really strange. That error message has always implied a floating point issue on my end.

    I don't use Python. I could try to reproduce on my end if you gave a small complete working sample. Your sample above only shows the order code.

    One other guess - do you need to fill in other price fields (like auxPrice) with 0s? Is there another price field that IB could be complaining about?
     
  10. That's the full example, if you were willing to try! You can just have your boilerplate code and enter the order exactly as given above but replace the orderId with 80085 (or some other unused order id).

    I tried your idea about setting other fields. I am nearly 100% sure this is a floating point issue on TWS side like you suggested, nothing else really makes sense except... why does it work properly with the paper trading account?
     
    #10     May 7, 2020