ranaroussi / ezibpy

ezIBpy, a Pythonic Client for Interactive Brokers API
Apache License 2.0
324 stars 116 forks source link

portfolio (ibConn.portfolio) has no currency #32

Open nono-london opened 5 years ago

nono-london commented 5 years ago

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

nono-london commented 4 years ago

Hi, is this not getting added?