Skip to content


Repository files navigation

The Kite Connect API Go client

The official Go 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.

Zerodha Technology (c) 2021. Licensed under the MIT License.



go get

API usage

package main

import (

	kiteconnect ""

const (
	apiKey    string = "my_api_key"
	apiSecret string = "my_api_secret"

func main() {
	// Create a new Kite connect instance
	kc := kiteconnect.New(apiKey)

	// Login URL from which request token can be obtained

	// Obtained request token after Kite Connect login flow
	requestToken := "request_token_obtained"

	// Get user details and access token
	data, err := kc.GenerateSession(requestToken, apiSecret)
	if err != nil {
		fmt.Printf("Error: %v", err)

	// Set access token

	// Get margins
	margins, err := kc.GetUserMargins()
	if err != nil {
		fmt.Printf("Error getting margins: %v", err)
	fmt.Println("margins: ", margins)

Kite ticker usage

package main

import (

	kiteconnect ""
	kitemodels ""
	kiteticker ""

var (
	ticker *kiteticker.Ticker

var (
	instToken = []uint32{408065, 112129}

// Triggered when any error is raised
func onError(err error) {
	fmt.Println("Error: ", err)

// Triggered when websocket connection is closed
func onClose(code int, reason string) {
	fmt.Println("Close: ", code, reason)

// Triggered when connection is established and ready to send and accept data
func onConnect() {
	err := ticker.Subscribe(instToken)
	if err != nil {
		fmt.Println("err: ", err)
	// Set subscription mode for the subscribed token
	// Default mode is Quote
	err = ticker.SetMode(kiteticker.ModeFull, instToken)
	if err != nil {
		fmt.Println("err: ", err)


// Triggered when tick is recevived
func onTick(tick kitemodels.Tick) {
	fmt.Println("Tick: ", tick)

// Triggered when reconnection is attempted which is enabled by default
func onReconnect(attempt int, delay time.Duration) {
	fmt.Printf("Reconnect attempt %d in %fs\n", attempt, delay.Seconds())

// Triggered when maximum number of reconnect attempt is made and the program is terminated
func onNoReconnect(attempt int) {
	fmt.Printf("Maximum no of reconnect attempt reached: %d", attempt)

// Triggered when order update is received
func onOrderUpdate(order kiteconnect.Order) {
	fmt.Printf("Order: ", order.OrderID)

func main() {
	apiKey := "my_api_key"
	accessToken := "my_access_token"

	// Create new Kite ticker instance
	ticker = kiteticker.New(apiKey, accessToken)

	// Assign callbacks

	// Start the connection


Check examples folder for more examples.

You can run the following after updating the API Keys in the examples:

go run examples/connect/basic/connect.go


Fetch mock responses for testcases

This needs to be run initially

git submodule update --init --recursive

Run unit tests

go test -v