Documentation
¶
Index ¶
- Constants
- func GenerateSignature(secretKey, data string) string
- func Timestamp() int64
- type APIError
- type Client
- func (c *Client) Borrow(ctx context.Context, asset string, amount float64, isIsolated bool, ...) (int64, error)
- func (c *Client) CancelOrder(ctx context.Context, symbol string, orderID int64, origClientOrderID string, ...) (*MarginOrder, error)
- func (c *Client) Delete(ctx context.Context, endpoint string, params map[string]interface{}, ...) error
- func (c *Client) Get(ctx context.Context, endpoint string, params map[string]interface{}, ...) error
- func (c *Client) GetAccount(ctx context.Context) (*MarginAccount, error)
- func (c *Client) GetIsolatedAccount(ctx context.Context, symbols string) (*IsolatedMarginAccount, error)
- func (c *Client) GetOrder(ctx context.Context, symbol string, orderID int64, origClientOrderID string, ...) (*MarginOrder, error)
- func (c *Client) PlaceOrder(ctx context.Context, params *PlaceOrderParams) (*OrderResponseFull, error)
- func (c *Client) Post(ctx context.Context, endpoint string, params map[string]interface{}, ...) error
- func (c *Client) Repay(ctx context.Context, asset string, amount float64, isIsolated bool, ...) (int64, error)
- func (c *Client) WithBaseURL(url string) *Client
- func (c *Client) WithCredentials(apiKey, secretKey string) *Client
- type IsolatedMarginAccount
- type IsolatedMarginAsset
- type IsolatedMarginSymbol
- type MarginAccount
- type MarginOrder
- type OrderResponseFull
- type PlaceOrderParams
- type TransactionResult
- type UserAsset
Constants ¶
const (
BaseURL = "https://api.binance.com"
)
Variables ¶
This section is empty.
Functions ¶
func GenerateSignature ¶
GenerateSignature generates an HMAC SHA256 signature
Types ¶
type Client ¶
type Client struct {
BaseURL string
APIKey string
SecretKey string
HTTPClient *http.Client
Logger *zap.SugaredLogger
}
func (*Client) Borrow ¶
func (c *Client) Borrow(ctx context.Context, asset string, amount float64, isIsolated bool, symbol string) (int64, error)
Borrow borrows an asset from the margin account Endpoint: POST /sapi/v1/margin/loan isIsolated: "TRUE" or "FALSE" (default "FALSE" if empty) symbol: mandatory if isIsolated is "TRUE"
func (*Client) CancelOrder ¶
func (c *Client) CancelOrder(ctx context.Context, symbol string, orderID int64, origClientOrderID string, isIsolated bool) (*MarginOrder, error)
CancelOrder excels a margin order Endpoint: DELETE /sapi/v1/margin/order
func (*Client) GetAccount ¶
func (c *Client) GetAccount(ctx context.Context) (*MarginAccount, error)
GetAccount queries the cross margin account details Endpoint: GET /sapi/v1/margin/account
func (*Client) GetIsolatedAccount ¶
func (c *Client) GetIsolatedAccount(ctx context.Context, symbols string) (*IsolatedMarginAccount, error)
GetIsolatedAccount queries the isolated margin account details Endpoint: GET /sapi/v1/margin/isolated/account symbols: Optional, max 5 symbols, comma separated (e.g. "BTCUSDT,ETHUSDT")
func (*Client) GetOrder ¶
func (c *Client) GetOrder(ctx context.Context, symbol string, orderID int64, origClientOrderID string, isIsolated bool) (*MarginOrder, error)
GetOrder queries a margin order Endpoint: GET /sapi/v1/margin/order
func (*Client) PlaceOrder ¶
func (c *Client) PlaceOrder(ctx context.Context, params *PlaceOrderParams) (*OrderResponseFull, error)
PlaceOrder places a margin order Endpoint: POST /sapi/v1/margin/order
func (*Client) Repay ¶
func (c *Client) Repay(ctx context.Context, asset string, amount float64, isIsolated bool, symbol string) (int64, error)
Repay repays a loan for the margin account Endpoint: POST /sapi/v1/margin/repay isIsolated: "TRUE" or "FALSE" (default "FALSE" if empty) symbol: mandatory if isIsolated is "TRUE"
func (*Client) WithBaseURL ¶
func (*Client) WithCredentials ¶
type IsolatedMarginAccount ¶
type IsolatedMarginAccount struct {
Assets []IsolatedMarginSymbol `json:"assets"`
TotalAssetOfBtc string `json:"totalAssetOfBtc"`
TotalLiabilityOfBtc string `json:"totalLiabilityOfBtc"`
TotalNetAssetOfBtc string `json:"totalNetAssetOfBtc"`
}
type IsolatedMarginAsset ¶
type IsolatedMarginAsset struct {
Asset string `json:"asset"`
BorrowEnabled bool `json:"borrowEnabled"`
Borrowed string `json:"borrowed"`
Free string `json:"free"`
Interest string `json:"interest"`
Locked string `json:"locked"`
NetAsset string `json:"netAsset"`
NetAssetOfBtc string `json:"netAssetOfBtc"`
RepayEnabled bool `json:"repayEnabled"`
TotalAsset string `json:"totalAsset"`
}
type IsolatedMarginSymbol ¶
type IsolatedMarginSymbol struct {
BaseAsset IsolatedMarginAsset `json:"baseAsset"`
QuoteAsset IsolatedMarginAsset `json:"quoteAsset"`
Symbol string `json:"symbol"`
IsolatedCreated bool `json:"isolatedCreated"`
Enabled bool `json:"enabled"`
MarginLevel string `json:"marginLevel"`
MarginLevelStatus string `json:"marginLevelStatus"`
MarginRatio string `json:"marginRatio"`
IndexPrice string `json:"indexPrice"`
LiquidatePrice string `json:"liquidatePrice"`
LiquidateRate string `json:"liquidateRate"`
TradeEnabled bool `json:"tradeEnabled"`
}
type MarginAccount ¶
type MarginAccount struct {
BorrowEnabled bool `json:"borrowEnabled"`
MarginLevel string `json:"marginLevel"`
TotalAssetOfBtc string `json:"totalAssetOfBtc"`
TotalLiabilityOfBtc string `json:"totalLiabilityOfBtc"`
TotalNetAssetOfBtc string `json:"totalNetAssetOfBtc"`
TradeEnabled bool `json:"tradeEnabled"`
TransferEnabled bool `json:"transferEnabled"`
UserAssets []UserAsset `json:"userAssets"`
}
MarginAccount represents the response from /sapi/v1/margin/account
type MarginOrder ¶
type MarginOrder 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"`
Type string `json:"type"`
Side string `json:"side"`
IsIsolated bool `json:"isIsolated"`
}
MarginOrder represents the response from order placement
type OrderResponseFull ¶
type OrderResponseFull struct {
MarginOrder
Fills []struct {
Price string `json:"price"`
Qty string `json:"qty"`
Commission string `json:"commission"`
CommissionAsset string `json:"commissionAsset"`
} `json:"fills"`
}
type PlaceOrderParams ¶
type TransactionResult ¶
type TransactionResult struct {
TranId int64 `json:"tranId"`
}
TransactionResult represents the response for Borrow/Repay