/bitmart-go-sdk-api

Go client for the BitMart API

Primary LanguageGo

Logo

BitMart-Go-SDK-API

Build Status

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

Installation

  • 1.Go 1.12.7 support

  • 2.Downloads or updates code's dependencies

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

Usage

  • An example of a spot trade API
  • Replace it with your own API KEY
  • Run

Spot API Example

package gotest

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

func main() {

	client := bitmart.NewClient(bitmart.Config{
		Url:"https://api-cloud.bitmart.com", // Ues Https url
		ApiKey:"Your API KEY",
		SecretKey:"Your Secret KEY",
		Memo:"Your Memo",
		TimeoutSecond:10,
		IsPrint:true,
	})

	var ac, err = client.PostSpotSubmitOrder(bitmart.Order{Symbol: TEST_SYMBOL, Side: "buy", Type: "limit", Size: "0.1", Price: "8800", Notional: ""})
	if err != nil {
		log.Panic(err)
	} else {
		bitmart.PrintResponse(ac)
	}

}

Spot WebSocket Public Channel Example

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

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

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

	ws := bitmart.NewWS(bitmart.Config{
                        		WsUrl: "wss://ws-manager-compress.bitmart.com/api?protocol=1.1",
                        		ApiKey:"Your API KEY",
                        		SecretKey:"Your Secret KEY",
                        		Memo:"Your Memo",
                        		TimeoutSecond:10,
                        		IsPrint:true,
                        	})
	_ = ws.Connection(OnMessage)

	channels := []string{
		// public channel
		bitmart.CreateChannel(WS_PUBLIC_SPOT_TICKER, "BTC_USDT"),
	}
	ws.SubscribeWithLogin(channels)


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

WebSocket Private Channel Example

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

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

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

	ws := bitmart.NewWS(bitmart.Config{
                        		WsUrl: "wss://ws-manager-compress.bitmart.com/user?protocol=1.1",
                        		ApiKey:"Your API KEY",
                        		SecretKey:"Your Secret KEY",
                        		Memo:"Your Memo",
                        		TimeoutSecond:10,
                        		IsPrint:true,
                        	})
	_ = ws.Connection(OnMessage)

	channels := []string{
		// private channel
		bitmart.CreateChannel(WS_USER_SPOT_ORDER, "BTC_USDT"),
	}
	ws.SubscribeWithLogin(channels)


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

Contract WebSocket Public Channel Example

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

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

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

	ws := bitmart.NewWSContract(bitmart.Config{
                        		WsUrl: "wss://openapi-ws.bitmart.com/api?protocol=1.1",
                        		ApiKey:"Your API KEY",
                        		SecretKey:"Your Secret KEY",
                        		Memo:"Your Memo",
                        		TimeoutSecond:10,
                        		IsPrint:true,
                        	})
	_ = ws.Connection(OnMessage)

	channels := []string{
      // public channel
      WS_PUBLIC_CONTRACT_TICKER,
      CreateChannel(WS_PUBLIC_CONTRACT_DEPTH20, "BTCUSDT"),
      CreateChannel(WS_PUBLIC_CONTRACT_KLINE_1M, "BTCUSDT"),
	}
	ws.SubscribeWithoutLogin(channels)


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

Contract WebSocket Private Channel Example

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

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

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

	ws := bitmart.NewWSContract(bitmart.Config{
                        		WsUrl: "wss://openapi-ws.bitmart.com/user?protocol=1.1",
                        		ApiKey:"Your API KEY",
                        		SecretKey:"Your Secret KEY",
                        		Memo:"Your Memo",
                        		TimeoutSecond:10,
                        		IsPrint:true,
                        	})
	_ = ws.Connection(OnMessage)

	channels := []string{
      // private channel
      WS_USER_CONTRACT_UNICAST,
      WS_USER_CONTRACT_POSITION,
      CreateChannel(WS_USER_CONTRACT_ASSET, "USDT"),
	}
	ws.SubscribeWithLogin(channels)
	
	// Just test, Please do not use in production.
	wg.Wait()
}

Release Notes

