Python based Algo trading bot for Nifty / Banknifty futures and options

Overview

Fully automated Alice Blue Algo Trading with Python on NSE and MCX for Nifty / Crude / Banknifty futures and options , absolutely FREE !

This algo trading bot is my first attempt to try, learn and implement my python programming skills. Please use this only for reference and at your own risk.
This repository contains python code to perform algo trading on India, NSE through AliceBlue broker. You need to have a valid AliceBlue client ID, password, 2FA authentication password set and API enabled (ask aliceblue support) to get this working. This program is focused on Nifty and Crude futures with a simple Supertrend with RSI strategy. Initially, I had developed this for windows then later moved to linux (ubuntu) platform on AWS. Now I am working on moving this to Oracle cloud as its free :) and this version works smoothly with the free tier as well ;-)

There are 2 programs:

  1. For Options trading - ab_options.py which uses ab_options.ini as configuration/parameter file.
  2. For Futures trading - ab.py which uses ab.ini as configuration/parameter file.

These programs basically uses 3min (low) , 6min (medium) time frame supertrend and RSI indicators (adjusted through parameters) to generate signals. For any other strategy you need to modify the main program. My wish list includes parameterisation of this strategy peice as well.

There is a background program (ab_bg.py) which runs at the background and helps us to control our algo bot from anywhere using telegram. We can send commands through telegram chats to do various activities in realtime like start/stop trading, set MTM levels, manage SL, get detailed logs etc. basically all the realtime config parameters can be managed/modified through telegram chats.

The main program ab.py/ab_options.py which needs to be scheduled at 8:59:30 AM / 9:14:00 AM daily through linux crontab. Crude(MCX) opens at 9:00 AM and Nifty at 9:15 AM. You can setup AWS instance to start at 8:45 AM and stop at 11:45 PM (After MCX Close) through AWS Lambda. I typically set both of the programs on seperate AWS instances and configure two seperate IDs. You can read through the comments in the ab.py/ab_options.py for detailed understanding.

There is an ab.ini/ab_options.ini file which is the key configuration file through which you can control all the parameters of this program, even at realtime using Telegram chats.

Will update proper documentation soon...

Although this is still work in progress, kindly suggest your feedback. It will help me improve.

Feel free to use/diustrubte this code freely so that new algo developers can get started easily.

You might also like...
A Discord bot to allow people to create lists of random characters, with limit reroll options.

Mugen Bot A small bot I made to practice python and allow people to publically select random characters on a discord server. Uses py-cord, as that is

A discord token nuker With loads of options that will screw an account up real bad, also has inbuilt massreport, GroupChat Spammer and Token/Password/Creditcard grabber and so much more!
A discord token nuker With loads of options that will screw an account up real bad, also has inbuilt massreport, GroupChat Spammer and Token/Password/Creditcard grabber and so much more!

Installation | Important | Changelogs | Discord NOTE: Hazard is not finished! You can expect bugs, crashes, and non-working functions. Please make an

A discord token nuker With loads of options that will screw an account up real bad
A discord token nuker With loads of options that will screw an account up real bad

A discord token nuker With loads of options that will screw an account up real bad, also has inbuilt massreport, GroupChat Spammer and Token/Password/Creditcard grabber and so much more!

A Multi-Tool with 30+Options.
A Multi-Tool with 30+Options.

A Multi-Tool with 30+Options.

This is a cryptocurrency trading bot that analyses Reddit sentiment and places trades on Binance based on reddit post and comment sentiment. If you like this project please consider donating via brave. Thanks.

This is a cryptocurrency trading bot that analyses Reddit sentiment and places trades on Binance based on reddit post and comment sentiment. The bot f

Fully Dockerized cryptocurrencies Trading Bot, based on Freqtrade engine. Multi instances.

Cryptocurrencies Trading Bot - Freqtrade Manager This automated Trading Bot is based on the amazing Freqtrade one. It allows you to manage many Freqtr

A Pancakeswap and Uniswap trading client (and bot) with limit orders, marker orders, stop-loss, custom gas strategies, a GUI and much more.
A Pancakeswap and Uniswap trading client (and bot) with limit orders, marker orders, stop-loss, custom gas strategies, a GUI and much more.

Pancakeswap and Uniswap trading client Adam A A Pancakeswap and Uniswap trading client (and bot) with market orders, limit orders, stop-loss, custom g

