accounting

package
v1.0.0-rc Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TransactionTypeToAction = map[string]Action{
	"Buy":               BUY,
	"Sell":              SELL,
	"Paid for an order": SELL,
	"Send":              SELL,
	"Convert":           SELL,
	"Coinbase Earn":     BUY,
}

TransactionTypeToAction converts Coinbase transaction types into BUY or SELL Actions

Functions

This section is empty.

Types

type Account

type Account struct {
	Holdings map[string]*LotHistory
}

Account is a Coinbase account, containing a LotHistory per crypto asset

func NewAccount

func NewAccount() *Account

NewAccount initializes an Account struct

func (*Account) ProcessTransaction

func (a *Account) ProcessTransaction(t *Transaction, sales chan<- *Sale) error

ProcessTransaction replays a transaction in the account, sending any resulting Sales to the sales channel

func (*Account) Report

func (a *Account) Report() string

Report returns a string containing an account summary

type Action

type Action int

Action is either a buy or sale of a crypto

const (
	// BUY is a purchase event of crypto
	BUY Action = iota
	// SELL is a crypto sale event, including conversion into a different asset or paying for an order
	SELL Action = iota
)

type Lot

type Lot struct {
	PurchaseDate time.Time
	Quantity     decimal.Decimal
	Spot         decimal.Decimal
}

Lot is an amount of crypto purchased in a single event. Used for calculating cost basis and date purchased for accounting purposes.

func (Lot) TotalCost

func (l Lot) TotalCost() decimal.Decimal

TotalCost is the cost (in USD) of a lot

type LotHistory

type LotHistory struct {
	Asset string
	Lots  []*Lot
}

LotHistory is a queue data structure that is used to account for all lots of a specific crypto asset.

func (*LotHistory) Buy

func (h *LotHistory) Buy(l *Lot) error

Buy adds a lot to the lot record

func (*LotHistory) Quantity

func (h *LotHistory) Quantity() decimal.Decimal

Quantity returns the total number of shares in the LotHistory

func (*LotHistory) Sell

func (h *LotHistory) Sell(quantity decimal.Decimal, spot decimal.Decimal, date time.Time, sales chan<- *Sale) error

Sell processes a transaction against this LotHistory, adding any resulting Sale events to the sales channel

func (*LotHistory) TotalCost

func (h *LotHistory) TotalCost() decimal.Decimal

TotalCost returns the total cost (in USD) of the shares in the LotHistory

type NegativeQuantityErr

type NegativeQuantityErr struct{}

NegativeQuantityErr is an error for a transaction with a negative quantity

func (*NegativeQuantityErr) Error

func (m *NegativeQuantityErr) Error() string

type NegativeSpotErr

type NegativeSpotErr struct{}

NegativeSpotErr is an error for a transaction with a negative spot price

func (*NegativeSpotErr) Error

func (m *NegativeSpotErr) Error() string

type Sale

type Sale struct {
	Asset        string
	SaleDate     time.Time
	PurchaseDate time.Time
	Quantity     decimal.Decimal
	FifoCost     decimal.Decimal
	Proceeds     decimal.Decimal
}

Sale is a taxable sale event

type Transaction

type Transaction struct {
	Timestamp time.Time
	Action    Action
	Asset     string
	Quantity  decimal.Decimal
	Spot      decimal.Decimal
	Currency  string
}

Transaction is a crypto transaction as reported by Coinbase

func (Transaction) ToLot

func (t Transaction) ToLot() *Lot

ToLot converts a transaction to a Lot used for accounting purposes

Jump to

Keyboard shortcuts

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