-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathportfolio_overview.py
48 lines (42 loc) · 2.4 KB
/
portfolio_overview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from questrade_helper import Portfolio
from symbol_search import Symbol
import sys
import argparse
def main():
parser = argparse.ArgumentParser(description="Retrieve a QT account by type then calculates the target composition delta and provide automatic balancing figures")
parser.add_argument('-t', '--type', dest="account_type", type=str, help="define account type")
parser.add_argument('-c', '--cash', dest="cash_injection", type=float, help="define the additional cash injection on top of what's available in the account", default=0.0 )
parser.add_argument('-e', '--exchange', dest="cash_injection_cad", type=str2bool, help="define what the cash injection's currency is, true = CAD, false = USD", default=True )
parser.add_argument('-r', '--refresh-token', dest='refresh_token', type=str, help="refresh token for API")
parser.add_argument('-s', '--symbol', dest="symbol_search", type=str, help="symbol or ticker to perform a search")
parser.add_argument('-n', '--no-cash-mode', dest="no_cash_mode", type=str2bool, help="the account is treated as if there's no cash in the account, a pure re-balance")
args = parser.parse_args()
if len(sys.argv) < 3:
print("Required at least one argument please see usage below")
print("=====================================================")
parser.print_help()
sys.exit(1)
if args.account_type and not args.symbol_search:
OUTPUT = Portfolio(
account_type=args.account_type,
cash_injection=args.cash_injection,
cash_injection_cad=args.cash_injection_cad,
refresh_token=args.refresh_token,
no_cash_mode=args.no_cash_mode)
print(OUTPUT.final_output.T)
print("Current exchange rate USD to CAD: {:.4f}".format(OUTPUT.exchange_rate_USD_CAD))
elif args.symbol_search and not args.account_type:
Symbol(symbol = args.symbol_search, refresh_token = args.refresh_token)
else:
raise argparse.ArgumentError("Either an account type full portfolio overview or a symbol looking up is required")
def str2bool(value: str):
if isinstance(value, bool):
return value
if value.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif value.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')
if __name__=="__main__":
main()