### Install Gokiteconnect Go Client Source: https://github.com/zerodha/gokiteconnect/blob/master/README.md Command to fetch and install the Gokiteconnect Go client library using go get. This is the first step to integrating Kite Connect API in your Go applications. ```bash go get github.com/zerodha/gokiteconnect/v4 ``` -------------------------------- ### Bash: Run Gokiteconnect Example Source: https://github.com/zerodha/gokiteconnect/blob/master/README.md Command to execute a basic example provided within the Gokiteconnect library's examples folder. This allows developers to quickly test the integration after updating API keys. ```bash go run examples/connect/basic/connect.go ``` -------------------------------- ### Go: Authenticate and Fetch User Margins using Kite Connect Source: https://github.com/zerodha/gokiteconnect/blob/master/README.md Example Go code demonstrating how to create a Kite Connect client instance, generate a user session using an API secret and request token, set the access token, and retrieve user margins. It requires API keys and a request token obtained through the Kite Connect login flow. ```go 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) } ``` -------------------------------- ### Bash: Run Gokiteconnect Unit Tests Source: https://github.com/zerodha/gokiteconnect/blob/master/README.md Command to execute the unit tests for the Gokiteconnect Go library. This is a standard command for Go projects to verify the correctness of the codebase. ```bash go test -v ``` -------------------------------- ### Bash: Initialize Gokiteconnect Git Submodules Source: https://github.com/zerodha/gokiteconnect/blob/master/README.md Command to initialize and update git submodules for the Gokiteconnect project, typically required for fetching mock responses used in test cases during development. ```bash git submodule update --init --recursive ``` -------------------------------- ### Go: Stream Live Market Data with Kite Ticker Source: https://github.com/zerodha/gokiteconnect/blob/master/README.md Go program demonstrating how to use the Kite Ticker to establish a WebSocket connection for streaming live market data. It includes setting up callbacks for connection events, errors, ticks, and order updates, and subscribing to specific instrument tokens. ```go 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() } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.