Go client for interacting with Namebase Exchange API.
Some requests require an API key. You can generate a key from https://www.namebase.io/pro.
See the original API documentation: https://github.com/namebasehq/exchange-api-documentation/
- go 1.10 or greater
go get github.com/sniperem/namebase
Query order book:
pair := namebase.NewCurrencyPair("hns", "btc")
if d, err := nb.GetDepth(pair, 0); err != nil {
log.Fatal(err)
} else {
log.Printf("ask 1: %+v, bid 1: %+v", d.Asks[0], d.Bids[0])
}
Place order
if o, err := nb.LimitBuy(decimal.NewFromFloat(100), decimal.NewFromFloat(0.00009),pair); err != nil {
log.Print("failed to buy: ", err)
}
Query account info
if acct, err := nb.GetAccount(); err != nil {
log.Print("failed to get account info: ", err)
} else {
log.Printf("%+v", acct)
}
Withdraw assets (change deposit address before testing, or it would deposit to my wallet) ๐
tokenAmount := decimal.NewFromFloat(2000)
if err := nb.Withdraw("HNS", tokenAmount,
"hs1qc7kmegpjkn4qrhuactul9feu69nvsqnjpkk6sy", ""); err != nil {
t.Error(err)
}
Maintain a local order book:
if chDepth, err := nb.SubDepth(pair); err != nil {
log.Print("failed to subscribe order book")
} else {
go func() {
for d := range chDepth {
log.Printf("ask 1: %+v, bid 1: %+v", d.Asks[0], d.Bids[0])
}
}()
}
Subscribe trade info of pair:
if chTrade, err := nb.SubTrades(pair); err != nil {
log.Print("failed to subscribe trade info")
} else {
go func() {
for t := range chTrade {
log.Printf("latest trade: %+v",t)
}
}()
}