Skip to content

Commit

Permalink
fix holdings with multi account
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonDane committed Jan 22, 2024
1 parent 1c5108b commit 4708a23
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions webullAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def webull_init(WEBULL_EXTERNAL=None):
# Initialize .env file
load_dotenv()
# Import Webull account
wb_obj = Brokerage("Webull")
if not os.getenv("WEBULL") and WEBULL_EXTERNAL is None:
print("Webull not found, skipping...")
return None
Expand All @@ -41,9 +42,9 @@ def webull_init(WEBULL_EXTERNAL=None):
if WEBULL_EXTERNAL is None
else WEBULL_EXTERNAL.strip().split(",")
)
for account in accounts:
for index, account in enumerate(accounts):
print("Logging in to Webull...")
name = f"Webull {accounts.index(account) + 1}"
name = f"Webull {index + 1}"
account = account.split(":")
if len(account) != 4:
print(
Expand All @@ -60,8 +61,6 @@ def webull_init(WEBULL_EXTERNAL=None):
break
if i == MAX_WB_RETRIES - 1:
raise Exception(f"Unable to log in to {name}. Check credentials.")
# Initialize Webull account
wb_obj = Brokerage("Webull")
wb_obj.set_logged_in_object(name, wb, "wb")
wb_obj.set_logged_in_object(name, account[3], "trading_pin")
# Get all accounts
Expand Down Expand Up @@ -98,7 +97,7 @@ def webull_holdings(wbo: Brokerage, loop=None):
if positions is None:
positions = obj.get_positions(v2=True)
# List of holdings dictionaries
if positions != []:
if positions is not None and positions != []:
for item in positions:
sym = item["ticker"]["symbol"]
if sym == "":
Expand All @@ -110,7 +109,7 @@ def webull_holdings(wbo: Brokerage, loop=None):
printAndDiscord(f"{key} {account}: Error getting holdings: {e}", loop)
traceback.print_exc()
continue
printHoldings(wbo, loop=loop)
printHoldings(wbo, loop=loop)


def webull_transaction(wbo: Brokerage, orderObj: stockOrder, loop=None):
Expand Down

0 comments on commit 4708a23

Please sign in to comment.