fyers

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2021 License: MIT Imports: 8 Imported by: 0

README

Fyers API GoLang Client

Go Reference

Fyers api golang client will help user to connect with various apis and subscribing with websocket notification. User can execute orders at real time and get order status as well as stream live market data via websocket.

Features

  • Place real time single and multiple orders
  • Modify pending order, cancel order, exit positions
  • Get quotes of single of multiple symbols
  • Get user profile, funds, holdings
  • List orders, positions, trades
  • Stream live data from market via fyers go client
  • Get Historical data, market depth

Installation

Fyers client is just a go get away

go get github.com/rishi-anand/fyers-go-client

API usage

package main

import (
	"fmt"

	"github.com/rishi-anand/fyers-go-client"
)

func main() {
	apiKey := "<YOUR_API_KEY>"
	accessToken := "<YOUR_ACCESS_TOKEN>"
	symbols := []string{"NSE:SBIN-EQ", "NSE:ONGC-EQ"}

	cli := fyers.New(apiKey, accessToken)
	if quotes, err := cli.GetQuote(symbols); err != nil {
		fmt.Errorf("failed to get quote from fyers. %v", err)
	} else {
		fmt.Println(quotes)
	}
}

Websocket Notification (for live market data)

package main

import (
	"fmt"

	"github.com/rishi-anand/fyers-go-client/api"
	fyerswatch "github.com/rishi-anand/fyers-go-client/websocket"
)

func main() {
	apiKey := "<YOUR_API_KEY>"
	accessToken := "<YOUR_ACCESS_TOKEN>"

	onConnectFunc := func() {
		fmt.Println("watch subscription is connected")
	}

	onMessageFunc := func(notification api.Notification) {
		fmt.Println(notification.Type, notification.SymbolData)
	}

	onErrorFunc := func(err error) {
		fmt.Errorf("failed to watch | disconnected from watch. %v", err)
	}

	onCloseFunc := func() {
		fmt.Println("watch connection is closed")
	}

	cli := fyerswatch.NewNotifier(apiKey, accessToken).
		WithOnConnectFunc(onConnectFunc).
		WithOnMessageFunc(onMessageFunc).
		WithOnErrorFunc(onErrorFunc).
		WithOnCloseFunc(onCloseFunc)

	cli.Subscribe(api.SymbolDataTick, "NSE:SBIN-EQ", "NSE:ONGC-EQ")

	/*
		symbols := []string {"NSE:SBIN-EQ", "NSE:ONGC-EQ"}
		cli.Subscribe(api.SymbolDataTick, symbols...)
	*/
}

Examples

Check examples examples folder for more examples.

Documentation

Index

Constants

View Source
const (
	Host                 = "https://api.fyers.in"
	ApiV2                = "/api/v2"
	DataV2               = "/data-rest/v2"
	OrdersUrl            = "/orders"
	MultiOrderUrl        = "/orders-multi"
	PositionsUrl         = "/positions"
	QuoteUrl             = "/quotes/"
	ProfileUrl           = "/profile"
	FundsUrl             = "/funds"
	HoldingsUrl          = "/holdings"
	TradeBookUrl         = "/tradebook"
	HistoricalDataApiUrl = "/history"
	MarketDepthApiUrl    = "/depth/"

	QueryParam        = "?"
	AndQueryParam     = "&"
	IdQueryParam      = "id="
	SymbolQueryParam  = "symbol="
	SymbolsQueryParam = "symbols="
	OhlcvQueryParam   = "ohlcv_flag=1"
)

Variables

This section is empty.

Functions

func New

func New(apiKey, accessToken string) *client

Types

type DomainHistoricalData added in v0.0.4

type DomainHistoricalData struct {
	Status  string      `json:"s,omitempty" yaml:"s,omitempty"`
	Candles [][]float64 `json:"candles,omitempty" yaml:"candles,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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