From 1dabdfaae76ec8b8d5a1e64032e78a1116e6fcbc Mon Sep 17 00:00:00 2001 From: paramkr2 Date: Fri, 7 Jun 2024 08:21:45 +0530 Subject: [PATCH 1/3] Added functionality reqPositionsMulti --- ib_async/ib.py | 10 +++++++++- ib_async/wrapper.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ib_async/ib.py b/ib_async/ib.py index 749b1f8..b78a437 100644 --- a/ib_async/ib.py +++ b/ib_async/ib.py @@ -2502,7 +2502,15 @@ def reqUserInfoAsync(self): future = self.wrapper.startReq(reqId) self.client.reqUserInfo(reqId) return future - + + def reqPositionsMulti(self,account,modelCode) -> List[Position]: + return self._run(self.reqPositionsMultiAsync(account,modelCode)) + + def reqPositionsMultiAsync(self,account,modelCode) -> Awaitable[List[Position]]: + reqId = self.client.getReqId() + future = self.wrapper.startReq(reqId, container=[]) + self.client.reqPositionsMulti(reqId, account, modelCode) + return future if __name__ == "__main__": loop = util.getLoop() diff --git a/ib_async/wrapper.py b/ib_async/wrapper.py index 5b9c8da..4ec799f 100644 --- a/ib_async/wrapper.py +++ b/ib_async/wrapper.py @@ -1495,3 +1495,13 @@ def tcpDataProcessed(self): ticker.time = self.lastTime ticker.updateEvent.emit(ticker) self.ib.pendingTickersEvent.emit(self.pendingTickers) + + def positionMulti( + self, reqId: int, account: str, modelCode: str, + contract: Contract, pos: float, avgCost: float): + results = self._results.get(reqId) ; + if results is not None: + results.append({'account':account,'modelCode':modelCode , 'symbol':contract.symbol,'secType':contract.secType,'currency':contract.currency,'position':pos , 'avgCost':avgCost } ) + + def positionMultiEnd(self, reqId: int): + self._endReq(reqId) \ No newline at end of file From ab1b065211503a262c0883dec198908b534bf9c8 Mon Sep 17 00:00:00 2001 From: paramkr2 Date: Fri, 7 Jun 2024 08:25:19 +0530 Subject: [PATCH 2/3] Added functionality reqPositionsMulti --- ib_async/wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ib_async/wrapper.py b/ib_async/wrapper.py index 4ec799f..897eb2d 100644 --- a/ib_async/wrapper.py +++ b/ib_async/wrapper.py @@ -1499,7 +1499,7 @@ def tcpDataProcessed(self): def positionMulti( self, reqId: int, account: str, modelCode: str, contract: Contract, pos: float, avgCost: float): - results = self._results.get(reqId) ; + results = self._results.get(reqId) ; if results is not None: results.append({'account':account,'modelCode':modelCode , 'symbol':contract.symbol,'secType':contract.secType,'currency':contract.currency,'position':pos , 'avgCost':avgCost } ) From 85669bb91f2dc5db4651f66a9d61aea282a10be3 Mon Sep 17 00:00:00 2001 From: paramkr2 Date: Fri, 7 Jun 2024 08:28:16 +0530 Subject: [PATCH 3/3] Added functionality reqPositionsMulti, Fix duplicate --- ib_async/wrapper.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/ib_async/wrapper.py b/ib_async/wrapper.py index 897eb2d..4b2e5db 100644 --- a/ib_async/wrapper.py +++ b/ib_async/wrapper.py @@ -442,18 +442,14 @@ def positionEnd(self): self._endReq("positions") def positionMulti( - self, - reqId: int, - account: str, - modelCode: str, - contract: Contract, - pos: float, - avgCost: float, - ): - pass + self, reqId: int, account: str, modelCode: str, + contract: Contract, pos: float, avgCost: float): + results = self._results.get(reqId) ; + if results is not None: + results.append({'account':account,'modelCode':modelCode , 'symbol':contract.symbol,'secType':contract.secType,'currency':contract.currency,'position':pos , 'avgCost':avgCost } ) def positionMultiEnd(self, reqId: int): - pass + self._endReq(reqId) def pnl( self, reqId: int, dailyPnL: float, unrealizedPnL: float, realizedPnL: float @@ -1496,12 +1492,5 @@ def tcpDataProcessed(self): ticker.updateEvent.emit(ticker) self.ib.pendingTickersEvent.emit(self.pendingTickers) - def positionMulti( - self, reqId: int, account: str, modelCode: str, - contract: Contract, pos: float, avgCost: float): - results = self._results.get(reqId) ; - if results is not None: - results.append({'account':account,'modelCode':modelCode , 'symbol':contract.symbol,'secType':contract.secType,'currency':contract.currency,'position':pos , 'avgCost':avgCost } ) + - def positionMultiEnd(self, reqId: int): - self._endReq(reqId) \ No newline at end of file