gocoin

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

README

Go-Coin

A Go command line application to easily retrieve your personal account activity (buys, sell, transactions) through the Coinbase API.

The application supports the API key Authentication method

Installation

Enable API Key access for your Coinbase account. The application uses the GoDotEnv library to load a .env file from the project root during startup. (Note: This file should not be committed to source control) This file should contain API key and secret.

API_KEY=<your key>
API_SECRET=<your secret>>

Usage

Obtain the latest version with:

go get github.com/cdugga/gocoin

Build and Run with:

$go build github.com/cdugga/gocoin

$./gocoin

Application Details

The application fetches a user's accounts, including bitcoin, bitcoin cash, litecoin and ethereum wallets, fiat currency accounts, and vaults. The List accounts API call, https://api.coinbase.com/v2/accounts, lists current user's accounts to which the authenticated method has access to.
The JSON response contains account and pagination information. To return all objects, the application paginates through the results using the ID of the last resource as the starting_after parameter for the next call. The API call constructs this next call into the returned next_uri value automatically. All results have been received when the next_uri is empty.

Documentation

Index

Constants

View Source
const (
	GET_ACCOUNTS_PATH = "/v2/accounts"
	BASE_URL          = "https://api.coinbase.com"
)
View Source
const (
	BUY  int = 0
	SELL int = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account interface {
	// contains filtered or unexported methods
}

type AccountActivity

type AccountActivity struct {
	//Transactions []GenericTransaction
	Wallet       GenericAccount
	ActiveWallet bool
	BuyOrders    []GenericBuy
	Type         int
	SellOrders   []GenericSell
}

type AccountService

type AccountService struct {
	Env *Environment
}

type Accounts

type Accounts struct {
	Pagination Pagination `json:"pagination"`
	Data       []Data     `json:"data"`
}

type Balance

type Balance struct {
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
}

type Broker

type Broker interface {
	GetAccounts() ([]GenericAccount, error)
	GetAccountActivity(ctx context.Context, acc []GenericAccount) (t []AccountActivity)
	GetTransactions(nextUrl string)
}

type BrokerImpl

type BrokerImpl struct {
	AccountService Account
}

func (*BrokerImpl) GetAccountActivity

func (b *BrokerImpl) GetAccountActivity(ctx context.Context, acc []GenericAccount) (t []AccountActivity)

func (*BrokerImpl) GetAccounts

func (b *BrokerImpl) GetAccounts() (uAcc []GenericAccount, err error)

func (*BrokerImpl) GetTransactions

func (b *BrokerImpl) GetTransactions(nextUrl string)

type BrokerService

type BrokerService struct {
	Client Broker
}

func NewBrokerService

func NewBrokerService(env *Environment) *BrokerService

type Buys

type Buys struct {
	Pagination struct {
		EndingBefore  interface{} `json:"ending_before"`
		StartingAfter interface{} `json:"starting_after"`
		Limit         int         `json:"limit"`
		Order         string      `json:"order"`
		PreviousURI   interface{} `json:"previous_uri"`
		NextURI       interface{} `json:"next_uri"`
	} `json:"pagination"`
	Data []struct {
		ID            string `json:"id"`
		Status        string `json:"status"`
		PaymentMethod struct {
			ID           string `json:"id"`
			Resource     string `json:"resource"`
			ResourcePath string `json:"resource_path"`
		} `json:"payment_method"`
		Transaction struct {
			ID           string `json:"id"`
			Resource     string `json:"resource"`
			ResourcePath string `json:"resource_path"`
		} `json:"transaction"`
		Amount struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"amount"`
		Total struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"total"`
		Subtotal struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"subtotal"`
		CreatedAt    string `json:"created_at"`
		UpdatedAt    string `json:"updated_at"`
		Resource     string `json:"resource"`
		ResourcePath string `json:"resource_path"`
		Committed    bool   `json:"committed"`
		Instant      bool   `json:"instant"`
		Fee          struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"fee"`
		PayoutAt string `json:"payout_at"`
	} `json:"data"`
}

type Client

type Client struct {
	Signer Signer
	Sender Dispatcher
}

func NewClient

func NewClient() *Client

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, m Message, apikey, apiSecret string) ([]byte, error)

type Data

