binance

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GLOBAL_API_BASE_URL = "https://api.binance.com"
	US_API_BASE_URL     = "https://api.binance.us"
	JE_API_BASE_URL     = "https://api.binance.je"

	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        = "time"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AggTrade added in v1.0.4

type AggTrade struct {
	Trade
	FirstBreakdownTradeID int64 `json:"f"`
	LastBreakdownTradeID  int64 `json:"l"`
	TradeTime             int64 `json:"T"`
}

type Binance

type Binance struct {
	*ExchangeInfo
	// contains filtered or unexported fields
}

func New

func New(client *http.Client, api_key, secret_key string) *Binance

func NewWithConfig added in v1.2.3

func NewWithConfig(config *APIConfig) *Binance

func (*Binance) CancelOrder

func (bn *Binance) CancelOrder(orderId string, currencyPair CurrencyPair) (bool, error)

func (*Binance) GetAccount

func (bn *Binance) GetAccount() (*Account, error)

func (*Binance) GetDepth

func (bn *Binance) GetDepth(size int, currencyPair CurrencyPair) (*Depth, error)

func (*Binance) GetExchangeInfo added in v1.2.3

func (bn *Binance) GetExchangeInfo() (*ExchangeInfo, error)

func (*Binance) GetExchangeName

func (bn *Binance) GetExchangeName() string

func (*Binance) GetKlineRecords

func (bn *Binance) GetKlineRecords(currency CurrencyPair, period, size, since int) ([]Kline, error)

func (*Binance) GetOneOrder

func (bn *Binance) GetOneOrder(orderId string, currencyPair CurrencyPair) (*Order, error)

func (*Binance) GetOrderHistorys

func (bn *Binance) GetOrderHistorys(currency CurrencyPair, currentPage, pageSize int) ([]Order, error)

func (*Binance) GetTicker

func (bn *Binance) GetTicker(currency CurrencyPair) (*Ticker, error)

func (*Binance) GetTradeSymbol added in v1.2.3

func (bn *Binance) GetTradeSymbol(currencyPair CurrencyPair) (*TradeSymbol, error)

func (*Binance) GetTrades

func (bn *Binance) GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error)

非个人,整个交易所的交易记录 注意:since is fromId

func (*Binance) GetUnfinishOrders

func (bn *Binance) GetUnfinishOrders(currencyPair CurrencyPair) ([]Order, error)

func (*Binance) LimitBuy

func (bn *Binance) LimitBuy(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)

func (*Binance) LimitSell

func (bn *Binance) LimitSell(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)

func (*Binance) MarketBuy

func (bn *Binance) MarketBuy(amount, price string, currencyPair CurrencyPair) (*Order, error)

func (*Binance) MarketSell

func (bn *Binance) MarketSell(amount, price string, currencyPair CurrencyPair) (*Order, error)

func (*Binance) Ping added in v1.2.3

func (bn *Binance) Ping() bool

type BinanceSwap added in v1.2.3

type BinanceSwap struct {
	Binance
}

func NewBinanceSwap added in v1.2.3

func NewBinanceSwap(config *APIConfig) *BinanceSwap

func (*BinanceSwap) FutureCancelAllOrders added in v1.2.3

func (bs *BinanceSwap) FutureCancelAllOrders(currencyPair CurrencyPair, contractType string) (bool, error)

func (*BinanceSwap) FutureCancelOrder added in v1.2.3

func (bs *BinanceSwap) FutureCancelOrder(currencyPair CurrencyPair, contractType, orderId string) (bool, error)

*

  • 取消订单
  • @param symbol btc_usd:比特币 ltc_usd :莱特币
  • @param contractType 合约类型: this_week:当周 next_week:下周 month:当月 quarter:季度
  • @param orderId 订单ID

func (*BinanceSwap) FutureCancelOrders added in v1.2.3

func (bs *BinanceSwap) FutureCancelOrders(currencyPair CurrencyPair, contractType string, orderIdList []string) (bool, error)

func (*BinanceSwap) GetContractValue added in v1.2.3

func (bs *BinanceSwap) GetContractValue(currencyPair CurrencyPair) (float64, error)

*

*获取每张合约价值

func (*BinanceSwap) GetDeliveryTime added in v1.2.3

func (bs *BinanceSwap) GetDeliveryTime() (int, int, int, int)

*

*获取交割时间 星期(0,1,2,3,4,5,6),小时,分,秒

func (*BinanceSwap) GetExchangeName added in v1.2.3

func (bs *BinanceSwap) GetExchangeName() string

func (*BinanceSwap) GetFee added in v1.2.3

func (bs *BinanceSwap) GetFee() (float64, error)

*

*获取交易费

func (*BinanceSwap) GetFutureDepth added in v1.2.3

func (bs *BinanceSwap) GetFutureDepth(currency CurrencyPair, contractType string, size int) (*Depth, error)

func (*BinanceSwap) GetFutureEstimatedPrice added in v1.2.3

func (bs *BinanceSwap) GetFutureEstimatedPrice(currencyPair CurrencyPair) (float64, error)

*

*获取交割预估价

func (*BinanceSwap) GetFutureIndex added in v1.2.3

func (bs *BinanceSwap) GetFutureIndex(currencyPair CurrencyPair) (float64, error)

*

  • 期货指数
  • @param currencyPair btc_usd:比特币 ltc_usd :莱特币

func (*BinanceSwap) GetFutureOrder added in v1.2.3

func (bs *BinanceSwap) GetFutureOrder(orderId string, currencyPair CurrencyPair, contractType string) (*FutureOrder, error)

*

*获取单个订单信息

func (*BinanceSwap) GetFutureOrders added in v1.2.3

func (bs *BinanceSwap) GetFutureOrders(orderIds []string, currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

*

*获取订单信息

func (*BinanceSwap) GetFuturePosition added in v1.2.3

func (bs *BinanceSwap) GetFuturePosition(currencyPair CurrencyPair, contractType string) ([]FuturePosition, error)

*

  • 用户持仓查询
  • @param symbol btc_usd:比特币 ltc_usd :莱特币
  • @param contractType 合约类型: this_week:当周 next_week:下周 month:当月 quarter:季度
  • @return

func (*BinanceSwap) GetFutureTicker added in v1.2.3

func (bs *BinanceSwap) GetFutureTicker(currency CurrencyPair, contractType string) (*Ticker, error)

*

  • 期货行情
  • @param currency_pair btc_usd:比特币 ltc_usd :莱特币
  • @param contractType 合约类型: this_week:当周 next_week:下周 month:当月 quarter:季度

func (*BinanceSwap) GetFutureUserinfo added in v1.2.3

func (bs *BinanceSwap) GetFutureUserinfo(currencyPair ...CurrencyPair) (*FutureAccount, error)

*

*全仓账户

func (*BinanceSwap) GetKlineRecords added in v1.2.3

func (bs *BinanceSwap) GetKlineRecords(contractType string, currency CurrencyPair, period, size, since int) ([]FutureKline, error)

*

  • 获取K线数据

func (*BinanceSwap) GetServerTime added in v1.2.3

func (bs *BinanceSwap) GetServerTime() (int64, error)

func (*BinanceSwap) GetTrades added in v1.2.3

func (bs *BinanceSwap) GetTrades(contractType string, currencyPair CurrencyPair, since int64) ([]Trade, error)

func (*BinanceSwap) GetUnfinishFutureOrders added in v1.2.3

func (bs *BinanceSwap) GetUnfinishFutureOrders(currencyPair CurrencyPair, contractType string) ([]FutureOrder, error)

*

*获取未完成订单信息

func (*BinanceSwap) LimitFuturesOrder added in v1.2.3

func (bs *BinanceSwap) LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error)

func (*BinanceSwap) MarketFuturesOrder added in v1.2.3

func (bs *BinanceSwap) MarketFuturesOrder(currencyPair CurrencyPair, contractType, amount string, openType int) (*FutureOrder, error)

func (*BinanceSwap) Ping added in v1.2.3

func (bs *BinanceSwap) Ping() bool

func (*BinanceSwap) PlaceFutureOrder added in v1.2.3

func (bs *BinanceSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error)

func (*BinanceSwap) PlaceFutureOrder2 added in v1.2.3

func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (*FutureOrder, error)

*

  • @deprecated
  • 期货下单
  • @param currencyPair btc_usd:比特币 ltc_usd :莱特币
  • @param contractType 合约类型: this_week:当周 next_week:下周 month:当月 quarter:季度
  • @param price 价格
  • @param amount 委托数量
  • @param openType 1:开多 2:开空 3:平多 4:平空
  • @param matchPrice 是否为对手价 0:不是 1:是 ,当取值为1时,price无效

func (*BinanceSwap) SetBaseUri added in v1.2.3

func (bs *BinanceSwap) SetBaseUri(uri string)

func (*BinanceSwap) Transfer added in v1.2.3

func (bs *BinanceSwap) Transfer(currency Currency, transferType int, amount float64) (int64, error)

transferType - 1: 现货账户向合约账户划转 2: 合约账户向现货账户划转

type BinanceWs added in v1.0.3

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

func NewBinanceWs added in v1.0.3

func NewBinanceWs() *BinanceWs

func (*BinanceWs) Close added in v1.2.3

func (bnWs *BinanceWs) Close()

func (*BinanceWs) ProxyUrl added in v1.0.3

func (bnWs *BinanceWs) ProxyUrl(proxyUrl string)

func (*BinanceWs) SetBaseUrl added in v1.0.3

func (bnWs *BinanceWs) SetBaseUrl(baseURL string)

func (*BinanceWs) SetCallbacks added in v1.0.3

func (bnWs *BinanceWs) SetCallbacks(
	tickerCallback func(*Ticker),
	depthCallback func(*Depth),
	tradeCallback func(*Trade),
	klineCallback func(*Kline, int),
)

func (*BinanceWs) SetCombinedBaseURL added in v1.0.3

func (bnWs *BinanceWs) SetCombinedBaseURL(combinedBaseURL string)

