Skip to content
Official GO client for Kite Connect API's
Go
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples chore: modify examples Jan 9, 2019
mock_responses Add tests and minor fixes Aug 1, 2018
ticker fix: access token and api key getting appended multiple times in ticker Oct 11, 2018
.gitignore feat: convert package to go module Sep 3, 2018
.travis.yml chore: add go 1.11 to travis config Sep 3, 2018
CHANGELOG.md Add changelog Jun 26, 2018
LICENSE Add LICENSE, README and gitignore file Aug 20, 2017
README.md Update README Jun 26, 2018
connect.go Refactor connect variable names Apr 4, 2018
connect_test.go test: fix test for Cancel Order Jan 9, 2019
errors.go Update doc comments Mar 29, 2018
errors_test.go test: added tests for errors Aug 6, 2018
go.mod feat: convert package to go module Sep 3, 2018
http.go Refactor http client interface Apr 4, 2018
http_test.go Add user API unit tests and mock responses Mar 30, 2018
market.go feat: fix tests and make struct members of instrument public Aug 14, 2018
market_test.go feat: fix tests and make struct members of instrument public Aug 14, 2018
mutualfunds.go Add tests and minor fixes Aug 1, 2018
mutualfunds_test.go Add tests and minor fixes Aug 1, 2018
orders.go fix: change type of instrument token in orders response struct to uint32 Apr 2, 2019
orders_test.go Add tests and minor fixes Aug 1, 2018
portfolio.go fix: remove models.PlainResponse from user and portfolio calls Jul 5, 2018
portfolio_test.go Add tests and minor fixes Aug 1, 2018
user.go fix: remove models.PlainResponse from user and portfolio calls Jul 5, 2018
user_test.go Add user segment margin tests and other connect tests Apr 4, 2018
utils.go Update doc comments Mar 29, 2018
utils_test.go Update util tests Mar 29, 2018

README.md

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) 2018. Licensed under the MIT License.

Documentation

Installation

go get github.com/zerodhatech/gokiteconnect

API usage

package main

import (
	"fmt"

	"github.com/zerodhatech/gokiteconnect"
)

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
	fmt.Println(kc.GetLoginURL())

	// 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)
		return
	}

	// Set access token
	kc.SetAccessToken(data.AccessToken)

	// 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 (
	"fmt"
	"time"

	kiteconnect "github.com/zerodhatech/gokiteconnect"
	"github.com/zerodhatech/gokiteconnect/ticker"
)

var (
	ticker *kiteticker.Ticker
)

// 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() {
	fmt.Println("Connected")
	err := ticker.Subscribe([]uint32{53718535})
	if err != nil {
		fmt.Println("err: ", err)
	}
}

// Triggered when tick is recevived
func onTick(tick kiteticker.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
	ticker.OnError(onError)
	ticker.OnClose(onClose)
	ticker.OnConnect(onConnect)
	ticker.OnReconnect(onReconnect)
	ticker.OnNoReconnect(onNoReconnect)
	ticker.OnTick(onTick)
	ticker.OnOrderUpdate(onOrderUpdate)

	// Start the connection
	ticker.Serve()
}

Examples

Check examples folder for more examples.

Run unit tests

go test -v

Changelog

Check CHANGELOG.md

You can’t perform that action at this time.