bitmart

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 23 Imported by: 0

README

Logo

BitMart-Go-SDK-API

go.dev reference Go version

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
  • Provide webSocket apis calls
  • Supported APIs:
    • /spot/*
    • /contract/*
    • /account/*
    • Spot WebSocket Market Stream
    • Spot User Data Stream
    • Contract User Data Stream
    • Contract 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
Get Recent Trades
package main

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

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

  // Get Recent Trades
  var ac, err = client.GetSpotSymbolTrade("BTC_USDT")
  if err != nil {
    log.Panic(err)
  } else {
    log.Println(bitmart.GetResponse(ac))
  }
  
}
Spot / Margin Trading Endpoints Example
New Order(v2) (SIGNED)

package main

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

/*
	POST /spot/v2/submit_order
	Doc: https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
*/
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(bitmart.GetResponse(ac))
	}

}



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


Spot Websocket Endpoints
Subscribe Public Channel: Ticker

package main

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

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

// https://developer-pro.bitmart.com/en/spot/#public-ticker-channel
func main() {
	ws := bitmart.NewWS(bitmart.Config{WsUrl: bitmart.WS_URL})

	_ = ws.Connection(OnMessage)

	// 【Public】Ticker Channel
	channels := []string{
		"spot/ticker:BTC_USDT",
	}

	ws.SubscribeWithoutLogin(channels)

}


Subscribe Private Channel: Order Progress

package main

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

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

// https://developer-pro.bitmart.com/en/spot/#private-order-progress
func main() {

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

	ws := bitmart.NewWS(bitmart.Config{
		WsUrl:     bitmart.WS_URL_USER,
		ApiKey:    yourApiKey,
		SecretKey: yourSecretKey,
		Memo:      yourMemo,
	})

	_ = ws.Connection(OnMessage)

	// 【Private】Order Progress
	channels := []string{
		"spot/user/order:BTC_USDT",
	}

	ws.SubscribeWithLogin(channels)

}


Futures Trading Endpoints
Submit Order (SIGNED)

package main

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

/*
	POST /contract/private/submit-order
	Doc: https://developer-pro.bitmart.com/en/futures/#submit-order-signed
*/
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,
	})

	// 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(bitmart.GetResponse(ac))
	}

}


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


Futures Websocket Endpoints
Subscribe Public Channel: Ticker

package main

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

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

// https://developer-pro.bitmart.com/en/futures/#public-ticker-channel
func main() {
	ws := bitmart.NewWSContract(bitmart.Config{WsUrl: bitmart.CONTRACT_WS_URL})

	_ = ws.Connection(OnMessage)

	// 【Public】Ticker Channel
	channels := []string{
		"futures/ticker",
	}

	ws.SubscribeWithoutLogin(channels)

	// Just test, Please do not use in production.
	time.Sleep(60 * time.Second)
}



Subscribe Private Channel: Assets

package main

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

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

// https://developer-pro.bitmart.com/en/futures/#private-assets-channel
func main() {

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

	ws := bitmart.NewWSContract(bitmart.Config{
		WsUrl:     bitmart.CONTRACT_WS_PRIVATE_URL,
		ApiKey:    yourApiKey,
		SecretKey: yourSecretKey,
		Memo:      yourMemo,
	})

	_ = ws.Connection(OnMessage)

	// 【Private】Assets Channel
	channels := []string{
		"futures/asset:USDT",
	}
	ws.SubscribeWithLogin(channels)

	// Just test, Please do not use in production.
	time.Sleep(60 * time.Second)
}

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,
})
Debug

If you want to print the request and response information, you can set it to true.

client := bitmart.NewClient(bitmart.Config{
    IsPrint: true,
})

Documentation

Index

Constants

View Source
const (
	API_URL_PRO             = "https://api-cloud.bitmart.com"                           // rest api url
	WS_URL                  = "wss://ws-manager-compress.bitmart.com/api?protocol=1.1"  // spot-ws-public
	WS_URL_USER             = "wss://ws-manager-compress.bitmart.com/user?protocol=1.1" // spot-ws-private
	CONTRACT_WS_URL         = "wss://openapi-ws.bitmart.com/api?protocol=1.1"           // contract-ws-public
	CONTRACT_WS_PRIVATE_URL = "wss://openapi-ws.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.0.1"

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

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

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

	// 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"

	// 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_TICKER_URL          = "/spot/v2/ticker"
	API_SPOT_TICKER_DETAIL_URL   = "/spot/v1/ticker_detail"
	API_SPOT_STEPS_URL           = "/spot/v1/steps"
	API_SPOT_SYMBOLS_KLINE_URL   = "/spot/v1/symbols/kline"
	API_SPOT_SYMBOLS_BOOK_URL    = "/spot/v1/symbols/book"
	API_SPOT_SYMBOLS_TRADES_URL  = "/spot/v1/symbols/trades"

	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"

	// 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/v2/batch_orders"
	API_SPOT_CANCEL_ORDER_URL        = "/spot/v3/cancel_order"
	API_SPOT_CANCEL_ORDERS_URL       = "/spot/v1/cancel_orders"

	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_KLINE_URL         = "/contract/public/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_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_POSITION_URL          = "/contract/private/position"
	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_TRANSFER_URL        = "/account/v1/transfer-contract"
	API_CONTRACT_SUBMIT_LEVERAGE_URL = "/contract/private/submit-leverage"

	// 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"
)

