Skip to main content

5 posts tagged with "double-entry accounting"

View all tags

The Accounting Cycle, Beancount-Style

· 9 min read
Mike Thrift
Mike Thrift
Marketing Manager

Financial statements don't appear by magic. They are the final product of a structured, repeatable process known as the accounting cycle. While the principles are universal, the tools you use can dramatically change the experience. This guide walks you through the accounting cycle with a focus on Beancount, the powerful plain-text accounting tool.

We'll see how Beancount's text-first approach eliminates tedious steps, what you should automate, and which reports give you the clearest picture of your financial health. 🧑‍💻

2025-08-13-the-accounting-cycle-beancount-style


TL;DR: The Beancount Workflow

  • Capture & Journal: Record every transaction as a clean, double-entry posting in your .beancount text file.
  • Validate & Reconcile: Use balance assertions to confirm your ledger matches bank statements and run bean-check to catch errors.
  • Review: Generate an unadjusted trial balance for a quick sanity check.
  • Adjust: Post entries for accruals, deferrals, depreciation, and other period-end items.
  • Re-review: Check the adjusted trial balance to ensure everything is correct.
  • Publish & Close: Generate your Income Statement, Balance Sheet, and Cash Flow statement. Closing the books is optional in Beancount, as reports are date-aware.

This flow can be visualized like this:


Step 1: Capture and Record Transactions

This is the foundational step. Every financial event—a sale, a purchase, a bank fee—must be recorded. In Beancount, you do this by creating transactions in a simple text file, typically named main.beancount or organized into multiple files by year.

Each transaction must follow the rules of double-entry bookkeeping, meaning the sum of all postings must be zero. Beancount enforces this for you.

2025-08-10 * "Walmart" "Purchase of office supplies"
Expenses:Office:Supplies 45.67 USD
Assets:Bank:Checking -45.67 USD
  • Pro-Tip: Use tags like #project-phoenix or #client-acme to add dimensions to your data. This makes querying and reporting incredibly flexible later on.

Reconciliation Hygiene ✅

The most powerful feature for ensuring accuracy is the balance assertion. At the end of a statement period (e.g., end of the month), you declare what the balance of an account should be.

2025-08-31 balance Assets:Bank:Checking  12345.67 USD

If the sum of all transactions affecting Assets:Bank:Checking up to that date doesn't equal 12345.67 USD, Beancount will raise an error. This simple directive turns your ledger into a self-auditing document.

For those backfilling historical data, the pad directive can automatically create a balancing transaction to make your opening balances match your first assertion.


Step 2: "Post to the Ledger" (A Freebie!)

In traditional accounting systems, you first write entries in a "journal," and then a separate "posting" step copies those values to the "general ledger."

With Beancount, your .beancount file is both the journal and the ledger. When you write and save a transaction, you've already posted it. There is no separate step. This directness is a core advantage of plain-text accounting—what you see is what you get.


Step 3: Prepare an Unadjusted Trial Balance

Before you start making adjustments, you need a quick "does this all add up?" check. A trial balance is a simple report that lists every account and its total balance. The grand total of all debit balances must equal the grand total of all credit balances.

You can generate this with a simple query:

bean-query main.beancount \
"SELECT account, sum(position) GROUP BY 1 ORDER BY 1"

Or, for a more visual approach, open your ledger in Fava (the web interface for Beancount) and navigate to the "Trial Balance" report. Look for anything unusual—an asset account with a credit balance, or an expense account with a strange value.


Step 4: Book Adjusting Entries

Adjusting entries are crucial for accurate reporting under the accrual basis of accounting. They ensure that revenues are recognized when earned and expenses are recognized when incurred, regardless of when cash changes hands.

Common adjustments include:

  • Accruals: Recording revenue you've earned but haven't invoiced yet, or an expense you've incurred but haven't paid.
  • Deferrals: Handling prepayments. If a customer pays you for a year of service upfront, you book it as a liability (Liabilities:UnearnedRevenue) and recognize 1/12th of it as income each month.
  • Non-Cash Items: Recording things like depreciation of assets.
  • Corrections: Fixing errors or accounting for missed items from bank feeds, like a small interest payment.

