Skip to content

Commit 5bca594

Browse files
committed
chore: add example of how to get CC balance
Fixes #40
1 parent 272550d commit 5bca594

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

README.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,30 @@ class WSApiTest:
102102
# This is an "unknown" account, for which description is generic; please open an issue on https://github.com/gboudreau/ws-api-python/issues and include the following:
103103
print(f" Unknown account: {account}")
104104

105-
if account['currency'] == 'CAD':
106-
value = account['financials']['currentCombined']['netLiquidationValue']['amount']
107-
print(f" Net worth: {value} {account['currency']}")
108-
# Note: For USD accounts, value is the CAD value converted to USD
109-
# For USD accounts, only the balance & positions are relevant
110-
111-
# Cash and positions balances
112-
balances = ws.get_account_balances(account['id'])
113-
cash_balance_key = 'sec-c-usd' if account['currency'] == 'USD' else 'sec-c-cad'
114-
cash_balance = float(balances.get(cash_balance_key, 0))
115-
print(f" Available (cash) balance: {cash_balance} {account['currency']}")
116-
117-
if len(balances) > 1:
118-
print(" Assets:")
119-
for security, bal in balances.items():
120-
if security in ['sec-c-cad', 'sec-c-usd']:
121-
continue
122-
print(f" - {security} x {bal}")
123-
105+
if 'credit-card' in account['id']:
106+
cc_infos = ws.get_creditcard_account(account['id'])
107+
balance = cc_infos['balance']['current']
108+
print(f" Credit card balance: {balance} CAD")
109+
else:
110+
if account['currency'] == 'CAD':
111+
value = account['financials']['currentCombined']['netLiquidationValue']['amount']
112+
print(f" Net worth: {value} {account['currency']}")
113+
# Note: For USD accounts, value is the CAD value converted to USD
114+
# For USD accounts, only the balance & positions are relevant
115+
116+
# Cash and positions balances
117+
balances = ws.get_account_balances(account['id'])
118+
cash_balance_key = 'sec-c-usd' if account['currency'] == 'USD' else 'sec-c-cad'
119+
cash_balance = float(balances.get(cash_balance_key, 0))
120+
print(f" Available (cash) balance: {cash_balance} {account['currency']}")
121+
122+
if len(balances) > 1:
123+
print(" Assets:")
124+
for security, bal in balances.items():
125+
if security in ['sec-c-cad', 'sec-c-usd']:
126+
continue
127+
print(f" - {security} x {bal}")
128+
124129
print(" Historical Value & Gains:")
125130
historical_fins = ws.get_account_historical_financials(account['id'], account['currency'])
126131
for hf in historical_fins:

0 commit comments

Comments
 (0)