Kite connect python client example

This is a simple example which uses Python Kite connect client to receive ticks and save it to Postgresql database. Celery is used as a Task queue manager to insert to database without blocking main Kite connect WebSocket thread.

Kite ticker subscribes to tokens in specified in stream.py with 5 second delay. Ticks received are sent to celery taske queue where it will be inserted to db.

Requirements

  1. Redis or any AMQP client for Celery
  2. Postgresql db (Can be replaced with any other db)

Install

pip install celery
pip install psycopg2
pip install kiteconnect

Create database and table

Create a database called ticks

CREATE DATABASE ticks;

Create a table called ticks in ticks table

CREATE TABLE ticks (
    token integer NOT NULL,
    date timestamp without time zone,
    price double precision
);

Configure celery and database in db.py

  1. Update broker URL in db.py with redis or any other AMQP client.
  2. Update user, password and host details for Postgresql in db.py

 Run Celery worker

celery -A db worker --loglevel=info

Run Python client

python stream.py