• Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official Go client for Kite Connect API's

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.

Documentation

Installation

go get github.com/zerodha/gokiteconnect/v4

API usage

package main

import (
	"fmt"

	kiteconnect "github.com/zerodha/gokiteconnect/v4"
)

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/zerodha/gokiteconnect/v4"
	kitemodels "github.com/zerodha/gokiteconnect/v4/models"
	kiteticker "github.com/zerodha/gokiteconnect/v4/ticker"
)

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() {
	fmt.Println("Connected")
	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
	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.

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

go run examples/connect/basic/connect.go

Development

Fetch mock responses for testcases

This needs to be run initially

git submodule update --init --recursive

Run unit tests

go test -v

More Repositories

1

pykiteconnect

The official Python client library for the Kite Connect trading APIs
Python
981
star
2

dungbeetle

A distributed job server built specifically for queuing and executing heavy SQL read jobs asynchronously. Separate out reporting layer from apps. MySQL, Postgres, ClickHouse.
Go
506
star
3

kiteconnectjs

The official typescript client library for the Kite Connect trading APIs
TypeScript
314
star
4

javakiteconnect

The official Java client for communicating with Kite Connect API.
Java
203
star
5

nomad-cluster-setup

Terraform modules for creating Nomad servers and clients nodes on AWS.
HCL
144
star
6

frappe-attachments-s3

A frappe app to upload file attachments in doctypes to s3.
Python
121
star
7

logf

Extremely fast, light weight, zero alloc logfmt logging library for Go.
Go
91
star
8

gchatgpt

Google Chat bot for OpenAI ChatGPT
Go
81
star
9

fastglue

Fastglue is an opinionated, bare bones wrapper that glues together fasthttp and fasthttprouter to act as a micro HTTP framework.
Go
80
star
10

dotnetkiteconnect

.NET library for Kite connect
C#
78
star
11

kaf-relay

Replicate and sync Kafka topics between clusters in realtime. Supports topic re-mapping, healthchecks, and hot failovers for high availability.
Go
67
star
12

kite-connect-python-example

Kite connect Python client example
Python
62
star
13

simplesessions

simplesessions is a Go session management library that is completely agnostic of HTTP libraries and frameworks, backend stores, and even cookie jars.
Go
62
star
14

rbiparser

A utility for downloading, parsing and sanitizing bank database (IFSC, MICR, address etc.) Excel sheets from the RBI website.
Python
54
star
15

zerodhatech.github.io

The zerodha.tech blog
HTML
48
star
16

cppkiteconnect

C++ Kite Connect API library / SDK
C++
47
star
17

kiteconnect-rs

The official Rust client library for the Kite Connect trading APIs
Rust
45
star
18

jpdfsigner

A HTTP server and a CLI for digitally signing PDFs.
Java
43
star
19

phpkiteconnect

The official PHP client library for the Kite Connect trading APIs
PHP
43
star
20

fastcache

fastcache is an HTTP response caching package that plugs into fastglue that simplifies "dumb" caching of API endpoints.
Go
34
star
21

py-frappe-client

Frappe client for humans
Python
31
star
22

pdf_text_overlay

pdf_text_overlay is a python library to write text on top of pdf.
Python
27
star
23

vendor-payments

A frappe app that has workflows and reports to make payments to vendors by a company and track them
Python
26
star
24

kiteconnect-mocks

Mock responses for kiteconnect
25
star
25

mii-lama

A tool for posting metrics from node-exporter to LAMA (Indian stock market regulatory framework) API gateways
Go
19
star
26

rms-consolidated-scrips-status

A utility that parse Zerodha Consolidated google spreadsheets and render category-wise scrip details(margins, multiplier, etc)
Python
19
star
27

fastglue-csrf

CSRF middleware for https://github.com/zerodha/fastglue
Go
15
star
28

nithinkamath.me

HTML
13
star
29

fastglue-metrics

Prometheus Metrics exposed for Fastglue HTTP Handlers.
Go
12
star
30

subscription_coupons

Subscription discount coupon code manager
Python
11
star
31

osticket-autoassign

Osticket plugin to assign tickets automatically to random agents based on teams, department, and activity
PHP
11
star
32

osticket-archive

A utility to archive all closed tickets beyond a certain age to disk (including attachments) and delete them from the database. The tickets are archived as JSON files.
PHP
8
star
33

flask-kiteconnect

Flask extension for kiteconnect API
Python
7
star
34

python-wheels

Python wheels used in other Python projects
5
star
35

kite-discourse-sso

Discourse SSO in Go for Kite Connect. Serves as a template for implementing other Discourse integrations.
Go
5
star
36

fastglue-adapter

net/http adapter for fastglue
Go
3
star
37

pdfrender

Python
2
star