Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61

VJAY

Well-Known Member
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_
but arent the answer random
how do you solve that issue??
 
Make all your 2FA passwords the same. So it doesn't matter what question is asked.
Master hack ;)
Python:
   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 ( )
little confuse where should i make the necessary changes?
 

Similar threads