zerodhaapi

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 13 Imported by: 0

README

Golang package to provide fully automated zerodha login/authentication and ticker. This package is for demo purpose only. Use at your own will & risk.

Installation

go get github.com/parag-b/zerodha-api

How to use

To Authenticate - Zerodha API

    var zd zerodhaapi.ZerodhaApi        // create variable

    zd.UserId = ""                      // provide credentials
    zd.Password = ""
    zd.TotpKey = ""
    zd.ApiKey = ""
    zd.ApiSecret = ""    

    err := zerodhaapi.New(&zd)          // Authenticate with zerodha
    if err != nil {
        fmt.Println(err)
    }

Error responses

  • Invalid credentials - Check zerodha credentials.  (zd.UserId) and/or (zd.Password)
  • Invalid ToptKey - Check the seed key (zd.TotpKey) while enabling TOTP on zerodha
  • Invalid ApiKey -  Check the ApiKey generated at kite.trade (zd.ApiKey)
  • Invalid ApiSecret -  Check the ApiSecret generated at kite.trade (zd.ApiSecret)

Using Ticker

zd.TickerSubscribeTokens = []uint32{8972034, 8972290}   // provide instruments

var TicksCh = make(chan kitemodels.Tick, 1000)          // create buffered ch
zd.TickerCh = TicksCh                                   // assign the channel
zd.StartTicker()                                        // start ticks websocket

Zerodha APIs

margins, _ := zd.KiteConn.GetUserMargins()
fmt.Println(margins)

Refer ticker_test.go for complete example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(za *ZerodhaApi) error

Authencticates the user and stores the access token

Types

type ZerodhaApi

type ZerodhaApi struct {
	// authentication settings (zerodha user)
	UserId    string
	Password  string
	ApiKey    string
	ApiSecret string
	TotpKey   string

	// ticker settings
	TickerSubscribeTokens []uint32
	TickerCh              chan kitemodels.Tick
	TickDebug             bool // to print every tick

	// kite instance data
	Ticker            *kiteticker.Ticker
	KiteConn          *kiteconnect.Client
	TicksPerSec       int64 // number of ticks received per seconds
	IsTickerConnected bool
	IsKiteAuth        bool
	KiteReqId         string
	KiteReqToken      string
	AccessToken       string
}

struct has 3 categories of variables 1. User information to be used for authentication 2. Tikcer config varaibles 3. Instance variables, there are updated by this package. For read only by the application

func (ZerodhaApi) CashBalance

func (z ZerodhaApi) CashBalance() (float64, error)

Returns the Equity part of margins data

func (*ZerodhaApi) CloseTicker added in v0.2.0

func (z *ZerodhaApi) CloseTicker()

Closes the ticker and channel

func (*ZerodhaApi) StartTicker added in v0.2.0

func (z *ZerodhaApi) StartTicker()

Registers instruments with zerodha for tick data Setups call backs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL