kite-connect-python-example
kite-connect-python-example copied to clipboard
Kite connect Python client example
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
- Redis or any AMQP client for Celery
- 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 database
CREATE TABLE ticks (
token integer NOT NULL,
date timestamp without time zone,
price double precision
);
Configure celery and database in db.py
- Update
brokerURL indb.pywith redis or any other AMQP client. - Update
user,passwordandhostdetails for Postgresql indb.py
# Run Celery worker
celery -A db worker --loglevel=info
Run Python client
python stream.py