Init params.
The WebSocket client for connecting to Kite connect streaming quotes service.
const KiteTicker = require("kiteconnect").KiteTicker;
const ticker = new KiteTicker({
api_key: "api_key",
access_token: "access_token"
});
ticker.connect();
ticker.on("ticks", onTicks);
ticker.on("connect", subscribe);
function onTicks(ticks) {
console.log("Ticks", ticks);
}
function subscribe() {
const items = [738561];
ticker.subscribe(items);
ticker.setMode(ticker.modeFull, items);
}
[{ tradable: true, mode: 'full', instrument_token: 208947, last_price: 3939, last_quantity: 1, average_price: 3944.77, volume: 28940, buy_quantity: 4492, sell_quantity: 4704, ohlc: { open: 3927, high: 3955, low: 3927, close: 3906 }, change: 0.8448540706605223, last_trade_time: 1515491369, timestamp: 1515491373, oi: 24355, oi_day_high: 0, oi_day_low: 0, depth: buy: [{ quantity: 59, price: 3223, orders: 5 }, { quantity: 164, price: 3222, orders: 15 }, { quantity: 123, price: 3221, orders: 7 }, { quantity: 48, price: 3220, orders: 7 }, { quantity: 33, price: 3219, orders: 5 }], sell: [{ quantity: 115, price: 3224, orders: 15 }, { quantity: 50, price: 3225, orders: 5 }, { quantity: 175, price: 3226, orders: 14 }, { quantity: 49, price: 3227, orders: 10 }, { quantity: 106, price: 3228, orders: 13 }] } }, ...]
Auto reonnection is enabled by default and it can be disabled by passing reconnect
param while initialising KiteTicker
.
Auto reonnection mechanism is based on Exponential backoff algorithm in which
next retry interval will be increased exponentially. max_delay
and max_tries
params can be used to tweak
the alogrithm where max_delay
is the maximum delay after which subsequent reconnection interval will become constant and
max_tries
is maximum number of retries before it quits reconnection.
For example if max_delay
is 60 seconds and max_tries
is 50 then the first reconnection interval starts from
minimum interval which is 2 seconds and keep increasing up to 60 seconds after which it becomes constant and when reconnection attempt
is reached upto 50 then it stops reconnecting.
Callback reconnect
will be called with current reconnect attempt and next reconnect interval and
on_noreconnect
is called when reconnection attempts reaches max retries.
Here is an example demonstrating auto reconnection.
const KiteTicker = require("kiteconnect").KiteTicker;
const ticker = new KiteTicker({
api_key: "api_key",
access_token: "access_token"
});
// set autoreconnect with 10 maximum reconnections and 5 second interval
ticker.autoReconnect(true, 10, 5)
ticker.connect();
ticker.on("ticks", onTicks);
ticker.on("connect", subscribe);
ticker.on("noreconnect", function() {
console.log("noreconnect");
});
ticker.on("reconnect", function(reconnect_count, reconnect_interval) {
console.log("Reconnecting: attempt - ", reconnect_count, " interval - ", reconnect_interval);
});
ticker.on("message", function(binary_msg){ console.log("Binary message", binary_msg); });
function onTicks(ticks) {
console.log("Ticks", ticks);
}
function subscribe() {
const items = [738561];
ticker.subscribe(items);
ticker.setMode(ticker.modeFull, items);
}
KiteTicker
Generated using TypeDoc
Classdesc
API client class. In production, you may initialise a single instance of this class per
api_key
. This module provides an easy to use abstraction over the HTTP APIs. The HTTP calls have been converted to methods and their JSON responses. See the Kite Connect API documentation for the complete list of APIs, supported parameters and values, and response formats.Getting started with API
API promises
All API calls returns a promise which you can use to call methods like
.then(...)
and.catch(...)
.Name
KiteConnect
Example
Initialize KiteConnect object