MaxxRK / chaseinvest-api

MIT License
6 stars 4 forks source link

It can not click the trade button. #42

Closed Thesyjaga closed 2 months ago

Thesyjaga commented 2 months ago

I think the website is changed in the elements part

MaxxRK commented 2 months ago

Can you post a screenshot of what it looks like when it gets stuck? Mark out sensitive information of course.

Thesyjaga commented 2 months ago

it can not get past this page

image

Thesyjaga commented 2 months ago

this is my code rn

import sys from chase import account as acc from chase import order from chase import session from playwright.sync_api import sync_playwright import time

def get_current_price(stock_symbol): stock_data = yf.Ticker(stock_symbol) current_price = stock_data.history(period="1d")["Close"].iloc[-1] return current_price

Create Session

cs = session.ChaseSession(title="ChaseProfile", headless=False, profile_path='./chase_profile')

Login to Chase.com

login_one = cs.login("", "", "")

Wait for 12 seconds to allow for login to process

time.sleep(12)

Check if login succeeded without needing 2fa

if not login_one: print('Login succeeded without needing 2fa...') else: code = input('Please input code that was sent to your phone: ') login_two = cs.login_two(code)

all_accounts = acc.AllAccount(cs)

if all_accounts.account_connectors is None: sys.exit("Failed to get account connectors, exiting script...")

account_ids = list(all_accounts.account_connectors.keys())

Display options

print("Options:") print("1. Buy") print("2. Sell") choice = input("Enter your choice (1 for BUY or 2 for SELL): ")

if choice == "1": buy_or_sell = "BUY" elif choice == "2": buy_or_sell = "SELL" else: sys.exit("Invalid choice. Please enter '1' for BUY or '2' for SELL.")

stock_symbol = input("Enter the stock ticker: ") quantity = int(input("Enter the quantity: "))

Get the current price of the stock

current_price = get_current_price(stock_symbol)

Place order for the specified stock symbol and quantity in all accounts

order_module = order.Order(cs) # Creating an instance of Order

for account_id in account_ids: try: search_input = cs.page.wait_for_selector('input[name="search"]', timeout=1000) search_input.fill(stock_symbol) except Exception as e: print(f"Error finding search input: {e}") time.sleep(0.5)

# Ensure the interface has enough time to react
time.sleep(2)

try:
    order_messages = order_module.place_order(
        account_id,
        quantity,
        order.PriceType.MARKET,
        stock_symbol,
        order.Duration.DAY,
        order.OrderSide[buy_or_sell],
        dry_run=False,
    )

    if order_messages.get("ORDER CONFIRMATION"):
        print(order_messages["ORDER CONFIRMATION"])
    else:
        print(order_messages)

except Exception as e:
    print(f"Error placing order for account {account_id}: {e}")

# Wait for 4 seconds before proceeding to the next account
time.sleep(0.1)
MaxxRK commented 2 months ago

Can you show me the traceback that it gives you when you fail? It is just not getting to the order page at all right now.

Thesyjaga commented 2 months ago

It was my bad I am really sorry I have imported to my new device and I had an older version downloaded