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.
- Redis or any AMQP client for Celery
- Postgresql db (Can be replaced with any other db)
pip install celery
pip install psycopg2
pip install kiteconnect
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
);
- Update
broker
URL indb.py
with redis or any other AMQP client. - Update
user
,password
andhost
details for Postgresql indb.py
# Run Celery worker
celery -A db worker --loglevel=info
python stream.py