Framework for creating and running trading strategies. Blatantly stolen copy of qtpylib to make it work for Indian markets.

Overview

>_• Kinetick Trade Bot

**>_•**

Branch state Python version PyPi version Chat on Discord

Kinetick is a framework for creating and running trading strategies without worrying about integration with broker and data streams (currently integrates with zerodha [*]). Kinetick is aimed to make systematic trading available for everyone.

Leave the heavy lifting to kinetick so that you can focus on building strategies.

Changelog »

📱 Screenshots

screen1 screen2 screen3

Features

  • A continuously-running Blotter that lets you capture market data even when your algos aren't running.
  • Tick, Bar and Trade data is stored in MongoDB for later analysis and backtesting.
  • Using pub/sub architecture using ØMQ (ZeroMQ) for communicating between the Algo and the Blotter allows for a single Blotter/multiple Algos running on the same machine.
  • Support for Order Book, Quote, Time, Tick or Volume based strategy resolutions.
  • Includes many common indicators that you can seamlessly use in your algorithm.
  • Market data events use asynchronous, non-blocking architecture.
  • Realtime alerts and order confirmation delivered to your mobile via Telegram bot (requires a Telegram bot token).
  • Full integration with TA-Lib via dedicated module (see example).
  • Ability to import any Python library (such as scikit-learn or TensorFlow) to use them in your algorithms.
  • Live charts powered by TradingView
  • RiskAssessor to manage and limit the risk even if strategy goes unexpected
  • Power packed batteries included
  • Deploy wherever Docker lives

Installation

Install using pip:

$ pip install kinetick

Quickstart

There are 5 main components in Kinetick:

  1. Bot - sends alert and signals with actions to perform.
  2. Blotter - handles market data retrieval and processing.
  3. Broker - sends and process orders/positions (abstracted layer).
  4. Algo - (sub-class of Broker) communicates with the Blotter to pass market data to your strategies, and process/positions orders via Broker.
  5. Lastly, Your Strategies, which are sub-classes of Algo, handle the trading logic/rules. This is where you'll write most of your code.

1. Get Market Data

To get started, you need to first create a Blotter script:

# blotter.py
from kinetick.blotter import Blotter

class MainBlotter(Blotter):
    pass # we just need the name

if __name__ == "__main__":
    blotter = MainBlotter()
    blotter.run()

Then run the Blotter from the command line:

$ python -m blotter

If your strategy needs order book / market depth data, add the --orderbook flag to the command:

$ python -m blotter --orderbook

2. Write your Algorithm

While the Blotter running in the background, write and execute your algorithm:

# strategy.py
from kinetick.algo import Algo

class CrossOver(Algo):

    def on_start(self):
        pass

    def on_fill(self, instrument, order):
        pass

    def on_quote(self, instrument):
        pass

    def on_orderbook(self, instrument):
        pass

    def on_tick(self, instrument):
        pass

    def on_bar(self, instrument):
        # get instrument history
        bars = instrument.get_bars(window=100)

        # or get all instruments history
        # bars = self.bars[-20:]

        # skip first 20 days to get full windows
        if len(bars) < 20:
            return

        # compute averages using internal rolling_mean
        bars['short_ma'] = bars['close'].rolling(window=10).mean()
        bars['long_ma']  = bars['close'].rolling(window=20).mean()

        # get current position data
        positions = instrument.get_positions()

        # trading logic - entry signal
        if bars['short_ma'].crossed_above(bars['long_ma'])[-1]:
            if not instrument.pending_orders and positions["position"] == 0:

                """ buy one contract.
                 WARNING: buy or order instrument methods will bypass bot and risk assessor.
                 Instead, It is advised to use create_position, open_position and close_position instrument methods
                 to route the order via bot and risk assessor. """
                instrument.buy(1)

                # record values for later analysis
                self.record(ma_cross=1)

        # trading logic - exit signal
        elif bars['short_ma'].crossed_below(bars['long_ma'])[-1]:
            if positions["position"] != 0:

                # exit / flatten position
                instrument.exit()

                # record values for later analysis
                self.record(ma_cross=-1)


if __name__ == "__main__":
    strategy = CrossOver(
        instruments = ['ACC', 'SBIN'], # scrip symbols
        resolution  = "1T", # Pandas resolution (use "K" for tick bars)
        tick_window = 20, # no. of ticks to keep
        bar_window  = 5, # no. of bars to keep
        preload     = "1D", # preload 1 day history when starting
        timezone    = "Asia/Calcutta" # convert all ticks/bars to this timezone
    )
    strategy.run()

To run your algo in a live environment, from the command line, type:

