def _downloadBalance(ib: IB.IB, lenient: bool) -> AccountBalance:
    accountValues = (val for val in ib.accountSummary()
                     if val.account == "All" and val.tag == "TotalCashBalance"
                     and val.currency != "BASE")

    cashByCurrency: Dict[Currency, Cash] = {}

    for cash in parsetools.lenientParse(accountValues,
                                        transform=_extractCash,
                                        lenient=lenient):
        cashByCurrency[cash.currency] = (cashByCurrency.get(
            cash.currency, Cash(currency=cash.currency, quantity=Decimal(0))) +
                                         cash)

    return AccountBalance(cash=cashByCurrency)
Example #2
0
market = 'snp'

# ...variables initialization
with open('var.json', 'r') as fp:
    data = json.load(fp)

host = data['common']['host']
port = data[market]['port']
cid = 1

# ...connect to IB
ib = IB().connect(host=host, port=port, clientId=cid)
acct = ib.managedAccounts()[0]

# ..get account summary
accsum = ib.accountSummary(account=acct)

# ..get liquidity and funds dictionary
funds = {
    t.tag: t.value
    for t in accsum if t.tag in ["NetLiquidation", "AvailableFunds"]
}

# ..dailyPnl
ib.reqPnL(acct)
ib.sleep(8)
pnlobj = ib.pnl()[0]
ib.cancelPnL(acct)

pnldict = {
    'dailyPnL': pnlobj.dailyPnL,