Code Monkey home page Code Monkey logo

kiteconnectjs's Introduction

The Kite Connect API Javascript client

The official Javascript node client for communicating with the Kite Connect API.

Kite Connect is a set of REST-like APIs that expose many capabilities required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (WebSockets), and more, with the simple HTTP API collection

Rainmatter (c) 2016. Licensed under the MIT License.

Documentation

Installation

This module is installed via npm:

npm install --save kiteconnect

Getting started with API

var KiteConnect = require("kiteconnect").KiteConnect;

var kc = new KiteConnect("your_api_key");

kc.requestAccessToken("request_token", "api_secret")
	.then(function(response) {
		init();
	})
	.catch(function(err) {
		console.log(err.response);
	})

function init() {
	// Fetch equity margins.
	// You can have other api calls here.

	kc.margins("equity")
		.then(function(response) {
			// You got user's margin details.
		}).catch(function(err) {
			// Something went wrong.
		});
}

API promises

All API calls returns a promise which you can use to call methods like .then(...), .catch(...), and .finally(...).

kiteConnectApiCall
	.then(function(v) {
	    // On success
	})
	.catch(function(e) {
		// On rejected
	})
	.finally(function(e) {
		// On finish
	});

You can access the full list of Bluebird Promises API here.

Getting started WebSocket client

var KiteTicker = require("kiteconnect").KiteTicker;
var ticker = new KiteTicker(api_key, user_id, public_token);

ticker.connect();
ticker.on("tick", setTick);
ticker.on("connect", subscribe);

function setTick(ticks) {
	console.log("Ticks", ticks);
}

function subscribe() {
	var items = [738561];
	ticker.subscribe(items);
	ticker.setMode(ticker.modeFull, items);
}

A typical web application

In a typical web application where a new instance of views, controllers etc. are created per incoming HTTP request, you will need to initialise a new instance of Kite client per request as well. This is because each individual instance represents a single user that's authenticated, unlike an admin API where you may use one instance to manage many users.

Hence, in your web application, typically:

  • You will initialise an instance of the Kite client
  • Redirect the user to the login_url()
  • At the redirect url endpoint, obtain the request_token from the query parameters
  • Initialise a new instance of Kite client, use request_access_token() to obtain the access_token along with authenticated user data
  • Store this response in a session and use the stored access_token and initialise instances of Kite client for subsequent API calls.

kiteconnectjs's People

Contributors

sivamgr avatar vividvilla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.