fyersapi

package
v0.0.0-...-5ce0ef2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	URIGetOrders       string = "/orders"
	URIGetTrades       string = "/trades"
	URIGetPositionss   string = "/positions"
	URIGetOrderHistory string = "/orders/%s" // "/orders/{id}"
	URIOrder           string = "/orders/sync"
	URIMultiOrder      string = "/multi-order/sync"
	URIGetHistory      string = "/history"
	URIGetQuotes       string = "/quotes"
	URIGetDepth        string = "/depth"
)

API endpoints

View Source
const (
	DefaultBaseURI     string = "https://api-t1.fyers.in/api/v3"
	DefaultBaseURIData string = "https://api-t1.fyers.in/data"
)

BASE URI

Variables

This section is empty.

Functions

This section is empty.

Types

type DepthBidAskResp

type DepthBidAskResp struct {
	Price  float64 `json:"price"`
	Volume int     `json:"volume"`
	Ord    int     `json:"ord"`
}

type DepthDResp

type DepthDResp struct {
	Totalbuyqty  int               `json:"totalbuyqty"`
	Totalsellqty int               `json:"totalsellqty"`
	Bids         []DepthBidAskResp `json:"bids"`
	Ask          []DepthBidAskResp `json:"ask"`
	O            float64           `json:"o"`
	H            float64           `json:"h"`
	L            float64           `json:"l"`
	C            float64           `json:"c"`
	Chp          float64           `json:"chp"`
	TickSize     float64           `json:"tick_Size"`
	Ch           float64           `json:"ch"`
	Ltq          int               `json:"ltq"`
	Ltt          int               `json:"ltt"`
	Ltp          float64           `json:"ltp"`
	V            int               `json:"v"`
	Atp          float64           `json:"atp"`
	LowerCkt     float64           `json:"lower_ckt"`
	UpperCkt     float64           `json:"upper_ckt"`
	Expiry       string            `json:"expiry"`
	Oi           int               `json:"oi"`
	Oiflag       bool              `json:"oiflag"`
	Pdoi         int               `json:"pdoi"`
	Oipercent    float64           `json:"oipercent"`
}

type DepthQuery

type DepthQuery struct {
	Symbol    string `url:"symbol"`
	OhlcvFlag int    `url:"ohlcv_flag"`
}

type DepthResp

type DepthResp struct {
	S       string                `json:"s"`
	D       map[string]DepthDResp `json:"d"`
	Message string                `json:"message"`
}

type ExitPositionBody

type ExitPositionBody struct {
	Id          []string `json:"id,omitempty"`
	ExitAll     int      `json:"exit_all,omitempty"`
	Segment     []int    `json:"segment,omitempty"`
	Side        []int    `json:"side,omitempty"`
	ProductType []string `json:"productType,omitempty"`
}

type ExitPositionResp

