Cash quantity stock orders via the API

Discussion in 'Interactive Brokers' started by nijshar28, Jun 9, 2020.

  1. Hi. I was wondering if it is possible to place a cash quantity stock order via the API.

    As illustrated here (, the idea is that the number of shares would be calculated dynamically by IB based on the current stock price.

    I tried placing API orders specifying cashQty and leaving totalQuantity unspecified (or setting it to '' and None) in the Order class. However, that returns "Error 321, [...]- The size value cannot be zero: [...] Canceled order: [...].

    Any advice would be highly appreciated. Thank you.
  2. No, I don't think that it is available "out of the box". You would have to take two steps:
    step 1a: use reqMktData() to get the latest bid and/or ask price.
    step 1b: based on the received price calculate the appropriate quantity.
    step 2: submit your order line for the calculated quantity.
    nijshar28 likes this.
  3. Yep. Makes sense.
  4. Any idea why is it available "out of the box" when using TWS GUI, and not wen using TWS API?
  5. I submitted a ticket to the IB support, so will update here after get a response
  6. I am not familiar with the TWS code base, but my assumption is that they do the exact same steps. The user does not get to see those steps, only the end result, wrapped in a nice looking GUI.
  7. Ok, the reply from IB is:

    Unfortunately Cash Quantity orders are only supported for forex orders via TWS API. You may submit your feature request on the Interactive Brokers feature poll under ‘API’ Category. Below is the link for the same: