bitmart

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 22 Imported by: 0

README

Logo

BitMart-Go-SDK-API

go.dev reference Go version Telegram

BitMart Exchange official Go client for the BitMart Cloud API.

Feature

  • Provides exchange quick trading API
  • Easier withdrawal
  • Efficiency, higher speeds, and lower latencies
  • Priority in development and maintenance
  • Dedicated and responsive technical support
  • Supported APIs:
    • /spot/*
    • /contract/*
    • /account/*
  • Supported websockets:
    • Spot WebSocket Market Stream
    • Spot User Data Stream
    • futures User Data Stream
    • futures WebSocket Market Stream
  • Test cases and examples

Installation

go get -u github.com/bitmartexchange/bitmart-go-sdk-api

To reference the package in your code, use the following import statement:

import (
    "github.com/bitmartexchange/bitmart-go-sdk-api"
)

Documentation

API Documentation

Example

Spot Market Endpoints Example
package main

import (
  "github.com/bitmartexchange/bitmart-go-sdk-api"
  "log"
)

func main() {
  client := bitmart.NewClient(bitmart.Config{})

  // Get List of Trading Pairs
  var ac, _ = client.GetSpotSymbol()
  log.Println(ac.Response)
  
  // Get Ticker of a Trading Pair (V3)
  ac, _ = client.GetSpotV3Ticker("BTC_USDT")
  log.Println(ac.Response)
  
  // Get Ticker of All Pairs (V3)
  ac, _ = client.GetSpotV3Tickers()
  log.Println(ac.Response)
  
  // Get Depth (V3)
  ac, _ = client.GetSpotV3Book("BTC_USDT")
  log.Println(ac.Response)

}
Spot / Margin Trading Endpoints Example

package main

import (
	"github.com/bitmartexchange/bitmart-go-sdk-api"
	"log"
)

func main() {

	var yourApiKey = "Your API KEY"
	var yourSecretKey = "Your Secret KEY"
	var yourMemo = "Your Memo"

	client := bitmart.NewClient(bitmart.Config{
		ApiKey:        yourApiKey,
		SecretKey:     yourSecretKey,
		Memo:          yourMemo,
		TimeoutSecond: 5,
	})

	// New Order(v2) (SIGNED)
	var ac, err = client.PostSpotSubmitOrder(bitmart.Order{
		Symbol:        "BTC_USDT",
		Side:          "buy",
		Type:          "limit",
		ClientOrderId: "",
		Size:          "0.1",
		Price:         "8800",
		Notional:      "",
	})

	if err != nil {
		log.Panic(err)
	} else {
		log.Println(ac.Response)
	}

}



Please find examples/spot folder to check for more endpoints.


Spot Websocket Endpoints : Subscribe Public Channel
package main

import (
  "fmt"
  "github.com/bitmartexchange/bitmart-go-sdk-api"
  "os"
  "sync"
)

func Callback(message string) {
  fmt.Println("------------------------>" + message)
}

func main() {
  var wg sync.WaitGroup
  wg.Add(1)

  ws := bitmart.NewSpotWSClient(bitmart.Config{
    WsUrl:        bitmart.SPOT_WS_URL,
  }, Callback)

  // Ticker
  ws.Send(`{"op": "subscribe", "args": ["spot/ticker:BTC_USDT"]}`)

  // Kline
  ws.Send(`{"op": "subscribe", "args": ["spot/kline1m:BTC_USDT"]}`)

  // Trade
  ws.Send(`{"op": "subscribe", "args": ["spot/trade:BTC_USDT"]}`)

  // Depth
  ws.Send(`{"op": "subscribe", "args": ["spot/depth5:BTC_USDT"]}`)

  // Just test, Please do not use in production.
  wg.Wait()
}

Spot Websocket Endpoints : Subscribe Private Channel
package main

import (
  "fmt"
  "github.com/bitmartexchange/bitmart-go-sdk-api"
  "sync"
)

func Callback(message string) {
  fmt.Println("------------------------>" + message)
}

func main() {
  var wg sync.WaitGroup
  wg.Add(1)

  var yourApiKey = "Your API KEY"
  var yourSecretKey = "Your Secret KEY"
  var yourMemo = "Your Memo"

  ws := bitmart.NewSpotWSClient(bitmart.Config{
    WsUrl:     bitmart.SPOT_WS_USER,
    ApiKey:    yourApiKey,
    SecretKey: yourSecretKey,
    Memo:      yourMemo,
  }, Callback)

  // login
  ws.Login()

  // 【Private】Balance Change
  ws.Send(`{"op": "subscribe", "args": ["spot/user/balance:BALANCE_UPDATE"]}`)

  // Just test, Please do not use in production.
  wg.Wait()

}

Please find examples/spot/websocket folder to check for more endpoints.


Futures Market Endpoints
package main

import (
	"github.com/bitmartexchange/bitmart-go-sdk-api"
    "log"
)

func main() {
	client := bitmart.NewClient(bitmart.Config{
      Url: bitmart.API_URL_V2_PRO,
    })

	// Get Contract Details
    var ac, _ = client.GetContractDetails("BTCUSDT")
    log.Println(ac.Response)
    // Get Current Funding Rate
    ac, _ = client.GetContractFundingRate("BTCUSDT")
	log.Println(ac.Response)
    
    // Get Futures Open Interest
    ac, _ = client.GetContractOpenInterest("BTCUSDT")
    log.Println(ac.Response)
  
    // Get Market Depth
    ac, _ = client.GetContractDepth("BTCUSDT")
    log.Println(ac.Response)
}

Futures Trading Endpoints

package main

import (
	"github.com/bitmartexchange/bitmart-go-sdk-api"
	"log"
)

func main() {

	var yourApiKey = "Your API KEY"
	var yourSecretKey = "Your Secret KEY"
	var yourMemo = "Your Memo"

	client := bitmart.NewClient(bitmart.Config{
        Url:           bitmart.API_URL_V2_PRO,
		ApiKey:        yourApiKey,
		SecretKey:     yourSecretKey,
		Memo:          yourMemo,
		TimeoutSecond: 5,
	})

	// Submit Order (SIGNED)
	var ac, err = client.PostContractSubmitOrder(bitmart.ContractOrder{
		Symbol:   "ETHUSDT",
		Side:     4,
		Type:     "limit",
		Leverage: "1",
		OpenType: "isolated",
		Size:     10,
		Price:    "2000",
	})

	if err != nil {
		log.Panic(err)
	} else {
		log.Println(ac.Response)
	}

}


Please find examples/futures folder to check for more endpoints.


Futures Websocket Endpoints : Subscribe Public Channel
package main

import (
  "fmt"
  "github.com/bitmartexchange/bitmart-go-sdk-api"
  "os"
  "sync"
)

func Callback(message string) {
  fmt.Println("------------------------>" + message)
}

func main() {
  var wg sync.WaitGroup
  wg.Add(3)

  ws := bitmart.NewFuturesWSClient(bitmart.Config{
    WsUrl:        bitmart.FUTURES_WS_URL,
    CustomLogger: bitmart.NewCustomLogger(bitmart.INFO, os.Stdout),
  }, Callback)

  ws.Send(`{"action":"subscribe","args":["futures/ticker"]}`)

  ws.Send(`{"action":"subscribe","args":["futures/depth20:BTCUSDT"]}`)

  ws.Send(`{"action":"subscribe","args":["futures/klineBin1m:BTCUSDT"]}`)

  ws.Send(`{"action":"subscribe","args":["futures/trade:BTCUSDT"]}`)

  // Just test, Please do not use in production.
  wg.Wait()
}

Futures Websocket Endpoints : Subscribe Private Channel
package main

import (
  "fmt"
  "github.com/bitmartexchange/bitmart-go-sdk-api"
  "sync"
)

func Callback(message string) {
  fmt.Println("------------------------>" + message)
}

func main() {
  var wg sync.WaitGroup
  wg.Add(3)

  var yourApiKey = "Your API KEY"
  var yourSecretKey = "Your Secret KEY"
  var yourMemo = "Your Memo"

  ws := bitmart.NewFuturesWSClient(bitmart.Config{
    WsUrl:     bitmart.FUTURES_WS_USER,
    ApiKey:    yourApiKey,
    SecretKey: yourSecretKey,
    Memo:      yourMemo,
  }, Callback)

  // login
  ws.Login()

  // 【Private】Assets Channel
  ws.Send(`{"action": "subscribe","args":["futures/asset:USDT", "futures/asset:BTC", "futures/asset:ETH"]}`)

  // Just test, Please do not use in production.
  wg.Wait()
}

Extra Options

Authentication
client := bitmart.NewClient(bitmart.Config{
    ApiKey:    yourApiKey,
    SecretKey: yourSecretKey,
    Memo:      yourMemo,
})
Timeout

Through the bitmart.Config configuration class, you can set the timeout period for http requests. If not set, the default is 30 seconds.

client := bitmart.NewClient(bitmart.Config{
    TimeoutSecond: 5,
})
Logging

If you want to print out the request information, you can do so by setting the log level to DEBUG.

client := bitmart.NewClient(bitmart.Config{
    CustomLogger: bitmart.NewCustomLogger(bitmart.DEBUG, os.Stdout)
})

Can I write the log to a file? Of course you can. Here is an example of writing a file:

// Create a log file output
file, err3 := os.OpenFile("./custom_log.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err3 != nil {
    log.Fatalf("Failed to open log file: %v", err3)
}
defer file.Close()

client := bitmart.NewClient(bitmart.Config{
    CustomLogger: bitmart.NewCustomLogger(bitmart.DEBUG, file)]
})

Other settings explained:

  • os.O_CREATE: If the custom_log.log file does not exist, Go will automatically create it.
  • os.O_WRONLY: The file can only be used for writing.
  • os.O_APPEND: The newly written data will be appended to the end of the file without overwriting the existing data in the file.
  • The last parameter 0666:
    1. It specifies the permissions for the newly created file.
    2. 0666 means the file's read and write permissions are: the owner, group, and other users can read and write the file.
Custom request headers

You can add your own request header information here, but please do not fill in X-BM-KEY, X-BM-SIGN, X-BM-TIMESTAMP

client := bitmart.NewClient(bitmart.Config{Headers: map[string]string{
      "X-Custom-Header1": "HeaderValue1",
      "X-Custom-Header2": "HeaderValue2",
}})
client.GetSpotV3Ticker("BTC_USDT")
Response Metadata

The bitmart API server provides the endpoint rate limit usage in the header of each response. This information can be obtained from the headers property. x-bm-ratelimit-remaining indicates the number of times the current window has been used, x-bm-ratelimit-limit indicates the maximum number of times the current window can be used, and x-bm-ratelimit-reset indicates the current window time.

Example:

x-bm-ratelimit-mode: IP
x-bm-ratelimit-remaining: 10
x-bm-ratelimit-limit: 600
x-bm-ratelimit-reset: 60

This means that this IP can call the endpoint 600 times within 60 seconds, and has called 10 times so far.

var ac, err = client.GetSpotV3Ticker("BTC_USDT")
if err != nil {
    log.Panic(err)
} else {
    log.Println(ac.Limit.Limit)
    log.Println(ac.Limit.Remaining)
    log.Println(ac.Limit.Reset)
    log.Println(ac.Limit.Mode)
}

Documentation

Index

Constants

View Source
const (
	API_URL_PRO     = "https://api-cloud.bitmart.com"                           // rest api url
	API_URL_V2_PRO  = "https://api-cloud-v2.bitmart.com"                        // rest api url
	SPOT_WS_URL     = "wss://ws-manager-compress.bitmart.com/api?protocol=1.1"  // spot-ws-public
	SPOT_WS_USER    = "wss://ws-manager-compress.bitmart.com/user?protocol=1.1" // spot-ws-private
	FUTURES_WS_URL  = "wss://openapi-ws-v2.bitmart.com/api?protocol=1.1"        // contract-ws-public
	FUTURES_WS_USER = "wss://openapi-ws-v2.bitmart.com/user?protocol=1.1"       // contract-ws-private

	X_BM_KEY       = "X-BM-KEY"
	X_BM_SIGN      = "X-BM-SIGN"
	X_BM_TIMESTAMP = "X-BM-TIMESTAMP"

	CONTENT_TYPE = "Content-Type"
	ACCEPT       = "Accept"
	USER_AGENT   = "User-Agent"
	VERSION      = "bitmart-go-sdk-api/1.3.0"

	APPLICATION_JSON      = "application/json"
	APPLICATION_JSON_UTF8 = "application/json; charset=UTF-8"

	GET    = "GET"
	POST   = "POST"
	DELETE = "DELETE"

	// API_SYSTEM_TIME_URL System Status Endpoints: https://developer-pro.bitmart.com/en/spot/#system-status
	API_SYSTEM_TIME_URL    = "/system/time"
	API_SYSTEM_SERVICE_URL = "/system/service"

	// API_ACCOUNT_CURRENCIES_URL Funding Account Endpoints: https://developer-pro.bitmart.com/en/spot/#funding-account
	API_ACCOUNT_CURRENCIES_URL               = "/account/v1/currencies"
	API_ACCOUNT_WALLET_URL                   = "/account/v1/wallet"
	API_ACCOUNT_DEPOSIT_ADDRESS_URL          = "/account/v1/deposit/address"
	API_ACCOUNT_WITHDRAW_CHARGE_URL          = "/account/v1/withdraw/charge"
	API_ACCOUNT_WITHDRAW_APPLY_URL           = "/account/v1/withdraw/apply"
	API_ACCOUNT_DEPOSIT_WITHDRAW_HISTORY_URL = "/account/v2/deposit-withdraw/history"
	API_ACCOUNT_DEPOSIT_WITHDRAW_DETAIL_URL  = "/account/v1/deposit-withdraw/detail"
	API_SPOT_MARGIN_ACCOUNT_ISOLATED_URL     = "/spot/v1/margin/isolated/account"
	API_SPOT_MARGIN_ASSET_TRANSFER_URL       = "/spot/v1/margin/isolated/transfer"
	API_SPOT_USER_FEE_URL                    = "/spot/v1/user_fee"
	API_SPOT_TRADE_FEE_URL                   = "/spot/v1/trade_fee"

	// API_SPOT_CURRENCIES_URL Public Market Data Endpoints: https://developer-pro.bitmart.com/en/spot/#public-market-data
	API_SPOT_CURRENCIES_URL      = "/spot/v1/currencies"
	API_SPOT_SYMBOLS_URL         = "/spot/v1/symbols"
	API_SPOT_SYMBOLS_DETAILS_URL = "/spot/v1/symbols/details"

	API_SPOT_V3_TICKERS_URL       = "/spot/quotation/v3/tickers"
	API_SPOT_V3_TICKER_URL        = "/spot/quotation/v3/ticker"
	API_SPOT_V3_LATEST_KLINE_URL  = "/spot/quotation/v3/lite-klines"
	API_SPOT_V3_HISTORY_KLINE_URL = "/spot/quotation/v3/klines"
	API_SPOT_V3_BOOKS_URL         = "/spot/quotation/v3/books"
	API_SPOT_V3_TRADES_URL        = "/spot/quotation/v3/trades"

	// API_SPOT_WALLET_URL Spot / Margin Trading Endpoints: https://developer-pro.bitmart.com/en/spot/#spot-margin-trading
	API_SPOT_WALLET_URL              = "/spot/v1/wallet"
	API_SPOT_SUBMIT_ORDER_URL        = "/spot/v2/submit_order"
	API_SPOT_SUBMIT_MARGIN_ORDER_URL = "/spot/v1/margin/submit_order"
	API_SPOT_BATCH_ORDERS_URL        = "/spot/v4/batch_orders"
	API_SPOT_CANCEL_ORDER_URL        = "/spot/v3/cancel_order"
	API_SPOT_CANCEL_ORDERS_URL       = "/spot/v4/cancel_orders"
	API_SPOT_CANCEL_ALL_URL          = "/spot/v4/cancel_all"

	API_SPOT_V4_QUERY_ORDER_BY_ID_URL     = "/spot/v4/query/order"
	API_SPOT_V4_QUERY_ORDER_BY_CLIENT_URL = "/spot/v4/query/client-order"
	API_SPOT_V4_QUERY_OPEN_ORDERS_URL     = "/spot/v4/query/open-orders"
	API_SPOT_V4_QUERY_HISTORY_ORDERS_URL  = "/spot/v4/query/history-orders"
	API_SPOT_V4_QUERY_TRADES_URL          = "/spot/v4/query/trades"
	API_SPOT_V4_QUERY_ORDER_TRADES_URL    = "/spot/v4/query/order-trades"

	// Margin Loan Endpoints: https://developer-pro.bitmart.com/en/spot/#margin-loan
	API_MARGIN_BORROW_ISOLATED_URL             = "/spot/v1/margin/isolated/borrow"
	API_MARGIN_REPAY_ISOLATED_URL              = "/spot/v1/margin/isolated/repay"
	API_BORROW_ROCORD_ISOLATED_URL             = "/spot/v1/margin/isolated/borrow_record"
	API_REPAYMENT_ROCORD_ISOLATED_URL          = "/spot/v1/margin/isolated/repay_record"
	API_TRADING_PAIR_BORROWING_RATE_AND_AMOUNT = "/spot/v1/margin/isolated/pairs"

	// broker url
	API_BROKER_REBATE_URL = "/spot/v1/broker/rebate"

	// Futures Market Data Endpoints: https://developer-pro.bitmart.com/en/futures/#futures-market-data
	API_CONTRACT_DETAILS_URL              = "/contract/public/details"
	API_CONTRACT_DEPTH_URL                = "/contract/public/depth"
	API_CONTRACT_OPEN_INTEREST_URL        = "/contract/public/open-interest"
	API_CONTRACT_FUNDING_RATE_URL         = "/contract/public/funding-rate"
	API_CONTRACT_FUNDING_RATE_HISTORY_URL = "/contract/public/funding-rate-history"
	API_CONTRACT_KLINE_URL                = "/contract/public/kline"
	API_CONTRACT_MARK_PRICE_KLINE_URL     = "/contract/public/markprice-kline"

	// Futures Account Data Endpoints: https://developer-pro.bitmart.com/en/futures/#futures-account-data
	API_CONTRACT_ASSETS_DETAIL_URL = "/contract/private/assets-detail"

	// Futures Trading Endpoints: https://developer-pro.bitmart.com/en/futures/#futures-trading
	API_CONTRACT_TRADE_FEE_RATE_URL      = "/contract/private/trade-fee-rate"
	API_CONTRACT_ORDER_URL               = "/contract/private/order"
	API_CONTRACT_ORDER_HISTORY_URL       = "/contract/private/order-history"
	API_CONTRACT_OPEN_ORDERS_URL         = "/contract/private/get-open-orders"
	API_CONTRACT_CURRENT_PLAN_ORDER_URL  = "/contract/private/current-plan-order"
	API_CONTRACT_POSITION_URL            = "/contract/private/position"
	API_CONTRACT_POSITION_RISK_URL       = "/contract/private/position-risk"
	API_CONTRACT_TRANSACTION_HISTORY_URL = "/contract/private/transaction-history"
	API_CONTRACT_TRADES_URL              = "/contract/private/trades"
	API_CONTRACT_TRANSFER_LIST_URL       = "/account/v1/transfer-contract-list"
	API_CONTRACT_SUBMIT_ORDER_URL        = "/contract/private/submit-order"
	API_CONTRACT_CANCEL_ORDER_URL        = "/contract/private/cancel-order"
	API_CONTRACT_CANCEL_ORDERS_URL       = "/contract/private/cancel-orders"
	API_CONTRACT_SUBMIT_PLAN_ORDER_URL   = "/contract/private/submit-plan-order"
	API_CONTRACT_CANCEL_PLAN_ORDER_URL   = "/contract/private/cancel-plan-order"
	API_CONTRACT_SUBMIT_TRAIL_ORDER_URL  = "/contract/private/submit-trail-order"
	API_CONTRACT_CANCEL_TRAIL_ORDER_URL  = "/contract/private/cancel-trail-order"

	API_CONTRACT_TRANSFER_URL                 = "/account/v1/transfer-contract"
	API_CONTRACT_SUBMIT_LEVERAGE_URL          = "/contract/private/submit-leverage"
	API_CONTRACT_SUBMIT_TP_SL_ORDER_URL       = "/contract/private/submit-tp-sl-order"
	API_CONTRACT_MODIFY_PLAN_ORDER_URL        = "/contract/private/modify-plan-order"
	API_CONTRACT_MODIFY_PRESET_PLAN_ORDER_URL = "/contract/private/modify-preset-plan-order"
	API_CONTRACT_MODIFY_TP_SL_ORDER_URL       = "/contract/private/modify-tp-sl-order"

	// web socket
	// spot common
	WS_PUBLIC_SPOT_TICKER     = "spot/ticker"
	WS_PUBLIC_SPOT_TRADE      = "spot/trade"
	WS_PUBLIC_SPOT_DEPTH5     = "spot/depth5"
	WS_PUBLIC_SPOT_DEPTH20    = "spot/depth20"
	WS_PUBLIC_SPOT_DEPTH50    = "spot/depth50"
	WS_PUBLIC_SPOT_KLINE_1M   = "spot/kline1m"
	WS_PUBLIC_SPOT_KLINE_3M   = "spot/kline3m"
	WS_PUBLIC_SPOT_KLINE_5M   = "spot/kline5m"
	WS_PUBLIC_SPOT_KLINE_15M  = "spot/kline15m"
	WS_PUBLIC_SPOT_KLINE_30M  = "spot/kline30m"
	WS_PUBLIC_SPOT_KLINE_1H   = "spot/kline1H"
	WS_PUBLIC_SPOT_KLINE_2H   = "spot/kline2H"
	WS_PUBLIC_SPOT_KLINE_4H   = "spot/kline4H"
	WS_PUBLIC_SPOT_KLINE_1D   = "spot/kline1D"
	WS_PUBLIC_SPOT_KLINE_1W   = "spot/kline1W"
	WS_PUBLIC_SPOT_KLINE_1MON = "spot/kline1M"

	// spot user
	WS_USER_SPOT_ORDER = "spot/user/order"

	// contract common
	WS_PUBLIC_CONTRACT_TICKER    = "futures/ticker"
	WS_PUBLIC_CONTRACT_DEPTH5    = "futures/depth5"
	WS_PUBLIC_CONTRACT_DEPTH20   = "futures/depth20"
	WS_PUBLIC_CONTRACT_DEPTH50   = "futures/depth50"
	WS_PUBLIC_CONTRACT_KLINE_1M  = "futures/klineBin1m"
	WS_PUBLIC_CONTRACT_KLINE_5M  = "futures/klineBin5m"
	WS_PUBLIC_CONTRACT_KLINE_15M = "futures/klineBin15m"
	WS_PUBLIC_CONTRACT_KLINE_30M = "futures/klineBin30m"
	WS_PUBLIC_CONTRACT_KLINE_1H  = "futures/klineBin1H"
	WS_PUBLIC_CONTRACT_KLINE_2H  = "futures/klineBin2H"
	WS_PUBLIC_CONTRACT_KLINE_4H  = "futures/klineBin4H"
	WS_PUBLIC_CONTRACT_KLINE_1D  = "futures/klineBin1D"
	WS_PUBLIC_CONTRACT_KLINE_1W  = "futures/klineBin1W"

	// contract user
	WS_USER_CONTRACT_ASSET    = "futures/asset"
	WS_USER_CONTRACT_POSITION = "futures/position"
	WS_USER_CONTRACT_UNICAST  = "futures/unicast"
)
View Source
const (
	DEBUG = iota
	INFO
	WARN
	ERROR
)

Variables

This section is empty.

Functions

func AddParams added in v1.0.2

func AddParams(params map[string]interface{}, options ...map[string]interface{}) map[string]interface{}

AddParams add param

func AddToParams added in v1.0.2

func AddToParams(key string, value interface{}, params map[string]interface{})

AddToParams add to params

func CreateChannel

func CreateChannel(channel string, symbol string) string

CreateChannel create channel

func CreateParams added in v1.0.2

func CreateParams(options ...map[string]interface{}) map[string]interface{}

CreateParams get param

func CreateQueryString

func CreateQueryString(params map[string]interface{}) string

CreateQueryString create query string

func CreateSubscribeParam

func CreateSubscribeParam(channels []string) ([]byte, error)

CreateSubscribeParam create subscribe param

func GetHttpStatus deprecated

func GetHttpStatus(response *CloudResponse) int

Deprecated: Use `.HttpStatus` instead. GetHttpStatus get http status

func GetResponse deprecated

func GetResponse(response *CloudResponse) string

Deprecated: Use `.Response` instead. GetResponse get response

func Headers

func Headers(request *http.Request, apiKey string, timestamp string, sign string, additionalHeaders map[string]string)

Headers set headers

func HmacSha256Base64Signer

func HmacSha256Base64Signer(message string, secretKey string) (string, error)

HmacSha256Base64Signer hmac sha256 base64 signer

func Int64ToString

func Int64ToString(arg int64) string

Int64ToString int64 to string

func IntToString

func IntToString(arg int) string

IntToString int to string

func InterfaceToString

func InterfaceToString(inter interface{}) string

func JsonBytesToStrut

func JsonBytesToStrut(jsonBytes []byte, result interface{}) error

JsonBytesToStrut jsonBytes to struct

func NewParams

func NewParams() map[string]interface{}

NewParams create params

func ParseRequestParams

func ParseRequestParams(params interface{}) (string, *bytes.Reader, error)

ParseRequestParams /** Parse request params to json and bin styles

func PreHashString

func PreHashString(timestamp string, memo string, body string) string

PreHashString pre hash string /** timestamp + "#" + memo + "#" + queryString

func PrintRequest

func PrintRequest(request *http.Request, body string)

PrintRequest print request

func PrintResponse

func PrintResponse(response *CloudResponse)

PrintResponse print response

func StringToInt

func StringToInt(arg string) int

StringToInt string to int

func UTCTime

func UTCTime() string

UTCTime utc time /** Get a UTC-0 timeZ

Types

type ApiMessage

type ApiMessage struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type Auth

type Auth int
const (
	NONE   Auth = 0
	KEYED  Auth = 1
	SIGNED Auth = 2
)

type BatchOrder added in v1.0.2

type BatchOrder struct {
	Side          string `json:"side"`
	Type          string `json:"type"`
	ClientOrderId string `json:"clientOrderId,omitempty"`
	Size          string `json:"size,omitempty"`
	Price         string `json:"price,omitempty"`
	Notional      string `json:"notional,omitempty"`
}

BatchOrder /** Spot Order Parameters

type Callback

type Callback func(message string)

Callback function

type CloudClient

type CloudClient struct {
	Config     Config
	HttpClient *http.Client
}

func NewClient

func NewClient(config Config) *CloudClient

NewClient /** Get a http client

func (*CloudClient) GetAccountCurrencies

func (cloudClient *CloudClient) GetAccountCurrencies() (*CloudResponse, error)

GetAccountCurrencies /** Get Currencies

func (*CloudClient) GetAccountDepositAddress

func (cloudClient *CloudClient) GetAccountDepositAddress(currency string) (*CloudResponse, error)

GetAccountDepositAddress /** Deposit Address (KEYED)

func (*CloudClient) GetAccountWithdrawCharge

func (cloudClient *CloudClient) GetAccountWithdrawCharge(currency string) (*CloudResponse, error)

GetAccountWithdrawCharge /** Withdraw Quota (KEYED)

func (*CloudClient) GetActualTradeFeeRate

func (cloudClient *CloudClient) GetActualTradeFeeRate(symbol string) (*CloudResponse, error)

GetActualTradeFeeRate /** Get Actual Trade Fee Rate (KEYED)

func (*CloudClient) GetBasicFeeRate

func (cloudClient *CloudClient) GetBasicFeeRate() (*CloudResponse, error)

GetBasicFeeRate /** Get Basic Fee Rate (KEYED)

func (*CloudClient) GetBorrowRecordIsolated

func (cloudClient *CloudClient) GetBorrowRecordIsolated(symbol string, borrowId string, startTime int64, endTime int64, N int) (*CloudResponse, error)

GetBorrowRecordIsolated /** Get Borrow Record(Isolated) (KEYED)

func (*CloudClient) GetBrokerRebate

func (cloudClient *CloudClient) GetBrokerRebate() (*CloudResponse, error)

GetBrokerRebate broker rebate

func (*CloudClient) GetBrokerRebateByTimestamp

func (cloudClient *CloudClient) GetBrokerRebateByTimestamp(startTime int64, endTime int64) (*CloudResponse, error)

GetBrokerRebateByTimestamp broker rebate by timestamp

func (*CloudClient) GetContractAssetsDetail

func (cloudClient *CloudClient) GetContractAssetsDetail() (*CloudResponse, error)

GetContractAssetsDetail assets-detail /** Get Contract Assets (KEYED)

func (*CloudClient) GetContractCurrentPlanOrders added in v1.0.2

func (cloudClient *CloudClient) GetContractCurrentPlanOrders(options ...map[string]interface{}) (*CloudResponse, error)

GetContractCurrentPlanOrders /** Get All Current Plan Orders (KEYED) Parameters: - Options.symbol: Symbol of the contract(like BTCUSDT) - Options.type: Order type -limit - market - Options.limit: The number of returned results, with a maximum of 100 and a default of 100 - Options.plan_type: Plan order type -plan - profit_loss (default all)

func (*CloudClient) GetContractDepth

func (cloudClient *CloudClient) GetContractDepth(contractSymbol string) (*CloudResponse, error)

GetContractDepth depth /** Get Market Depth

func (*CloudClient) GetContractDetails

func (cloudClient *CloudClient) GetContractDetails(contractSymbol string) (*CloudResponse, error)

GetContractDetails details /** Get Contract Details

func (*CloudClient) GetContractFundingRate

func (cloudClient *CloudClient) GetContractFundingRate(contractSymbol string) (*CloudResponse, error)

GetContractFundingRate funding-rate /** Get Current Funding Rate

func (*CloudClient) GetContractFundingRateHistory added in v1.3.0

func (cloudClient *CloudClient) GetContractFundingRateHistory(contractSymbol string, limit int) (*CloudResponse, error)

GetContractFundingRateHistory funding-rate-history /** Get Funding Rate History

func (*CloudClient) GetContractKline

func (cloudClient *CloudClient) GetContractKline(contractSymbol string, startTime, endTime, step int) (*CloudResponse, error)

GetContractKline kline /** Get K-line

func (*CloudClient) GetContractMarkPriceKline added in v1.3.0

func (cloudClient *CloudClient) GetContractMarkPriceKline(contractSymbol string, startTime, endTime, step int) (*CloudResponse, error)

GetContractMarkPriceKline mark kline /** Get MarkPrice K-line

func (*CloudClient) GetContractOpenInterest

func (cloudClient *CloudClient) GetContractOpenInterest(contractSymbol string) (*CloudResponse, error)

GetContractOpenInterest open-interest /** Get Futures Open Interest

func (*CloudClient) GetContractOpenOrders added in v1.0.1

func (cloudClient *CloudClient) GetContractOpenOrders(options ...map[string]interface{}) (*CloudResponse, error)

GetContractOpenOrders open orders /** Get All Open Orders (KEYED) Parameters: - Options.symbol: Symbol of the contract(like BTCUSDT) - Options.type: Order type -limit - market - trailing - Options.order_state: Order state -all(default) - partially_filled - Options.limit: The number of returned results, with a maximum of 100 and a default of 100

func (*CloudClient) GetContractOrder

func (cloudClient *CloudClient) GetContractOrder(contractSymbol string, orderId string) (*CloudResponse, error)

GetContractOrder order /** Get Order Detail (KEYED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - orderId: Order ID

func (*CloudClient) GetContractOrderHistory

func (cloudClient *CloudClient) GetContractOrderHistory(contractSymbol string, options ...map[string]interface{}) (*CloudResponse, error)

GetContractOrderHistory order-history /** Get Order History (KEYED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - Options.start_time: Start time, default is the last 7 days - Options.end_time: End time, default is the last 7 days

func (*CloudClient) GetContractPosition

func (cloudClient *CloudClient) GetContractPosition(options ...map[string]interface{}) (*CloudResponse, error)

GetContractPosition position /** Get Current Position (KEYED) Parameters: - Options.symbol: Symbol of the contract(like BTCUSDT)

func (*CloudClient) GetContractPositionRisk added in v1.0.2

func (cloudClient *CloudClient) GetContractPositionRisk(options ...map[string]interface{}) (*CloudResponse, error)

GetContractPositionRisk /** Get Current Position Risk Details(KEYED) Parameters: - Options.symbol: Symbol of the contract(like BTCUSDT)

func (*CloudClient) GetContractTradeFeeRate added in v1.2.0

func (cloudClient *CloudClient) GetContractTradeFeeRate(contractSymbol string) (*CloudResponse, error)

GetContractTradeFeeRate order /** Get Trade Fee Rate (KEYED) Parameters: - symbol: Symbol of the contract(like BTCUSDT)

func (*CloudClient) GetContractTrades

func (cloudClient *CloudClient) GetContractTrades(contractSymbol string, options ...map[string]interface{}) (*CloudResponse, error)

GetContractTrades trades /** Get Order Trade (KEYED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - Options.start_time: Start time, default is the last 7 days - Options.end_time: End time, default is the last 7 days

func (*CloudClient) GetContractTransactionHistory added in v1.3.0

func (cloudClient *CloudClient) GetContractTransactionHistory(options ...map[string]interface{}) (*CloudResponse, error)

GetContractTransactionHistory /** Get Transaction History (KEYED) Parameters: - Options.symbol: Symbol of the contract(like BTCUSDT) - Options.flow_type: Type - 0 = All (default) - 1 = Transfer - 2 = Realized PNL - 3 = Funding Fee - 4 = Commission Fee - 5 = Liquidation Clearance - Options.start_time: Start time, timestamp in ms - Options.end_time: End time, timestamp in ms - Options.page_size: Default 100; max 1000

func (*CloudClient) GetContractTransferList

func (cloudClient *CloudClient) GetContractTransferList(options ...map[string]interface{}) (*CloudResponse, error)

GetContractTransferList /** Get Transfer List (SIGNED) Parameters: - Options.currency: Currency (like USDT) - Options.time_start: Start time in milliseconds, (e.g. 1681701557927) - Options.time_end: End time in milliseconds, (e.g. 1681701557927) - Options.page: Number of pages, allowed range [1,1000] - Options.limit: Number of queries, allowed range [10,100] - Options.recvWindow: Trade time limit, allowed range (0,60000], default: 5000 milliseconds

func (*CloudClient) GetDepositWithdrawDetail

func (cloudClient *CloudClient) GetDepositWithdrawDetail(id string) (*CloudResponse, error)

GetDepositWithdrawDetail /** Get A Deposit Or Withdraw Detail (KEYED)

func (*CloudClient) GetDepositWithdrawHistory

func (cloudClient *CloudClient) GetDepositWithdrawHistory(operationType string, n int, options ...map[string]interface{}) (*CloudResponse, error)

GetDepositWithdrawHistory /** Get Deposit And Withdraw History (KEYED) Parameters: - operationType: type -deposit=deposit -withdraw=withdraw - n: Recent N records (value range 1-100) - Options: currency - Token symbol, e.g., 'BTC'

func (*CloudClient) GetMarginAccountDetailsIsolated

func (cloudClient *CloudClient) GetMarginAccountDetailsIsolated(options ...map[string]interface{}) (*CloudResponse, error)

GetMarginAccountDetailsIsolated /** Get Margin Account Details(Isolated) (KEYED) Parameters: - Options: symbol - Trading pair (e.g. BMX_USDT), no symbol is passed, and all isolated margin assets are returned

func (*CloudClient) GetRepaymentRecordIsolated

func (cloudClient *CloudClient) GetRepaymentRecordIsolated(symbol string, repayId string, currency string, startTime int64, endTime int64, N int) (*CloudResponse, error)

GetRepaymentRecordIsolated /** Get Repayment Record(Isolated) (KEYED)

func (*CloudClient) GetSpotAccountOrders

func (cloudClient *CloudClient) GetSpotAccountOrders(symbol string, orderMode string, startTime int64, endTime int64, limit int, recvWindow int) (*CloudResponse, error)

GetSpotAccountOrders /** Query Account Orders (v4) (SIGNED)

func (*CloudClient) GetSpotAccountTradeList

func (cloudClient *CloudClient) GetSpotAccountTradeList(symbol string, orderMode string, startTime int64, endTime int64, limit int, recvWindow int) (*CloudResponse, error)

GetSpotAccountTradeList /** Account Trade List (v4) (SIGNED)

func (*CloudClient) GetSpotAccountWallet

func (cloudClient *CloudClient) GetSpotAccountWallet(options ...map[string]interface{}) (*CloudResponse, error)

GetSpotAccountWallet /** Get Account Balance (KEYED) Parameters: - Options: currency - currency, .e.g. "BTC", "ETH", "USDT"

func (*CloudClient) GetSpotCurrencies

func (cloudClient *CloudClient) GetSpotCurrencies() (*CloudResponse, error)

GetSpotCurrencies /** Get Currency List (v1)

func (*CloudClient) GetSpotOpenOrders

func (cloudClient *CloudClient) GetSpotOpenOrders(symbol string, orderMode string, startTime int64, endTime int64, limit int, recvWindow int) (*CloudResponse, error)

GetSpotOpenOrders /** Query Open Orders (v4) (SIGNED)

func (*CloudClient) GetSpotOrderByClientOrderId

func (cloudClient *CloudClient) GetSpotOrderByClientOrderId(clientOrderId string, queryState string, recvWindow int) (*CloudResponse, error)

GetSpotOrderByClientOrderId /** Query Order By clientOrderId(v4) (SIGNED)

func (*CloudClient) GetSpotOrderByOrderId

func (cloudClient *CloudClient) GetSpotOrderByOrderId(orderId string, queryState string, recvWindow int) (*CloudResponse, error)

GetSpotOrderByOrderId /** Query Order By Id (v4) (SIGNED)

func (*CloudClient) GetSpotOrderTradeList

func (cloudClient *CloudClient) GetSpotOrderTradeList(orderId string, recvWindow int) (*CloudResponse, error)

GetSpotOrderTradeList /** Order Trade List(v4) (SIGNED)

func (*CloudClient) GetSpotSymbol

func (cloudClient *CloudClient) GetSpotSymbol() (*CloudResponse, error)

GetSpotSymbol /** Get List of Trading Pairs (v1)

func (*CloudClient) GetSpotSymbolDetail

func (cloudClient *CloudClient) GetSpotSymbolDetail() (*CloudResponse, error)

GetSpotSymbolDetail /** Get List of Trading Pair Details (v1)

func (*CloudClient) GetSpotV3Book added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3Book(symbol string, options ...map[string]interface{}) (*CloudResponse, error)

GetSpotV3Book /** Get Depth (V3) Parameters: - symbol - Trading pair (e.g. BMX_USDT) - Options: limit - Order book depth per side. Maximum 50, e.g. 50 bids + 50 asks. Default returns to 35 depth data, e.g. 35 bids + 35 asks.

func (*CloudClient) GetSpotV3HistoryKline added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3HistoryKline(symbol string, options ...map[string]interface{}) (*CloudResponse, error)

GetSpotV3HistoryKline /** Get History K-Line (V3)

Parameters: - symbol - Trading pair (e.g. BMX_USDT) - Options: before - Query timestamp (unit: second, e.g. 1525760116), query the data before this time - Options: after - Query timestamp (unit: second, e.g. 1525769116), query the data after this time - Options: step - k-line step, value [1, 3, 5, 15, 30, 45, 60, 120, 180, 240, 1440, 10080, 43200] unit: minute, default 1 - Options: limit - Return number, the maximum value is 200, default is 100

func (*CloudClient) GetSpotV3LatestKline added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3LatestKline(symbol string, options ...map[string]interface{}) (*CloudResponse, error)

GetSpotV3LatestKline /** Get Latest K-Line (V3)

Parameters: - symbol - Trading pair (e.g. BMX_USDT) - Options: before - Query timestamp (unit: second, e.g. 1525760116), query the data before this time - Options: after - Query timestamp (unit: second, e.g. 1525769116), query the data after this time - Options: step - k-line step, value [1, 3, 5, 15, 30, 45, 60, 120, 180, 240, 1440, 10080, 43200] unit: minute, default 1 - Options: limit - Return number, the maximum value is 200, default is 100

func (*CloudClient) GetSpotV3Ticker added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3Ticker(symbol string) (*CloudResponse, error)

GetSpotV3Ticker /** Get Ticker of a Trading Pair (V3)

func (*CloudClient) GetSpotV3Tickers added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3Tickers() (*CloudResponse, error)

GetSpotV3Tickers /** Get Ticker of All Pairs (V3)

func (*CloudClient) GetSpotV3Trade added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3Trade(symbol string, options ...map[string]interface{}) (*CloudResponse, error)

GetSpotV3Trade /** Get Recent Trades (V3) Parameters: - symbol - Trading pair (e.g. BMX_USDT) - Options: limit - Number of returned items, maximum is 50, default 50

func (*CloudClient) GetSpotWallet

func (cloudClient *CloudClient) GetSpotWallet() (*CloudResponse, error)

GetSpotWallet /** Get Account Balance (KEYED)

func (*CloudClient) GetSystemService

func (cloudClient *CloudClient) GetSystemService() (*CloudResponse, error)

GetSystemService /** Get System Service Status (NONE)

func (*CloudClient) GetSystemTime

func (cloudClient *CloudClient) GetSystemTime() (*CloudResponse, error)

GetSystemTime /** Get System Time (NONE)

func (*CloudClient) GetTradingPairBorrowingRateAndAmount

func (cloudClient *CloudClient) GetTradingPairBorrowingRateAndAmount(symbol string) (*CloudResponse, error)

GetTradingPairBorrowingRateAndAmount /** Get Trading Pair Borrowing Rate and Amount (KEYED)

func (*CloudClient) MarginAssetTransfer

func (cloudClient *CloudClient) MarginAssetTransfer(transfer MarginAssetTransfer) (*CloudResponse, error)

MarginAssetTransfer /** Margin Asset Transfer (SIGNED)

func (*CloudClient) MarginBorrowIsolated

func (cloudClient *CloudClient) MarginBorrowIsolated(symbol string, currency string, amount string) (*CloudResponse, error)

MarginBorrowIsolated /** Margin Borrow (Isolated) (SIGNED)

func (*CloudClient) MarginRepayIsolated

func (cloudClient *CloudClient) MarginRepayIsolated(symbol string, currency string, amount string) (*CloudResponse, error)

MarginRepayIsolated /** Margin Repay (Isolated) (SIGNED)

func (*CloudClient) PostAccountWithdrawApply

func (cloudClient *CloudClient) PostAccountWithdrawApply(apply WithdrawApply) (*CloudResponse, error)

PostAccountWithdrawApply /** Withdraw (SIGNED)

func (*CloudClient) PostContractCancelOrder

func (cloudClient *CloudClient) PostContractCancelOrder(contractSymbol string, options ...map[string]interface{}) (*CloudResponse, error)

PostContractCancelOrder cancel-order /** Cancel Order (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - options.order_id: Order ID - options.client_order_id: Client-defined OrderId

func (*CloudClient) PostContractCancelOrders

func (cloudClient *CloudClient) PostContractCancelOrders(contractSymbol string) (*CloudResponse, error)

PostContractCancelOrders cancel-orders /** Cancel All Orders (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT)

func (*CloudClient) PostContractCancelPlanOrder

func (cloudClient *CloudClient) PostContractCancelPlanOrder(contractSymbol string, options ...map[string]interface{}) (*CloudResponse, error)

PostContractCancelPlanOrder cancel-plan-order /** Cancel Plan Order (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - options.order_id: Order ID - options.client_order_id: Client Order ID

func (*CloudClient) PostContractCancelTrailOrder added in v1.3.0

func (cloudClient *CloudClient) PostContractCancelTrailOrder(contractSymbol string, options ...map[string]interface{}) (*CloudResponse, error)

PostContractCancelTrailOrder cancel-trail-order /** Cancel Trail Order (SIGNED)

func (*CloudClient) PostContractModifyPlanOrder added in v1.1.0

func (cloudClient *CloudClient) PostContractModifyPlanOrder(contractSymbol string, orderType string,
	triggerPrice string, priceType int, options ...map[string]interface{}) (*CloudResponse, error)

PostContractModifyPlanOrder /** Modify Plan Order (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - orderType: Order type -limit -market - triggerPrice: Trigger price - priceType: Trigger price type -1=last_price -2=fair_price - Options.order_id: Order ID(order_id or client_order_id must give one) - Options.executive_price: Execution price for plan order, mandatory when type = limit

func (*CloudClient) PostContractModifyPresetPlanOrder added in v1.1.0

func (cloudClient *CloudClient) PostContractModifyPresetPlanOrder(contractSymbol string, orderId string, options ...map[string]interface{}) (*CloudResponse, error)

PostContractModifyPresetPlanOrder /** Modify Preset Plan Order (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - orderId: Order ID - Options.preset_take_profit_price_type: Pre-set TP price type -1=last_price(default) -2=fair_price - Options.preset_stop_loss_price_type: Pre-set SL price type -1=last_price(default) -2=fair_price - Options.preset_take_profit_price: Pre-set TP price - Options.preset_stop_loss_price: Pre-set SL price

func (*CloudClient) PostContractModifyTpSlOrder added in v1.1.0

func (cloudClient *CloudClient) PostContractModifyTpSlOrder(contractSymbol string, triggerPrice string, priceType int, options ...map[string]interface{}) (*CloudResponse, error)

PostContractModifyTpSlOrder /** Modify TP/SL Order (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - triggerPrice: Trigger price - priceType: Trigger price type -1=last_price -2=fair_price - Options.order_id: Order ID(order_id or client_order_id must give one) - Options.client_order_id: Client order ID(order_id or client_order_id must give one) - Options.executive_price: Execution price for order, mandatory when plan_category = - Options.plan_category: TP/SL type -1=TP/SL -2=Position TP/SL - Options.category: Order type, Position TP/SL default market -limit -market

func (*CloudClient) PostContractPlanOrder

func (cloudClient *CloudClient) PostContractPlanOrder(planOrder ContractPlanOrder) (*CloudResponse, error)

PostContractPlanOrder plan-order /** Submit Plan Order (SIGNED)

func (*CloudClient) PostContractSubmitLeverage added in v1.0.1

func (cloudClient *CloudClient) PostContractSubmitLeverage(contractSymbol string, leverage string, openType string) (*CloudResponse, error)

PostContractSubmitLeverage submit-leverage /** Submit Leverage (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - leverage: Order leverage - openType: Open type, required at close position -cross -isolated

func (*CloudClient) PostContractSubmitOrder

func (cloudClient *CloudClient) PostContractSubmitOrder(order ContractOrder) (*CloudResponse, error)

PostContractSubmitOrder submit-order /** Submit Order (SIGNED)

func (*CloudClient) PostContractSubmitTpSlOrder added in v1.1.0

func (cloudClient *CloudClient) PostContractSubmitTpSlOrder(contractSymbol string, orderType string, side int,
	triggerPrice string, executivePrice string, priceType int, options ...map[string]interface{}) (*CloudResponse, error)

PostContractSubmitTpSlOrder /** Submit TP or SL Order (SIGNED) Parameters: - symbol: Symbol of the contract(like BTCUSDT) - orderType: Order type -take_profit -stop_loss - side: Order side -2=buy_close_short -3=sell_close_long - triggerPrice: Trigger price - executivePrice: Execution price - priceType: Trigger price type -1=last_price -2=fair_price - Options.size: Order size (Number of contracts) Default the size of position - Options.plan_category: TP/SL type -1=TP/SL(default) -2=Position TP/SL - Options.client_order_id: Client order ID - Options.category: Trigger order type, position TP/SL default market, -limit -market

func (*CloudClient) PostContractTrailOrder added in v1.3.0

func (cloudClient *CloudClient) PostContractTrailOrder(trailOrder ContractTrailOrder) (*CloudResponse, error)

PostContractTrailOrder plan-order /** Submit Trail Order (SIGNED)

func (*CloudClient) PostContractTransfer

func (cloudClient *CloudClient) PostContractTransfer(currency string, amount string, transferType string, recvWindow int) (*CloudResponse, error)

PostContractTransfer transfer /** Transfer (SIGNED) Parameters: - currency: Currency - amount: Transfer amount,allowed range[0.01,10000000000] - type: Transfer type -spot_to_contract -contract_to_spot - recvWindow: Trade time limit, allowed range (0,60000], default: 5000 milliseconds

func (*CloudClient) PostMarginSubmitOrder

func (cloudClient *CloudClient) PostMarginSubmitOrder(order MarginOrder) (*CloudResponse, error)

PostMarginSubmitOrder /** New Margin Order(v1) (SIGNED)

func (*CloudClient) PostSpotBatchOrders

func (cloudClient *CloudClient) PostSpotBatchOrders(symbol string, orderParams []BatchOrder, options ...map[string]interface{}) (*CloudResponse, error)

PostSpotBatchOrders /** Batch New Order(v4) (SIGNED) Parameters: - symbol: Trading pair (e.g. BTC_USDT) - orderParams: Order parameters, the number of transactions cannot exceed 10 - Options.recvWindow - Trade time limit, allowed range (0,60000], default: 5000 milliseconds

func (*CloudClient) PostSpotCancelAllOrder added in v1.0.2

func (cloudClient *CloudClient) PostSpotCancelAllOrder(options ...map[string]interface{}) (*CloudResponse, error)

PostSpotCancelAllOrder /** Cancel All Order(v4) (SIGNED) Parameters: - Options.symbol: Trading pair (e.g. BTC_USDT) - Options.side: Order side -buy -sell

func (*CloudClient) PostSpotCancelOrder

func (cloudClient *CloudClient) PostSpotCancelOrder(symbol string, options ...map[string]interface{}) (*CloudResponse, error)

PostSpotCancelOrder /** Cancel Order(v3) (SIGNED) Parameters: - symbol: Trading pair (e.g. BTC_USDT) - Options.order_id - Order ID - Options.client_order_id - Client-defined Order ID

func (*CloudClient) PostSpotCancelOrders

func (cloudClient *CloudClient) PostSpotCancelOrders(symbol string, options ...map[string]interface{}) (*CloudResponse, error)

PostSpotCancelOrders /** Cancel Batch Order(v4) (SIGNED) Parameters: - symbol: Trading pair (e.g. BTC_USDT) - Options.orderIds - Order Id List (Either orderIds or clientOrderIds must be provided) - Options.clientOrderIds - Client-defined OrderId List (Either orderIds or clientOrderIds must be provided) - Options.recvWindow - Trade time limit, allowed range (0,60000], default: 5000 milliseconds

func (*CloudClient) PostSpotSubmitOrder

func (cloudClient *CloudClient) PostSpotSubmitOrder(order Order) (*CloudResponse, error)

PostSpotSubmitOrder /** New Order(v2) (SIGNED)

func (*CloudClient) Request

func (cloudClient *CloudClient) Request(method string, requestPath string, params map[string]interface{}, auth Auth, cloudResponse *CloudResponse) (response *http.Response, err error)

Request /** Send a http request to remote server and get a response data

type CloudFuturesWSClient added in v1.2.0

type CloudFuturesWSClient struct {
	CloudWsClient
}

type CloudResponse

type CloudResponse struct {
	HttpStatus int
	Response   string
	Limit      RateLimit
}

type CloudSpotWSClient added in v1.2.0

type CloudSpotWSClient struct {
	CloudWsClient
}

func NewFuturesWSClient added in v1.2.0

func NewFuturesWSClient(config Config, callback Callback) *CloudSpotWSClient

func NewSpotWSClient added in v1.2.0

func NewSpotWSClient(config Config, callback Callback) *CloudSpotWSClient

type CloudWsClient added in v1.2.0

type CloudWsClient struct {
	Config Config
	Conn   *websocket.Conn
	// contains filtered or unexported fields
}

func (*CloudWsClient) FuturesCheckLogin added in v1.2.0

func (ws *CloudWsClient) FuturesCheckLogin(message []byte) bool

FuturesCheckLogin /* check login result

func (*CloudWsClient) FuturesLogin added in v1.2.0

func (ws *CloudWsClient) FuturesLogin() error

FuturesLogin /* Send Login Message

func (*CloudWsClient) FuturesPing added in v1.2.0

func (ws *CloudWsClient) FuturesPing()

FuturesPing /* Send Ping Message

func (*CloudWsClient) Init added in v1.2.0

func (ws *CloudWsClient) Init(isSpot bool, config Config, callback Callback)

func (*CloudWsClient) Login added in v1.2.0

func (ws *CloudWsClient) Login() error

Login /* Send Login message to Server

func (*CloudWsClient) Send added in v1.2.0

func (ws *CloudWsClient) Send(message string) error

Send /* Send message to Server

func (*CloudWsClient) SpotCheckLogin added in v1.2.0

func (ws *CloudWsClient) SpotCheckLogin(message []byte) bool

SpotCheckLogin /* check login result

func (*CloudWsClient) SpotLogin added in v1.2.0

func (ws *CloudWsClient) SpotLogin() error

SpotLogin /* Send Login Message

func (*CloudWsClient) SpotPing added in v1.2.0

func (ws *CloudWsClient) SpotPing()

SpotPing /* Send Ping Message

func (*CloudWsClient) Stop added in v1.2.0

func (ws *CloudWsClient) Stop()

Stop /* websocket close

type Config

type Config struct {
	Url           string
	WsUrl         string
	ApiKey        string
	SecretKey     string
	Memo          string
	TimeoutSecond int
	IsPrint       bool
	CustomLogger  *CustomLogger
	Headers       map[string]string
}

type ContractOrder

type ContractOrder struct {
	Symbol                    string `json:"symbol,omitempty"`
	ClientOrderId             string `json:"client_order_id,omitempty"`
	Type                      string `json:"type,omitempty"`
	Side                      int    `json:"side,omitempty"`
	Leverage                  string `json:"leverage,omitempty"`
	OpenType                  string `json:"open_type,omitempty"`
	Mode                      int    `json:"mode,omitempty"`
	Price                     string `json:"price,omitempty"`
	Size                      int    `json:"size,omitempty"`
	PresetTakeProfitPriceType int    `json:"preset_take_profit_price_type,omitempty"`
	PresetStopLossPriceType   int    `json:"preset_stop_loss_price_type,omitempty"`
	PresetTakeProfitPrice     string `json:"preset_take_profit_price,omitempty"`
	PresetStopLossPrice       string `json:"preset_stop_loss_price,omitempty"`
}

ContractOrder submit_contract order params

type ContractPlanOrder

type ContractPlanOrder struct {
	Symbol                    string `json:"symbol"`
	Type                      string `json:"type,omitempty"`
	Side                      int    `json:"side"`
	Leverage                  string `json:"leverage"`
	OpenType                  string `json:"open_type"`
	Mode                      int    `json:"mode,omitempty"`
	Size                      int    `json:"size"`
	TriggerPrice              string `json:"trigger_price"`
	ExecutivePrice            string `json:"executive_price"`
	PriceWay                  int    `json:"price_way"`
	PriceType                 int    `json:"price_type"`
	PlanCategory              int    `json:"plan_category"`
	PresetTakeProfitPriceType int    `json:"preset_take_profit_price_type"`
	PresetStopLossPriceType   int    `json:"preset_stop_loss_price_type"`
	PresetTakeProfitPrice     string `json:"preset_take_profit_price"`
	PresetStopLossPrice       string `json:"preset_stop_loss_price"`
}

type ContractTrailOrder added in v1.3.0

type ContractTrailOrder struct {
	Symbol              string `json:"symbol"`
	Side                int    `json:"side"`
	Leverage            string `json:"leverage"`
	OpenType            string `json:"open_type"`
	Size                int    `json:"size"`
	ActivationPrice     string `json:"activation_price"`
	CallbackRate        string `json:"callback_rate"`
	ActivationPriceType int    `json:"activation_price_type"`
}

type CustomLogger added in v1.0.2

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

func NewCustomLogger added in v1.0.2

func NewCustomLogger(logLevel int, output io.Writer) *CustomLogger

NewCustomLogger Creating a custom logger

func (*CustomLogger) Log added in v1.0.2

func (l *CustomLogger) Log(level int, msg string)

Log Print logs (support different log levels)

func (*CustomLogger) Logf added in v1.0.2

func (l *CustomLogger) Logf(level int, format string, v ...interface{})

Logf Create a log with formatting

func (*CustomLogger) SetLogLevel added in v1.0.2

func (l *CustomLogger) SetLogLevel(level int)

SetLogLevel Setting the log level

type FuturesWsRespMsg added in v1.2.0

type FuturesWsRespMsg struct {
	Action  string
	Success bool
}

type MarginAssetTransfer

type MarginAssetTransfer struct {
	Symbol   string `json:"symbol"`
	Currency string `json:"currency"`
	Amount   string `json:"amount"`
	Side     string `json:"side"`
}

type MarginOrder

type MarginOrder struct {
	Symbol        string `json:"symbol"`
	Side          string `json:"side"`
	Type          string `json:"type"`
	ClientOrderId string `json:"clientOrderId"`
	Size          string `json:"size"`
	Price         string `json:"price"`
	Notional      string `json:"notional"`
}

MarginOrder /** Margin Order Parameters

type Msg

type Msg struct {
	Action string
	Args   []string
}

type OpParam

type OpParam struct {
	Op   string   `json:"op"`
	Args []string `json:"args"`
}

type Order

type Order struct {
	Symbol        string `json:"symbol"`
	Side          string `json:"side"`
	Type          string `json:"type"`
	ClientOrderId string `json:"client_order_id,omitempty"`
	Size          string `json:"size,omitempty"`
	Price         string `json:"price,omitempty"`
	Notional      string `json:"notional,omitempty"`
}

Order /** Spot Order Parameters

type RateLimit

type RateLimit struct {
	Remaining int
	Limit     int
	Reset     int
	Mode      string
}

func GetLimit deprecated

func GetLimit(response *CloudResponse) RateLimit

Deprecated: Use `.Limit` instead. GetLimit get limit

type SpotWsRespMsg added in v1.2.0

type SpotWsRespMsg struct {
	Event     string
	ErrorCode string
}

type WithdrawApply

type WithdrawApply struct {
	Currency string `json:"currency"`
	Amount   string `json:"amount"`

	Destination string `json:"destination"`  // -To Digital Address
	Address     string `json:"address"`      // Withdraw address (only the address added on the official website is supported)
	AddressMemo string `json:"address_memo"` // Address tag(tag Or payment_id Or memo)

	Type     int    `json:"type"`     // Account type 1=CID 2=Email 3=Phone
	Value    string `json:"value"`    // Account
	AreaCode string `json:"areaCode"` // Phone area code, required when account type is phone, e.g.: 61
}

WithdrawApply Withdraw Parameters

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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