Example: Accruing Revenue

You finished a project on August 31st but won't send the invoice until September. To recognize the income in the correct period (August), you make an adjusting entry:

2025-08-31 * "Accrue revenue for client project #1042"
Assets:AccountsReceivable 3000.00 USD
Income:Consulting -3000.00 USD

Example: Recording Depreciation

Your company has a depreciation schedule for its assets. At the end of the period, you book the expense:

2025-12-31 * "Annual depreciation on computer equipment"
Expenses:Depreciation 4800.00 USD
Assets:Fixed:AccumulatedDepreciation -4800.00 USD

Step 5: Run an Adjusted Trial Balance & Validate

Once your adjusting entries are in, run the trial balance report again. This is your Adjusted Trial Balance. It provides the final set of numbers that will be used to create the financial statements.

This is also the perfect time to run Beancount's built-in sanity check:

bean-check main.beancount

This command verifies all syntax, balancing rules, and assertions. If it runs without any output, your books are mechanically sound.


Step 6: Publish Financial Statements 📊

This is the payoff. Using the numbers from your adjusted trial balance, you can now generate the key financial reports. Fava is the easiest way to do this, as it provides interactive, drill-down reports out of the box.

  • Income Statement (Profit & Loss): Shows your revenues and expenses over a period, resulting in your net income or loss.
  • Balance Sheet: A snapshot of what you own (Assets) and what you owe (Liabilities), as well as your net worth (Equity), on a specific date.
  • Cash Flow Statement: Reconciles your starting cash with your ending cash by showing where money came from and where it went.

For custom reports, you can use Beancount Query Language (BQL). Here’s a query for a monthly income statement:

-- P&L for August 2025
SELECT account, sum(position)
WHERE account ~ '^(Income|Expenses)'
AND date >= 2025-08-01 AND date <= 2025-08-31
GROUP BY account ORDER BY account;

Step 7: Closing the Books (Optional)

In traditional accounting, the "closing" process involves creating journal entries to zero out all temporary accounts (Income and Expenses) and transfer the net income into an equity account called Retained Earnings. This formally resets the temporary accounts for the next year.

In Beancount, this step is usually unnecessary. Fava's reports are date-aware; if you ask for a 2025 P&L, it will only use 2025 data. The balances don't "spill over." Most users simply leave the balances as they are.

However, if you need to perform a formal close for compliance or shareholder reporting, you can do so with a simple year-end transaction that moves the total income and expense balances into Equity:Retained-Earnings.


A Practical Monthly Close Checklist

Here’s a repeatable checklist to close your books each month using Beancount.

  • Capture: Import all bank and credit card transactions. Manually enter any cash expenses or out-of-band items.
  • Reconcile: Add balance assertions for all bank accounts, credit cards, and loan accounts, matching them to your statements.
  • Review: Scan the unadjusted trial balance in Fava. Investigate any strange or unexpected balances. Check for stale unpaid invoices (Assets:AccountsReceivable) or bills (Liabilities:AccountsPayable).
  • Adjust: Book entries for accrued revenue/expenses, deferred revenue, and any necessary corrections.
  • Validate: Run bean-check. Review the final adjusted trial balance.
  • Publish: Generate the P&L and Balance Sheet. Send them to stakeholders or save them for your records.
  • Wrap-up: Optionally, perform a closing entry if your business requires it. Archive a copy of your .beancount files for the period.

Why Beancount Shines for the Accounting Cycle

  • Transparency and Auditability: Your ledger is a text file. You can use git to version control your financial history, review changes with diff, and collaborate with your accountant in a clear, unambiguous format.
  • Total Control: You define your chart of accounts. You aren't locked into a software vendor's structure. Your data is yours, forever, in an open format.
  • Unmatched Power: The combination of SQL-like queries (BQL) and a rich web interface (Fava) gives you unparalleled power to slice, dice, and understand your financial data.