func (*BinanceWs) Subscribe added in v1.2.3

func (bnWs *BinanceWs) Subscribe(endpoint string, handle func(msg []byte) error) *WsConn

func (*BinanceWs) SubscribeAggTrade added in v1.0.4

func (bnWs *BinanceWs) SubscribeAggTrade(pair CurrencyPair, tradeCallback func(*Trade)) error

func (*BinanceWs) SubscribeDepth added in v1.0.3

func (bnWs *BinanceWs) SubscribeDepth(pair CurrencyPair, size int) error

func (*BinanceWs) SubscribeDiffDepth added in v1.0.4

func (bnWs *BinanceWs) SubscribeDiffDepth(pair CurrencyPair, depthCallback func(*Depth)) error

func (*BinanceWs) SubscribeKline added in v1.0.3

func (bnWs *BinanceWs) SubscribeKline(pair CurrencyPair, period int) error

func (*BinanceWs) SubscribeTicker added in v1.0.3

func (bnWs *BinanceWs) SubscribeTicker(pair CurrencyPair) error

func (*BinanceWs) SubscribeTrade added in v1.0.3

func (bnWs *BinanceWs) SubscribeTrade(pair CurrencyPair) error

type DiffDepth added in v1.0.4

type DiffDepth struct {
	Depth
	UpdateID      int64 `json:"u"`
	FirstUpdateID int64 `json:"U"`
}

type ExchangeInfo added in v1.0.3

type ExchangeInfo struct {
	Timezone        string        `json:"timezone"`
	ServerTime      int           `json:"serverTime"`
	ExchangeFilters []interface{} `json:"exchangeFilters,omitempty"`
	RateLimits      []RateLimit   `json:"rateLimits"`
	Symbols         []TradeSymbol `json:"symbols"`
}

type Filter added in v1.0.3

type Filter struct {
	FilterType          string  `json:"filterType"`
	MaxPrice            float64 `json:"maxPrice,string"`
	MinPrice            float64 `json:"minPrice,string"`
	TickSize            float64 `json:"tickSize,string"`
	MultiplierUp        float64 `json:"multiplierUp,string"`
	MultiplierDown      float64 `json:"multiplierDown,string"`
	AvgPriceMins        int     `json:"avgPriceMins"`
	MinQty              float64 `json:"minQty,string"`
	MaxQty              float64 `json:"maxQty,string"`
	StepSize            float64 `json:"stepSize,string"`
	MinNotional         float64 `json:"minNotional,string"`
	ApplyToMarket       bool    `json:"applyToMarket"`
	Limit               int     `json:"limit"`
	MaxNumAlgoOrders    int     `json:"maxNumAlgoOrders"`
	MaxNumIcebergOrders int     `json:"maxNumIcebergOrders"`
	MaxNumOrders        int     `json:"maxNumOrders"`
}

type RateLimit added in v1.0.3

type RateLimit struct {
	Interval      string `json:"interval"`
	IntervalNum   int64  `json:"intervalNum"`
	Limit         int64  `json:"limit"`
	RateLimitType string `json:"rateLimitType"`
}

type RawTrade added in v1.0.4

type RawTrade struct {
	Trade
	BuyerOrderID  int64 `json:"b"`
	SellerOrderID int64 `json:"a"`
}

type TradeSymbol added in v1.0.3

type TradeSymbol struct {
	Symbol                     string   `json:"symbol"`
	Status                     string   `json:"status"`
	BaseAsset                  string   `json:"baseAsset"`
	BaseAssetPrecision         int      `json:"baseAssetPrecision"`
	QuoteAsset                 string   `json:"quoteAsset"`
	QuotePrecision             int      `json:"quotePrecision"`
	BaseCommissionPrecision    int      `json:"baseCommissionPrecision"`
	QuoteCommissionPrecision   int      `json:"quoteCommissionPrecision"`
	Filters                    []Filter `json:"filters"`
	IcebergAllowed             bool     `json:"icebergAllowed"`
	IsMarginTradingAllowed     bool     `json:"isMarginTradingAllowed"`
	IsSpotTradingAllowed       bool     `json:"isSpotTradingAllowed"`
	OcoAllowed                 bool     `json:"ocoAllowed"`
	QuoteOrderQtyMarketAllowed bool     `json:"quoteOrderQtyMarketAllowed"`
	OrderTypes                 []string `json:"orderTypes"`
}

func (TradeSymbol) GetAmountPrecision added in v1.2.3

func (ts TradeSymbol) GetAmountPrecision() int

func (TradeSymbol) GetMinAmount added in v1.2.3

func (ts TradeSymbol) GetMinAmount() float64

func (TradeSymbol) GetMinPrice added in v1.2.3

func (ts TradeSymbol) GetMinPrice() float64

func (TradeSymbol) GetMinValue added in v1.2.3

func (ts TradeSymbol) GetMinValue() float64

func (TradeSymbol) GetPricePrecision added in v1.2.3

func (ts TradeSymbol) GetPricePrecision() int

Jump to

Keyboard shortcuts

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