option

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	BaseURL       = "https://eapi.binance.com"
	WSBaseURL     = "wss://nbstream.binance.com/eoptions"
	WSPublicPath  = "/ws" // wss://nbstream.binance.com/eoptions/ws/<stream>
	WSPrivatePath = "/ws" // user data stream uses /ws/<listenKey>
)

REST and WS endpoints for Binance European Options API.

View Source
const (
	EndpointExchangeInfo = "/eapi/v1/exchangeInfo"
	EndpointMark         = "/eapi/v1/mark"
	EndpointDepth        = "/eapi/v1/depth"
	EndpointTicker       = "/eapi/v1/ticker"
	EndpointKlines       = "/eapi/v1/klines"

	EndpointOrder         = "/eapi/v1/order"
	EndpointOpenOrders    = "/eapi/v1/openOrders"
	EndpointHistoryOrders = "/eapi/v1/historyOrders"

	EndpointAccount  = "/eapi/v1/account"
	EndpointPosition = "/eapi/v1/position"

	EndpointListenKey = "/eapi/v1/listenKey"
)

REST endpoint paths.

Variables

This section is empty.

Functions

func GenerateSignature

func GenerateSignature(secretKey, data string) string

GenerateSignature returns the HMAC-SHA256 signature Binance expects for signed REST/WS calls. Same algorithm as fapi/spapi.

func Timestamp

func Timestamp() int64

Timestamp returns the current epoch in milliseconds, matching Binance's wire convention.

Types

type AccountAsset

type AccountAsset struct {
	Asset         string `json:"asset"`
	MarginBalance string `json:"marginBalance"`
	Equity        string `json:"equity"`
	Available     string `json:"available"`
	Locked        string `json:"locked"`
	UnrealizedPNL string `json:"unrealizedPNL"`
}

type AccountGreek

type AccountGreek struct {
	Underlying string `json:"underlying"`
	Delta      string `json:"delta"`
	Gamma      string `json:"gamma"`
	Theta      string `json:"theta"`
	Vega       string `json:"vega"`
}

type AccountResponse

type AccountResponse struct {
	Asset       []AccountAsset `json:"asset"`
	GreekRecord []AccountGreek `json:"greek"`
	Time        int64          `json:"time"`
	RiskLevel   string         `json:"riskLevel"`
}

AccountResponse is /eapi/v1/account.

type Client

type Client struct {
	BaseURL    string
	APIKey     string
	SecretKey  string
	HTTPClient *http.Client
	Logger     *zap.SugaredLogger
}

Client is the REST client for Binance European Options (eapi.binance.com).

Only the methods needed by the Tier 2 reference adapter are implemented here: chain/mark/positions/account + place/cancel/query orders.

func NewClient

func NewClient() *Client

func (*Client) CancelOrder

func (c *Client) CancelOrder(ctx context.Context, symbol, orderID, clientOrderID string) (*OrderResponse, error)

CancelOrder cancels either by orderID or clientOrderID (one is required).

func (*Client) CloseListenKey

func (c *Client) CloseListenKey(ctx context.Context, key string) error

func (*Client) CreateListenKey

func (c *Client) CreateListenKey(ctx context.Context) (string, error)

func (*Client) GetAccount

func (c *Client) GetAccount(ctx context.Context) (*AccountResponse, error)

func (*Client) GetExchangeInfo

func (c *Client) GetExchangeInfo(ctx context.Context) (*ExchangeInfoResponse, error)

func (*Client) GetMark

func (c *Client) GetMark(ctx context.Context, symbol string) (MarkResponse, error)

GetMark returns mark info. If symbol is empty, all option symbols are returned.

func (*Client) GetOpenOrders

func (c *Client) GetOpenOrders(ctx context.Context, symbol string) ([]OrderResponse, error)

func (*Client) GetOrder

func (c *Client) GetOrder(ctx context.Context, symbol, orderID, clientOrderID string) (*OrderResponse, error)

func (*Client) GetPositions

func (c *Client) GetPositions(ctx context.Context, symbol string) (PositionResponse, error)

GetPositions returns open option positions. symbol filter is optional.

func (*Client) KeepAliveListenKey

func (c *Client) KeepAliveListenKey(ctx context.Context, key string) error

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(ctx context.Context, req *OrderRequest) (*OrderResponse, error)

func (*Client) WithCredentials

func (c *Client) WithCredentials(apiKey, secretKey string) *Client

func (*Client) WithHTTPClient

func (c *Client) WithHTTPClient(httpClient *http.Client) *Client

type ErrorResponse

type ErrorResponse struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

ErrorResponse — Binance error envelope.

type ExchangeInfoResponse

type ExchangeInfoResponse struct {
	Timezone        string           `json:"timezone"`
	ServerTime      int64            `json:"serverTime"`
	OptionContracts []OptionContract `json:"optionContracts"`
	OptionAssets    []OptionAsset    `json:"optionAssets"`
	OptionSymbols   []OptionSymbol   `json:"optionSymbols"`
}

ExchangeInfoResponse is /eapi/v1/exchangeInfo.

type ListenKeyResponse

type ListenKeyResponse struct {
	ListenKey string `json:"listenKey"`
}

