Coder Social home page Coder Social logo

namebase's Introduction

Namebase Exchange API client in Go

Go client for interacting with Namebase Exchange API.

Usage

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/

Installation

Requirements

  • go 1.10 or greater

Install

go get github.com/sniperem/namebase

Usage

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

namebase's People

Contributors

sniperem avatar wudi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

wudi

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.