Introduction to Algo Trading by Rivas
Topics Covered
- What is Algo Trading
- Prerequisites for Algo Trading
- Programming Languages for Algo Trading
- Brokers Providing APIs for Algo Trading
- Costs Involved in Algo Trading
- Subscription to Zerodha Trading APIs
- Types of APIs for Trading
- Basic Design of an Algo System
- Installing Python and Zerodha SDK
- Sample Python Program for Login Flow
- Risks Involved in Algorithmic Trading
What is Algo Trading
- Algorithmic trading (Algo Trading) is a program that trades on behalf of a human using predefined rules.
- It interacts with broker APIs for placing orders, modifying orders, and exiting trades.
- Can be semi-automated or fully automated.
Prerequisites for Algo Trading
- Access to broker APIs for interacting with the backend system.
- Some coding knowledge, preferably in Python for ease of use.
- Understanding of trading indicators and basics.
- Stable internet connection.
Programming Languages for Algo Trading
- Popular languages: Java, C, C++, PHP, Python.
- Python is suggested for ease of learning and extensive tutorials.
- High-frequency trading might require faster languages like C++ or C#.
Brokers Providing APIs for Algo Trading
- Popular brokers in India: Zerodha, Fires, Ally Blue, Stocks, Interactive Brokers, 5Paisa.
- Importance of robust APIs and low latency from brokers.
- Cost considerations: some brokers charge for APIs while some offer them for free.
Costs Involved in Algo Trading
- Cloud costs: Approx. ₹15,000 to ₹1,00,000 per annum depending on system complexity.
- Internet charges if running from a home PC.
- Broker API charges: Example, Zerodha charges ₹2000/month for trading APIs.
- Developer costs if you can’t code yourself.
- Usual trading costs like brokerage, STT, GST.
Subscription to Zerodha Trading APIs
- Access via developers.kite.trade/login.
- Create a new app and authorize it with your Zerodha trading account.
- Key steps: Provide client ID, redirect URL, and receive API key and secret.
Types of APIs for Trading
- Login APIs: For initial authentication.
- Instrument APIs: To fetch instrument details like symbols, strike prices, etc.
- Order APIs: For placing, modifying, or canceling orders.
- Quotes APIs: For current market data including price, volume, high/low.
- Historical Data APIs: To fetch historical candlestick data.
- Other APIs: For getting account positions, funds, etc.
Basic Design of an Algo System
- Login to Broker: Authenticate and receive access token.
- Fetch Instrument Data: Store for the session to use in trading activities.
- Initialize Ticker Service: For real-time market data (WebSocket preferred for high speed).
- Start Trading Strategy: Implement logic based on strategy rules.
- Order Management: Place and manage orders based on signals from the strategy.
- Monitor Orders and Positions: Continuously check and modify as required.
- Exit Trades: Close open positions by end of the day if intraday.
Installing Python and Zerodha SDK
- Installing Python on Windows.
- Use pip for package management (
pip install commands).
- Install Flask for creating a local server:
pip install Flask.
- Install Zerodha Kite Connect SDK:
pip install kiteconnect.
Sample Python Program for Login Flow
- Setup project structure with folders: src (for source code) and config (for configurations).
- Example server and user config files in JSON format.
- Python code for logging into Zerodha, handling redirects, and fetching positions and holdings.
- Install necessary tools like Microsoft Visual C++ Build Tools if errors occur during package installation.
Steps in Sample Code
- Setup Flask Server: Create and start HTTP server using Flask.
- Handling Login Flow: Implement routes for login redirects and API interactions.
- Fetch Positions and Holdings: Example endpoints to call Zerodha APIs after authentication.
Risks Involved in Algorithmic Trading
- Coding Errors: Small bugs can lead to significant losses.
- Broker Issues: Platform outages can affect open positions and order placements.
- Internet Connectivity: Loss of internet or power can affect trading algorithms running on a local machine.
- Broker Order Handling: Sudden spikes or falls may cause exchange issues, order cancellations, etc.
- Monitoring: Even fully automated systems need periodic checks to ensure smooth operations.
Conclusion
- Next steps include further videos on placing orders and advanced API usage during market hours.
- Importance of monitoring and handling risks in algorithmic trading.
Follow for further updates and inquiries: Twitter handle shared for ongoing support and question collection.