type MarkEntry

type MarkEntry struct {
	Symbol           string `json:"symbol"`
	MarkPrice        string `json:"markPrice"`
	BidIV            string `json:"bidIV"`
	AskIV            string `json:"askIV"`
	MarkIV           string `json:"markIV"`
	Delta            string `json:"delta"`
	Theta            string `json:"theta"`
	Gamma            string `json:"gamma"`
	Vega             string `json:"vega"`
	HighPriceLimit   string `json:"highPriceLimit"`
	LowPriceLimit    string `json:"lowPriceLimit"`
	RiskFreeInterest string `json:"riskFreeInterest"`
}

type MarkResponse

type MarkResponse []MarkEntry

MarkResponse is /eapi/v1/mark — one entry per option symbol queried.

type OptionAsset

type OptionAsset struct {
	Name string `json:"name"`
	ID   int64  `json:"id,omitempty"`
}

type OptionContract

type OptionContract struct {
	BaseAsset   string `json:"baseAsset"`
	QuoteAsset  string `json:"quoteAsset"`
	Underlying  string `json:"underlying"` // e.g. "BTCUSDT"
	SettleAsset string `json:"settleAsset"`
	ID          int64  `json:"id,omitempty"`
}

OptionContract describes one underlying (e.g. BTC) and its quote asset.

type OptionSymbol

type OptionSymbol struct {
	Symbol               string `json:"symbol"`
	Side                 string `json:"side"` // "CALL" or "PUT"
	StrikePrice          string `json:"strikePrice"`
	Underlying           string `json:"underlying"`
	Unit                 int64  `json:"unit"` // 1 (contract size in underlying)
	MakerFeeRate         string `json:"makerFeeRate"`
	TakerFeeRate         string `json:"takerFeeRate"`
	MinQty               string `json:"minQty"`
	MaxQty               string `json:"maxQty"`
	InitialMargin        string `json:"initialMargin"`
	MaintenanceMargin    string `json:"maintenanceMargin"`
	MinInitialMargin     string `json:"minInitialMargin"`
	MinMaintenanceMargin string `json:"minMaintenanceMargin"`
	PriceScale           int    `json:"priceScale"`
	QuantityScale        int    `json:"quantityScale"`
	ExpiryDate           int64  `json:"expiryDate"` // ms epoch
	ID                   int64  `json:"id,omitempty"`
	QuoteAsset           string `json:"quoteAsset"`
	ContractStatus       string `json:"contractStatus,omitempty"`
}

OptionSymbol is one tradable option instrument. Wire format of Symbol: "BTC-251226-100000-C".

type OrderRequest

type OrderRequest struct {
	Symbol        string // option symbol, e.g. "BTC-251226-100000-C"
	Side          string // "BUY" or "SELL"
	Type          string // "LIMIT" or "MARKET"
	Quantity      string // contracts
	Price         string // premium, required for LIMIT
	TimeInForce   string // "GTC", "IOC", "FOK"
	ReduceOnly    bool
	PostOnly      bool
	ClientOrderID string // user-defined ID
}

OrderRequest is used when placing an order.

type OrderResponse

type OrderResponse struct {
	OrderID       int64  `json:"orderId"`
	Symbol        string `json:"symbol"`
	Price         string `json:"price"`
	Quantity      string `json:"quantity"`
	ExecutedQty   string `json:"executedQty"`
	Fee           string `json:"fee"`
	Side          string `json:"side"`
	Type          string `json:"type"`
	TimeInForce   string `json:"timeInForce"`
	ReduceOnly    bool   `json:"reduceOnly"`
	PostOnly      bool   `json:"postOnly"`
	CreateTime    int64  `json:"createTime"`
	UpdateTime    int64  `json:"updateTime"`
	Status        string `json:"status"` // "ACCEPTED", "REJECTED", "PARTIALLY_FILLED", "FILLED", "CANCELLED"
	AvgPrice      string `json:"avgPrice"`
	ClientOrderID string `json:"clientOrderId"`
}

OrderResponse — POST/GET /eapi/v1/order.

type PositionEntry

type PositionEntry struct {
	EntryPrice    string `json:"entryPrice"`
	Symbol        string `json:"symbol"`
	Side          string `json:"side"` // "LONG" or "SHORT"
	Quantity      string `json:"quantity"`
	ReducibleQty  string `json:"reducibleQty"`
	MarkValue     string `json:"markValue"`
	Ror           string `json:"ror"`
	UnrealizedPNL string `json:"unrealizedPNL"`
	MarkPrice     string `json:"markPrice"`
	StrikePrice   string `json:"strikePrice"`
	PositionCost  string `json:"positionCost"`
	ExpiryDate    int64  `json:"expiryDate"`
	PriceScale    int    `json:"priceScale"`
	QuantityScale int    `json:"quantityScale"`
	OptionSide    string `json:"optionSide"` // "CALL" or "PUT"
	QuoteAsset    string `json:"quoteAsset"`
	Time          int64  `json:"time"`
}

type PositionResponse

type PositionResponse []PositionEntry

PositionResponse is /eapi/v1/position.

Jump to

Keyboard shortcuts

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