$ python -m strategy --logpath ~/orders

The resulting trades be saved in ~/orders/STRATEGY_YYYYMMDD.csv for later analysis.

3. Login to bot

While the Strategy running in the background:

Assuming you have added the telegram bot to your chat
  • /login <password> - password can be found in the strategy console.

commands

  • /report - get overview about trades
  • /help - get help
  • /resetrms - resets RiskAssessor parameters to its initial values.

Configuration

Can be specified either as env variable or cmdline arg

Parameter Required? Example Default Description
symbols   symbols=./symbols.csv    
LOGLEVEL   LOGLEVEL=DEBUG INFO  
zerodha_user yes - if live trading zerodha_user=ABCD    
zerodha_password yes - if live trading zerodha_password=abcd    
zerodha_pin yes - if live trading zerodha_pin=1234    
BOT_TOKEN optional BOT_TOKEN=12323:asdcldf..   IF not provided then orders will bypass
initial_capital yes initial_capital=10000 1000 Max capital deployed
initial_margin yes initial_margin=1000 100 Not to be mistaken with broker margin. This is the max amount you can afford to loose
risk2reward yes risk2reward=1.2 1 Set risk2reward for your strategy. This will be used in determining qty to trade
risk_per_trade yes risk_per_trade=200 100 Risk you can afford with each trade
max_trades yes max_trades=2 1 Max allowed concurrent positions
dbport   dbport=27017 27017  
dbhost   dbhost=localhost localhost  
dbuser   dbuser=user    
dbpassword   dbpassword=pass    
dbname   dbname=kinetick kinetick  
orderbook   orderbook=true false Enable orderbook stream
resolution   resolution=1m 1 Min Bar interval
preload_positions No preload_positions=30D
Loads only overnight positions.Available options: 1D - 1 Day, 1W - 1 Week, 1H - 1 Hour

Docker Instructions

  1. Build blotter

    $ docker build -t kinetick:blotter -f blotter.Dockerfile .

  2. Build strategy

    $ docker build -t kinetick:strategy -f strategy.Dockerfile .

  3. Run with docker-compose

    $ docker compose up

Backtesting

$ python -m strategy --start "2021-03-06 00:15:00" --end "2021-03-10 00:15:00" --backtest

Note

To get started checkout the patented BuyLowSellHigh strategy in strategies/ directory.

🙏 Credits

Thanks to @ran aroussi for all his initial work with Qtpylib. Most of work here is derived from his library

Disclaimer

Kinetick is licensed under the Apache License, Version 2.0. A copy of which is included in LICENSE.txt.

All trademarks belong to the respective company and owners. Kinetick is not affiliated to any entity.

[*] Kinetick is not affiliated to zerodha.
You might also like...
Indian Space Research Organisation API With Python

ISRO Indian Space Research Organisation API Installation pip install ISRO Usage import isro isro.spacecrafts() # returns spacecrafts data isro.lau

Rapid Sms Bomber For Indian Number.

Bombzilla Rapid Sms Bomber For Indian Number. Installation git clone https://github.com/sarv99/Bombzilla cd Bombzilla chmod +x setup.sh ./setup.sh Af

A lightweight Python wrapper for the IG Markets API
A lightweight Python wrapper for the IG Markets API

trading_ig A lightweight Python wrapper for the IG Markets API. Simplifies access to the IG REST and Streaming APIs with a live or demo account. What

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

This program is an automated trading bot that uses TDAmeritrades Thinkorswim trading platform's scanners and alerts system.
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

Trading bot - A Trading bot With Python
Trading bot - A Trading bot With Python

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

Crypto-trading-simulator - Cryptocurrency trading simulator using Python, Streamlit
Crypto-trading-simulator - Cryptocurrency trading simulator using Python, Streamlit

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

A powerful bot to copy your google drive data to your team drive
A powerful bot to copy your google drive data to your team drive

⚛️ Clonebot - Heroku version ⚡ CloneBot is a telegram bot that allows you to copy folder/team drive to team drives. One of the main advantage of this

 Using AWS Batch jobs to bulk copy/sync files in S3
Using AWS Batch jobs to bulk copy/sync files in S3

Using AWS Batch jobs to bulk copy/sync files in S3

Releases(v1.0.13)
Owner
Vinay
git pull github/imvinaypatil/bio.git
Vinay
Python: Asynchronous client for the Tailscale API

Python: Asynchronous client for the Tailscale API Asynchronous client for the Tailscale API. About This package allows you to control and monitor Tail

Franck Nijhof 9 Nov 22, 2022
一个基于Python3的Bot。目前支持以Docker的方式部署在vps上。支持Aria2、本子下载、网易云音乐下载、Pixiv榜单下载、Youtue-dl支持、搜图。

