IB API Execution Gone Wrong, Please Help.

Discussion in 'Order Execution' started by jennywestwong, Sep 17, 2020.

  1. Hi Everyone, I use IB API and python. I have been testing out my algo and it was working great, making reverse trades whenever my indicator gives a signal. However, once I switched computers, the execution started going haywire. The bottom of my image shows when things were working fine, buy, sell, buy, sell etc..(performing reversal). When I executed the algo from another machine, it would buy buy buy or sell sell sell for a full minute. Has anyone experienced this and know of a fix? I went back to my 1st computer and now it is also behaving like the 2nd computer...
     
  2. MattZ

    MattZ Sponsor

    When you switched computers, you went live?
     
    d08 likes this.
  3. It sounds like that there is something wrong in your code. You may want to review how you keep track of the open position size. And determine which trade actions are (not) allowed based on the current position size. For example: "if open position quantity > 0 then don't allow buy order". This would prevent a buy order if you are already long.
    It could also be that you first order (e.g. buy order) was not yet filled and your software determined that a long position is required, thus firing off another buy order.
     
    MoreLeverage, jennywestwong and Ninja like this.
  4. d08

    d08

    Simple debugging required. Look at the values as they are passed through your code.
     
    ET180 and rb7 like this.
  5. Thanks guys, I took a closer look at the IB log and it was something to do with margin requirements. @matt, no both of them were paper accounts, @ HobbyTrading, I am missing this in my code, but again because it worked initially so I didn't try to change my codes.
     
    MattZ likes this.
  6. Ninja

    Ninja

    Yes, something like that is always a good idea. You could also add an entry to a log file when a buy order is prevented, e.g. because of an already open position. So then you know how often such a condition occurs.

    You could consider this as part of your risk management by routing all orders through such a module and then log the decisions, e.g. based on which parameters/conditions orders are allowed or denied.
     
    Last edited: Sep 19, 2020