type Data struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	Primary      bool      `json:"primary"`
	Type         string    `json:"type"`
	Currency     string    `json:"currency"`
	Balance      Balance   `json:"balance"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	Resource     string    `json:"resource"`
	ResourcePath string    `json:"resource_path"`
	Ready        bool      `json:"ready,omitempty"`
}

type Dispatcher

type Dispatcher interface {
	Sign(m Message, apiSecret string) string
	GetEpochTime() int64
}

type Environment

type Environment struct {
	APIKey    string
	APISecret string
}

type GenericAccount

type GenericAccount struct {
	Name     string
	ID       string
	Currency string
	Amount   string
	Type     string
	Primary  bool
}

type GenericBuy

type GenericBuy struct {
	ID            string
	Status        string
	BuyQuantity   string
	BoughtWith    string
	BuyCurrency   string
	BuyTotal      string
	Fee           float64
	FeeCurrency   string
	Resource      string
	Committed     string
	CreatedAt     string
	TransactionID string
}

type GenericSell

type GenericSell struct {
	ID            string
	Status        string
	SellQuantity  string
	SoldWith      string
	SellCurrency  string
	SellTotal     string
	Fee           float64
	FeeCurrency   string
	Resource      string
	Committed     string
	CreatedAt     string
	TransactionID string
}

type Message

type Message struct {
	Method string
	Path   string
	Body   string
	Secret string
	URL    string
	Epoch  int64
}

type Pagination

type Pagination struct {
	EndingBefore  interface{} `json:"ending_before"`
	StartingAfter interface{} `json:"starting_after"`
	Limit         int         `json:"limit"`
	Order         string      `json:"order"`
	PreviousURI   interface{} `json:"previous_uri"`
	NextURI       interface{} `json:"next_uri"`
}

type Req

type Req string

func (Req) GetEpochTime

func (r Req) GetEpochTime() int64

func (Req) Sign

func (r Req) Sign(m Message, apiSecret string) string

type Sells

type Sells struct {
	Pagination struct {
		EndingBefore  interface{} `json:"ending_before"`
		StartingAfter interface{} `json:"starting_after"`
		Limit         int         `json:"limit"`
		Order         string      `json:"order"`
		PreviousURI   interface{} `json:"previous_uri"`
		NextURI       interface{} `json:"next_uri"`
	} `json:"pagination"`
	Data []struct {
		ID            string `json:"id"`
		Status        string `json:"status"`
		PaymentMethod struct {
			ID           string `json:"id"`
			Resource     string `json:"resource"`
			ResourcePath string `json:"resource_path"`
		} `json:"payment_method"`
		Transaction struct {
			ID           string `json:"id"`
			Resource     string `json:"resource"`
			ResourcePath string `json:"resource_path"`
		} `json:"transaction"`
		Amount struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"amount"`
		Total struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"total"`
		Subtotal struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"subtotal"`
		CreatedAt    string `json:"created_at"`
		UpdatedAt    string `json:"updated_at"`
		Resource     string `json:"resource"`
		ResourcePath string `json:"resource_path"`
		Committed    bool   `json:"committed"`
		Instant      bool   `json:"instant"`
		Fee          struct {
			Amount   string `json:"amount"`
			Currency string `json:"currency"`
		} `json:"fee"`
		PayoutAt string `json:"payout_at"`
	} `json:"data"`
}

type Sig

type Sig string

func (Sig) GenerateHMAC

func (s Sig) GenerateHMAC(data string, secret string) string

Hash-based message authentication code

func (Sig) GenerateSignature

func (s Sig) GenerateSignature(m Message) string

type Signer

type Signer interface {
	GenerateHMAC(data string, secret string) string
	GenerateSignature(message Message) string
}

type Task

type Task struct {
	Err     error
	ExecFn  func(ctx context.Context, acc GenericAccount) (AccountActivity, error)
	Account GenericAccount
}

func NewTask

func NewTask(f func(ctx context.Context, acc GenericAccount) (AccountActivity, error), account GenericAccount) *Task

func (*Task) Run

type WorkerPool

type WorkerPool struct {
	Done chan struct{}
	// contains filtered or unexported fields
}

func NewWorkerPool

func NewWorkerPool(concurrency int) WorkerPool

func (WorkerPool) GenerateFrom

func (wp WorkerPool) GenerateFrom(tasks []*Task)

func (WorkerPool) ResultSet

func (wp WorkerPool) ResultSet() <-chan AccountActivity

func (*WorkerPool) Run

func (wp *WorkerPool) Run(ctx context.Context)

Jump to

Keyboard shortcuts

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