Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

portfolio (ibConn.portfolio) has no currency #32

Description

@nono-london

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions