binance

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Binance exchange

Documentation

Index

Constants

View Source
const (
	ENDPOINT = "https://api.binance.com"
	API_V1   = "/api/v1/"
	API_V3   = "/api/v3/"

	TICKER_URI             = "ticker/24hr?symbol=%s"
	TICKERS_URI            = "ticker/allBookTickers"
	DEPTH_URI              = "depth?symbol=%s&limit=%d"
	ACCOUNT_URI            = "account?"
	ORDER_URI              = "order?"
	UNFINISHED_ORDERS_INFO = "openOrders?"
	KLINE_URI              = "klines"
	SERVER_TIME_URL        = "api/v1/time"
)
View Source
const (
	FUTURE_ENDPOINT       = "https://dapi.binance.com"
	FUTURE_KEEP_ALIVE_URI = "/dapi/v1/ping"

	FUTURE_TICKER_URI        = "/dapi/v1/ticker/24hr?"
	FUTURE_EXCHANGE_INFO_URI = "/dapi/v1/exchangeInfo"

	FUTURE_DEPTH_URI = "/dapi/v1/depth?"
	FUTURE_KLINE_URI = "/dapi/v1/continuousKlines?"
	FUTURE_TRADE_URI = "/dapi/v1/trades?"

	FUTURE_INCOME_URI       = "/dapi/v1/income?"
	FUTURE_ACCOUNT_URI      = "/dapi/v1/account?"
	FUTURE_POSITION_URI     = "/dapi/v1/positionRisk?"
	FUTURE_PLACE_ORDER_URI  = "/dapi/v1/order?"
	FUTURE_CANCEL_ORDER_URI = "/dapi/v1/order?"
	FUTURE_GET_ORDER_URI    = "/dapi/v1/order?"
	FUTURE_GET_ORDERS_URI   = "/dapi/v1/allOrders?"
)
View Source
const (
	SWAP_COUNTER_ENDPOINT   = "https://fapi.binance.com"
	SWAP_COUNTER_DEPTH_URI  = "/fapi/v1/depth?"
	SWAP_COUNTER_KLINE_URI  = "/fapi/v1/klines?"
	SWAP_COUNTER_TICKER_URI = "/fapi/v1/ticker/24hr?"

	SWAP_COUNTER_PLACE_ORDER_URI  = "/fapi/v1/order?"
	SWAP_COUNTER_GET_ORDER_URI    = "/fapi/v1/order?"
	SWAP_COUNTER_CANCEL_ORDER_URI = "/fapi/v1/order?"
	SWAP_COUNTER_INCOME_URI       = "/fapi/v1/income?"

	SWAP_BASIS_ENDPOINT   = "https://dapi.binance.com"
	SWAP_BASIS_DEPTH_URI  = "/dapi/v1/depth?"
	SWAP_BASIS_KLINE_URI  = "/dapi/v1/klines?"
	SWAP_BASIS_TICKER_URI = "/dapi/v1/ticker/24hr?"

	SWAP_BASIS_PLACE_ORDER_URI  = "/dapi/v1/order?"
	SWAP_BASIS_GET_ORDER_URI    = "/dapi/v1/order?"
	SWAP_BASIS_CANCEL_ORDER_URI = "/dapi/v1/order?"
	SWAP_BASIS_INCOME_URI       = "/dapi/v1/income?"

	SWAP_ACCOUNT_URI    = "/fapi/v1/account?"
	SWAP_GET_ORDERS_URI = "/fapi/v1/allOrders?"
)

Variables

This section is empty.

Functions

func GetDueTimestamp

func GetDueTimestamp(timestamp int64) (flag int, dueTimestamp map[string]int64)

Types

type Binance

type Binance struct {
	Spot   *Spot
	Margin *Margin
	Swap   *Swap
	Future *Future
	// contains filtered or unexported fields
}

func New

func New(config *APIConfig) *Binance

func (*Binance) DoRequest

func (this *Binance) DoRequest(httpMethod, uri, reqBody string, response interface{}) ([]byte, error)

func (*Binance) ExchangeInfo

func (this *Binance) ExchangeInfo() ([]byte, error)

func (*Binance) GetExchangeName

func (this *Binance) GetExchangeName() string

type BinanceWebsocket

type BinanceWebsocket struct {
	// contains filtered or unexported fields
}

func (*BinanceWebsocket) Close

func (this *BinanceWebsocket) Close()

func (*BinanceWebsocket) Init

