Skip to content

Commit

Permalink
Merge pull request #460 from MaxxRK/new_features
Browse files Browse the repository at this point in the history
add specific account#'s for buy transactions
  • Loading branch information
NelsonDane authored Jan 10, 2025
2 parents 424466a + 5eb03be commit 92b2edd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
8 changes: 7 additions & 1 deletion schwabAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion vanguardAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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():
Expand Down

0 comments on commit 92b2edd

Please sign in to comment.