spot_lever

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseURL = "https://api.binance.com"
	TestURL = ""
	Name    = "spot_lever"
	Version = "v1.0.0"
)
View Source
const (
	LIMIT             orderTypeEnum = "LIMIT"             // 限价单
	MARKET            orderTypeEnum = "MARKET"            // 市价单
	STOP_LOSS         orderTypeEnum = "STOP_LOSS"         // 止损单
	STOP_LOSS_LIMIT   orderTypeEnum = "STOP_LOSS_LIMIT"   // 限价止损单
	TAKE_PROFIT       orderTypeEnum = "TAKE_PROFIT"       // 止盈单
	TAKE_PROFIT_LIMIT orderTypeEnum = "TAKE_PROFIT_LIMIT" // 限价止盈单
	LIMIT_MAKER       orderTypeEnum = "LIMIT_MAKER"       // 限价只挂单
)
View Source
const (
	BUY  sideTypeEnum = "BUY"
	SELL sideTypeEnum = "SELL"
)
View Source
const (
	GTC timeInForceEnum = "GTC" // 成交为止 - 订单会一直有效,直到被成交或者取消
	IOC timeInForceEnum = "IOC" // 无法立即成交的部分就撤销 - 订单在失效前会尽量多的成交。
	FOK timeInForceEnum = "FOK" // 无法全部立即成交就撤销 - 如果无法全部成交,订单会失效。
)
View Source
const (
	ACK    newOrderRespTypeEnum = "ACK"
	RESULT newOrderRespTypeEnum = "RESULT"
	FULL   newOrderRespTypeEnum = "FULL"
)
View Source
const (
	NO_SIDE_EFFECT    sideEffectTypeEnum = "NO_SIDE_EFFECT"    // (普通模式): 直接使用槓桿賬戶內的現有數字資產下買/賣單。這種模式下,用戶需要在槓桿平台上手動借款/還款,或通過 POST /sapi/v1/margin/borrow-repay 借款/還款。
	MARGIN_BUY        sideEffectTypeEnum = "MARGIN_BUY"        // (自動借款模式):根據用戶的最大槓桿倍數,自動借入數字資產下買/賣單。簡而言之,相當於「借款 + 下單」。注意:下單成功即完成借款,借款與訂單成交沒有關係。
	AUTO_REPAY        sideEffectTypeEnum = "AUTO_REPAY"        // (自動還款模式):買/賣單成交後,系統自動使用收到的數字資產來償還該資產的負債。簡而言之,相當於「下單 + 訂單成交 + 還款」。還款依然遵循借什麼還什麼,先還利息再還本金的原則。自動還款模式不適用於介面“/sapi/v1/margin/order/otoco” 和 “/sapi/v1/margin/order/oto”。
	AUTO_BORROW_REPAY sideEffectTypeEnum = "AUTO_BORROW_REPAY" // (同時自動借款和還款):用户在下單時,結合MARGIN_BUY 和 AUTO_REPAY兩種模式,完成「借款 + 下單 + 訂單成交 + 還款」。
)
View Source
const (
	BORROW brTypeEnum = "BORROW" // 借
	REPAY  brTypeEnum = "REPAY"  // 还
)
View Source
const (
	UserNone   securityType = iota // 不需要鉴权的接口
	UserTrade                      // 需要有效的 API-KEY 和 签名
	UserData                       // 需要有效的 API-KEY 和 签名
	UserStream                     // 需要有效的 API-KEY
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BalanceResponse

type BalanceResponse struct {
	Created                    bool        `json:"created"` // true 表示已开户 false 表示未开户
	BorrowEnabled              bool        `json:"borrowEnabled"`
	MarginLevel                string      `json:"marginLevel"`
	CollateralMarginLevel      string      `json:"collateralMarginLevel"`
	TotalAssetOfBtc            string      `json:"totalAssetOfBtc"`
	TotalLiabilityOfBtc        string      `json:"totalLiabilityOfBtc"`
	TotalNetAssetOfBtc         string      `json:"totalNetAssetOfBtc"`
	TotalCollateralValueInUSDT string      `json:"TotalCollateralValueInUSDT"`
	TotalOpenOrderLossInUSDT   string      `json:"totalOpenOrderLossInUSDT"`
	TradeEnabled               bool        `json:"tradeEnabled"`
	TransferInEnabled          bool        `json:"transferInEnabled"`
	TransferOutEnabled         bool        `json:"transferOutEnabled"`
	AccountType                string      `json:"accountType"` // MARGIN_1 全仓Classic模式账户 MARGIN_2 全仓Pro模式账户
	UserAssets                 []UserAsset `json:"userAssets"`
}

type BalanceService

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

============================================== // 全仓杠杆账户详情 ============================================== //

func (*BalanceService) Do

func (s *BalanceService) Do(ctx context.Context, opts ...RequestOption) (resp *BalanceResponse, err error)

type BorrowRepayList

type BorrowRepayList struct {
	Type           string `json:"type"`           // 全仓借贷可返回:AUTO,MANUAL ; 全仓还款可返回:MANUAL,AUTO,BNB_AUTO_REPAY,POINT_AUTO_REPAY; 逐仓借贷或还款可返回:AUTO,MANUAL
	IsolatedSymbol string `json:"isolatedSymbol"` // 逐仓还款 返回逐仓symbol; 若是全仓不会返回此字段
	Amount         string `json:"amount"`         // 还款总额
	Asset          string `json:"asset"`          //
	Interest       string `json:"interest"`       // 支付的利息
	Principal      string `json:"principal"`      // 支付的本金
	Status         string `json:"status"`         // 状态: PENDING (等待执行), CONFIRMED (成功还款), FAILED (执行失败);
	Timestamp      int64  `json:"timestamp"`
	TxId           int64  `json:"txId"`
}

type BorrowRepayListResponse

type BorrowRepayListResponse struct {
	Rows  []BorrowRepayList `json:"rows"`
	Total int64             `json:"total"`
}

============================================== // 查询借贷/还款记录 ============================================== //

type BorrowRepayListService

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

func (*BorrowRepayListService) Asset

func (*BorrowRepayListService) Current

func (*BorrowRepayListService) Do

func (*BorrowRepayListService) EndTime

func (*BorrowRepayListService) IsolatedSymbol

func (s *BorrowRepayListService) IsolatedSymbol(isolatedSymbol string) *BorrowRepayListService

func (*BorrowRepayListService) Side

func (*BorrowRepayListService) StartTime

func (s *BorrowRepayListService) StartTime(startTime int64) *BorrowRepayListService

func (*BorrowRepayListService) TxId

func (*BorrowRepayListService) Type

type BorrowRepayResponse

type BorrowRepayResponse struct {
	TranId int64 `json:"tranId"`
}

============================================== // 杠杆账户借贷/还款 ============================================== //

type BorrowRepayService

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

func (*BorrowRepayService) Amount

func (s *BorrowRepayService) Amount(amount string) *BorrowRepayService

func (*BorrowRepayService) Asset

func (s *BorrowRepayService) Asset(asset string) *BorrowRepayService

func (*BorrowRepayService) Do

func (s *BorrowRepayService) Do(ctx context.Context, opts ...RequestOption) (resp *BorrowRepayResponse, err error)

func (*BorrowRepayService) IsIsolated

func (s *BorrowRepayService) IsIsolated(isIsolated string) *BorrowRepayService

func (*BorrowRepayService) Stype

func (s *BorrowRepayService) Stype(stype string) *BorrowRepayService

func (*BorrowRepayService) Symbol

func (s *BorrowRepayService) Symbol(symbol string) *BorrowRepayService

type CancelResponse

type CancelResponse struct {
	Symbol              string `json:"symbol"`
	OrderId             int64  `json:"orderId"`
	OrigClientOrderId   string `json:"origClientOrderId"`
	ClientOrderId       string `json:"clientOrderId"`
	Price               string `json:"price"`
	OrigQty             string `json:"origQty"`
	ExecutedQty         string `json:"executedQty"`
	CummulativeQuoteQty string `json:"cummulativeQuoteQty"`
	Status              string `json:"status"`
	TimeInForce         string `json:"timeInForce"`
	Type                string `json:"type"`
	Side                string `json:"side"`
	IsIsolated          bool   `json:"isIsolated"` // 是否是逐仓symbol交易
}

============================================== // 杠杆账户撤销订单 10(UID) ============================================== //

type CancelService

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

func (*CancelService) Do

func (s *CancelService) Do(ctx context.Context, opts ...RequestOption) (resp *CancelResponse, err error)

func (*CancelService) IsIsolated

func (s *CancelService) IsIsolated(isIsolated string) *CancelService

func (*CancelService) NewClientOrderId

func (s *CancelService) NewClientOrderId(newClientOrderId string) *CancelService

func (*CancelService) OrderId

func (s *CancelService) OrderId(orderId int64) *CancelService

func (*CancelService) OrigClientOrderId

func (s *CancelService) OrigClientOrderId(origClientOrderId string) *CancelService

func (*CancelService) Symbol

func (s *CancelService) Symbol(symbol string) *CancelService

type ChildFill

type ChildFill struct {
	Price           string `json:"price"`
	Qty             string `json:"qty"`
	Commission      string `json:"commission"`
	CommissionAsset string `json:"commissionAsset"`
	TradeId         int64  `json:"tradeId"`
}

type Client

type Client struct {
	APIKey     string
	SecretKey  string
	BaseURL    string
	HTTPClient *http.Client
	Debug      bool
	Logger     *log.Logger
	TimeOffset int64
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey, secretKey, baseURL string) *Client

func (*Client) NewBalanceService

func (c *Client) NewBalanceService() *BalanceService

全仓杠杆账户详情

func (*Client) NewCancelService

func (c *Client) NewCancelService() *CancelService

杠杆账户撤销订单 10(UID)

func (*Client) NewMaxLeverageService

func (c *Client) NewMaxLeverageService() *MaxLeverageService

调整全仓最大杠杆

func (*Client) NewOpenOrderService

func (c *Client) NewOpenOrderService() *OpenOrderService

查询当前挂单

func (*Client) NewOrderService

func (c *Client) NewOrderService() *OrderService

查询订单

func (*Client) NewTradeService

func (c *Client) NewTradeService() *TradeService

杠杆账户下单 6(UID)

type LeverageResponse

type LeverageResponse struct {
}

============================================== // 调整全仓最大杠杆 ============================================== //

type MaxBorrorwableResponse

type MaxBorrorwableResponse struct {
	Amount      string `json:"amount"`
	BorrowLimit string `json:"borrowLimit"`
}

============================================== // 账户最大可借贷额度 ============================================== //

type MaxBorrorwableService

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

func (*MaxBorrorwableService) Asset

func (*MaxBorrorwableService) Do

func (*MaxBorrorwableService) IsolatedSymbol

func (s *MaxBorrorwableService) IsolatedSymbol(isolatedSymbol string) *MaxBorrorwableService

type MaxLeverageService

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

func (*MaxLeverageService) Do

func (*MaxLeverageService) MaxLeverage

func (s *MaxLeverageService) MaxLeverage(leverage int64) *MaxLeverageService

type NextHourInterestRateResponse

type NextHourInterestRateResponse struct {
	Asset                  string `json:"asset"`
	NextHourlyInterestRate string `json:"nextHourlyInterestRate"`
}

============================================== // 查询下小时预估利率 ============================================== //

type NextHourInterestRateService

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

func (*NextHourInterestRateService) Assets

func (*NextHourInterestRateService) Do

func (*NextHourInterestRateService) IsIsolated

type OpenOrderResponse

type OpenOrderResponse struct {
	ClientOrderId           string `json:"clientOrderId"`
	CummulativeQuoteQty     string `json:"cummulativeQuoteQty"`
	ExecutedQty             string `json:"executedQty"`
	IcebergQty              string `json:"icebergQty"`
	IsWorking               bool   `json:"isWorking"`
	OrderId                 int64  `json:"orderId"`
	OrigQty                 string `json:"origQty"`
	Price                   string `json:"price"`
	Side                    string `json:"side"`
	Status                  string `json:"status"`
	StopPrice               string `json:"stopPrice"`
	Symbol                  string `json:"symbol"`
	IsIsolated              bool   `json:"isIsolated"` // 是否是逐仓symbol交易
	Time                    int64  `json:"time"`
	TimeInForce             string `json:"timeInForce"`
	Type                    string `json:"type"`
	SelfTradePreventionMode string `json:"selfTradePreventionMode"`
	UpdateTime              int64  `json:"updateTime"`
}

============================================== // 查询杠杆账户挂单记录 ============================================== //

type OpenOrderService

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

func (*OpenOrderService) Do

func (s *OpenOrderService) Do(ctx context.Context, opts ...RequestOption) (resp []*OpenOrderResponse, err error)

func (*OpenOrderService) IsIsolated

func (s *OpenOrderService) IsIsolated(isIsolated string) *OpenOrderService

func (*OpenOrderService) Symbol

func (s *OpenOrderService) Symbol(symbol string) *OpenOrderService

type OrderResponse

type OrderResponse struct {
	ClientOrderId           string `json:"clientOrderId"`
	CummulativeQuoteQty     string `json:"cummulativeQuoteQty"`
	ExecutedQty             string `json:"executedQty"`
	IcebergQty              string `json:"icebergQty"`
	IsWorking               bool   `json:"isWorking"`
	OrderId                 int64  `json:"orderId"`
	OrigQty                 string `json:"origQty"`
	Price                   string `json:"price"`
	Side                    string `json:"side"`
	Status                  string `json:"status"`
	StopPrice               string `json:"stopPrice"`
	Symbol                  string `json:"symbol"`
	IsIsolated              bool   `json:"isIsolated"`
	Time                    int64  `json:"time"`
	TimeInForce             string `json:"timeInForce"`
	Type                    string `json:"type"`
	SelfTradePreventionMode string `json:"selfTradePreventionMode"`
	UpdateTime              int64  `json:"updateTime"`
}

============================================== // 查询杠杆账户订单 ============================================== //

type OrderService

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

func (*OrderService) Do

func (s *OrderService) Do(ctx context.Context, opts ...RequestOption) (resp *OrderResponse, err error)

func (*OrderService) IsIsolated

func (s *OrderService) IsIsolated(isIsolated string) *OrderService

func (*OrderService) OrderId

func (s *OrderService) OrderId(orderId int64) *OrderService

func (*OrderService) OrigClientOrderId

func (s *OrderService) OrigClientOrderId(origClientOrderId string) *OrderService

func (*OrderService) Symbol

func (s *OrderService) Symbol(symbol string) *OrderService

type RequestOption

type RequestOption func(*request)

func WithRecvWindow

func WithRecvWindow(recvWindow int64) RequestOption

type TradeResponse

type TradeResponse struct {
	Symbol                  string      `json:"symbol"`
	OrderId                 int64       `json:"orderId"`
	ClientOrderId           string      `json:"clientOrderId"`
	TransactTime            int64       `json:"transactTime"`
	Price                   string      `json:"price"`
	OrigQty                 string      `json:"origQty"`
	ExecutedQty             string      `json:"executedQty"`
	CummulativeQuoteQty     string      `json:"cummulativeQuoteQty"`
	Status                  string      `json:"status"`
	TimeInForce             string      `json:"timeInForce"`
	Stype                   string      `json:"type"`
	Side                    string      `json:"side"`
	MarginBuyBorrowAmount   float64     `json:"marginBuyBorrowAmount"` // 下单后没有发生借款则不返回该字段
	MarginBuyBorrowAsset    string      `json:"marginBuyBorrowAsset"`  // 下单后没有发生借款则不返回该字段
	Fills                   []ChildFill `json:"fills"`
	IsIsolated              bool        `json:"isIsolated"`
	SelfTradePreventionMode string      `json:"selfTradePreventionMode"`
}

============================================== // 杠杆账户下单 6(UID) ============================================== //

type TradeService

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

func (*TradeService) AutoRepayAtCancel

func (s *TradeService) AutoRepayAtCancel(autoRepayAtCancel bool) *TradeService

func (*TradeService) Do

func (s *TradeService) Do(ctx context.Context, opts ...RequestOption) (resp *TradeResponse, err error)

func (*TradeService) IcebergQty

func (s *TradeService) IcebergQty(icebergQty float64) *TradeService

func (*TradeService) IsIsolated

func (s *TradeService) IsIsolated(isIsolated string) *TradeService

func (*TradeService) NewClientOrderId

func (s *TradeService) NewClientOrderId(newClientOrderId string) *TradeService

func (*TradeService) NwOrderRespType

func (s *TradeService) NwOrderRespType(newOrderRespType newOrderRespTypeEnum) *TradeService

func (*TradeService) Price

func (s *TradeService) Price(price float64) *TradeService

func (*TradeService) Quantity

func (s *TradeService) Quantity(quantity float64) *TradeService

func (*TradeService) QuoteOrderQty

func (s *TradeService) QuoteOrderQty(quoteOrderQty float64) *TradeService

func (*TradeService) SelfTradePreventionMode

func (s *TradeService) SelfTradePreventionMode(selfTradePreventionMode string) *TradeService

func (*TradeService) Side

func (s *TradeService) Side(side sideTypeEnum) *TradeService

func (*TradeService) SideEffectType

func (s *TradeService) SideEffectType(sideEffectType sideEffectTypeEnum) *TradeService

func (*TradeService) StopPrice

func (s *TradeService) StopPrice(stopPrice float64) *TradeService

func (*TradeService) Stype

func (s *TradeService) Stype(stype orderTypeEnum) *TradeService

func (*TradeService) Symbol

func (s *TradeService) Symbol(symbol string) *TradeService

func (*TradeService) TimeInForce

func (s *TradeService) TimeInForce(timeInForce timeInForceEnum) *TradeService

type UserAsset

type UserAsset struct {
	Asset    string `json:"asset"`
	Borrowed string `json:"borrowed"`
	Free     string `json:"free"` // 余额
	Interest string `json:"interest"`
	Locked   string `json:"locked"`
	NetAsset string `json:"netAsset"` // 仓位
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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