func (this *BinanceWebsocket) Init()

func (*BinanceWebsocket) Start

func (this *BinanceWebsocket) Start()

func (*BinanceWebsocket) Subscribe

func (this *BinanceWebsocket) Subscribe(channel string) error

type Future

type Future struct {
	*Binance
	Locker        sync.Locker
	Contracts     FutureContracts
	LastTimestamp int64
	// contains filtered or unexported fields
}

func (*Future) CancelOrder

func (future *Future) CancelOrder(order *FutureOrder) ([]byte, error)

func (*Future) DoRequest

func (future *Future) DoRequest(httpMethod, uri, reqBody string, response interface{}) ([]byte, error)

func (*Future) GetAccount

func (future *Future) GetAccount() (*FutureAccount, []byte, error)

func (*Future) GetContract

func (future *Future) GetContract(pair Pair, contractType string) (*FutureContract, error)

func (*Future) GetDepth

func (future *Future) GetDepth(pair Pair, contractType string, size int) (*FutureDepth, []byte, error)

func (*Future) GetIndex

func (future *Future) GetIndex(pair Pair) (float64, []byte, error)

func (*Future) GetKlineRecords

func (future *Future) GetKlineRecords(
	contractType string,
	pair Pair,
	period, size, since int,
) ([]*FutureKline, []byte, error)

func (*Future) GetLimit

func (future *Future) GetLimit(pair Pair, contractType string) (float64, float64, error)

func (*Future) GetMark

func (future *Future) GetMark(pair Pair, contractType string) (float64, []byte, error)

func (*Future) GetOrder

func (future *Future) GetOrder(order *FutureOrder) ([]byte, error)

func (*Future) GetOrders

func (future *Future) GetOrders(pair Pair, contractType string) ([]*FutureOrder, []byte, error)

func (*Future) GetPairFlow

func (future *Future) GetPairFlow(pair Pair) ([]*FutureAccountItem, []byte, error)

func (*Future) GetTicker

func (future *Future) GetTicker(pair Pair, contractType string) (*FutureTicker, []byte, error)

func (*Future) GetTrades

func (future *Future) GetTrades(pair Pair, contractType string) ([]*Trade, []byte, error)

func (*Future) KeepAlive

func (future *Future) KeepAlive()

func (*Future) PlaceOrder

func (future *Future) PlaceOrder(order *FutureOrder) ([]byte, error)

type Margin

type Margin struct {
	*Binance
}

func (*Margin) CancelOrder

func (margin *Margin) CancelOrder(order *Order) ([]byte, error)

func (*Margin) GetAccount

func (margin *Margin) GetAccount(pair Pair) (*MarginAccount, []byte, error)

func (*Margin) GetDepth

func (margin *Margin) GetDepth(pair Pair, size int) (*Depth, []byte, error)

func (*Margin) GetExchangeRule

func (margin *Margin) GetExchangeRule(pair Pair) (*Rule, []byte, error)

func (*Margin) GetKlineRecords

func (margin *Margin) GetKlineRecords(pair Pair, period, size, since int) ([]*Kline, []byte, error)

func (*Margin) GetLoan

func (margin *Margin) GetLoan(loan *Loan) ([]byte, error)

func (*Margin) GetOrder

func (margin *Margin) GetOrder(order *Order) ([]byte, error)

func (*Margin) GetOrders

func (margin *Margin) GetOrders(pair Pair) ([]*Order, []byte, error)

get all orders in desc.

func (*Margin) GetTicker

func (margin *Margin) GetTicker(pair Pair) (*Ticker, []byte, error)

public api

func (*Margin) GetUnFinishOrders

func (margin *Margin) GetUnFinishOrders(pair Pair) ([]*Order, []byte, error)

func (*Margin) KeepAlive

func (margin *Margin) KeepAlive()

util api

func (*Margin) PlaceLoan

func (margin *Margin) PlaceLoan(loan *Loan) ([]byte, error)

func (*Margin) PlaceOrder

func (margin *Margin) PlaceOrder(order *Order) ([]byte, error)

private api

func (*Margin) ReturnLoan

func (margin *Margin) ReturnLoan(loan *Loan) ([]byte, error)

type Spot

type Spot struct {
	*Binance
}

func (*Spot) CancelOrder

func (spot *Spot) CancelOrder(order *Order) ([]byte, error)

func (*Spot) GetAccount

func (spot *Spot) GetAccount() (*Account, []byte, error)