Copy-Paste Snippets to Get Started

Simple Chart of Accounts:

option "title" "My Personal Ledger"
option "operating_currency" "USD"

;; --- Accounts ---
1970-01-01 open Assets:Bank:Checking
1970-01-01 open Assets:AccountsReceivable
1970-01-01 open Liabilities:CreditCard
1970-01-01 open Liabilities:UnearnedRevenue
1970-01-01 open Equity:Owner:Capital
1970-01-01 open Equity:Retained-Earnings
1970-01-01 open Income:Consulting
1970-01-01 open Expenses:Office:Supplies
1970-01-01 open Expenses:Software
1970-01-01 open Expenses:Depreciation

Useful BQL Query:

-- Find all customers with an outstanding balance
SELECT payee, sum(position)
WHERE account = 'Assets:AccountsReceivable'
GROUP BY payee
HAVING sum(position) > 0
ORDER BY sum(position) DESC;

By mapping the timeless accounting cycle to Beancount's modern, text-based tools, you gain a system that is robust, transparent, and built to last. Happy bookkeeping!

Beancount.io vs. Traditional Accounting Software: Which One Fits You Best?

· 7 min read
Mike Thrift
Mike Thrift
Marketing Manager

For decades, the world of business accounting has been dominated by a familiar cast of closed, GUI-based systems like QuickBooks, Xero, and FreshBooks. They have set the standard, offering ease-of-use and visual workflows that cater to non-technical users. But for developers, power users, and anyone who values absolute transparency and control, a radically different approach has emerged: Beancount.io.

This article provides a direct comparison of Beancount.io with traditional accounting software. We'll break down their core differences in philosophy, flexibility, cost, and long-term maintainability to help you decide which system truly fits your needs.

2025-08-08-beancount-io-vs-traditional-accounting-software

1. Philosophy and Workflow

The most fundamental difference between these two approaches lies in their core philosophy.

Beancount.io Beancount.io is built on the philosophy of plain-text accounting. At its heart, every single financial transaction is an entry in a simple text file. This "accounting as code" model prioritizes human-readable, version-controllable records. Your financial data lives in a timeless, open format that you own completely—it can never be locked away by a vendor. This workflow is designed for users who are comfortable with code editors, version control systems like Git, and command-line tools.

Traditional Software Traditional accounting platforms are GUI-based and form-driven. You enter data using wizards, dropdown menus, and visual forms. This approach prioritizes immediacy and accessibility, making it easy for non-technical users to get started without a steep learning curve. However, your data is stored in a proprietary format or a cloud database, often requiring complex export and import procedures if you ever decide to migrate to another service.

Verdict: If you prioritize full control, data ownership, transparency, and automation, Beancount.io is the clear winner. If you need a "click and go" interface with a minimal learning curve, traditional software will feel more natural.

2. Flexibility and Customization

How well can the software adapt to your specific needs?

Beancount.io Being 100% scriptable is Beancount.io’s superpower. It integrates seamlessly with Python, allowing you to connect to any API, automate data fetching from bank feeds, programmatically tag transactions based on complex rules, and generate custom reports tailored to your exact specifications. Your ability to extend and customize is practically infinite, free from any vendor-imposed limitations.

Traditional Software These platforms offer a curated selection of integrations with popular tools like PayPal, Stripe, and various payroll services. While convenient, you are operating within the vendor's walled garden. Customization is limited to what the platform allows, and advanced reporting or automation often requires upgrading to a higher-tier plan or purchasing third-party add-ons. You can work with their APIs, but you'll always be bound by their ecosystem's rules and rate limits.

Verdict: Beancount.io provides unmatched flexibility for developers and technical users. Traditional tools are better suited for standard, plug-and-play workflows with popular business applications.

3. Collaboration and Transparency

