Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61
i have been getting exceptions through this code
how to improve this code
how do i open html file
Python:
from selenium import webdriver
driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
driver.get('file://C://Users//vinit//Downloads//Github//tutorial2//tradingsystem//zerodha_order.html')
driver.implicitly_wait(4)
driver.find_element_by_class_name("button-primary").click()
driver.quit()
Python:
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('file:\\C:\\Users\\Shivam\\Trading python\\tutorial-master\\tradingsystem\\zero.html')
driver.implicitly_wait(4)
driver.find_element_by_class_name("button-primary").click()
driver.implicitly_wait(4)
driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='uppercase su-input-group']/input").send_keys('USERNAME')
driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='su-input-group']/input").send_keys('PASSWORD')

driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='actions']/button[@class='button-orange wide']").click()

and so on working fine
 
Python:
from selenium import webdriver
driver = webdriver.Firefox(executable_path="C:\\Users\\vinit\\Downloads\\geckodriver-v0.23.0-win64\\geckodriver.exe")
driver.get('file://C://Users//vinit//Downloads//Github//tutorial2//tradingsystem//zerodha_order.html')
driver.implicitly_wait(4)
driver.find_element_by_class_name("button-primary").click()
driver.find_element_by_class_name("button button-blue").click()
driver.quit()
 
Python:
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('file:\\C:\\Users\\Shivam\\Trading python\\tutorial-master\\tradingsystem\\zero.html')
driver.implicitly_wait(4)
driver.find_element_by_class_name("button-primary").click()
driver.implicitly_wait(4)
driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='uppercase su-input-group']/input").send_keys('USERNAME')
driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='su-input-group']/input").send_keys('PASSWORD')

driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='actions']/button[@class='button-orange wide']").click()

and so on working fine
But then username is enter n password is also enter n the window closes down
 
remove
driver.quit()
coz next step is main:cool:
Python:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\\Users\\vinit\\Downloads\\chromedriver_win32\\chromedriver.exe")
driver.get('file://C://Users//vinit//Downloads//Github//tutorial2//tradingsystem//zerodha_order.html')
driver.implicitly_wait(4)
driver.find_element_by_class_name("button-primary").click()
driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='uppercase su-input-group']/input").send_keys('Username')
driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='su-input-group']/input").send_keys('Password')
driver.find_element_by_xpath("/html/body[@class='app-view- outer-app-wrapper']/div[@id='outer-app']/div[@class='content']/div[@id='outer-base']/div[@id='container']/div[@class='content']/div[@class='row']/div[@class='login-form']/form/div[@class='actions']/button[@class='button-orange wide']").click()
driver.find_element_by_class_name("button button blue").click()
driver.quit()
Then again security questions thats my main issue how do you automate that because questions are random
 
Reinstall .NET framework 3.5
https://www.microsoft.com/en-in/download/details.aspx?id=21

Not sure what happens when uninstalling (may be NEST/NOW depends on it)
@Shivam_ @vinit_7801 May throw some light on it
i only know this master
Using System File Checker in Windows 10

System File Checker is a utility in Windows 10 that checks for system file corruption. It's recommended for advanced users. To run it:
  • In the search box on the taskbar, enter Command Prompt. Press and hold (or right-click) Command Prompt (Desktop app) from the search results and select Run as administrator.
  • Enter DISM.exe /Online /Cleanup-image /Restorehealth (note the space before each "/"). (Note: This step may take a few minutes to start and up to 30 minutes to run and complete.)
  • Enter sfc /scannow (note the space between "sfc" and "/").
for problems out of understanding:D
 

UberMachine

Well-Known Member
Is there any chance of you sharing your selenium code?
This is the code for Linux; modified it a bit. This would log into zerodha automatically.
Replace with necessary code.
Make all your 2FA passwords the same. This would make things simple.
Python:
def place_order_via_browser(user_id, password, answer):
    """
    Login to the browser and place orders
    user_id
        user id to log in zerodha
    password
        password for zerodha
    answer
        answer to 2FA question. Answers should be same for all
        the questions zerodha

    """
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.chrome.options import Options
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    driver = webdriver.Chrome(chrome_options=options)
    driver.get("https://kite.zerodha.com")
    login_form = WebDriverWait(driver, 45).until(
        EC.presence_of_element_located((By.CLASS_NAME, "login-form")))
    login_form.find_elements_by_tag_name('input')[0].send_keys(user_id)
    login_form.find_elements_by_tag_name('input')[1].send_keys(password)
    WebDriverWait(driver, 45).until(
        EC.presence_of_element_located((By.CLASS_NAME, "button-orange")))
    driver.find_element_by_xpath('//button[@type="submit"]').click()
    twofa_form = WebDriverWait(driver, 45).until(
        EC.presence_of_element_located((By.CLASS_NAME, "twofa-form")))
    twofa_form.find_elements_by_tag_name('input')[0].send_keys(answer)
    twofa_form.find_elements_by_tag_name('input')[1].send_keys(answer)
    WebDriverWait(driver, 45).until(
        EC.presence_of_element_located((By.CLASS_NAME, "button-orange")))
    driver.find_element_by_xpath('//button[@type="submit"]').click()
 
    time.sleep(2)
    driver.quit()
I prefer automation only if you are away from your system. Else you can log into zerodha and automate only the order place part which is far simpler as quoted by @Shivam_
 

Similar threads