Skip to content

mikejoh/coinbase-go

Repository files navigation

coinbase-go

Test workflow

An alternative Golang package to interact with the Coinbase v2 API.

Note that this project is still work in progress!

Installation

Install:

go get github.com/mikejoh/coinbase-go

Import (with alias):

import cb "github.com/mikejoh/coinbase-go"

Examples

Instantiate client with config (using import alias):

package main

import cb "github.com/mikejoh/coinbase-go"

func main() {
	config := cb.NewConfig(
		cb.ApiKey("key"),
		cb.Secret("secret"),
	)

	client := cb.NewClient(config)
}

Exchange rates

rates, err := client.ExchangeRates(context.Background(), "BTC")
if err != nil {
	log.Fatal(err)
}

fmt.Println(rates)

Currencies

currencies, err := client.Currencies(context.Background())
if err != nil {
	log.Fatal(err)
}

fmt.Println(currencies)

Prices

prices, err := client.Prices(context.Background(), "BTC-SEK", "sell")
if err != nil {
	log.Fatal(err)
}

fmt.Println(prices)

Time

time, err := client.Time(context.Background())
if err != nil {
	log.Fatal(err)
}

fmt.Println(time)

Coinbase CLI

  1. Build:
make client

The binary is created in ./bin.

  1. Example usage:
./bin/cb currencies
./bin/cb prices --pair BTC-SEK --type buy
./bin/cb exchange-rates
./bin/cb exchange-rates --currency SEK
./bin/cb time

Resources

v2 API ref

Todo

  • Add code documentation
  • Rate limit
  • Pagination
  • Header signing (auth)
  • Implement Wallet endpoints
  • Implement a more generic way of making client API calls, DRY.