How you work with others and audit your records differs significantly.

Beancount.io Collaboration on Beancount.io is managed through Git. This makes every change to your financial ledger completely transparent and auditable. You can see who changed what, when, and why—just like a code review workflow. This is ideal for distributed teams that already embrace tools like GitHub or GitLab. Furthermore, there are no hidden calculations; every number in a report can be traced back to the exact line-item entry in your ledger file, ensuring complete auditability.

Traditional Software Collaboration is handled through built-in user roles and permissions. You can invite your accountant, bookkeeper, or business partners to access the books directly through the web interface. This is highly effective for businesses that follow a traditional model of financial oversight. The downside is that some internal operations, like tax calculations or automated balance adjustments, can be opaque "black boxes," making it difficult to independently verify the logic.

Verdict: Beancount.io is perfect for teams that value granular auditability and code-style collaboration. Traditional systems are more accountant-friendly for real-time, shared GUI access.

4. Cost and Ownership

The financial models and the concept of data ownership are worlds apart.

Beancount.io The core Beancount software is open-source and free. You only pay for the value-added services of Beancount.io, which include hosting, intelligent automation, and premium features. There are no per-seat licensing fees, so you can scale your team without incurring extra costs. Most importantly, there is zero vendor lock-in. Your data is a collection of text files that you can move, edit, or store anywhere, anytime.

Traditional Software These services operate on a subscription model, typically billed monthly or yearly. Pricing is often tiered based on features, and you may face per-user or per-company fees that scale with your organization. This creates a dependency; if you stop paying, you risk losing access to your data and the software's functionality. This vendor lock-in is a significant long-term risk.

Verdict: Beancount.io is significantly more cost-effective in the long run, especially for technical teams that value data sovereignty. Traditional software offers predictable subscription costs but creates long-term dependency.

5. Learning Curve and Adoption

How quickly can you get up and running?

Beancount.io The learning curve is undeniably steeper. Adopting this system requires comfort with text-based editing, understanding basic syntax, and familiarity with tools like Git. However, the initial investment pays off. Once mastered, Beancount enables incredibly fast, repeatable workflows and provides a much deeper, foundational understanding of your financial picture.

Traditional Software These platforms are designed for non-technical business owners and offer minimal onboarding friction. You can be up and running, sending invoices and categorizing expenses, within minutes. That said, learning the more advanced features, such as custom report building or setting up multi-entity accounting, still requires a significant time investment.

Verdict: Beancount.io is the right choice if you're willing to invest time in learning a powerful system. Traditional software is faster to start with for non-technical users who need immediate results.

Side-by-Side Comparison

FeatureBeancount.ioTraditional Accounting Software
Core PhilosophyAccounting as code; plain-text ledgerGUI-based; form-driven
Data FormatOpen (Plain Text)Proprietary (Database)
Data Ownership100% user-owned and portableVendor-controlled; potential lock-in
FlexibilityInfinite; fully scriptable with PythonLimited to vendor's ecosystem & APIs
CollaborationGit-based; transparent change historyRole-based user permissions
TransparencyFully auditable; no hidden calculationsSome calculations can be opaque
Cost ModelOpen-source core; pay for hosting/automationMonthly/annual subscription (SaaS)
Learning CurveSteeper for non-technical usersLow; designed for quick start
Ideal UserDevelopers, power users, data analystsSMB owners, non-technical teams

When to Choose Each

The decision ultimately comes down to your team's skills, priorities, and workflow.

Choose Beancount.io if you:

  • Are a developer, data analyst, or technically-inclined power user.
  • Value absolute transparency, control, and long-term data portability above all else.
  • Want to fully automate your accounting and integrate it deeply into your custom workflows.
  • Are comfortable treating your financial records with the same rigor as source code.

Choose Traditional Accounting Software if you:

  • Want a quick-start, visual interface without any technical setup.
  • Need to provide immediate, accountant-friendly access with minimal training.
  • Prefer a managed, hosted solution where the vendor handles all updates and compliance.
  • Your integration needs are met by popular, off-the-shelf apps.

