Distinguish open position in IB for different bots (strategies)

Discussion in 'Order Execution' started by ac02nwt, May 25, 2022.

  1. ac02nwt


    Hi all,

    I am building a bot to send order to IB for trade with Python. In order to run multiple strategies, i am running multiple bots in which every bot will be assigned different OrderRef to place order to IB. But when i want to square the open position, how can i identify which open position belongs to which strategies? I tried reqPositions but the information is insufficient to differentiate. It seems that there is reqPositionsMulti, but i don't know how to use it. (What do reqId, modelCode mean? Appreciate if someone can share an example to illustrate) and I am not sure if this "reqPositionsMulti" can help.

    def positionMulti(self, reqId: int, account: str, modelCode: str,contract: Contract, pos: float, avgCost: float): super().positionMulti(reqId, account, modelCode, contract, pos, avgCost)
  2. M.W.


    You can attach a ref string, forgot the parameter name. Check out the documentation.


  3. Place order with Order(.... modelCode = 'model_name', ....)

    Get positions back with positionMulti(...., modelCode = 'model name', ....)

    M.W. likes this.
  4. M.W.


    Right, apologies, I did not read the question carefully, it was about positions not the orders...

  5. ac02nwt


    Thanks for your advice. Let me try.