>_• <./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>
_
.. |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| | +-----------+-----------+-----------+
Ø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.Telegram bot <https://t.me/botfather>
_ token).TA-Lib <https://pypi.org/project/TA-Lib/>
_ via dedicated module (see example <strategies/macd_super_strategy.py>
_).scikit-learn <http://scikit-learn.org>
or TensorFlow <https://www.tensorflow.org>
) to use them in your algorithms.Docker <https://www.docker.com>
_ livesInstall 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
There are 5 main components in Kinetick:
Bot
- sends alert and signals with actions to perform.
Blotter
- handles market data retrieval and processing.
Broker
- sends and process orders/positions (abstracted layer).
Algo
- (sub-class of Broker
) communicates with the Blotter
to pass market data to your strategies, and process/positions orders via Broker
.
Lastly, Your Strategies, which are sub-classes of Algo
, handle the trading logic/rules. This is where you'll write most of your code.
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
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.
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/report
- get overview about trades/help
- get help/resetrms
- resets RiskAssessor parameters to its initial values.Can be specified either as env variable or cmdline arg
.. list-table::
symbols
LOGLEVEL
zerodha_user
zerodha_password
zerodha_pin
BOT_TOKEN
initial_capital
initial_margin
risk2reward
risk_per_trade
max_trades
dbport
dbhost
dbuser
dbpassword
dbname
orderbook
resolution
preload_positions
CHAT_ID
Build blotter
$ docker build -t kinetick:blotter -f blotter.Dockerfile .
Build strategy
$ docker build -t kinetick:strategy -f strategy.Dockerfile .
Run with docker-compose
$ docker compose up
.. 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.
Thanks to @ran aroussi for all his initial work with Qtpylib. Most of work here is derived from his library
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.