Giter Club home page Giter Club logo

bitmart-go-sdk-api's Introduction

Logo

BitMart-Go-SDK-API

go.dev reference Go version License: MIT

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.