binance

package
v1.11.8 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TickerPriceURL 最新交易对价格列表路由
	TickerPriceURL = "/api/v3/ticker/price"

	// SpecificationURL 行情规范路由
	SpecificationURL = "/api/v3/exchangeInfo"

	// OrderURL 订单路由
	OrderURL = "/api/v3/order"

	// TestOrderURL 测试订单路由
	TestOrderURL = "/api/v3/order/test"
)
View Source
const BaseURL = "https://api.binance.com"

BaseURL 基础接口

View Source
const BroadcastMessageTypeTickerPrice = "TickerPrice"

Variables

View Source
var SpecificationInfo = &Info{}

SpecificationInfo 交易所规范信息

View Source
var SpecificationSymbolInfo = map[string]*InfoSymbol{}

SpecificationSymbolInfo 交易所交易对规范

Functions

func InitBroadcastService

func InitBroadcastService()

InitBroadcastService 初始化广播服务

func InitSpecification

func InitSpecification()

InitSpecification 初始化交易所规范

Types

type Broadcast

type Broadcast struct {
	Service *utils.Broadcast //	广播服务
	// contains filtered or unexported fields
}

Broadcast 广播

var BroadcastService *Broadcast

BroadcastService 广播服务

func (*Broadcast) TickerPrice

func (c *Broadcast) TickerPrice(second time.Duration)

TickerPrice 广播最新价格

type Exchange

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

Exchange 币安交易所

func NewExchange

func NewExchange() *Exchange

NewExchange 新建币安交易所模型

func (*Exchange) Buy

func (c *Exchange) Buy(p map[string]interface{}) (interfaces.Resp, error)

Buy 买入

func (*Exchange) Conf

func (c *Exchange) Conf(conf interfaces.Conf) interfaces.Exchange

Conf 配置交易所配置

func (*Exchange) MarketBuy

func (c *Exchange) MarketBuy(symbol string, quoteOrderQty float64) (interfaces.Resp, error)

MarketBuy 市价买入

func (*Exchange) MarketSell

func (c *Exchange) MarketSell(symbol string, quantity float64) (interfaces.Resp, error)

MarketSell 市价卖出

func (*Exchange) Sell

func (c *Exchange) Sell(p map[string]interface{}) (interfaces.Resp, error)

Sell 卖出

func (*Exchange) SpecificationInfo

func (c *Exchange) SpecificationInfo() (*Info, error)

SpecificationInfo 交易所规范信息

func (*Exchange) TestOrder

func (c *Exchange) TestOrder() interfaces.Exchange

TestOrder 测试订单

func (*Exchange) TickerPrice

func (c *Exchange) TickerPrice() (interfaces.Ticker, error)

TickerPrice 请求交易对最新价格列表

type ExchangeTicker

type ExchangeTicker struct {
	Symbol string `json:"symbol"` //	交易对
	Price  string `json:"price"`  //	最新价格
}

type Info

type Info struct {
	Timezone   string        `json:"timezone"`   //	时区
	ServerTime time.Duration `json:"serverTime"` //	服务器时间
	//	交易平台API使用的一些次数要求
	//	rateLimits有三种类型,别分是
	//		一分钟内请求权重之和的上限
	//		每秒钟交易次数的上限
	//		每天交易次数的上限
	RateLimits []*InfoRateLimits `json:"rateLimits"`
	Symbols    []*InfoSymbol     `json:"symbols"`
}

type InfoRateLimits

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

InfoRateLimits api 要求

type InfoSymbol

type InfoSymbol struct {
	Symbol                     string                            `json:"symbol"`                     //	交易对
	Status                     string                            `json:"status"`                     //	状态,trading应该表示可交易
	BaseAsset                  string                            `json:"baseAsset"`                  //
	BaseAssetPrecision         int                               `json:"baseAssetPrecision"`         //	资产精确的小数点位数,这里是8位
	QuoteAsset                 string                            `json:"quoteAsset"`                 //
	QuotePrecision             int                               `json:"quotePrecision"`             //
	QuoteAssetPrecision        int                               `json:"quoteAssetPrecision"`        //	同理
	BaseCommissionPrecision    int                               `json:"baseCommissionPrecision"`    //
	QuoteCommissionPrecision   int                               `json:"quoteCommissionPrecision"`   //
	OrderTypes                 []string                          `json:"orderTypes"`                 //	交易的类别有哪些
	IcebergAllowed             bool                              `json:"icebergAllowed"`             //	是否允许——冰山订单
	OcoAllowed                 bool                              `json:"ocoAllowed"`                 //	是否允许——OCO订单
	QuoteOrderQtyMarketAllowed bool                              `json:"quoteOrderQtyMarketAllowed"` //
	IsSpotTradingAllowed       bool                              `json:"isSpotTradingAllowed"`       //	是否允许——现货交易订单
	IsMarginTradingAllowed     bool                              `json:"isMarginTradingAllowed"`     //	是否允许——保证金交易订单
	Filters                    []map[string]interface{}          `json:"filters"`                    //	筛选器,订单不满足这些筛选器的要求是无法进行交易的
	FiltersMap                 map[string]map[string]interface{} `json:"filtersMap"`                 //	筛选器,处理之后的
}

InfoSymbol 交易对

type Resp

type Resp struct {
	Symbol             string        `json:"symbol"`              //	交易对
	OrderId            int64         `json:"orderId"`             //	订单ID
	OrderListId        int64         `json:"orderListId"`         //	OCO订单的ID,不然就是-1
	ClientOrderId      string        `json:"clientOrderId"`       //	客户自己设置的ID
	TransactTime       time.Duration `json:"transactTime"`        //	交易的时间戳
	Price              string        `json:"price"`               //	订单价格
	OrigQty            string        `json:"origQty"`             //	用户设置的原始订单数量
	ExecutedQty        string        `json:"executedQty"`         //	交易的订单数量
	CumulativeQuoteQty string        `json:"cummulativeQuoteQty"` //	累计交易的金额
	Status             string        `json:"status"`              //	订单状态
	TimeInForce        string        `json:"timeInForce"`         //	订单的时效方式
	Type               string        `json:"type"`                //	订单类型, 比如市价单,现价单等
	Side               string        `json:"side"`                //	订单方向,买还是卖
	Fills              []*RespFills  `json:"fills"`               //	订单中交易的信息
}

func (*Resp) GetCumulativeQty

func (c *Resp) GetCumulativeQty() float64

GetCumulativeQty 获取累计交易的金额

func (*Resp) GetExecutedQty

func (c *Resp) GetExecutedQty() float64

GetExecutedQty 获取执行的数量

func (*Resp) GetFeeQty

func (c *Resp) GetFeeQty() (float64, string)

GetFeeQty 获取手续费的数量

func (*Resp) GetPrice

func (c *Resp) GetPrice() float64

GetPrice 获取价格

type RespFills

type RespFills struct {
	Price           string `json:"price"`           //	交易的价格
	Qty             string `json:"qty"`             //	交易的数量
	Commission      string `json:"commission"`      //	手续费金额
	CommissionAsset string `json:"commissionAsset"` //	手续费的币种
}

RespFills 订单中的交易信息

type Ticker

type Ticker struct {
	TickerList []*ExchangeTicker
	TickerMap  map[string]float64
}

func NewTicker

func NewTicker() *Ticker

func (*Ticker) SymbolPrice

func (c *Ticker) SymbolPrice(symbol string) float64

SymbolPrice 交易对最新的价格

func (*Ticker) SymbolPriceMap

func (c *Ticker) SymbolPriceMap() map[string]float64

SymbolPriceMap 交易对列表最新价格

func (*Ticker) TickerListToTickerMap

func (c *Ticker) TickerListToTickerMap() map[string]float64

TickerListToTickerMap 最新价格数组转最新价格Map

Jump to

Keyboard shortcuts

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