ynab

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 10 Imported by: 0

README

ynab-go

This is a You Need a Budget client but it's incomplete. Right now the only supported endpoints are the ones necessary to do the Age of Money calculation.

Age of Money

This command will print out more information about how old your money is.

Set YNAB_TOKEN to your API token in your environment. You can find your token on the Settings page: https://app.youneedabudget.com/settings

Finally, run the binary:

go run ./cmd/ynab-age-of-money --budget='Personal Budget'

The output will look something like this:

 70 earned: 2019-02-07 spent: 2019-04-18     $25.00 Cash Exxon Mobil
 71 earned: 2019-02-07 spent: 2019-04-19      $3.00 Cash Shaska Cafe
 71 earned: 2019-02-07 spent: 2019-04-19      $2.00 Cash Shaska Cafe
 72 earned: 2019-02-07 spent: 2019-04-20      $4.00 Cash Aces
 75 earned: 2019-02-07 spent: 2019-04-23      $6.00 Cash Corner Store
 75 earned: 2019-02-07 spent: 2019-04-23      $3.00 Cash Lava Java
 76 earned: 2019-02-07 spent: 2019-04-24    $123.45 Shared Checking Transfer : Credit Card 1
 76 earned: 2019-02-07 spent: 2019-04-24    $456.78 Shared Checking Transfer : Credit Card 2
 77 earned: 2019-02-07 spent: 2019-04-25      $3.00 Cash Lava Java
 77 earned: 2019-02-07 spent: 2019-04-25      $2.00 Cash Corner Store

upcoming spending thresholds (and age if you spent today):
 78 2019-02-07   $1000.00 Personal Checking Employer 1
 74 2019-02-11   $2000.00 Shared Checking Employer 2
 73 2019-02-12   $2020.00 Personal Checking Venmo
 71 2019-02-14   $3020.00 Shared Checking Employer 2
 66 2019-02-19   $3060.00 Cash Laura Cash
 60 2019-02-25   $3065.00 Shared Checking Bank Interest
 60 2019-02-25   $3070.00 Personal Checking Bank Interest

The number in the far left hand column is the age of money, in days, for each transaction. The thresholds show the upcoming age of money when you spend it.

The flags are:

  -budget-name string
    	Name of the budget to compute AOM for
  -debug
    	Enable debug
  -file string
    	Filename to read txns from

You will need to specify --budget-name if you have more than one budget. --debug provides more information about all of the buckets you have as well as all of the accounts you have. --file is useful if you are making a lot of requests - save the JSON transaction data to a file and load it from there.

Errata

YNAB uses a weighted average to calculate age of money for a single transaction if it spans multiple buckets. I choose the date of the bucket the last penny was taken out of, so the numbers may be slightly lower here than in your dashboard.

YNAB averages the last ten transactions to get the Age of Money. I print accurate results for each transaction in your account.

Largest Inputs and Outputs

The ynab-largest-inputs-outputs command finds the largest inputs and outputs to your Net Worth, optionally filtered by a month argument. Any income or outflows that come into either your budget accounts or your tracking accounts will appear here. One exception is that credit card spending is accounted at the time of payment, not at the time the money is spent.

Pass the --month flag to filter by a given month. The flag accepts arguments in the form of 'Jan 2006', e.g. --month='Aug 2019'.

Disclaimer

I spot checked the results against my account, and they appeared to be accurate. They may not be correct for your account. This software is provided "as is" and I am not liable for any claim or damages arising from how you use this library.

License

MIT

Support

You can hire me: https://burke.services

I maintain this software in my free time. Donations free up time to make improvements to the library, and respond to bug reports. You can send donations via Paypal's "Send Money" feature to kev@inburke.com. Donations are not tax deductible in the USA.

Documentation

Index

Constants

View Source
const Version = "1.2.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID              string
	Name            string
	Type            string
	OnBudget        bool `json:"on_budget"`
	Closed          bool
	Note            string
	Balance         int64
	StartingBalance int64 `json:"starting_balance"`
	Deleted         bool
}

func (Account) CashBacked

func (a Account) CashBacked() bool

type AccountListResponse

type AccountListResponse struct {
	Data AccountListWrapper `json:"data"`
}

type AccountListWrapper

type AccountListWrapper struct {
	Accounts []*Account `json:"accounts"`
}

type Budget

type Budget struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type BudgetListResponse

type BudgetListResponse struct {
	Data BudgetListWrapper `json:"data"`
}

type BudgetListWrapper

type BudgetListWrapper struct {
	Budgets []*Budget `json:"budgets"`
}

type BudgetService

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

func (*BudgetService) Accounts added in v1.0.0

func (b *BudgetService) Accounts(ctx context.Context, data url.Values) (*AccountListResponse, error)

func (*BudgetService) Categories added in v1.0.0

func (b *BudgetService) Categories(ctx context.Context, data url.Values) (*CategoryListResponse, error)