Variables

This section is empty.

Functions

func CreateChannel

func CreateChannel(channel string, symbol string) string

CreateChannel create channel

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

func GetHttpStatus(response *CloudResponse) int

GetHttpStatus get http status

func GetResponse

func GetResponse(response *CloudResponse) string

GetResponse get response

func Headers

func Headers(request *http.Request, apiKey string, timestamp string, sign 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 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) 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) GetContractKline

func (cloudClient *CloudClient) GetContractKline(contractSymbol string, from, to, step int) (*CloudResponse, error)

GetContractKline kline /** Get 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(contractSymbol string, orderType string, orderState string, limit int) (*CloudResponse, error)

GetContractOpenOrders open orders /** Get All Open Orders (KEYED)

func (*CloudClient) GetContractOrder

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

GetContractOrder order /** Get Order Detail (KEYED)

func (*CloudClient) GetContractOrderHistory

func (cloudClient *CloudClient) GetContractOrderHistory(contractSymbol string, from, to int) (*CloudResponse, error)

GetContractOrderHistory order-history /** Get Order History (KEYED)

func (*CloudClient) GetContractPosition

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

GetContractPosition position /** Get Current Position (KEYED)

func (*CloudClient) GetContractTrades

func (cloudClient *CloudClient) GetContractTrades(contractSymbol string, from, to int) (*CloudResponse, error)

GetContractTrades trades /** Get Order Trade (KEYED)

func (*CloudClient) GetContractTransferList

func (cloudClient *CloudClient) GetContractTransferList(contractSymbol string, timeStart, timeEnd int64, page, limit, recvWindow int) (*CloudResponse, error)

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(history HistoryApply) (*CloudResponse, error)

GetDepositWithdrawHistory /** Get Deposit And Withdraw History (KEYED)

func (*CloudClient) GetMarginAccountDetailsIsolated

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

GetMarginAccountDetailsIsolated /** Get Margin Account Details(Isolated) (KEYED)

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(currency string) (*CloudResponse, error)

GetSpotAccountWallet /** Get Account Balance (KEYED)

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) GetSpotSteps deprecated

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

Deprecated: k-line step, value [1, 3, 5, 15, 30, 45, 60, 120, 180, 240, 1440, 10080, 43200] GetSpotSteps /** Get K-Line Step (V1)

func (*CloudClient) GetSpotSymbol

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

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

func (*CloudClient) GetSpotSymbolBook deprecated

func (cloudClient *CloudClient) GetSpotSymbolBook(symbol string, precision int, size int) (*CloudResponse, error)

Deprecated: Use `GetSpotV3Book` instead. GetSpotSymbolBook /** Get Depth (V1)

func (*CloudClient) GetSpotSymbolDetail

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

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

func (*CloudClient) GetSpotSymbolKline deprecated

func (cloudClient *CloudClient) GetSpotSymbolKline(symbol string, from int64, to int64, step int) (*CloudResponse, error)

Deprecated: Use `GetSpotV3LatestKline` or `GetSpotV3HistoryKline` instead. GetSpotSymbolKline /** Get K-Line (V1)

func (*CloudClient) GetSpotSymbolTrade deprecated

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

Deprecated: Use `GetSpotV3Trade` instead. GetSpotSymbolTrade /** Get Recent Trades (V1)

func (*CloudClient) GetSpotTicker deprecated

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

Deprecated: Use `GetSpotV3Tickers` instead. GetSpotTicker /** Get Ticker of All Pairs (V2)

func (*CloudClient) GetSpotTickerDetail deprecated

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

Deprecated: Use `GetSpotV3Ticker` instead. GetSpotTickerDetail /** Get Ticker of a Trading Pair (V1)

func (*CloudClient) GetSpotV3Book added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3Book(symbol string, limit int) (*CloudResponse, error)

GetSpotV3Book /** Get Depth (V3)

func (*CloudClient) GetSpotV3HistoryKline added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3HistoryKline(symbol string, before, after int64, step, limit int) (*CloudResponse, error)

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

func (*CloudClient) GetSpotV3LatestKline added in v1.0.1

func (cloudClient *CloudClient) GetSpotV3LatestKline(symbol string, before, after int64, step, limit int) (*CloudResponse, error)

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

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, limit int) (*CloudResponse, error)

GetSpotV3Trade /** Get Recent Trades (V3)

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, orderId string) (*CloudResponse, error)

PostContractCancelOrder cancel-order /** Cancel Order (SIGNED)

func (*CloudClient) PostContractCancelOrders

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

PostContractCancelOrders cancel-orders /** Cancel All Orders (SIGNED)

func (*CloudClient) PostContractCancelPlanOrder

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

PostContractCancelPlanOrder cancel-plan-order /** Cancel Plan Order (SIGNED)

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)

func (*CloudClient) PostContractSubmitOrder

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

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

func (*CloudClient) PostContractTransfer

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

PostContractTransfer transfer /** Transfer (SIGNED)

func (*CloudClient) PostMarginSubmitOrder

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

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

func (*CloudClient) PostSpotBatchOrders

func (cloudClient *CloudClient) PostSpotBatchOrders(orderParams []Order) (*CloudResponse, error)

PostSpotBatchOrders /** Batch New Order(v2) (SIGNED)

func (*CloudClient) PostSpotCancelOrder

func (cloudClient *CloudClient) PostSpotCancelOrder(symbol string, orderId string, clientOrderId string) (*CloudResponse, error)

PostSpotCancelOrder /** Cancel Order(v3) (SIGNED)

func (*CloudClient) PostSpotCancelOrders

func (cloudClient *CloudClient) PostSpotCancelOrders(symbol string, side string) (*CloudResponse, error)

PostSpotCancelOrders /** Cancel Batch Order(v1) (SIGNED)

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 CloudResponse

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

type CloudWS

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

func NewWS

func NewWS(config Config) *CloudWS

func (*CloudWS) Connection

func (ws *CloudWS) Connection(callback Callback) error

Connection to websocket

func (*CloudWS) SubscribeWithLogin

func (ws *CloudWS) SubscribeWithLogin(channels []string)

SubscribeWithLogin Support public channel and private channel

func (*CloudWS) SubscribeWithoutLogin

func (ws *CloudWS) SubscribeWithoutLogin(channels []string)

SubscribeWithoutLogin Only support public channel

type CloudWSContract

type CloudWSContract struct {
	CloudWS
}

func NewWSContract

func NewWSContract(config Config) *CloudWSContract

func (*CloudWSContract) SubscribeWithLogin

func (ws *CloudWSContract) SubscribeWithLogin(channels []string)

SubscribeWithLogin Support public channel and private channel

func (*CloudWSContract) SubscribeWithoutLogin

func (ws *CloudWSContract) SubscribeWithoutLogin(channels []string)

SubscribeWithoutLogin Only support public channel

type Config

type Config struct {
	Url           string
	WsUrl         string
	ApiKey        string
	SecretKey     string
	Memo          string
	TimeoutSecond int
	IsPrint       bool
}

type ContractOrder

type ContractOrder struct {
	Symbol        string `json:"symbol"`
	ClientOrderId string `json:"client_order_id"`
	Type          string `json:"type,omitempty"`
	Side          int    `json:"side"`
	Leverage      string `json:"leverage"`
	OpenType      string `json:"open_type"`
	Mode          int    `json:"mode"`
	Price         string `json:"price"`
	Size          int    `json:"size"`
}

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"`
}

type HistoryApply

type HistoryApply struct {
	Currency      string `json:"currency"`
	OperationType string `json:"operation_type"` // type -deposit=deposit -withdraw=withdraw
	N             int    `json:"N"`
}

HistoryApply Query Withdraw/Deposit History Parameters

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"`
	Size          string `json:"size"`
	Price         string `json:"price"`
	Notional      string `json:"notional"`
}

Order /** Spot Order Parameters

type RateLimit

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

func GetLimit

func GetLimit(response *CloudResponse) RateLimit

GetLimit get limit

type RespMsg

type RespMsg struct {
	Action  string
	Success bool
}

type WithdrawApply

type WithdrawApply struct {
	Currency    string `json:"currency"`
	Amount      string `json:"amount"`
	Destination string `json:"destination"` // -To Digital Address
	Address     string `json:"address"`
	AddressMemo string `json:"address_memo"`
}

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