/Python-Algo-Trading-Zerodha

This repo contains sample templates for implementing strategies in python.

Primary LanguagePythonMIT LicenseMIT

Python-Algo-Trading-Zerodha

This repo contains sample templates for implementing strategies in python.

I have used Zerodha's kiteconnect api for developing sample strategies.

Zerodha kiteconnect

Here are some important links that you may need to go through to understand the login and other related stuff.

  1. KiteConnect API Doc
  2. KiteConnect Python Doc
  3. KiteConnect github page
  4. KiteConnect developer login
  5. KiteConnect developer forum

Install dependencies

pip install -r requirements.txt

Automate the login process

For first time run

  1. pip install selenium
  2. Download the correct webdriver from here and place the .exe file in the directory having access_token.py
  3. Create api_key.txt file with the following info -
    • API KEY - Obtained from the trading app in your developer account.
    • API SECRET - Obtained from the trading app in your developer account.
    • USER ID - Zerodha Kite user id.
    • PASSWORD - Zerodha Kite password.
    • PIN - Zerodha Kite pin.

python access_token.py

Strategy

Buy when PSAR crosses below candle and sell when PSAR crosses above candle. The code for the same is in strategy_PSAR.py and other utility functions are in utils.py

Daily Usage

It is recommended to change the global variables in strategy_PSAR.py as per the new startegy. Also run the strategy_PSAR.py a minute later than candle start( if working with larger duration candles like 15minutes or bigger). For ex. if you want to start at 9:15 AM run the code at 9:16 AM to avoid some signals being missed.

  1. run python access_token.py
  2. run strategy_PSAR.py

NOTE_1 - This is just a sample strategy to get started with kiteconnect and zerodha. It is always recommended to use one's own strategy for best results.

NOTE_2 - For coding technical indicators use pandas-ta and NOT TA-Lib. TA-Lib gave wrong PSAR values many times during PSAR reversals.