Bot for investing

22 views Asked by At

I'm trying to create a bot to automatically invest on Brazilian Certificate of Deposits (CD). These are offered by a specific stock broker but they don't last even 4 seconds. The code below refers to the automatic steps after manually typing login, password and token. When I run the program, when I type the login, before entering the password the website blocks my access. How can I tackle this issue?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# Investment page URL
investments_url = "https://experiencia.xpi.com.br/renda-fixa/#/emissao-bancaria"

# WebDriver configuration (you need to have ChromeDriver or another driver installed)
driver = webdriver.Chrome()

# Open the browser and manually login if necessary
input("Please login and press Enter to continue...")

# Function to perform the investment process
def perform_investment():
    # Navigate to the investments page
    driver.get(investments_url)
    
    # Wait for the investments page to load
    time.sleep(2)
    
    # Find all available investments in the table
    investments_table = driver.find_element_by_css_selector(".sc-bkEOxz.jStPvy.soma-table-body.hydrated")
    rows = investments_table.find_elements_by_xpath(".//tr")

    # Check each investment
    for row in rows:
        # Extract investment information
        asset = row.find_element_by_xpath(".//td[1]").text
        issuer = row.find_element_by_xpath(".//td[2]").text
        profitability = float(row.find_element_by_xpath(".//td[3]").text.replace('%', '').replace(',', '.'))

        # Check if the investment meets the specified criteria
        if "SICREDI" in asset.upper() and profitability > 12.50:
            print(f"Investment found: {asset}, Issuer: {issuer}, Profitability: {profitability}%")
            
            # Click the "Invest" button on the table row where the investment was identified
            invest_button = row.find_element_by_xpath(".//button[contains(text(),'Investir')]")
            invest_button.click()
            
            # Wait for the next page to load
            time.sleep(2)
            
            # Fill in the desired quantity (in this example, we fill in with 2)
            quantity_input = driver.find_element_by_xpath("//input[@id='input_quantidade']")
            quantity_input.send_keys("2")
            
            # Click on "Advance step"
            next_button = driver.find_element_by_xpath("//button[contains(text(),'Avançar etapa')]")
            next_button.click()
            
            # Click 6 times on the button with the numeral "0" (for electronic signature)
            for _ in range(6):
                button_0 = driver.find_element_by_xpath("//button[contains(text(),'0')]")
                button_0.click()
                time.sleep(0.1)  # Small interval to ensure clicks are processed
            
            # Click on "Advance step" to finalize the investment
            final_next_button = driver.find_element_by_xpath("//button[contains(text(),'Avançar etapa')]")
            final_next_button.click()
            
            print("Investment successfully made!")
            
            # No need to continue checking investments after making one
            return

# Perform the investment process
perform_investment()

# Close the browser
driver.quit()

I was expecting to get to the webpage "https://experiencia.xpi.com.br/renda-fixa/#/emissao-bancaria" and get the investment done as soon as an investment from the bank SICREDI appears, automatically choosing a quantity of 2 and typyng my electronic signature.

0

There are 0 answers