Comments
  • STX Issue in Supertrend while trying to run it.

    STX Issue in Supertrend while trying to run it.

    Hi, Can you please let me know why am I getting this issue, also if you have done some update to the code can you please share. STX contains NaN as assigned in ab_lib.py from the supertrend function.

    Traceback (most recent call last): File "C:/Users/Rex/Desktop/Trading/alice_blue-main_Rajesh/ab_options.py", line 1368, in strMsg="BankNifty: #={}, ST_LOW={}, ST_LOW_SL={}, ATR={}, ST_MED={}, ST_MED_SL={}, ltp_bank_ATM_CE={}, ltp_bank_ATM_PE={}".format(df_bank_cnt, super_trend_bank[-1], round(df_bank.ST.iloc[-1]), round(df_bank.ATR.iloc[-1],1), df_bank_med.STX.iloc[-1], round(df_bank_med.ST.iloc[-1]), ltp_bank_ATM_CE, ltp_bank_ATM_PE) File "C:\Users\Rex\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\generic.py", line 5487, in getattr return object.getattribute(self, name) AttributeError: 'DataFrame' object has no attribute 'STX'

    opened by rex3992 5
  • Key error while checking the order history in alice blue

    Key error while checking the order history in alice blue

    Hi, Rajesh

    I am frequently checking the order history of my orderId . Consider it is less than second time frame .

    Following is the error i am getting, looks like the order history dictionary output is missing in between when i am querying.

    Traceback (most recent call last):

    orders = alice.get_order_history()["data"]["completed_orders"] KeyError: 'completed_orders'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

    Basically my script almost ran for 15 minutes in the loop where it was able to check the status continuously. If you are able to judge, please guide me with some solution.

    Sent the same issue to krishna also. Incase if you are aware please help me.

    On further debug i understood that , after some 5 to 10minutes, there is a break happening for the output too. But that is not creating the exception.

    If we run the following code for 1 hr and notice we can see following 2 conditions :

    1. Sometimes order history output will take a break of more than 30 seconds
    2. Sometimes exception on the "order_complete" handle too.

    Code used for checking :

    while(True): orders=alice.get_order_history()["data"]["completed_orders"] print(f'orders is {orders}')

    Thanks and Regards Arjunesh

    opened by arjuneshm 2
  • Please help me with it

    Please help me with it

    i am getting this error. please help me

    2021-10-04 09:52:40.426895|1|Initialising D:\Python\alice_blue-main\ab.py 2021-10-04 09:52:40.883586|1|Setting up initial sleep time of 2 seconds. Traceback (most recent call last): File "C:\Users\home\AppData\Local\Programs\Python\Python39\lib\configparser.py", line 789, in get value = d[option] File "C:\Users\home\AppData\Local\Programs\Python\Python39\lib\collections_init_.py", line 941, in getitem return self.missing(key) # support subclasses that define missing File "C:\Users\home\AppData\Local\Programs\Python\Python39\lib\collections_init_.py", line 933, in missing raise KeyError(key) KeyError: 'nifty_no_trade_zones'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "D:\Python\alice_blue-main\ab.py", line 236, in nifty_no_trade_zones = eval(cfg.get("info", "nifty_no_trade_zones")) File "C:\Users\home\AppData\Local\Programs\Python\Python39\lib\configparser.py", line 792, in get raise NoOptionError(option, section) configparser.NoOptionError: No option 'nifty_no_trade_zones' in section: 'info'

    opened by raypixell 1
Releases(v7.3.8)
Owner
Rajesh Sivadasan
Coding is my passion!
Rajesh Sivadasan
Trading bot - A Trading bot With Python

Trading_bot Trading bot intended for 1) Tracking current prices of tokens 2) Set

Tymur Kotkov 29 Dec 1, 2022
Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering

Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering

Alexandr Savinov 326 Jan 3, 2023
Utilizing the freqtrade high-frequency cryptocurrency trading framework to build and optimize trading strategies. The bot runs nonstop on a Rasberry Pi.

Freqtrade Strategy Repository Please test all scripts and dry run them before using them in live mode Contact me on discord if you have any questions!

Michael Fourie 90 Jan 1, 2023
This program is an automated trading bot that uses TDAmeritrades Thinkorswim trading platform's scanners and alerts system.

Python Trading Bot w/ Thinkorswim Description This program is an automated trading bot that uses TDAmeritrades Thinkorswim trading platform's scanners

Trey Thomas 201 Jan 3, 2023
Market calendar RESTful API with holiday, late open, and early close. Over 50+ unique exchange calendars for global equity and futures markets.

Trading Calendar Market calendar RESTful API with holiday, late open, and early close. Over 50+ unique exchange calendars for global equity and future

Apptastic Software 1 Feb 3, 2022
Crypto-trading-simulator - Cryptocurrency trading simulator using Python, Streamlit

Crypto Trading Simulator Run streamlit run main.py Dependency Python 3 streamli

Brad 12 Jul 2, 2022
Binance leverage futures Hook

Simple binance futures Attention Just use leverage. The fee difference between futures and spot is not considered. For example, funding rate, etc. Onl

Adriance 26 Aug 27, 2022
Dashboard to monitor the performance of your Binance Futures account

futuresboard A python based scraper and dashboard to monitor the performance of your Binance Futures account. Note: A local sqlite3 database config/fu

null 86 Dec 29, 2022
Binance Futures Client

Binance Futures Client

null 4 Aug 2, 2022