Final Thoughts

Beancount.io isn’t trying to be a better QuickBooks—it’s a fundamentally different way of thinking. It represents accounting as code. For technical professionals, this shift offers the same leap forward that version control with Git brought to software development: complete transparency, perfect reproducibility, and ultimate control.

At the same time, traditional accounting software continues to win on out-of-the-box ease-of-use and ready-made integrations for non-technical teams. The right choice isn't about which is "better" overall, but which is the perfect fit for your workflow, your priorities, and the degree of control you demand over your financial data.

Understanding Receivables and Payables in Beancount

· 3 min read
Mike Thrift
Mike Thrift
Marketing Manager

Hello everyone! In today's blog post, we're diving into the world of Beancount, a double-entry accounting tool that's loved by many for its simplicity and power. More specifically, we're going to talk about two key concepts: Receivables and Payables.

Understanding these terms is crucial to using Beancount (or any double-entry accounting system) effectively. But don't worry if you're a beginner - we're going to break it all down, step by step!

Receivables and Payables: The Basics

2023-05-30-receiveable-and-payable

In accounting, "receivables" and "payables" are terms used to track money that is owed. "Receivables" refers to money that others owe to you, while "payables" refers to money that you owe to others.

Let's take an example:

  1. Accounts Receivable (A/R): Suppose you own a bookstore and a customer buys a book on credit. The money they owe you for the book is an account receivable.

  2. Accounts Payable (A/P): On the flip side, imagine you order a new set of books from a publisher, but you don't pay for them upfront. The money you owe the publisher is an account payable.

In Beancount, these are typically tracked through corresponding accounts. The main benefit here is that it provides you with a clear and accurate picture of your financial position at any point in time.

Setting Up Receivables and Payables in Beancount

The structure of your Beancount file can be as simple or as complex as you need it to be. For receivables and payables, you'll likely want to create separate accounts under your Assets and Liabilities sections.

Here is a simple example:

1970-01-01 open Assets:AccountsReceivable
1970-01-01 open Liabilities:AccountsPayable

Tracking Transactions

Payee side

After setting up your accounts, you can track transactions that involve receivables and payables. Let's look at an example:

2023-05-29 * "Sold books to customer on credit"
Assets:AccountsReceivable 100 USD
Income:BookSales -100 USD

