coinbase

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: MIT Imports: 3 Imported by: 0

README

Go-Coinbase - Go Coinbase API unofficial Client

Getting started

Grab this dep

go get "github.com/BillotP/go-coinbase"

Write your api key and secrets in a .env file for example

COINBASE_APIKEY=myawesomeapikey
COINBASE_APISECRET=mysuperapisecret

And then in your code

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/BillotP/coinbase"
	"github.com/BillotP/coinbase/lib/models"
)

func main() {
	var (
		err        error
		pub        = os.Getenv("COINBASE_APIKEY")
		priv       = os.Getenv("COINBASE_APISECRET")
		myaccounts *models.Accounts
		// Load client
		client = coinbase.New(&pub, &priv)
	)
	// Get all your accounts
	if myaccounts, err = client.GetAccounts(); err != nil {
		log.Fatal(err)
	}
	// List them
	for _, account := range myaccounts.Datas {
		fmt.Printf("%s: %s (%s %s)\n",
			account.Balance.Currency,
			account.Balance.Amount,
			account.NativeBalance.Amount,
			account.NativeBalance.Currency,
		)
	}
}

And finally run the whole thing

source .env
COINBASE_APIKEY=$COINBASE_APIKEY COINBASE_APISECRET=$COINBASEAPISECRET go run .

Et voila !

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the struct from which all API requests are made

var CoinbaseClient *Client

CoinbaseClient is the global blablabla

func New

func New(pubkey *string, privkey *string) *Client

New return an authenticated client

func (Client) Delete

func (c Client) Delete(path string, params interface{}, holder interface{}) error

Delete sends a DELETE request and marshals response data into holder

func (Client) Get

func (c Client) Get(path string, params interface{}, holder interface{}) error

Get sends a GET request and marshals response data into holder

func (Client) GetAccountByID

func (c Client) GetAccountByID(accountID string) (*models.Accounts, error)

GetAccountByID returns a coinbase account by its ID

func (Client) GetAccounts

func (c Client) GetAccounts() (*models.Accounts, error)

GetAccounts returns a list of all coinbase accounts

func (Client) GetSpotPrice added in v0.3.1

func (c Client) GetSpotPrice(base, quote string) (*models.SpotPrice, error)

GetSpotPrice returns the last sport price for a currency pair

func (Client) GetTransactionsByAccountID added in v0.2.1

func (c Client) GetTransactionsByAccountID(accountID string) (*models.Transactions, error)

GetTransactionsByAccountID lists account’s transactions

func (Client) Post

func (c Client) Post(path string, params interface{}, holder interface{}) error

Post sends a POST request and marshals response data into holder

func (Client) Put

func (c Client) Put(path string, params interface{}, holder interface{}) error

Put sends a PUT request and marshals response data into holder

Directories

Path Synopsis
lib
rpc

Jump to

Keyboard shortcuts

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