bitmex-go

command module
v0.0.0-...-1e0a6df Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

Golang SDK for bitmex

implementation of https://github.com/BitMEX/api-connectors, https://www.bitmex.com/api/explorer

all structs and APIs are from the bitmex official api connectors, based on that, add authentication and fix bugs.

Why

the generated connectors by bitmex have too many mistakes to use, this SDK fix these bugs to ensure bitmex API can get right results.

Installation

go get github.com/maurodelazeri/bitmex-go

Examples

  1. Get order book
apiClient = swagger.NewAPIClient(swagger.NewConfiguration())
orderBookApi := restful.NewOrderBookApi(apiClient.OrderBookApi)
orderBooks, err := orderBookApi.OrderBookGetL2("XBTUSD", 5)
if err != nil {
    log.Println("error wihle get orderbook: ", err)
}
for _, v := range orderBooks.AskList {
    log.Printf("%+v\n", v)
}
for _, v := range orderBooks.BidList {
    log.Printf("%+v\n", v)
}
  1. Get your position
apiClient = swagger.NewAPIClient(swagger.NewConfiguration())
auth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{
        Key:    apiKey,
        Secret: secretKey,
    })

positionApi := apiClient.PositionApi
params := map[string]interface{}{
    "filter":  "{\"symbol\": \"XBTUSD\"}",
    "columns": "",
    "count":   float32(10),
}
positions, response, err := positionApi.PositionGet(auth, params)
if err != nil {
    log.Println("error: ", err)
}
log.Println(response.Status)
log.Printf("%+v\n", positions)
  1. Get your wallet
apiClient = swagger.NewAPIClient(swagger.NewConfiguration())
auth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{
        Key:    apiKey,
        Secret: secretKey,
    })

userApi := apiClient.UserApi
params := map[string]interface{}{
    "currency": "",
}
wallet, response, err := userApi.UserGetWallet(auth, params)
if err != nil {
    log.Println("error: ", err)
}
log.Println(response.Status)
log.Printf("wallet: %+v\n", wallet)
  1. Get margin info
apiClient = swagger.NewAPIClient(swagger.NewConfiguration())
auth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{
        Key:    apiKey,
        Secret: secretKey,
    })

userApi := apiClient.UserApi
margin, response, err := userApi.UserGetMargin(auth, nil)
if err != nil {
    log.Println("error: ", err)
}
log.Println(response.Status)
log.Printf("margin: %+v\n", margin)
  1. Buy & Sell
apiClient = swagger.NewAPIClient(swagger.NewConfiguration())
auth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{
        Key:    apiKey,
        Secret: secretKey,
    })

// buy
orderApi := restful.NewOrderApi(apiClient.OrderApi, auth)
resp, orderId, err := orderApi.LimitBuy("XBTUSD", 1.0, 13000, "maurodelazeri_f_f_")
if err != nil {
    log.Println("error: ", err)
}
log.Printf("response: %s, orderId: %s\n", resp.Status, orderId)

// sell
resp, orderId, err := orderApi.LimitSell("XBTUSD", 1.0, 20000, "maurodelazeri_f_f_")
if err != nil {
    log.Println("error: ", err)
}
log.Printf("result: %s, orderId: %s\n", resp.Status, orderId)
  1. Get your order
apiClient = swagger.NewAPIClient(swagger.NewConfiguration())
auth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{
        Key:    apiKey,
        Secret: secretKey,
    })

orderApi := apiClient.OrderApi
params := map[string]interface{}{
    "symbol":    "XBTUSD",
    "filter":    "",
    "columns":   "",
    "count":     float32(5),
    "start":     nil,
    "reverse":   true,
    "startTime": nil,
    "endTime":   nil,
}
orders, response, err := orderApi.OrderGetOrders(auth, params)
if err != nil {
    log.Println("error: ", err)
}
log.Println(response.Status)
log.Printf("orders: %+v\n", orders)
  1. Even chat through RESTFul api
apiClient = swagger.NewAPIClient(swagger.NewConfiguration())
auth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{
        Key:    apiKey,
        Secret: secretKey,
    })

chatApi := apiClient.ChatApi
params := map[string]interface{}{
    "channelID": 2.0,
}
chat, response, err := chatApi.ChatNew(auth, "hello", params)
if err != nil {
    log.Println("error: ", err)
}
log.Println(response.Status)
log.Printf("%+v\n", chat)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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