2022-11-8
  • New endpoints for Contract Market
    • /contract/public/detailsGet contract details
    • /contract/public/depthGet contract depth
    • /contract/public/open-interestGet contract open interest
    • /contract/public/funding-rateGet contract funding rate
    • /contract/public/klineGet contract kline
  • New endpoints for Contract Account
    • /contract/private/assets-detailGet contract user assets detail
  • New endpoints for Contract Trade
    • /contract/private/orderGet contract order detail
    • /contract/private/order-historyGet contract order history
    • /contract/private/positionGet contract position
    • /contract/private/tradesGet contract trades
    • /contract/private/submit_orderPost contract submit order
    • /contract/private/cancel_orderPost contract cancel order
    • /contract/private/cancel_ordersPost contract batch cancel orders
  • New endpoints for Contract WebSocket
    • contract websocket public channel addresswss://openapi-ws.bitmart.com/api?protocol=1.1
    • contract websocket private channel addresswss://openapi-ws.bitmart.com/user?protocol=1.1
2022-11-03
  • New endpoints for API Broker
    • /spot/v1/broker/rebateApplicable to query API Broker's rebate records
  • Update endpoints for Spot / Margin trading
    • /spot/v3/orders /spot/v2/tradesadd start_time and end_time field for flexible querying
    • add new order status 11 = Partially filled and canceled
2022-10-20
  • Upgrade endpoints for Spot
    • /spot/v1/ticker has been upgraded to /spot/v2/ticker and /spot/v1/ticker_detail
    • /spot/v1/submit_order has been upgraded to /spot/v2/submit_order
    • /spot/v1/batch_orders has been upgraded to /spot/v2/batch_orders
    • /spot/v2/cancel_order has been upgraded to /spot/v3/cancel_order
    • /spot/v1/order_detail has been upgraded to /spot/v2/order_detail
    • /spot/v2/orders has been upgraded to /spot/v3/orders
    • /spot/v1/trades has been upgraded to /spot/v2/trades
  • New endpoints for Spot & Margin
    • /spot/v1/margin/isolated/accountApplicable for isolated margin account inquiries
    • /spot/v1/margin/isolated/transferFor fund transfers between a margin account and spot account
    • /spot/v1/user_feeFor querying the base rate of the current user
    • /spot/v1/trade_feeFor the actual fee rate of the trading pairs
    • /spot/v1/margin/submit_orderApplicable for margin order placement
    • /spot/v1/margin/isolated/borrowApplicable to isolated margin account borrowing operations
    • /spot/v1/margin/isolated/repayApplicable to isolated margin account repayment operations
    • /spot/v1/margin/isolated/borrow_recordApplicable to the inquiry of borrowing records of an isolated margin account
    • /spot/v1/margin/isolated/repay_recordApplicable to the inquiry of repayment records of isolated margin account
    • /spot/v1/margin/isolated/pairsApplicable for checking the borrowing rate and borrowing amount of trading pairs
2022-01-20
  • Update endpoints for Spot
    • /spot/v1/symbols/detailsAdd a new respond parameter trade_status, to show the trading status of a trading pair symbol.
2022-01-18
  • websocket public channel addresswss://ws-manager-compress.bitmart.com?protocol=1.1will be taken down on 2022-02-28 UTC time,The new address iswss://ws-manager-compress.bitmart.com/api?protocol=1.1
2021-11-24
  • New endpoints for Spot
    • /spot/v2/ordersGet User Order History V2
    • /spot/v1/batch_ordersBatch Order
  • Update endpoints for Spot
    • /spot/v1/symbols/klineAdd new field 'quote_volume'
    • /spot/v1/symbols/tradesAdd optional parameter N to return the number of items, the default is up to 50 items
    • /spot/v1/order_detailAdd new field 'unfilled_volume'
    • /spot/v1/submit_orderThe request parameter type added limit_maker and ioc order types
  • New endpoints for Account
    • /account/v2/deposit-withdraw/historyGet Deposit And Withdraw History V2
  • Update endpoints for Account
    • /account/v1/walletRemove the account_type,Only respond to currency accounts; you can bring currency parameters (optional)
2021-11-06
  • Update endpoints for Spot WebSocket
    • Public-Depth Channel:
      • spot/depth50 50 Level Depth Channel
      • spot/depth100 100 Level Depth Channel
    • User-Trade Channel:
      • Eligible pushes add new orders successfully
2021-01-19
  • New endpoints for Spot WebSocket
    • Public - ticket channels
    • Public - K channel
    • Public - trading channels
    • Public - depth channels
    • Login
    • User - Trading Channel
2020-07-16
  • Interface Spot API Cancel Order update to v2 version that is POST https://api-cloud.bitmart.com/spot/v2/cancel_order
  • UserAgent set "BitMart-GO-SDK/1.0.1"
2020-09-21
  • Interface Spot API /spot/v1/symbols/book add size parameter, which represents the number of depths

License