BitMart-Go-SDK-API
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
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,
})