Here, you're adding $100 to your receivables because a customer owes you this amount. Simultaneously, you're reducing your income by the same amount to maintain the balance (since you haven't actually received the money yet).

When the customer eventually pays, you'll record it like this:

2023-06-01 * "Received payment from customer"
Assets:Bank:Savings 100 USD
Assets:AccountsReceivable -100 USD

Payer side

The same principle applies for payables, but with reversed signs:

2023-05-30 * "Bought books from publisher on credit"
Liabilities:AccountsPayable 200 USD
Expenses:BookPurchases -200 USD

And when you pay off your debt:

2023-06-02 * "Paid off debt to publisher"
Liabilities:AccountsPayable -200 USD
Assets:Bank:Checking 200 USD

Wrapping Up

Receivables and payables are at the heart of any accounting system. By accurately tracking these, you gain a comprehensive understanding of your financial health.

This is just a starting point, and Beancount is capable of much more. I hope this blog post helps clarify these important concepts. As always, happy accounting!

Beancount Cheat Sheet

· 2 min read
Mike Thrift
Mike Thrift
Marketing Manager

Example Account Name

Assets:US:BofA:Checking

cheatsheet-en

Account Types

Assets          +
Liabilities -
Income -
Expenses +
Equity -

Commodities

CNY, EUR, CAD, AUD
GOOG, AAPL, RBF1005
HOME_MAYST, AIRMILES
HOURS

Directives

General syntax

YYYY-MM-DD <Directive> <Parameters...>

Opening & Closing Accounts

2001-05-29 open Expenses:Restaurant
2001-05-29 open Assets:Checking USD,EUR ; Currency constraints

2015-04-23 close Assets:Checking

Declaring Commodities (Optional)

1998-07-22 commodity AAPL
name: "Apple Computer Inc."

Prices

2015-04-30 price AAPL   125.15 CNY
2015-05-30 price AAPL 130.28 CNY

Notes

2013-03-20 note Assets:Checking "Called to ask about rebate"

Documents

2013-03-20 document Assets:Checking "path/to/statement.pdf"

Transactions

2015-05-30 * "Some narration about this transaction"
Liabilities:CreditCard -101.23 CNY
Expenses:Restaurant 101.23 CNY

2015-05-30 ! "Cable Co" "Phone Bill" #tag ˆlink
id: "TW378743437" ; Meta-data
Expenses:Home:Phone 87.45 CNY
Assets:Checking ; You may leave one amount out

Postings

  ...    123.45 USD                             Simple
... 10 GOOG {502.12 USD} With per-unit cost
... 10 GOOG {{5021.20 USD}} With total cost
... 10 GOOG {502.12 # 9.95 USD} With both costs
... 1000.00 USD @ 1.10 CAD With per-unit price
... 10 GOOG {502.12 USD} @ 1.10 CAD With cost & price
... 10 GOOG {502.12 USD, 2014-05-12} With date
! ... 123.45 USD ... With flag

Balance Assertions and Padding

; Asserts the amount for only the given currency:
2015-06-01 balance Liabilities:CreditCard -634.30 CNY

; Automatic insertion of transaction to fulfill the following assertion:
2015-06-01pad Assets:Checking Equity:Opening-Balances

Events

2015-06-01 event "location" "New York, USA"
2015-06-30 event "address" "123 May Street"

Options

option "title" "My Personal Ledger"

Other

pushtag #trip-to-peru
...
poptag #trip-to-peru
; Comments begin with a semi-colon

Introduction to Beancount.io

· 5 min read
Mike Thrift
Mike Thrift
Marketing Manager

Why Modern Bookkeeping Matters

Still managing your investments with spreadsheets? While spreadsheets are versatile, they can become cumbersome and error-prone as your investment portfolio grows. Enter Beancount.io – a sophisticated yet user-friendly investment tracking platform designed specifically for managing stock and cryptocurrency portfolios. Built with engineers and financial minimalists in mind, Beancount.io combines powerful features with an intuitive interface to streamline your investment tracking experience.

2019-09-07-introduction-to-beancount

Expenses

Income Statement

Balance Sheet

Double-entry Bookkeeping: The Foundation of Accuracy

Beancount.io is built on the principles of double-entry accounting – a time-tested methodology used by financial institutions worldwide. This system ensures mathematical accuracy through a simple yet powerful concept: every financial transaction must balance perfectly.

In double-entry bookkeeping, each transaction requires at least two entries – a debit (+) and a credit (-) – across different accounts. This built-in verification system makes it virtually impossible to record unbalanced transactions, ensuring your financial records remain accurate and reliable.

1970-01-01 open Income:BeancountCorp
1970-01-01 open Assets:Cash
1970-01-01 open Expenses:Food
1970-01-01 open Assets:Receivables:Alice
1970-01-01 open Assets:Receivables:Bob
1970-01-01 open Assets:Receivables:Charlie
1970-01-01 open Liabilities:CreditCard

2019-05-31 * "BeancountCorp" "Salary of May 15th to May 31st"
Income:BeancountCorp -888 USD
Assets:Cash 888 USD

2019-07-12 * "Popeyes chicken sandwiches" "dinner with Alice, Bob, and Charlie"
Expenses:Food 20 USD
Assets:Receivables:Alice 20 USD
Assets:Receivables:Bob 20 USD
Assets:Receivables:Charlie 20 USD
Liabilities:CreditCard -80 USD

As you can see in the two examples above, every transaction must fulfill the accounting equation.

Assets = Liabilities + Equity(aka Net Assets)

We used the Beancount syntax by Martin Blais and the web project Fava by Jakob Schnitzer to build this website. And it will alert you if any transaction has any legs not summing to zero.

Error Alert

Now you understand how we enforce the correctness of the ledger. But you may ask what are those "accounts"?

Understanding Accounts: The Water Bucket Analogy

Think of your financial accounts as a system of interconnected water buckets, where money flows like water between them. This analogy makes double-entry bookkeeping intuitive: when you transfer money from one account to another, it's like pouring water from one bucket to another – the total amount of water (money) in the system remains constant.

Beancount.io introduces five kinds of accounts.

  1. Income — Its amount is always negative or in debit. This is because you are making money, and then the money is debiting from "Income" account and crediting to your "Assets."
  2. Expenses — Its amount is always positive or in credit. This is because you are spending money, and the money is flowing from the "Assets" or "Liabilities" to the "Expenses."
  3. Liabilities — Its amount is positive or zero. Your credit card liabilities are a good example, which rises and falls in cycles.
  4. Assets — Its amount is positive or zero. Your cash or houses are always worth some prices.
  5. Equity — Your net assets. The system will calculate automatically for you. Equity = Assets - Liabilities and it reflects how wealthy you are.

Now you can open your customized accounts with those keywords above:

1970-01-01 open Assets:Cash
1970-01-01 open Assets:Stock:Robinhood
1970-01-01 open Assets:Crypto:Coinbase
1970-01-01 open Expenses:Transportation:Taxi
1970-01-01 open Equity:OpeningBalance

Advanced Investment Tracking with Commodities

Beancount.io excels at tracking diverse investments, from stocks to cryptocurrencies. Let's explore how it handles complex investment scenarios. For example, here's how you would record purchasing 10 Bitcoins at $100 each in 2014:

2014-08-08 * "Buy 10 Bitcoin"
Assets:Trade:Cash -1000.00 USD
Assets:Trade:Positions 10 BTC {100.00 USD}

And then three years later, you sell them (originally with costs of $100 per unit annotated with {100.00 USD}) at the price of $10,000 per unit annotated with @ 10,000.00 USD.

2017-12-12 * "Sell 2 Bitcoin"
Assets:Trade:Positions -2 BTC {100.00 USD} @ 10,000.00 USD
Assets:Trade:Cash 20,000.00 USD
Income:Trade:PnL -19,800.00 USD

Or the same transaction with @@ 20,000.00 USD means that at the price of $20,000 in total.

2017-12-12 * "Sell 2 Bitcoin"
Assets:Trade:Positions -2 BTC {100.00 USD} @@ 20,000.00 USD
Assets:Trade:Cash 20,000.00 USD
Income:Trade:PnL -19,800.00 USD

The sum of all legs of the transaction, including -2 BTC {100.00 USD}, are still, as always, zero.

The costs {100.00 USD} tag is important because you might have bought the same commodity at different costs.

100 BTC {10.00 USD, 2012-08-08}
10 BTC {100.00 USD, 2014-08-08}

If you want to simplify the process, you can set up the account at the beginning with FIFO or LIFO. FIFO stands for first in, first out, while LIFO stands for last in, first out. In the US, IRS uses FIFO to calculate your PnL and tax accordingly.

1970-01-01 open Assets:Trade:Positions "FIFO"

And then when you sell it in shorthand like -2 BTC {}, beancount will apply FIFO strategy automatically and sell the oldest commodity.

Getting Started with Beancount.io

Beancount.io is a modern cloud-based financial management platform that transforms your text-based transaction records into comprehensive financial statements, including income statements, balance sheets, and trial balances. By combining the reliability of plain text files with powerful visualization tools, Beancount.io helps you maintain precise control over your financial life while gaining valuable insights into your investment performance.

Start your financial journey with Beancount.io - Free during our promotional period!