type ExitPositionResp struct {
	S       string `json:"s"`
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type FyersApi

type FyersApi struct {
	AppId       string
	AppSecret   string
	RedirectUrl string

	Logger common.LoggerInterface
	NetworkInterface
	// contains filtered or unexported fields
}

func NewFyersApi

func NewFyersApi(Opt ...FyersApiOptions) *FyersApi

func (*FyersApi) CancelOrder

func (f *FyersApi) CancelOrder(ctx context.Context, Body OrderCancelBody) (OrderResp, error)

func (*FyersApi) ConvertPosition

func (*FyersApi) DeleteMultiOrder

func (f *FyersApi) DeleteMultiOrder(ctx context.Context, Body []OrderPlacementBody) (MultiOrderResponse, error)

func (*FyersApi) ExitPosition

func (f *FyersApi) ExitPosition(ctx context.Context, Body ExitPositionBody) (ExitPositionResp, error)

func (*FyersApi) GetAccessToken

func (f *FyersApi) GetAccessToken() string

func (*FyersApi) GetDepth

func (f *FyersApi) GetDepth(ctx context.Context, DepthQuery HistoryQuery) (DepthResp, error)

func (*FyersApi) GetHistory

func (f *FyersApi) GetHistory(ctx context.Context, HistQuery HistoryQuery) (HistoryResp, error)

func (*FyersApi) GetOrderHistory

func (f *FyersApi) GetOrderHistory(ctx context.Context, OrderId string) (OrderHistResp, error)

func (*FyersApi) GetOrderbook

func (f *FyersApi) GetOrderbook(ctx context.Context, Orderquery OrderBookQuery) (OrderBookResp, error)

func (*FyersApi) GetPositionbook

func (f *FyersApi) GetPositionbook(ctx context.Context) (PositionBookResp, error)

func (*FyersApi) GetQuotes

func (f *FyersApi) GetQuotes(ctx context.Context, QotQuery QuotesQuery) (QuotesResp, error)

func (*FyersApi) GetTradebook

func (f *FyersApi) GetTradebook(ctx context.Context, Tradequery TradeBookQuery) (TradeBookResp, error)

func (*FyersApi) HeaderBuilder

func (f *FyersApi) HeaderBuilder() http.Header

func (*FyersApi) ModifyMultiOrder

func (f *FyersApi) ModifyMultiOrder(ctx context.Context, Body []OrderPlacementBody) (MultiOrderResponse, error)

func (*FyersApi) ModifyOrder

func (f *FyersApi) ModifyOrder(ctx context.Context, Body OrderModificationBody) (OrderResp, error)

func (*FyersApi) PlaceMultiOrder

func (f *FyersApi) PlaceMultiOrder(ctx context.Context, Body []OrderPlacementBody) (MultiOrderResponse, error)

func (*FyersApi) PlaceOrder

func (f *FyersApi) PlaceOrder(ctx context.Context, Body OrderPlacementBody) (OrderResp, error)

func (*FyersApi) SetAccessToken

func (f *FyersApi) SetAccessToken(accessToken string)

func (*FyersApi) SetAppID

func (f *FyersApi) SetAppID(appId string)

func (*FyersApi) SetAppSecret

func (f *FyersApi) SetAppSecret(appSecret string)

func (*FyersApi) SetRedirectURL

func (f *FyersApi) SetRedirectURL(redirectURL string)

type FyersApiOptions

type FyersApiOptions struct {
	Version     string
	Debug       bool
	BaseURI     string
	BaseURIData string
	LogFilePath string
	WriteToFile *bool
	Logger      common.LoggerInterface
	NetworkInterface
}

type HistoryQuery

type HistoryQuery struct {
	Symbol     string `url:"symbol"`
	Resolution string `url:"resolution"`
	DateFormat int    `url:"date_format"`
	RangeFrom  string `url:"range_from"`
	RangeTo    string `url:"range_to"`
	ContFlag   string `url:"cont_flag"`
}

type HistoryResp

type HistoryResp struct {
	Candles [][]any `json:"candles"`
	Code    int     `json:"code"`
	Message string  `json:"message"`
	S       string  `json:"s"`
}

type HttpLayer

type HttpLayer struct {
	Logger common.LoggerInterface
	Debug  bool
}

func (*HttpLayer) DoWrapper

func (h *HttpLayer) DoWrapper(ctx context.Context, httpMethod, URL string, query url.Values, headers http.Header, requestBody, input any) error

type MultiOrderResponse

type MultiOrderResponse struct {
	S       string                `json:"s"`
	Code    int                   `json:"code"`
	Message string                `json:"message"`
	Data    MultiOrderSubResponse `json:"data"`
}

type MultiOrderSubResponse

type MultiOrderSubResponse struct {
	Statuscode        int       `json:"statusCode"`
	Body              OrderResp `json:"body"`
	StatusDescription string    `json:"statusDescription"`
}

type NetworkInterface

type NetworkInterface interface {
	DoWrapper(ctx context.Context, httpMethod, URL string, query url.Values, header http.Header, requestBody, input any) error
}

type OrderBookItem

type OrderBookItem struct {
	ClientID          string  `json:"clientId"`
	ID                string  `json:"id"`
	ExchOrdID         string  `json:"exchOrdId"`
	Qty               int     `json:"qty"`
	RemainingQuantity int     `json:"remainingQuantity"`
	FilledQty         int     `json:"filledQty"`
	DiscloseQty       int     `json:"discloseQty"`
	LimitPrice        float64 `json:"limitPrice"`
	StopPrice         int     `json:"stopPrice"`
	TradedPrice       float64 `json:"tradedPrice"`
	Type              int     `json:"type"`
	FyToken           string  `json:"fyToken"`
	Exchange          int     `json:"exchange"`
	Segment           int     `json:"segment"`
	Symbol            string  `json:"symbol"`
	Instrument        int     `json:"instrument"`
	Message           string  `json:"message"`
	OfflineOrder      bool    `json:"offlineOrder"`
	OrderDateTime     string  `json:"orderDateTime"`
	OrderValidity     string  `json:"orderValidity"`
	Pan               string  `json:"pan"`
	ProductType       string  `json:"productType"`
	Side              int     `json:"side"`
	Status            int     `json:"status"`
	Source            string  `json:"source"`
	ExSym             string  `json:"ex_sym"`
	Description       string  `json:"description"`
	Ch                float64 `json:"ch"`
	Chp               float64 `json:"chp"`
	Lp                float64 `json:"lp"`
	SlNo              int     `json:"slNo"`
	DqQtyRem          int     `json:"dqQtyRem"`
	OrderNumStatus    string  `json:"orderNumStatus"`
	DisclosedQty      int     `json:"disclosedQty"`
	OrderTag          string  `json:"orderTag"`
}

type OrderBookItems

type OrderBookItems []OrderBookItem

type OrderBookQuery

type OrderBookQuery struct {
	Id       string `url:"id,omitempty"`
	OrderTag string `url:"order_tag,omitempty"`
}

type OrderBookResp

type OrderBookResp struct {
	S         string         `json:"s"`
	Code      int            `json:"code"`
	Message   string         `json:"message"`
	OrderBook OrderBookItems `json:"orderBook"`
}

type OrderCancelBody

type OrderCancelBody struct {
	ID string `json:"id"`
}

type OrderHistResp

type OrderHistResp struct {
	S       string         `json:"s"`
	Code    int            `json:"code"`
	Message string         `json:"message"`
	Data    OrderBookItems `json:"data"`
}

type OrderModificationBody

type OrderModificationBody struct {
	Id         string  `json:"id"`
	Qty        int     `json:"qty,omitempty"`
	Type       int     `json:"type,omitempty"`
	LimitPrice float64 `json:"limitPrice,omitempty"`
	StopPrice  float64 `json:"stopPrice,omitempty"`
	Validity   string  `json:"validity,omitempty"`
	TakeProfit float64 `json:"takeProfit,omitempty"`
	StopLoss   float64 `json:"stopLoss,omitempty"`
}

type OrderPlacementBody

type OrderPlacementBody struct {
	Symbol       string  `json:"symbol"`
	Qty          int     `json:"qty"`
	Type         int     `json:"type"`
	Side         int     `json:"side"`
	ProductType  string  `json:"productType"`
	LimitPrice   float64 `json:"limitPrice"`
	StopPrice    float64 `json:"stopPrice"`
	Validity     string  `json:"validity"`
	DisclosedQty int     `json:"disclosedQty"`
	OfflineOrder bool    `json:"offlineOrder"`
	TakeProfit   float64 `json:"takeProfit"`
	StopLoss     float64 `json:"stopLoss,omitempty"`
	OrderTag     string  `json:"orderTag,omitempty"`
}

type OrderResp

type OrderResp struct {
	S       string `json:"s"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	ID      string `json:"id"`
}

type PositionBookNetResp

type PositionBookNetResp struct {
	NetQty           int    `json:"netQty"`
	Qty              int    `json:"qty"`
	AvgPrice         int    `json:"avgPrice"`
	NetAvg           int    `json:"netAvg"`
	Side             int    `json:"side"`
	ProductType      string `json:"productType"`
	RealizedProfit   int    `json:"realized_profit"`
	UnrealizedProfit int    `json:"unrealized_profit"`
	Pl               int    `json:"pl"`
	Ltp              int    `json:"ltp"`
	BuyQty           int    `json:"buyQty"`
	BuyAvg           int    `json:"buyAvg"`
	BuyVal           int    `json:"buyVal"`
	SellQty          int    `json:"sellQty"`
	SellAvg          int    `json:"sellAvg"`
	SellVal          int    `json:"sellVal"`
	SlNo             int    `json:"slNo"`
	FyToken          string `json:"fyToken"`
	CrossCurrency    string `json:"crossCurrency"`
	RbiRefRate       int    `json:"rbiRefRate"`
	QtyMultiCom      int    `json:"qtyMulti_com"`
	Segment          int    `json:"segment"`
	Symbol           string `json:"symbol"`
	ID               string `json:"id"`
	CfBuyQty         int    `json:"cfBuyQty"`
	CfSellQty        int    `json:"cfSellQty"`
	DayBuyQty        int    `json:"dayBuyQty"`
	DaySellQty       int    `json:"daySellQty"`
	Exchange         int    `json:"exchange"`
}

type PositionBookNetResps

type PositionBookNetResps []PositionBookNetResp

type PositionBookOverallResp

type PositionBookOverallResp struct {
	CountTotal   int `json:"count_total"`
	CountOpen    int `json:"count_open"`
	PlTotal      int `json:"pl_total"`
	PlRealized   int `json:"pl_realized"`
	PlUnrealized int `json:"pl_unrealized"`
}

type PositionBookResp

type PositionBookResp struct {
	S            string                  `json:"s"`
	Code         int                     `json:"code"`
	Message      string                  `json:"message"`
	NetPositions PositionBookNetResps    `json:"netPositions"`
	Overall      PositionBookOverallResp `json:"overall"`
}

type PositionConversionBody

type PositionConversionBody struct {
	Symbol      string `json:"symbol"`
	Side        int    `json:"positionSide"`
	Qty         int    `json:"convertQty"`
	FromProduct string `json:"convertFrom"`
	ToProduct   string `json:"convertTo"`
	Overnight   int    `json:"overnight"`
}

type PositionConversionResp

type PositionConversionResp struct {
	S               string `json:"s"`
	Code            int    `json:"code"`
	Message         string `json:"message"`
	PositionDetails int    `json:"positionDetails"`
}

type QuotesCmdResp

type QuotesCmdResp struct {
	C  float64 `json:"c"`
	H  float64 `json:"h"`
	L  float64 `json:"l"`
	O  float64 `json:"o"`
	T  int     `json:"t"`
	Tf string  `json:"tf"`
	V  int     `json:"v"`
}

type QuotesDResp

type QuotesDResp struct {
	N string      `json:"n"`
	S string      `json:"s"`
	V QuotesVResp `json:"v"`
}

type QuotesQuery

type QuotesQuery struct {
	Symbols []string
}

type QuotesResp

type QuotesResp struct {
	Code    int           `json:"code"`
	D       []QuotesDResp `json:"d"`
	Message string        `json:"message"`
	S       string        `json:"s"`
}

type QuotesVResp

type QuotesVResp struct {
	Ask            float64       `json:"ask"`
	Bid            float64       `json:"bid"`
	Ch             float64       `json:"ch"`
	Chp            float64       `json:"chp"`
	Cmd            QuotesCmdResp `json:"cmd"`
	Description    string        `json:"description"`
	Exchange       string        `json:"exchange"`
	FyToken        string        `json:"fyToken"`
	HighPrice      float64       `json:"high_price"`
	LowPrice       float64       `json:"low_price"`
	Lp             float64       `json:"lp"`
	OpenPrice      float64       `json:"open_price"`
	OriginalName   string        `json:"original_name"`
	PrevClosePrice float64       `json:"prev_close_price"`
	ShortName      string        `json:"short_name"`
	Spread         float64       `json:"spread"`
	Symbol         string        `json:"symbol"`
	Tt             string        `json:"tt"`
	Volume         int           `json:"volume"`
}

type TradeBookItem

type TradeBookItem struct {
	ClientID        string  `json:"clientId"`
	OrderDateTime   string  `json:"orderDateTime"`
	OrderNumber     string  `json:"orderNumber"`
	ExchangeOrderNo string  `json:"exchangeOrderNo"`
	Exchange        int     `json:"exchange"`
	Side            int     `json:"side"`
	Segment         int     `json:"segment"`
	OrderType       int     `json:"orderType"`
	FyToken         string  `json:"fyToken"`
	ProductType     string  `json:"productType"`
	TradedQty       int     `json:"tradedQty"`
	TradePrice      float64 `json:"tradePrice"`
	TradeValue      float64 `json:"tradeValue"`
	TradeNumber     string  `json:"tradeNumber"`
	Row             int     `json:"row"`
	Symbol          string  `json:"symbol"`
	OrderTag        string  `json:"orderTag"`
}

type TradeBookItems

type TradeBookItems []TradeBookItem

type TradeBookQuery

type TradeBookQuery struct {
	OrderTag string `url:"order_tag,omitempty"`
}

type TradeBookResp

type TradeBookResp struct {
	S         string         `json:"s"`
	Code      int            `json:"code"`
	Message   string         `json:"message"`
	OrderBook TradeBookItems `json:"tradeBook"`
}

Jump to

Keyboard shortcuts

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