介绍 一个基于Python3的Bot。目前支持以Docker的方式部署在vps上。 主要功能: 文件管理 修改主界面为 filebrowser,账号为admin,密码为admin,主界面路径:http://ip:port,请自行修改密码 FolderMagic自带的webdav:路径:http://

Ben 650 Jan 08, 2023
Discord Blogger Integration Using Blogger API

It's a very simple discord bot created in python using blogger api in order to search and send your website articles in your discord chat in form of an embedded message. It's pretty useful for people

Owen Singh 8 Oct 28, 2022
Discord Rich Presence implementation for Plex.

Perplex Perplex is a Discord Rich Presence implementation for Plex. Features Modern and beautiful Rich Presence for both movies and TV shows The Movie

Ethan 52 Dec 19, 2022
A simple tool that lets you know when you are out of Lost Ark's queues

Overview A simple tool that lets you know when you are out of Lost Ark's queues. You can be notified via: Sound: the app will play a sound Discord web

Nelson 3 Feb 15, 2022
Python binding for Terraform.

Python libterraform Python binding for Terraform. Installation $ pip install libterraform NOTE Please install version 0.3.1 or above, which solves the

Prodesire 28 Dec 29, 2022
AKShare is an elegant and simple financial data interface library for Python, built for human beings

AKShare is an elegant and simple financial data interface library for Python, built for human beings

AKFamily 5.8k Dec 30, 2022
A drop-in vanilla discord.py cog to add slash command support with little to no code modifications

discord.py /slash cog A drop-in vanilla discord.py cog that acts as a translation layer to add slash command support with little to no code modificati

marshall 3 Jun 01, 2022
A telegram bot that messages you available vaccine appointments in the Veneto region

Serenissimo, domande frequenti Chi sei? Sono Alberto Granzotto, libero professionista a Berlino. Mi occupo di servizi software, privacy, decentralizza

vrde 31 Sep 30, 2022
A discord token grabber made in Python 3

Discord Token Grabber A Discord token grabber written in Python 3. This version of the grabber only supports Windows. Features Transfers via Discord w

Mega145 4 Aug 04, 2022
Simple Telegram AI Chat bot made using OpenAI and Luna API

Yui Yui, is a simple telegram chat bot made using OpenAI and Luna Chat bot Deployment 👀 Deploying is easy 🤫 ! You can deploy this bot in Heroku or i

I'm Not A Bot #Left_TG 21 Dec 29, 2022
Satoshi is a discord bot template in python using discord.py that allow you to track some live crypto prices with your own discord bot.

Satoshi ~ DiscordCryptoBot Satoshi is a simple python discord bot using discord.py that allow you to track your favorites cryptos prices with your own

Théo 2 Sep 15, 2022
A simple weather information tool.

pwy A simple weather information tool. Table of Contents Features Dependencies Installation Usage Update Changelog Credits License Features ASCII art

Clint 105 Dec 31, 2022
Automatically Message From Discord Account

Discord-AutoMessage A robust and versatile solution for automated social interactions HOW TO INSTALL Open cmd cd into your project directory Run the f

13 Jul 11, 2022
Easy to use phishing tool with 63 website templates. Author is not responsible for any misuse.

PyPhisher [+] Created By KasRoudra [+] Description : Ultimate phishing tool in python. Includes popular websites like facebook, twitter, instagram, gi

KasRoudra 1.1k Jan 01, 2023
Simple Discord bot for the Collectez community.

Harvey - Discord Bot Simple Discord bot for the Collectez community. Features Ping the current status of Collectez's Teztools node. Steal emojis from

delintkhaum 1 Dec 26, 2021
A simple library for interacting with Amazon SQS.

qoo is a very simple Amazon SQS client, written in Python. It aims to be much more straight-forward to use than boto3, and specializes only in Amazon

Jacobi Petrucciani 2 Oct 30, 2020
This is a telegram bot built using the Oxford Dictionary API

Oxford Dictionaries Telegram Bot This is a telegram bot built using the Oxford Dictionary API Source: Oxford Dictionaries API Documentation Install En

Abhijith N T 2 Mar 18, 2022
Tracks how much money a profile has in their bank and graphs it, as long as they enable the bank api

Tracks how much money a profile has in their bank and graphs it, as long as they enable the bank api. (you could really use this to track anything from the hypixel api)

1 Feb 08, 2022
Stock market bot that will be used to learn about API calls and database connections.

Stock market bot that will be used to learn about API calls and database connections.

1 Dec 24, 2021