GithubHelp home page GithubHelp logo

gokitesession's Introduction

Kite API Session Client

The Go client to generate user tokens automatically for using with KiteConnect and Kiteticker API.

Usage Instructions

Required:

  • userId : Your kite user_id
  • password : Your kite password
  • totpSecret : Its a value which you can copy while setting your external 2FA TOTP

Obtaining 2FA TOTP Secret

  • Set up External 2FA TOTP Auth by going to "My Profile > Settings > Account Security > External 2FA TOTP" and copy the value, while setting.

Installation

go get github.com/nsvirk/gokitesession

Sample code

package main

import (
	"fmt"
	"os"

	kitesession "github.com/nsvirk/gokitesession"
)

var (
	userId     = os.Getenv("KITE_USER_ID")
	password   = os.Getenv("KITE_PASSWORD")
	totpSecret = os.Getenv("KITE_TOTP_SECRET")
)

func main() {

	// Create a new Kite session instance
	ks := kitesession.New(userId)

	// Set debug mode
	ks.SetDebug(true)

	// Generate totp value
	totpValue, err := ks.GenerateTotpValue(totpSecret)
	if err != nil {
		fmt.Printf("Error generating totp value: %v", err)
		return
	}

	// Check the inputs values
	fmt.Println("--------------------------------------------------------------")
	fmt.Println("Kite User")
	fmt.Println("--------------------------------------------------------------")
	fmt.Println("User ID     	: ", userId)
	fmt.Println("Password     	: ", password)
	fmt.Println("Totp Value  	: ", totpValue)
	fmt.Println("")

	// Get kite session data
	session, err := ks.GenerateSession(password, totpValue)
	if err != nil {
		fmt.Printf("Error generating session: %v", err)
		return
	}

	fmt.Println("--------------------------------------------------------------")
	fmt.Println("Kite Session")
	fmt.Println("--------------------------------------------------------------")
	fmt.Println("user_id     	: ", session.UserId)
	fmt.Println("public_token	: ", session.PublicToken)
	fmt.Println("kf_session   	: ", session.KfSession)
	fmt.Println("enctoken    	: ", session.Enctoken)
	fmt.Println("login_time  	: ", session.LoginTime)
	fmt.Println("username   	: ", session.Username)
	fmt.Println("user_shortname	: ", session.UserShortname)
	fmt.Println("avatar_url  	: ", session.AvatarURL)
	fmt.Println("")
	// fmt.Println(session)

	// Check if the enctoken is valid
	isValid, err := ks.CheckEnctokenValid(session.Enctoken)
	if err != nil {
		fmt.Printf("Error checking enctoken valid: %v", err)
		return
	}

	fmt.Println("--------------------------------------------------------------")
	fmt.Println("Check Enctoken Valid")
	fmt.Println("--------------------------------------------------------------")
	fmt.Println("Enctoken Valid	: ", isValid)
	fmt.Println("")
	fmt.Println("--------------------------------------------------------------")
}

gokitesession's People

Contributors

nsvirk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.