`>_• <./resources/kinetick512.png>`_ Kinetick Trade Bot
=======================================================
.. image:: .resources/kinetick-beta128.png
:height: 128
:width: 128
:alt: **>_•**
\
.. image:: https://img.shields.io/github/checks-status/imvinaypatil/kinetick/main
:target: https://github.com/imvinaypatil/kinetick
:alt: Branch state
.. image:: https://img.shields.io/badge/python-3.4+-blue.svg?style=flat
:target: https://pypi.python.org/pypi/kinetick
:alt: Python version
.. image:: https://img.shields.io/pypi/v/kinetick.svg?maxAge=60
:target: https://pypi.python.org/pypi/kinetick
:alt: PyPi version
.. image:: https://img.shields.io/discord/881151290741256212?logo=discord
:target: https://discord.gg/xqD6RmqvBV
:alt: 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 and you focus on building strategies.
WARNING
This project is still in its early stages, please be cautious when dealing with real money.
`Changelog » <./CHANGELOG.rst>`_
📱 Screenshots
==============
.. |screen1| image:: .resources/screenshot1.jpeg
:scale: 100%
:align: middle
.. |screen2| image:: .resources/screenshot2.jpeg
:scale: 100%
:align: top
.. |screen3| image:: .resources/screenshot3.jpeg
:scale: 100%
:align: middle
+-----------+-----------+-----------+
| |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 <http://zeromq.org>`_ (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 <https://t.me/botfather>`_ token).
- Full integration with `TA-Lib <https://pypi.org/project/TA-Lib/>`_ via dedicated module (`see example <strategies/macd_super_strategy.py>`_).
- Ability to import any Python library (such as `scikit-learn <http://scikit-learn.org>`_ or `TensorFlow <https://www.tensorflow.org>`_) 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 <https://www.docker.com>`_ lives
-----
Installation
============
Install using ``pip``:
.. code:: bash
$ pip install kinetick
Telegram bot must be configured in order to take TOTP input for zerodha login
use ``/zlogin <totp>`` command to login to zerodha
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:
.. code:: python
# 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:
.. code:: bash
$ python -m blotter
If your strategy needs order book / market depth data, add the ``--orderbook`` flag to the command:
.. code:: bash
$ python -m blotter --orderbook
2. Write your Algorithm
-----------------------
While the Blotter running in the background, write and execute your algorithm:
.. code:: python
# 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:
.. code:: bash
$ 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. This step is required if you have not provided your telegram chat id as an env var
- ``/zlogin <totp>`` Command to login to zerodha using totp
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
.. list-table::
* - 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
* - ``CHAT_ID``
- No
- CHAT_ID=12345
- -
- default chat user id to which trade notifications are sent requiring no login
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
===========
.. code:: bash
$ python -m strategy --start "2021-03-06 00:15:00" --end "2021-03-10 00:15:00" --backtest --backfill
.. 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.
Raw data
{
"_id": null,
"home_page": "https://github.com/imvinaypatil/kinetick",
"name": "kinetick",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "kinetick algotrading algo trading zerodha brokers stocks",
"author": "vin8tech",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/55/4a/271bf5f4b891fdc6e65ddfc14413d4fccd3ecd066d3f76ae2ab8e84dbbfc/kinetick-1.0.15.tar.gz",
"platform": "any",
"description": "`>_\u2022 <./resources/kinetick512.png>`_ Kinetick Trade Bot\n=======================================================\n.. image:: .resources/kinetick-beta128.png\n :height: 128\n :width: 128\n :alt: **>_\u2022**\n\n\\\n\n.. image:: https://img.shields.io/github/checks-status/imvinaypatil/kinetick/main\n :target: https://github.com/imvinaypatil/kinetick\n :alt: Branch state\n\n.. image:: https://img.shields.io/badge/python-3.4+-blue.svg?style=flat\n :target: https://pypi.python.org/pypi/kinetick\n :alt: Python version\n\n.. image:: https://img.shields.io/pypi/v/kinetick.svg?maxAge=60\n :target: https://pypi.python.org/pypi/kinetick\n :alt: PyPi version\n\n.. image:: https://img.shields.io/discord/881151290741256212?logo=discord\n :target: https://discord.gg/xqD6RmqvBV\n :alt: Chat on Discord\n\n\\\n\n Kinetick is a framework for creating and running trading strategies without worrying\n about integration with broker and data streams (currently integrates with zerodha [*]_).\n Kinetick is aimed to make systematic trading available for everyone.\n\nLeave the heavy lifting to kinetick and you focus on building strategies.\n\nWARNING\n\nThis project is still in its early stages, please be cautious when dealing with real money.\n\n`Changelog \u00bb <./CHANGELOG.rst>`_\n\n\ud83d\udcf1 Screenshots\n==============\n\n.. |screen1| image:: .resources/screenshot1.jpeg\n :scale: 100%\n :align: middle\n.. |screen2| image:: .resources/screenshot2.jpeg\n :scale: 100%\n :align: top\n.. |screen3| image:: .resources/screenshot3.jpeg\n :scale: 100%\n :align: middle\n\n+-----------+-----------+-----------+\n| |screen1| | |screen2| | |screen3| |\n+-----------+-----------+-----------+\n\nFeatures\n========\n\n- A continuously-running Blotter that lets you capture market data even when your algos aren't running.\n- Tick, Bar and Trade data is stored in MongoDB for later analysis and backtesting.\n- Using pub/sub architecture using `\u00d8MQ <http://zeromq.org>`_ (ZeroMQ) for communicating between the Algo and the Blotter allows for a single Blotter/multiple Algos running on the same machine.\n- **Support for Order Book, Quote, Time, Tick or Volume based strategy resolutions**.\n- Includes many common indicators that you can seamlessly use in your algorithm.\n- **Market data events use asynchronous, non-blocking architecture**.\n- Realtime alerts and order confirmation delivered to your mobile via Telegram bot (requires a `Telegram bot <https://t.me/botfather>`_ token).\n- Full integration with `TA-Lib <https://pypi.org/project/TA-Lib/>`_ via dedicated module (`see example <strategies/macd_super_strategy.py>`_).\n- Ability to import any Python library (such as `scikit-learn <http://scikit-learn.org>`_ or `TensorFlow <https://www.tensorflow.org>`_) to use them in your algorithms.\n- Live charts powered by TradingView\n- **RiskAssessor** to manage and limit the risk even if strategy goes unexpected\n- Power packed batteries included\n- Deploy wherever `Docker <https://www.docker.com>`_ lives\n\n-----\n\nInstallation\n============\n\nInstall using ``pip``:\n\n.. code:: bash\n\n $ pip install kinetick\n\nTelegram bot must be configured in order to take TOTP input for zerodha login\n\n use ``/zlogin <totp>`` command to login to zerodha\n\nQuickstart\n==========\n\nThere are 5 main components in Kinetick:\n\n1. ``Bot`` - sends alert and signals with actions to perform.\n2. ``Blotter`` - handles market data retrieval and processing.\n3. ``Broker`` - sends and process orders/positions (abstracted layer).\n4. ``Algo`` - (sub-class of ``Broker``) communicates with the ``Blotter`` to pass market data to your strategies, and process/positions orders via ``Broker``.\n5. Lastly, **Your Strategies**, which are sub-classes of ``Algo``, handle the trading logic/rules. This is where you'll write most of your code.\n\n\n1. Get Market Data\n------------------\n\nTo get started, you need to first create a Blotter script:\n\n.. code:: python\n\n # blotter.py\n from kinetick.blotter import Blotter\n\n class MainBlotter(Blotter):\n pass # we just need the name\n\n if __name__ == \"__main__\":\n blotter = MainBlotter()\n blotter.run()\n\nThen run the Blotter from the command line:\n\n.. code:: bash\n\n $ python -m blotter\n\nIf your strategy needs order book / market depth data, add the ``--orderbook`` flag to the command:\n\n.. code:: bash\n\n $ python -m blotter --orderbook\n\n\n2. Write your Algorithm\n-----------------------\n\nWhile the Blotter running in the background, write and execute your algorithm:\n\n.. code:: python\n\n # strategy.py\n from kinetick.algo import Algo\n\n class CrossOver(Algo):\n\n def on_start(self):\n pass\n\n def on_fill(self, instrument, order):\n pass\n\n def on_quote(self, instrument):\n pass\n\n def on_orderbook(self, instrument):\n pass\n\n def on_tick(self, instrument):\n pass\n\n def on_bar(self, instrument):\n # get instrument history\n bars = instrument.get_bars(window=100)\n\n # or get all instruments history\n # bars = self.bars[-20:]\n\n # skip first 20 days to get full windows\n if len(bars) < 20:\n return\n\n # compute averages using internal rolling_mean\n bars['short_ma'] = bars['close'].rolling(window=10).mean()\n bars['long_ma'] = bars['close'].rolling(window=20).mean()\n\n # get current position data\n positions = instrument.get_positions()\n\n # trading logic - entry signal\n if bars['short_ma'].crossed_above(bars['long_ma'])[-1]:\n if not instrument.pending_orders and positions[\"position\"] == 0:\n\n \"\"\" buy one contract.\n WARNING: buy or order instrument methods will bypass bot and risk assessor.\n Instead, It is advised to use create_position, open_position and close_position instrument methods\n to route the order via bot and risk assessor. \"\"\"\n instrument.buy(1)\n\n # record values for later analysis\n self.record(ma_cross=1)\n\n # trading logic - exit signal\n elif bars['short_ma'].crossed_below(bars['long_ma'])[-1]:\n if positions[\"position\"] != 0:\n\n # exit / flatten position\n instrument.exit()\n\n # record values for later analysis\n self.record(ma_cross=-1)\n\n\n if __name__ == \"__main__\":\n strategy = CrossOver(\n instruments = ['ACC', 'SBIN'], # scrip symbols\n resolution = \"1T\", # Pandas resolution (use \"K\" for tick bars)\n tick_window = 20, # no. of ticks to keep\n bar_window = 5, # no. of bars to keep\n preload = \"1D\", # preload 1 day history when starting\n timezone = \"Asia/Calcutta\" # convert all ticks/bars to this timezone\n )\n strategy.run()\n\n\nTo run your algo in a **live** environment, from the command line, type:\n\n.. code:: bash\n\n $ python -m strategy --logpath ~/orders\n\n\nThe resulting trades be saved in ``~/orders/STRATEGY_YYYYMMDD.csv`` for later analysis.\n\n\n3. Login to bot\n----------------------\n\nWhile the Strategy running in the background:\n\n Assuming you have added the telegram bot to your chat\n\n- ``/login <password>`` - Password can be found in the strategy console. This step is required if you have not provided your telegram chat id as an env var\n- ``/zlogin <totp>`` Command to login to zerodha using totp\n\n\ncommands\n--------\n\n- ``/report`` - get overview about trades\n- ``/help`` - get help\n- ``/resetrms`` - resets RiskAssessor parameters to its initial values.\n\n\n\nConfiguration\n-------------\nCan be specified either as env variable or cmdline arg\n\n.. list-table::\n\n * - Parameter\n - Required?\n - Example\n - Default\n - Description\n * - ``symbols``\n -\n - symbols=./symbols.csv\n -\n -\n * - ``LOGLEVEL``\n -\n - LOGLEVEL=DEBUG\n - INFO\n -\n * - ``zerodha_user``\n - yes - if live trading\n - zerodha_user=ABCD\n -\n -\n * - ``zerodha_password``\n - yes - if live trading\n - zerodha_password=abcd\n -\n -\n * - ``zerodha_pin``\n - yes - if live trading\n - zerodha_pin=1234\n -\n -\n * - ``BOT_TOKEN``\n - optional\n - BOT_TOKEN=12323:asdcldf..\n -\n - IF not provided then orders will bypass\n * - ``initial_capital``\n - yes\n - initial_capital=10000\n - 1000\n - Max capital deployed\n * - ``initial_margin``\n - yes\n - initial_margin=1000\n - 100\n - Not to be mistaken with broker margin. This is the max amount you can afford to loose\n * - ``risk2reward``\n - yes\n - risk2reward=1.2\n - 1\n - Set risk2reward for your strategy. This will be used in determining qty to trade\n * - ``risk_per_trade``\n - yes\n - risk_per_trade=200\n - 100\n - Risk you can afford with each trade\n * - ``max_trades``\n - yes\n - max_trades=2\n - 1\n - Max allowed concurrent positions\n * - ``dbport``\n -\n - dbport=27017\n - 27017\n -\n * - ``dbhost``\n -\n - dbhost=localhost\n - localhost\n -\n * - ``dbuser``\n -\n - dbuser=user\n -\n -\n * - ``dbpassword``\n -\n - dbpassword=pass\n -\n -\n * - ``dbname``\n -\n - dbname=kinetick\n - kinetick\n -\n * - ``orderbook``\n -\n - orderbook=true\n - false\n - Enable orderbook stream\n * - ``resolution``\n -\n - resolution=1m\n - 1\n - Min Bar interval\n * - ``preload_positions``\n - No\n - preload_positions=30D\n - -\n - Loads only overnight positions.Available options: 1D - 1 Day, 1W - 1 Week, 1H - 1 Hour\n * - ``CHAT_ID``\n - No\n - CHAT_ID=12345\n - -\n - default chat user id to which trade notifications are sent requiring no login\n\nDocker Instructions\n===================\n\n1. Build blotter\n\n ``$ docker build -t kinetick:blotter -f blotter.Dockerfile .``\n\n2. Build strategy\n\n ``$ docker build -t kinetick:strategy -f strategy.Dockerfile .``\n\n3. Run with docker-compose\n\n ``$ docker compose up``\n\n\nBacktesting\n===========\n\n.. code:: bash\n\n $ python -m strategy --start \"2021-03-06 00:15:00\" --end \"2021-03-10 00:15:00\" --backtest --backfill\n\n\n.. note::\n\n To get started checkout the patented BuyLowSellHigh strategy in ``strategies/`` directory.\n\n\n\ud83d\ude4f Credits\n==========\n\nThanks to @ran aroussi for all his initial work with Qtpylib.\nMost of work here is derived from his library\n\nDisclaimer\n==========\n\nKinetick is licensed under the **Apache License, Version 2.0**. A copy of which is included in LICENSE.txt.\n\nAll trademarks belong to the respective company and owners. Kinetick is not affiliated to any entity.\n\n.. [*] Kinetick is not affiliated to zerodha.\n\n",
"bugtrack_url": null,
"license": "LGPL",
"summary": "Simplifying Trading",
"version": "1.0.15",
"split_keywords": [
"kinetick",
"algotrading",
"algo",
"trading",
"zerodha",
"brokers",
"stocks"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2858798e26c24fabd5b4cc7b8113b290a1eb16ce768cb25156d33cec4166b519",
"md5": "03157c8cf5bcd5c076a3d6a56214b4b5",
"sha256": "0def9b70097f3e60caa6db7ae304784afe56dfaf122317406b3ad9a36d499a4a"
},
"downloads": -1,
"filename": "kinetick-1.0.15-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "03157c8cf5bcd5c076a3d6a56214b4b5",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 105215,
"upload_time": "2023-01-17T13:46:18",
"upload_time_iso_8601": "2023-01-17T13:46:18.316390Z",
"url": "https://files.pythonhosted.org/packages/28/58/798e26c24fabd5b4cc7b8113b290a1eb16ce768cb25156d33cec4166b519/kinetick-1.0.15-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "554a271bf5f4b891fdc6e65ddfc14413d4fccd3ecd066d3f76ae2ab8e84dbbfc",
"md5": "30c9244a13cfbbfa30c1d486b0c4f250",
"sha256": "ecc0a576350e7f66f83bfe392cca3556200c18967ada0573569fd32b5b574c9a"
},
"downloads": -1,
"filename": "kinetick-1.0.15.tar.gz",
"has_sig": false,
"md5_digest": "30c9244a13cfbbfa30c1d486b0c4f250",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 97217,
"upload_time": "2023-01-17T13:46:20",
"upload_time_iso_8601": "2023-01-17T13:46:20.308270Z",
"url": "https://files.pythonhosted.org/packages/55/4a/271bf5f4b891fdc6e65ddfc14413d4fccd3ecd066d3f76ae2ab8e84dbbfc/kinetick-1.0.15.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-17 13:46:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "imvinaypatil",
"github_project": "kinetick",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "kinetick"
}