private api

func (*Spot) GetDepth

func (spot *Spot) GetDepth(pair Pair, size int) (*Depth, []byte, error)

func (*Spot) GetExchangeRule

func (spot *Spot) GetExchangeRule(pair Pair) (*Rule, []byte, error)

func (*Spot) GetKlineRecords

func (spot *Spot) GetKlineRecords(pair Pair, period, size, since int) ([]*Kline, []byte, error)

func (*Spot) GetOHLCs

func (spot *Spot) GetOHLCs(symbol string, period, size, since int) ([]*OHLC, []byte, error)

func (*Spot) GetOrder

func (spot *Spot) GetOrder(order *Order) ([]byte, error)

func (*Spot) GetOrders

func (spot *Spot) GetOrders(pair Pair) ([]*Order, error)

func (*Spot) GetTicker

func (spot *Spot) GetTicker(pair Pair) (*Ticker, []byte, error)

public api

func (*Spot) GetTrades

func (spot *Spot) GetTrades(pair Pair, since int64) ([]*Trade, error)

func (*Spot) GetUnFinishOrders

func (spot *Spot) GetUnFinishOrders(pair Pair) ([]*Order, []byte, error)

func (*Spot) KeepAlive

func (spot *Spot) KeepAlive()

util api

func (*Spot) PlaceOrder

func (spot *Spot) PlaceOrder(order *Order) ([]byte, error)

type Swap

type Swap struct {
	*Binance
	sync.Locker

	LastKeepLiveTime time.Time // 上一次keep live时间。
	// contains filtered or unexported fields
}

func (*Swap) AddMargin

func (swap *Swap) AddMargin(pair Pair, openType FutureType, marginAmount float64) ([]byte, error)

func (*Swap) CancelOrder

func (swap *Swap) CancelOrder(order *SwapOrder) ([]byte, error)

func (*Swap) DoRequest

func (swap *Swap) DoRequest(httpMethod, uri, reqBody string, response interface{}, settleMode int64) ([]byte, error)

func (*Swap) GetAccount

func (swap *Swap) GetAccount() (*SwapAccount, []byte, error)

func (*Swap) GetAccountFlow

func (swap *Swap) GetAccountFlow() ([]*SwapAccountItem, []byte, error)

func (*Swap) GetContract

func (swap *Swap) GetContract(pair Pair) *SwapContract

func (*Swap) GetDepth

func (swap *Swap) GetDepth(pair Pair, size int) (*SwapDepth, []byte, error)

func (*Swap) GetFundingFee

func (swap *Swap) GetFundingFee(pair Pair) (float64, error)

func (*Swap) GetFundingFees

func (swap *Swap) GetFundingFees(pair Pair) ([][]interface{}, []byte, error)

func (*Swap) GetKline

func (swap *Swap) GetKline(pair Pair, period, size, since int) ([]*SwapKline, []byte, error)

func (*Swap) GetLimit

func (swap *Swap) GetLimit(pair Pair) (float64, float64, error)

func (*Swap) GetMark

func (swap *Swap) GetMark(pair Pair) (float64, error)

func (*Swap) GetOpenAmount

func (swap *Swap) GetOpenAmount(pair Pair) (float64, int64, []byte, error)

func (*Swap) GetOrder

func (swap *Swap) GetOrder(order *SwapOrder) ([]byte, error)

func (*Swap) GetOrders

func (swap *Swap) GetOrders(pair Pair) ([]*SwapOrder, []byte, error)

func (*Swap) GetPairFlow

func (swap *Swap) GetPairFlow(pair Pair) ([]*SwapAccountItem, []byte, error)

func (*Swap) GetPosition

func (swap *Swap) GetPosition(pair Pair, openType FutureType) (*SwapPosition, []byte, error)

func (*Swap) GetTicker

func (swap *Swap) GetTicker(pair Pair) (*SwapTicker, []byte, error)

func (*Swap) GetUnFinishOrders

func (swap *Swap) GetUnFinishOrders(pair Pair) ([]*SwapOrder, []byte, error)

func (*Swap) KeepAlive

func (swap *Swap) KeepAlive()

func (*Swap) PlaceOrder

func (swap *Swap) PlaceOrder(order *SwapOrder) ([]byte, error)

func (*Swap) ReduceMargin

func (swap *Swap) ReduceMargin(pair Pair, openType FutureType, marginAmount float64) ([]byte, error)

Jump to

Keyboard shortcuts

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