diff --git a/README.md b/README.md index 981ca736..51e4a2d2 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,9 @@ Required `.env` variables: - `SCHWAB_PASSWORD` - `SCHWAB_TOTP_SECRET` (If 2fa is enabled, else NA) +Optional `.env` variables: +- `SCHWAB_ACCOUNT_NUMBERS=ACCOUNT#1:ACCOUNT#2` (Optional, to specify the single account numbers the bot should use when buying. If not specified, all accounts will be used) + `.env` file format: - With 2fa: `SCHWAB=SCHWAB_USERNAME:SCHWAB_PASSWORD:SCHWAB_TOTP_SECRET` - Without 2fa: `SCHWAB=SCHWAB_USERNAME:SCHWAB_PASSWORD:NA` @@ -385,6 +388,7 @@ Required `.env` variables: Optional `.env` variables: - `DEBUG` (Set to `True` to enable debug mode, otherwise `False`) +- `VG_ACCOUNT_NUMBERS=ACCOUNT#1:ACCOUNT#2` (Optional, to specify the single account numbers the bot should use when buying. If not specified, all accounts will be used) `.env` file format: - `VANGUARD=VANGUARD_USERNAME:VANGUARD_PASSWORD:PHONE_LAST_FOUR:DEBUG` diff --git a/schwabAPI.py b/schwabAPI.py index aee849b7..ab4cfd2b 100644 --- a/schwabAPI.py +++ b/schwabAPI.py @@ -87,7 +87,8 @@ def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): print("Schwab") print("==============================") print() - # Buy on each account + # Use each account (unless specified in .env) + purchase_accounts = os.getenv("SCHWAB_ACCOUNT_NUMBERS", "").strip().split(":") for s in orderObj.get_stocks(): for key in schwab_o.get_account_numbers(): printAndDiscord( @@ -97,6 +98,11 @@ def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): obj: Schwab = schwab_o.get_logged_in_objects(key) for account in schwab_o.get_account_numbers(key): print_account = maskString(account) + if purchase_accounts != [""] and orderObj.get_action().lower() != "sell" and str(account) not in purchase_accounts: + print( + f"Skipping account {print_account}, not in SCHWAB_ACCOUNT_NUMBERS" + ) + continue # If DRY is True, don't actually make the transaction if orderObj.get_dry(): printAndDiscord( diff --git a/vanguardAPI.py b/vanguardAPI.py index fbf2c62f..52199d8c 100644 --- a/vanguardAPI.py +++ b/vanguardAPI.py @@ -140,7 +140,8 @@ def vanguard_transaction(vanguard_o: Brokerage, orderObj: stockOrder, loop=None) print("Vanguard") print("==============================") print() - # Buy on each account + # Use each account (unless specified in .env) + purchase_accounts = os.getenv("VG_ACCOUNT_NUMBERS", "").strip().split(":") for s in orderObj.get_stocks(): for key in vanguard_o.get_account_numbers(): printAndDiscord( @@ -150,6 +151,11 @@ def vanguard_transaction(vanguard_o: Brokerage, orderObj: stockOrder, loop=None) try: for account in vanguard_o.get_account_numbers(key): print_account = maskString(account) + if purchase_accounts != [""] and orderObj.get_action().lower() != "sell" and str(account) not in purchase_accounts: + print( + f"Skipping account {print_account}, not in VG_ACCOUNT_NUMBERS" + ) + continue obj: session.VanguardSession = vanguard_o.get_logged_in_objects(key) # If DRY is True, don't actually make the transaction if orderObj.get_dry():