From a11f05bd7653db1212437bacd1aeeb729e6c3b29 Mon Sep 17 00:00:00 2001 From: Donald Ryan Gullett <45299186+MaxxRK@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:52:03 -0500 Subject: [PATCH 1/8] update schwab-api2 version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bef8f809..e474e5b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ python-dotenv==1.0.0 requests==2.31.0 robin_stocks==3.0.6 schwab-api==0.2.3 -schwab-api2==0.2.8 +schwab-api2==0.2.9 selenium==4.12.0 tastytrade==6.1 webdriver-manager==4.0.0 From 6350cb36b449887d79ac2bafa8700c5188f097f8 Mon Sep 17 00:00:00 2001 From: Donald Ryan Gullett <45299186+MaxxRK@users.noreply.github.com> Date: Wed, 25 Oct 2023 19:13:49 -0500 Subject: [PATCH 2/8] func added to try and fix playwright close --- schwabAPI.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/schwabAPI.py b/schwabAPI.py index 034c6115..4ff14f9b 100644 --- a/schwabAPI.py +++ b/schwabAPI.py @@ -2,6 +2,7 @@ # Schwab API import os +import psutil from time import sleep from dotenv import load_dotenv @@ -19,6 +20,22 @@ SCHWAB_BETA = False +def check_playwright(): + processes = psutil.process_iter() + for process in processes: + try: + # Get the process name and command line arguments + name = process.name() + cmdline = process.cmdline() + + # Check if the process is a Playwright process + if "playwright" in name or "playwright" in cmdline: + print("Terminating Playwright process:", name, cmdline) + process.terminate() + except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): + pass + + def schwab_init(SCHWAB_EXTERNAL=None): # Initialize .env file load_dotenv() @@ -86,6 +103,7 @@ def schwab_holdings(schwab_o: Brokerage, loop=None): if SCHWAB_BETA: print(f"Closing session for {key}") obj.close_session() + check_playwright() def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): @@ -157,3 +175,4 @@ def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): if SCHWAB_BETA: print(f"Closing session for {key}") obj.close_session() + check_playwright() From 0ba3e524f44b1206d732910b99f637c4f0dbba81 Mon Sep 17 00:00:00 2001 From: Donald Ryan Gullett <45299186+MaxxRK@users.noreply.github.com> Date: Wed, 25 Oct 2023 19:56:11 -0500 Subject: [PATCH 3/8] add psutil --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e474e5b3..e80055fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ schwab-api2==0.2.9 selenium==4.12.0 tastytrade==6.1 webdriver-manager==4.0.0 +psutil==5.9.6 From 7597a7c39eb47e1b2769d6d26c585fe662e5c3a4 Mon Sep 17 00:00:00 2001 From: Donald Ryan Gullett <45299186+MaxxRK@users.noreply.github.com> Date: Wed, 25 Oct 2023 20:31:58 -0500 Subject: [PATCH 4/8] add ps-util to dockerfile --- Dockerfile | 1 + requirements.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bbea096d..3601fcd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ wget \ gpg \ python3-pip \ + python3-psutil \ tzdata \ software-properties-common \ && rm -rf /var/lib/apt/lists/* diff --git a/requirements.txt b/requirements.txt index e80055fc..e474e5b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,3 @@ schwab-api2==0.2.9 selenium==4.12.0 tastytrade==6.1 webdriver-manager==4.0.0 -psutil==5.9.6 From 591ae1f756f9307153990cb310c3d247648414ee Mon Sep 17 00:00:00 2001 From: Donald Ryan Gullett <45299186+MaxxRK@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:16:44 -0500 Subject: [PATCH 5/8] remove check for playwright --- Dockerfile | 1 - schwabAPI.py | 19 ------------------- 2 files changed, 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3601fcd1..bbea096d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ wget \ gpg \ python3-pip \ - python3-psutil \ tzdata \ software-properties-common \ && rm -rf /var/lib/apt/lists/* diff --git a/schwabAPI.py b/schwabAPI.py index 4ff14f9b..034c6115 100644 --- a/schwabAPI.py +++ b/schwabAPI.py @@ -2,7 +2,6 @@ # Schwab API import os -import psutil from time import sleep from dotenv import load_dotenv @@ -20,22 +19,6 @@ SCHWAB_BETA = False -def check_playwright(): - processes = psutil.process_iter() - for process in processes: - try: - # Get the process name and command line arguments - name = process.name() - cmdline = process.cmdline() - - # Check if the process is a Playwright process - if "playwright" in name or "playwright" in cmdline: - print("Terminating Playwright process:", name, cmdline) - process.terminate() - except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): - pass - - def schwab_init(SCHWAB_EXTERNAL=None): # Initialize .env file load_dotenv() @@ -103,7 +86,6 @@ def schwab_holdings(schwab_o: Brokerage, loop=None): if SCHWAB_BETA: print(f"Closing session for {key}") obj.close_session() - check_playwright() def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): @@ -175,4 +157,3 @@ def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): if SCHWAB_BETA: print(f"Closing session for {key}") obj.close_session() - check_playwright() From 0d93eac479f72e2451ff11ec0e2e2e84f5234ee2 Mon Sep 17 00:00:00 2001 From: Donald Ryan Gullett <45299186+MaxxRK@users.noreply.github.com> Date: Thu, 26 Oct 2023 19:22:41 -0500 Subject: [PATCH 6/8] move close_session() --- schwabAPI.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/schwabAPI.py b/schwabAPI.py index 034c6115..8270c24e 100644 --- a/schwabAPI.py +++ b/schwabAPI.py @@ -154,6 +154,7 @@ def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): f"{key} {account}: Error submitting order: {e}", loop ) sleep(1) - if SCHWAB_BETA: - print(f"Closing session for {key}") - obj.close_session() + # Move over to be sure the session is not closed until after all operations are completed. + if SCHWAB_BETA: + print(f"Closing session for {key}") + obj.close_session() From a98aefa8eba01a527c65fe2a62d2fc227f088c19 Mon Sep 17 00:00:00 2001 From: Nelson Dane <47427072+NelsonDane@users.noreply.github.com> Date: Fri, 27 Oct 2023 07:40:53 -0700 Subject: [PATCH 7/8] kill all sessions --- schwabAPI.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/schwabAPI.py b/schwabAPI.py index 8270c24e..df1c5b7d 100644 --- a/schwabAPI.py +++ b/schwabAPI.py @@ -154,7 +154,9 @@ def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): f"{key} {account}: Error submitting order: {e}", loop ) sleep(1) - # Move over to be sure the session is not closed until after all operations are completed. + # Kill playwright sessions if SCHWAB_BETA: - print(f"Closing session for {key}") - obj.close_session() + for key in schwab_o.get_account_numbers(): + print(f"Closing session for {key}") + obj: Schwab = schwab_o.get_logged_in_objects(key) + obj.close_session() From 9479a3a44bf3b9cdde6a2a39fbceb34fcffde4eb Mon Sep 17 00:00:00 2001 From: Nelson Dane <47427072+NelsonDane@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:54:25 -0700 Subject: [PATCH 8/8] fix indentation --- schwabAPI.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/schwabAPI.py b/schwabAPI.py index df1c5b7d..5eba683a 100644 --- a/schwabAPI.py +++ b/schwabAPI.py @@ -122,12 +122,12 @@ def schwab_transaction(schwab_o: Brokerage, orderObj: stockOrder, loop=None): ) else: messages, success = obj.trade( - ticker=s, - side=orderObj.get_action().capitalize(), - qty=orderObj.get_amount(), - account_id=account, - dry_run=orderObj.get_dry(), - ) + ticker=s, + side=orderObj.get_action().capitalize(), + qty=orderObj.get_amount(), + account_id=account, + dry_run=orderObj.get_dry(), + ) printAndDiscord( f"{key} account {account}: The order verification was " + "successful"