Skip to content
Packages for work with bitmex rest and websocket API on golang
Branch: master
Clone or download
Latest commit 8a9e697 May 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bitmex Init Apr 9, 2018
config Timeout May 5, 2018
database Update Apr 11, 2018
rest Timeout May 5, 2018
swagger Timeout May 5, 2018
tools
websocket Init Apr 9, 2018
.gitignore Vendor May 5, 2018
Gopkg.lock Vendor May 5, 2018
Gopkg.toml Vendor May 5, 2018
LICENSE Initial commit Apr 9, 2018
README.md Update README.md Apr 30, 2018
config.json Timeout May 5, 2018
main.go Timeout May 5, 2018

README.md

Bitmex API

Packages for work with bitmex rest and websocket API on golang.
Target of this packages make easy access to bitmex API including testnet platform.

Usage

Please see full example in main.go

REST

// Load config
cfg := config.LoadConfig("config.json")
ctx := rest.MakeContext(cfg.Key, cfg.Secret, cfg.Host)

// Get wallet
wallet, response, err := rest.GetWallet(ctx)
tools.CheckErr(err)
fmt.Printf("Status: %v, wallet amount: %v\n", response.StatusCode, wallet.Amount)

// Place order
params := map[string]interface{}{
    "side":     "Buy",
    "symbol":   "XBTUSD",
    "ordType":  "Limit",
    "orderQty": 1,
    "price":    9000,
    "clOrdID":  "MyUniqID_123",
    "execInst": "ParticipateDoNotInitiate",
}
order, response, err := rest.NewOrder(ctx, params)
tools.CheckErr(err)
fmt.Printf("Order: %+v, Response: %+v\n", order, response)

Websocket

// Load config
cfg := config.LoadConfig("config.json")

// Connect to WS
conn := websocket.Connect(cfg.Host)
defer conn.Close()

// Listen read WS
chReadFromWS := make(chan []byte, 100)
go websocket.ReadFromWSToChannel(conn, chReadFromWS)

// Listen write WS
chWriteToWS := make(chan interface{}, 100)
go websocket.WriteFromChannelToWS(conn, chWriteToWS)

// Authorize
chWriteToWS <- websocket.GetAuthMessage(cfg.Key, cfg.Secret)

// Listen
go func() {
    for {
        message := <-chReadFromWS
        res, err := bitmex.DecodeMessage(message)
        tools.CheckErr(err)

        // Business logic
        switch res.Table {
        case "orderBookL2":
            if res.Action == "partial" {
                // Update table
            } else {
                // Update row
            }
        case "order":
            if res.Action == "partial" {
                // Update table
            } else {
                // Update row
            }
        case "position":
            if res.Action == "partial" {
                // Update table
            } else {
                // Update row
            }
        }
    }
}()

Example

Example of usage look in main.go

More

I will be glad of any support. Thank you!

eth: 0x3e9b92625c49Bfd41CCa371D1e4A1f0d4c25B6fC
btc: 35XDoFSA8QeM26EnCyhQPTMBZm4S1DvncE
You can’t perform that action at this time.