ACKNOWLEDGEMENTS
I would like to thank all my mentors, especially Mr. Vihan Singh.
I would like to also sincerely thank interns of Fox Trading Solutions, who have helped me in writing this book.
The book cover is designed by Snehil Agrawal and the creator should always be acknowledged.
PREFACE
This book is a concise summary of our years of work in Algorithmic Trading, creating algorithmic solutions for buying and selling instruments based on your wonderfully created complex or simple yet extremely elegant strategies. We have just tried to share a gist of it in this book Titled Algorithmic Trading using Zerodha's KiteConnect API in Python.
Throughout this book, we will take you through a journey from a beginner to an experienced Algorithmic Trader with basic knowledge in python, Algorithmic trading, and trading strategies. We will introduce the reader to the basics of python necessary for Algorithmic Trading. We will introduce the reader with enough python to have a comfortable understanding of this entire course.
The world of the stock market attracts every person some time or another by its glitter of easy earning and quick money. Nevertheless, soon they have to understand the stock markets are not all rosy and there are high risks and losses also. However, the thing about Algorithmic Trading is that we can assign this task of buying and selling instruments to an algorithm, which will make the readers' tasks more manageable and let the reader focus only on building automated trading strategies instead of execution. Which by the way we are experienced in doing, and it is time for you to sit back and let algorithms trade on your behalf.
CONTENTS
Introduction
1.1 Introduction
1.2 Installation & Setting of Python
1.3 Install Pip
1.4 Setting of Jupyter Notebook
1.5 Working with Jupyter Notebook
2. Variables
2.1 Input variables
2.2 User Input
2.3 Types of variables
2.4 Printing a variable
2.5 Identify variable type
2.6 Type Casting
3. Strings
3.1 Introduction
3.2 Splitting a string
3.3 Slicing a string
3.4 Concatenate String
3.5 String Formatting
4. Operators
4.1 Arithmetic, Assignment, Comparison operators
4.2 Logical and Identity operator
5. Conditional Statement
5.1 If
5.2 If Else
5.3 Elif
5.4 NestedIf
6. Loop
6.1 For
6.2 While
6.3 Continue & Pass
6.4 Break
7. List
7.1 Introduction to list
7.2 Add & Remove items in list
8. Tuple
8.1 What is Tuple
8.2 Operation in Tuple
9. Introduction to Dictionary
9.1 Loop through Dictionary
9.2 Add/Remove items in Dictionary
10. Functions
10.1 Introduction to Function
10.2 Default parameter & Written Statement
10.3 Lambda Function/ Anonymous Function
Classes & Objects
11.1 Object Oriented Programming
11.2 Class
11.3Implementation of Objects in Python
12. NumPy
12.1 NumPy
. Pandas
13.1 Data Frame & Series
13.2Indexing
14. Data Visualization
14.1 Matplotlib
14.2Seaborn
14.3Plotting
What is API
15.1API
15.2How to interact with API
16. Zerodha API
16.1 Getting Started With KiteConnect
16.2 Create a Trading Application
16.3 Access Token generation
16.4 Installing KiteConnect
16.5 Get Historical data
16.6 Fetching Instrument token
16.7 Streaming Trick Data
16.8 Placing order
16.9 Cancel order
16.10Order History
17. Technical Indicators & Price Action techniques
17.1 Import Technical Indicator from Library
17.2Coding technical indicators
17.2.1 MACD
17.2.2 Bollinger Band
17.2.3 Average True Range(ATR)
17.2.4 Relative Strength Index(RSI)
17.2.5 Average Directional Index (ADX)
17.2.6 Supertrend
17.2.7 Chaikin Money Flow(CMF)
17.2.8 Ichimoku Cloud
17.2.9 On-Balance Volume
17.3 Price Action Techniques
17.3.1 Doji
17.3.2 Hammer
17.3.3 Shooting Star
17.3.4 Marubozu
18. Handling Streaming Tick Data
18.1 Starting Streaming Data to CSV
18.2 Converting Ticks to Candles
18.3 Sample strategy
Chapter 1
Introduction
1.1 Introduction to Python
Python is a modern day programming language. It is the most simplified version of human-machine interaction.
Pythons official description:
It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
Features of python
Simple
Open Source
Easy syntax
Powerful Looping
High-Level Language
Object-Oriented
__________________________________________________
Fox Trading Solutions Repository:www.https://github.com/FoxTradingSolutions/
1.2 Installing & Setting up Python
Visit https://www.python.org/downloads/ and download the latest version. The current version of python is 3.8.2 and it gets updated pretty fast. Double click on exe to install.
Please make sure you check the option Add Python 3.8.2 to the PATH.If you forget to add python 3.8.2 to path, go to environment variables in windows and add python to PATH. This will enable you to access it from the command prompt.
The default interface which will be installed along with python is called IDLE. It runs the code line by line and is the least preferred option to work with. There are various IDEs which support python. The simplest and the most powerful being Jupyter notebook, which will be discussed further.
__________________________________________________
Fox Trading Solutions Repository:www.https://github.com/FoxTradingSolutions/
1.3 Installing PIP
PIP is the package installer for python. By using pip you can install any library you need. The library is a collection of pre-coded files which serves a purpose, they are built for specific purposes and can be used within our code.
The module PIP comes pre-installed in most of the python installations. If it is not there, you can install it by following the below mentioned steps.
To install PIP, you need to download the get-pip.py file from https://bootstrap.pypa.io/get-pip.py.
Open this link in any browser and save it by pressing Ctrl+S . The directory in which you are saving this file should be the same as the one in which python is installed.
After saving the file, go to command prompt and write the following code
python get-pip.py
This will install PIP.
__________________________________________________
Fox Trading Solutions Repository:www.https://github.com/FoxTradingSolutions/
1.4 Installing Jupyter Notebook
It is a web-based interpreter, used to run python code. It holds the title of being the simplest interpreter.Installing a Jupyter notebook is pretty simple.