func (*BudgetService) CreateTransaction added in v1.1.0

func (*BudgetService) ScheduledTransactions added in v1.0.0

func (b *BudgetService) ScheduledTransactions(ctx context.Context, data url.Values) (*ScheduledTransactionListResponse, error)

func (*BudgetService) Transactions added in v1.0.0

func (b *BudgetService) Transactions(ctx context.Context, data url.Values) (*TransactionListResponse, error)

func (*BudgetService) UpdateTransaction added in v1.0.0

func (b *BudgetService) UpdateTransaction(ctx context.Context, transactionID string, req *UpdateTransactionRequest) (*TransactionResponse, error)

type Category

type Category struct {
	ID              string
	Name            string
	CategoryGroupID string `json:"category_group_id"`
	Note            string
	Hidden          bool
	Budgeted        int64
	Activity        int64
}

type CategoryGroup

type CategoryGroup struct {
	ID         string
	Name       string
	Hidden     bool
	Deleted    bool
	Categories []*Category
}

type CategoryListResponse

type CategoryListResponse struct {
	Data CategoryListWrapper `json:"data"`
}

type CategoryListWrapper

type CategoryListWrapper struct {
	CategoryGroups []*CategoryGroup `json:"category_groups"`
}

type ClearedStatus added in v1.1.0

type ClearedStatus string

ClearedStatus represents the cleared status of a transaction

const (
	ClearedStatusCleared    ClearedStatus = "cleared"
	ClearedStatusUncleared  ClearedStatus = "uncleared"
	ClearedStatusReconciled ClearedStatus = "reconciled"
)

type Client

type Client struct {
	*restclient.Client

	Budgets func(budgetID string) *BudgetService
}

func NewClient

func NewClient(token string) *Client

func (*Client) GetBudgets added in v1.0.0

func (c *Client) GetBudgets(ctx context.Context, data url.Values) (*BudgetListResponse, error)

func (*Client) MakeRequest added in v0.6.0

func (c *Client) MakeRequest(ctx context.Context, method string, pathPart string, data url.Values, reqBody interface{}, v interface{}) error

func (*Client) NewRequestWithContext

func (c *Client) NewRequestWithContext(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)

func (*Client) PutResource added in v0.6.0

func (c *Client) PutResource(ctx context.Context, pathPart string, sid string, req interface{}, resp interface{}) error

type CreateTransactionData added in v1.1.0

type CreateTransactionData struct {
	TransactionIDs  []string     `json:"transaction_ids"`
	Transaction     *Transaction `json:"transaction,omitempty"`
	ServerKnowledge int64        `json:"server_knowledge"`
}

type CreateTransactionRequest added in v1.1.0

type CreateTransactionRequest struct {
	Transaction *NewTransaction `json:"transaction"`
}

type CreateTransactionResponse added in v1.1.0

type CreateTransactionResponse struct {
	Data CreateTransactionData `json:"data"`
}

type Date

type Date time.Time

func (Date) GoString

func (t Date) GoString() string

func (Date) MarshalJSON added in v0.5.0

func (t Date) MarshalJSON() ([]byte, error)

func (Date) String

func (t Date) String() string

func (*Date) UnmarshalJSON

func (t *Date) UnmarshalJSON(b []byte) error

type FlagColor added in v0.7.0

type FlagColor string

FlagColor represents the available flag colors for transactions

const (
	FlagColorRed    FlagColor = "red"
	FlagColorOrange FlagColor = "orange"
	FlagColorYellow FlagColor = "yellow"
	FlagColorGreen  FlagColor = "green"
	FlagColorBlue   FlagColor = "blue"
	FlagColorPurple FlagColor = "purple"
	FlagColorEmpty  FlagColor = ""
)

func (FlagColor) MarshalJSON added in v0.7.0

func (fc FlagColor) MarshalJSON() ([]byte, error)

func (*FlagColor) UnmarshalJSON added in v0.7.0

func (fc *FlagColor) UnmarshalJSON(b []byte) error

type NewSubTransaction added in v1.1.0

type NewSubTransaction struct {
	Amount     int64            `json:"amount"`
	PayeeID    types.NullString `json:"payee_id,omitempty"`
	PayeeName  types.NullString `json:"payee_name,omitempty"`
	CategoryID types.NullString `json:"category_id,omitempty"`
	Memo       types.NullString `json:"memo,omitempty"`
}

type NewTransaction added in v1.1.0

type NewTransaction struct {
	AccountID       string               `json:"account_id"`
	Date            Date                 `json:"date"`
	Amount          int64                `json:"amount"`
	PayeeID         types.NullString     `json:"payee_id,omitempty"`
	PayeeName       types.NullString     `json:"payee_name,omitempty"`
	CategoryID      types.NullString     `json:"category_id,omitempty"`
	Memo            types.NullString     `json:"memo,omitempty"`
	Cleared         ClearedStatus        `json:"cleared,omitempty"`
	Approved        bool                 `json:"approved"` // Defaults to false if not specified
	FlagColor       FlagColor            `json:"flag_color,omitempty"`
	Subtransactions []*NewSubTransaction `json:"subtransactions,omitempty"`
	ImportID        types.NullString     `json:"import_id,omitempty"`
}

