Skip to content

Open Directive ​

Overview ​

The open directive declares an account's existence and optionally constrains its allowed currencies and booking method.

Syntax ​

ebnf
open = date WHITESPACE "open" WHITESPACE account
       [WHITESPACE currency_list]
       [WHITESPACE booking_method]
       (NEWLINE metadata)*

currency_list  = currency ("," currency)*
booking_method = string

Components ​

Date ​

The date the account becomes available for use. Postings to this account before this date will produce validation errors.

Account ​

The full account name including root type:

beancount
2024-01-01 open Assets:US:BofA:Checking
2024-01-01 open Liabilities:CreditCard:Chase
2024-01-01 open Expenses:Food:Groceries

Currency Constraint ​

Optional list of allowed currencies:

beancount
; Allow only USD
2024-01-01 open Assets:Checking USD

; Allow multiple currencies
2024-01-01 open Assets:Brokerage USD,EUR,AAPL,MSFT

; Allow any currency (default)
2024-01-01 open Expenses:Food

When specified, postings using other currencies will produce validation errors.

Booking Method ​

Optional string specifying how lot matching works for reductions:

beancount
2024-01-01 open Assets:Brokerage USD,AAPL "FIFO"
2024-01-01 open Assets:Retirement USD,VTSAX "LIFO"
2024-01-01 open Assets:Trading USD,BTC "STRICT"

Booking Methods ​

MethodDescription
STRICTRequire exact lot specification (default)
STRICT_WITH_SIZELike STRICT but also requires matching size
FIFOFirst-in, first-out
LIFOLast-in, first-out
HIFOHighest cost first
NONEAllow any reduction (no lot tracking)
AVERAGEUse average cost basis

Booking methods MUST be uppercase. Lowercase methods (e.g., "fifo") are rejected.

See booking.md for detailed booking method documentation.

Examples ​

Basic Account ​

beancount
2024-01-01 open Assets:Checking

With Currency Constraint ​

beancount
2024-01-01 open Assets:US:Schwab:Cash USD
2024-01-01 open Assets:EU:Bank:Cash EUR

With Booking Method ​

beancount
; Retirement account with FIFO booking
2024-01-01 open Assets:Retirement:401k USD,VTSAX "FIFO"

; Trading account requiring explicit lot selection
2024-01-01 open Assets:Trading:Coinbase USD,BTC,ETH "STRICT"

With Metadata ​

beancount
2024-01-01 open Assets:Checking USD
  institution: "Bank of America"
  account-number: "****1234"
  opened-by: "online"

Account Naming ​

Root Types ​

Every account MUST start with one of five root types:

RootPurposeNormal Balance
AssetsThings you ownDebit
LiabilitiesThings you oweCredit
EquityNet worth, opening balancesCredit
IncomeMoney receivedCredit
ExpensesMoney spentDebit

Component Rules ​

  • Components are separated by colons (:)
  • Each component MUST begin with an uppercase ASCII letter (A-Z) or digit (0-9)
  • Subsequent characters may be letters (including UTF-8), numbers, or hyphens
  • UTF-8 characters are allowed ONLY after the first ASCII character
  • Components MUST NOT contain spaces

Valid Examples ​

Assets:US:BofA:Checking
Liabilities:CreditCard:Chase-Sapphire
Expenses:Food:Groceries
Income:Salary:2024
Equity:Opening-Balances

Invalid Examples ​

assets:Checking           ; lowercase root
Assets:checking           ; lowercase component
Assets:My Checking        ; space in component
Assets::Checking          ; empty component
Savings:Account           ; invalid root type

Validation ​

The following conditions produce validation errors:

ConditionError Type
Account already opened (duplicate open)ValidationError
Invalid account nameParserError
Posting uses currency not in constraint listValidationError
Invalid booking methodParserError

Auto Accounts Plugin ​

Implicit account opening (creating accounts on first use) is supported via a plugin:

beancount
plugin "beancount.plugins.auto_accounts"

When enabled, accounts are automatically opened on their first use. This is NOT recommended for production ledgers as it bypasses the validation that ensures all accounts are explicitly declared.

Relationship to Close ​

Accounts opened with open can be closed with close:

beancount
2020-01-01 open Assets:OldAccount USD
; ... transactions ...
2024-12-31 close Assets:OldAccount

After closing, the account cannot be used in new postings.

Implementation Notes ​

  1. Store the open date for lifecycle validation
  2. Store currency constraints for posting validation
  3. Store booking method for inventory operations
  4. Track all opened accounts for reference validation