Hi,
Do you think that it is possible to get the currency of each investments/positions ?
Currently neither portfolio dict nor positions, are showing the currency in which investments are made.
It makes it hard to calculate a P&L in a given currencies.
i have added this bit of code in the method handlePosition in class ezIBpy():
self._positions[msg.account][contractString] = {
"symbol": contractString,
**"currency": str(contract_tuple[3]),**
"position": int(msg.pos),
"avgCost": float(msg.avgCost),
"account": msg.account
}
and in handlePortolio:
self._portfolios[msg.accountName][contractString] = {
"symbol": contractString,
"position": int(msg.position),
"currency": str(contract_tuple[3]),
"marketPrice": float(msg.marketPrice),
"marketValue": float(msg.marketValue),
"averageCost": float(msg.averageCost),
"unrealizedPNL": float(msg.unrealizedPNL),
"realizedPNL": float(msg.realizedPNL),
"totalPNL": float(msg.realizedPNL) + float(msg.unrealizedPNL),
"account": msg.accountName
}
and it seems to work
Thanks
Best
I refer to these 2 dict/json:
ibConn.portfolio
ibConn.positions
Hi,
Do you think that it is possible to get the currency of each investments/positions ?
Currently neither portfolio dict nor positions, are showing the currency in which investments are made.
It makes it hard to calculate a P&L in a given currencies.
i have added this bit of code in the method handlePosition in class ezIBpy():
and in handlePortolio:
self._portfolios[msg.accountName][contractString] = {
"symbol": contractString,
"position": int(msg.position),
"currency": str(contract_tuple[3]),
"marketPrice": float(msg.marketPrice),
"marketValue": float(msg.marketValue),
"averageCost": float(msg.averageCost),
"unrealizedPNL": float(msg.unrealizedPNL),
"realizedPNL": float(msg.realizedPNL),
"totalPNL": float(msg.realizedPNL) + float(msg.unrealizedPNL),
"account": msg.accountName
}
and it seems to work
Thanks
Best
I refer to these 2 dict/json:
ibConn.portfolio
ibConn.positions