type NullDate added in v0.7.0

type NullDate struct {
	Valid bool
	Date  Date
}

A NullDate is a Date that may be null.

func (NullDate) MarshalJSON added in v0.7.0

func (nt NullDate) MarshalJSON() ([]byte, error)

func (*NullDate) UnmarshalJSON added in v0.7.0

func (nt *NullDate) UnmarshalJSON(b []byte) error

type ScheduledTransaction

type ScheduledTransaction struct {
	AccountID         string `json:"account_id"`
	AccountName       string `json:"account_name"`
	Amount            int64
	Approved          bool
	CategoryName      types.NullString `json:"category_name"`
	Cleared           string
	DateFirst         Date `json:"date_first"`
	DateNext          Date `json:"date_next"`
	Deleted           bool
	FlagColor         FlagColor `json:"flag_color"`
	Frequency         string
	ID                string `json:"id"`
	Memo              string
	PayeeName         string           `json:"payee_name"`
	TransferAccountID types.NullString `json:"transfer_account_id"`
	Subtransactions   []Transaction    `json:"subtransactions"`
}

type ScheduledTransactionListResponse

type ScheduledTransactionListResponse struct {
	Data ScheduledTransactionListWrapper `json:"data"`
}

type ScheduledTransactionListWrapper

type ScheduledTransactionListWrapper struct {
	ScheduledTransactions []*ScheduledTransaction `json:"scheduled_transactions"`
}

type SubTransaction added in v0.6.0

type SubTransaction struct {
	Amount     int64            `json:"amount"`
	PayeeID    types.NullString `json:"payee_id,omitempty"`
	PayeeName  types.NullString `json:"payee_name,omitempty"`
	CategoryID types.NullString `json:"category_id,omitempty"`
	Memo       types.NullString `json:"memo,omitempty"`
}

type Transaction

type Transaction struct {
	AccountID             string `json:"account_id"`
	AccountName           string `json:"account_name"`
	Amount                int64
	Approved              bool
	CategoryID            types.NullString `json:"category_id"`
	CategoryName          types.NullString `json:"category_name"`
	Cleared               string
	Date                  Date
	Deleted               bool
	FlagColor             FlagColor `json:"flag_color"`
	ID                    string    `json:"id"`
	Memo                  string
	PayeeName             string           `json:"payee_name"`
	TransferAccountID     types.NullString `json:"transfer_account_id"`
	TransferTransactionID types.NullString `json:"transfer_transaction_id"`
	MatchedTransactionID  types.NullString `json:"matched_transaction_id"`
	Subtransactions       []Transaction    `json:"subtransactions"`
}

type TransactionListResponse

type TransactionListResponse struct {
	Data TransactionListWrapper `json:"data"`
}

type TransactionListWrapper

type TransactionListWrapper struct {
	Transactions []*Transaction `json:"transactions"`
}

type TransactionResponse added in v0.6.0

type TransactionResponse struct {
	Data TransactionWrapper `json:"data"`
}

type TransactionWrapper added in v0.6.0

type TransactionWrapper struct {
	Transaction *Transaction `json:"transaction"`
}

type UpdateTransaction added in v0.6.0

type UpdateTransaction struct {
	AccountID       *string           `json:"account_id,omitempty"`
	Date            Date              `json:"date"`
	Amount          *int64            `json:"amount,omitempty"`
	PayeeID         types.NullString  `json:"payee_id,omitempty"`
	PayeeName       types.NullString  `json:"payee_name,omitempty"`
	CategoryID      types.NullString  `json:"category_id,omitempty"`
	Memo            types.NullString  `json:"memo,omitempty"`
	Cleared         types.NullString  `json:"cleared,omitempty"`
	Approved        *bool             `json:"approved,omitempty"`
	FlagColor       types.NullString  `json:"flag_color,omitempty"`
	Subtransactions []*SubTransaction `json:"subtransactions,omitempty"`
}

type UpdateTransactionRequest added in v0.6.0

type UpdateTransactionRequest struct {
	Transaction *UpdateTransaction `json:"transaction"`
}

Directories

Path Synopsis
The ynab-export-transactions command retrieves transactions and prints them to stdout in CSV format.
The ynab-export-transactions command retrieves transactions and prints them to stdout in CSV format.
The ynab-largest-inputs-outputs function finds the largest inputs and outputs to your Net Worth, optionally filtered by a month argument.
The ynab-largest-inputs-outputs function finds the largest inputs and outputs to your Net Worth, optionally filtered by a month argument.

Jump to

Keyboard shortcuts

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