coinbase

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 12 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version string

Functions

func ApiKey

func ApiKey(k string) func(*Config)

func BaseURL

func BaseURL(u string) func(*Config)

func Debug

func Debug(b bool) func(*Config)

func GetVersion added in v0.2.0

func GetVersion() string

func Secret

func Secret(s string) func(*Config)

func Timeout

func Timeout(t time.Duration) func(*Config)

func UserAgent

func UserAgent(ua string) func(*Config)

Types

type Client

type Client struct {
	Config *Config
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *Config) *Client

NewClient returns a client with sane defaults.

func (*Client) Currencies

func (c *Client) Currencies(ctx context.Context) (*currencies, error)

Currencies lists known currencies.

func (*Client) ExchangeRates

func (c *Client) ExchangeRates(ctx context.Context, currency string) (*exchangeRates, error)

ExchangeRates gets current exchange rates.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context) (*user, error)

User gets the current user’s public information.

func (*Client) NewRequest

func (c *Client) NewRequest(method string, u *url.URL, authenticate bool, json []byte) (*http.Request, error)

func (*Client) Prices

func (c *Client) Prices(ctx context.Context, currencyPair string, priceType string) (*prices, error)

Prices gets the total price to buy one bitcoin or ether.

func (*Client) Time

func (c *Client) Time(ctx context.Context) (*serverTime, error)

Time gets the Coinbase API server time.

type Config

type Config struct {
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(options ...Option) *Config

NewConfig returns a config with sane defaults.

type Option

type Option func(*Config)

Directories

Path Synopsis
cmd
cb command

Jump to

Keyboard shortcuts

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