trade-accounting

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Trade Accounting

交易会计

Run your trading operation like a business. Every SOL spent, every token acquired, every fee paid, every gain realized — tracked with double-entry bookkeeping so your books always balance. Whether you trade through a personal wallet or an LLC, proper accounting turns chaos into clarity.
Core principle: Every transaction touches at least two accounts. Buy a token? Cash goes down, token holdings go up — by the same amount. This double-entry constraint catches errors automatically: if debits do not equal credits, something is wrong.
像经营企业一样管理你的交易业务。每一笔支出的 SOL、每一笔获得的代币、每一笔支付的费用、每一项已实现收益——都通过复式记账进行追踪,确保账簿始终保持平衡。无论你通过个人钱包还是 LLC 进行交易,正确的会计核算都能将混乱化为清晰。
核心原则:每笔交易至少涉及两个账户。买入代币?现金减少,代币持仓增加——金额相同。这项复式记账约束能自动发现错误:如果借方不等于贷方,就说明出了问题。

Why Traders Need Accounting

为什么交易者需要会计核算

Most traders track P&L loosely — "I started with 50 SOL and now I have 62 SOL." That tells you nothing about:
  • How much came from realized trades vs unrealized positions
  • What you paid in cumulative fees (gas, priority fees, swap fees)
  • Whether your staking and LP income covers your operating costs
  • Your actual cost basis for each holding (critical for taxes)
  • Cash flow timing — are you profitable but illiquid?
Proper accounting answers all of these. It also separates trading P&L (mark-to-market, useful for strategy evaluation) from tax P&L (realized gains using a specific cost basis method, required for compliance).

大多数交易者只是粗略跟踪 P&L——“我开始时有 50 SOL,现在有 62 SOL。”这无法告诉你:
  • 有多少收益来自已实现交易,而非未实现头寸
  • 累计支付了多少手续费(gas、优先费、swap 费用)
  • 质押和 LP 收入是否足以覆盖运营成本
  • 每项持仓的实际成本基础(对税务至关重要)
  • 现金流时点——你是否账面盈利但流动性不足?
正确的会计核算可以回答所有这些问题。它还能将交易 P&L(按市值计价,适用于策略评估)与税务 P&L(采用特定成本基础方法计算已实现收益,用于合规)区分开来。

Account Types

账户类型

A trading operation uses four account categories following standard accounting:
CategoryNormal BalanceExamples
AssetsDebitCash (SOL/USDC), token holdings, LP positions, staking deposits, receivables
LiabilitiesCreditMargin borrowing, accrued taxes payable
IncomeCreditRealized trading gains, staking rewards, airdrop income, LP fee income
ExpensesDebitTrading fees, gas/priority fees, subscription costs, data feeds
EquityCreditOwner capital contributions, retained earnings, withdrawals (contra)
交易运营遵循标准会计原则,采用以下账户类别:
类别正常余额示例
资产借方现金(SOL/USDC)、代币持仓、LP 头寸、质押存款、应收款
负债贷方保证金借款、应计应付税款
收入贷方已实现交易收益、质押奖励、空投收入、LP 费用收入
费用借方交易手续费、gas/优先费、订阅成本、数据源
权益贷方所有者资本投入、留存收益、提款(权益抵减项)

Chart of Accounts

科目表

See
references/planned_features.md
for a full chart of accounts. A minimal setup:
1000  Assets
  1010  Cash – SOL
  1020  Cash – USDC
  1100  Token Holdings (one sub-account per token)
  1200  LP Positions
  1300  Staking Deposits

3000  Income
  3010  Realized Trading Gains
  3020  Staking Rewards
  3030  Airdrop Income
  3040  LP Fee Income

4000  Expenses
  4010  Trading Fees (DEX swap fees)
  4020  Gas & Priority Fees
  4030  Slippage Cost

5000  Equity
  5010  Owner Capital
  5020  Retained Earnings
  5030  Owner Withdrawals (contra-equity)

完整的科目表请参阅
references/planned_features.md
。最小化配置如下:
1000  Assets
  1010  Cash – SOL
  1020  Cash – USDC
  1100  Token Holdings (one sub-account per token)
  1200  LP Positions
  1300  Staking Deposits

3000  Income
  3010  Realized Trading Gains
  3020  Staking Rewards
  3030  Airdrop Income
  3040  LP Fee Income

4000  Expenses
  4010  Trading Fees (DEX swap fees)
  4020  Gas & Priority Fees
  4030  Slippage Cost

5000  Equity
  5010  Owner Capital
  5020  Retained Earnings
  5030  Owner Withdrawals (contra-equity)

Double-Entry Bookkeeping

复式记账

Every transaction records equal debits and credits. Debits increase asset and expense accounts; credits increase liability, income, and equity accounts.
每笔交易都记录金额相等的借方和贷方。借方增加资产和费用账户;贷方增加负债、收入和权益账户。

Entry Examples

分录示例

Buy 1000 BONK for 0.5 SOL (0.001 SOL gas fee):
AccountDebitCredit
Token Holdings – BONK0.501 SOL
Cash – SOL0.501 SOL
Or with the fee broken out explicitly:
AccountDebitCredit
Token Holdings – BONK0.5 SOL
Gas & Priority Fees0.001 SOL
Cash – SOL0.501 SOL
Sell 1000 BONK for 0.8 SOL (cost basis was 0.5 SOL, 0.001 SOL gas):
AccountDebitCredit
Cash – SOL0.799 SOL
Gas & Priority Fees0.001 SOL
Token Holdings – BONK0.5 SOL
Realized Trading Gains0.3 SOL
Receive staking rewards of 0.05 SOL:
AccountDebitCredit
Cash – SOL0.05 SOL
Staking Rewards0.05 SOL
Receive airdrop of 5000 JUP (valued at 2.1 SOL at receipt):
AccountDebitCredit
Token Holdings – JUP2.1 SOL
Airdrop Income2.1 SOL
Collect LP fees of 0.03 SOL:
AccountDebitCredit
Cash – SOL0.03 SOL
LP Fee Income0.03 SOL
Partial close — sell half a position:
If you hold 2000 BONK at cost basis 1.0 SOL and sell 1000 for 0.7 SOL:
AccountDebitCredit
Cash – SOL0.699 SOL
Gas & Priority Fees0.001 SOL
Token Holdings – BONK0.5 SOL
Realized Trading Gains0.2 SOL
The cost basis of the sold portion (0.5 SOL = half of 1.0 SOL) is removed from the asset account.

使用 0.5 SOL 买入 1000 BONK(gas 费为 0.001 SOL):
账户借方贷方
代币持仓 – BONK0.501 SOL
现金 – SOL0.501 SOL
或者将费用单独列明:
账户借方贷方
代币持仓 – BONK0.5 SOL
gas 与优先费0.001 SOL
现金 – SOL0.501 SOL
卖出 1000 BONK,获得 0.8 SOL(成本基础为 0.5 SOL,gas 费为 0.001 SOL):
账户借方贷方
现金 – SOL0.799 SOL
gas 与优先费0.001 SOL
代币持仓 – BONK0.5 SOL
已实现交易收益0.3 SOL
收到 0.05 SOL 的质押奖励:
账户借方贷方
现金 – SOL0.05 SOL
质押奖励0.05 SOL
收到 5000 JUP 空投(收到时估值为 2.1 SOL):
账户借方贷方
代币持仓 – JUP2.1 SOL
空投收入2.1 SOL
收取 0.03 SOL 的 LP 费用:
账户借方贷方
现金 – SOL0.03 SOL
LP 费用收入0.03 SOL
部分平仓——卖出一半头寸:
如果你持有 2000 BONK,成本基础为 1.0 SOL,并卖出 1000 个,获得 0.7 SOL:
账户借方贷方
现金 – SOL0.699 SOL
gas 与优先费0.001 SOL
代币持仓 – BONK0.5 SOL
已实现交易收益0.2 SOL
已卖出部分的成本基础(0.5 SOL,即 1.0 SOL 的一半)会从资产账户中扣除。

Transaction Types

交易类型

The ledger handles these trading flows:
FlowAccounts Touched
Fund accountCash (debit), Owner Capital (credit)
Withdraw fundsOwner Withdrawals (debit), Cash (credit)
Buy tokenToken Holdings (debit), Cash (credit), Gas Expense (debit)
Sell tokenCash (debit), Token Holdings (credit), Realized Gains (credit or debit for loss), Gas Expense (debit)
Partial closeSame as sell, pro-rated cost basis
Swap token for tokenToken B (debit), Token A (credit), fees
Staking depositStaking Deposits (debit), Cash (credit)
Staking rewardCash (debit), Staking Rewards (credit)
Airdrop receivedToken Holdings (debit), Airdrop Income (credit)
LP fee collectedCash (debit), LP Fee Income (credit)
Trading feeTrading Fees (debit), Cash (credit)
Gas/priority feeGas & Priority Fees (debit), Cash (credit)

账本处理以下交易流程:
流程涉及账户
账户注资现金(借方)、所有者资本(贷方)
提取资金所有者提款(借方)、现金(贷方)
买入代币代币持仓(借方)、现金(贷方)、gas 费用(借方)
卖出代币现金(借方)、代币持仓(贷方)、已实现收益(盈利时贷方,亏损时借方)、gas 费用(借方)
部分平仓与卖出相同,按比例计算成本基础
代币兑换代币代币 B(借方)、代币 A(贷方)、费用
质押存入质押存款(借方)、现金(贷方)
质押奖励现金(借方)、质押奖励(贷方)
收到空投代币持仓(借方)、空投收入(贷方)
收取 LP 费用现金(借方)、LP 费用收入(贷方)
交易手续费交易手续费(借方)、现金(贷方)
gas/优先费gas 与优先费(借方)、现金(贷方)

Reports

报告

Profit & Loss Statement

损益表

Shows income minus expenses for a period:
═══════════════════════════════════════════
  P&L Statement: 2026-02-01 to 2026-02-28
═══════════════════════════════════════════
INCOME
  Realized Trading Gains ........  4.200 SOL
  Staking Rewards ...............  0.150 SOL
  Airdrop Income ................  2.100 SOL
  LP Fee Income .................  0.090 SOL
                                  ─────────
  Total Income                     6.540 SOL

EXPENSES
  Trading Fees ..................  0.120 SOL
  Gas & Priority Fees ...........  0.045 SOL
  Slippage Cost .................  0.030 SOL
                                  ─────────
  Total Expenses                   0.195 SOL

═══════════════════════════════════════════
  NET INCOME                       6.345 SOL
═══════════════════════════════════════════
显示某一期间的收入减去费用:
═══════════════════════════════════════════
  P&L Statement: 2026-02-01 to 2026-02-28
═══════════════════════════════════════════
INCOME
  Realized Trading Gains ........  4.200 SOL
  Staking Rewards ...............  0.150 SOL
  Airdrop Income ................  2.100 SOL
  LP Fee Income .................  0.090 SOL
                                  ─────────
  Total Income                     6.540 SOL

EXPENSES
  Trading Fees ..................  0.120 SOL
  Gas & Priority Fees ...........  0.045 SOL
  Slippage Cost .................  0.030 SOL
                                  ─────────
  Total Expenses                   0.195 SOL

═══════════════════════════════════════════
  NET INCOME                       6.345 SOL
═══════════════════════════════════════════

Balance Sheet

资产负债表

Shows the accounting equation: Assets = Liabilities + Equity.
═══════════════════════════════════════════
  Balance Sheet: 2026-02-28
═══════════════════════════════════════════
ASSETS
  Cash – SOL ....................  32.450 SOL
  Cash – USDC ...................   0.000 SOL
  Token Holdings ................  12.300 SOL
  LP Positions ..................   5.000 SOL
  Staking Deposits ..............  10.000 SOL
                                  ─────────
  Total Assets                    59.750 SOL

EQUITY
  Owner Capital .................  50.000 SOL
  Retained Earnings .............   3.405 SOL
  Net Income (current period) ...   6.345 SOL
                                  ─────────
  Total Equity                    59.750 SOL

═══════════════════════════════════════════
  Assets - Equity = 0.000 SOL  ✓ Balanced
═══════════════════════════════════════════
显示会计恒等式:资产 = 负债 + 权益。
═══════════════════════════════════════════
  Balance Sheet: 2026-02-28
═══════════════════════════════════════════
ASSETS
  Cash – SOL ....................  32.450 SOL
  Cash – USDC ...................   0.000 SOL
  Token Holdings ................  12.300 SOL
  LP Positions ..................   5.000 SOL
  Staking Deposits ..............  10.000 SOL
                                  ─────────
  Total Assets                    59.750 SOL

EQUITY
  Owner Capital .................  50.000 SOL
  Retained Earnings .............   3.405 SOL
  Net Income (current period) ...   6.345 SOL
                                  ─────────
  Total Equity                    59.750 SOL

═══════════════════════════════════════════
  Assets - Equity = 0.000 SOL  ✓ Balanced
═══════════════════════════════════════════

Cash Flow Statement

现金流量表

Tracks where cash came from and where it went:
═══════════════════════════════════════════
  Cash Flow: 2026-02-01 to 2026-02-28
═══════════════════════════════════════════
OPERATING ACTIVITIES
  Trading proceeds ..............  8.500 SOL
  Token purchases ...............  (4.300) SOL
  Fees paid .....................  (0.195) SOL
  Staking rewards received ......  0.150 SOL
  LP fees received ..............  0.090 SOL
                                  ─────────
  Net Operating Cash Flow        4.245 SOL

INVESTING ACTIVITIES
  LP deposits ...................  (5.000) SOL
  Staking deposits ..............  (2.000) SOL
                                  ─────────
  Net Investing Cash Flow       (7.000) SOL

FINANCING ACTIVITIES
  Capital contributions .........  10.000 SOL
  Withdrawals ...................  (1.000) SOL
                                  ─────────
  Net Financing Cash Flow        9.000 SOL

═══════════════════════════════════════════
  Net Change in Cash              6.245 SOL
  Beginning Cash Balance         26.205 SOL
  Ending Cash Balance            32.450 SOL
═══════════════════════════════════════════

追踪现金的来源和去向:
═══════════════════════════════════════════
  Cash Flow: 2026-02-01 to 2026-02-28
═══════════════════════════════════════════
OPERATING ACTIVITIES
  Trading proceeds ..............  8.500 SOL
  Token purchases ...............  (4.300) SOL
  Fees paid .....................  (0.195) SOL
  Staking rewards received ......  0.150 SOL
  LP fees received ..............  0.090 SOL
                                  ─────────
  Net Operating Cash Flow        4.245 SOL

INVESTING ACTIVITIES
  LP deposits ...................  (5.000) SOL
  Staking deposits ..............  (2.000) SOL
                                  ─────────
  Net Investing Cash Flow       (7.000) SOL

FINANCING ACTIVITIES
  Capital contributions .........  10.000 SOL
  Withdrawals ...................  (1.000) SOL
                                  ─────────
  Net Financing Cash Flow        9.000 SOL

═══════════════════════════════════════════
  Net Change in Cash              6.245 SOL
  Beginning Cash Balance         26.205 SOL
  Ending Cash Balance            32.450 SOL
═══════════════════════════════════════════

Trading P&L vs Tax P&L

交易 P&L 与税务 P&L

These are different numbers and serve different purposes:
AspectTrading P&LTax P&L
PurposeStrategy evaluationCompliance, filing
Unrealized gainsIncluded (mark-to-market)Excluded (until realized)
Cost basis methodAverage cost (simple)FIFO, LIFO, or specific ID (jurisdiction-dependent)
TimingReal-timeAt disposal event
AirdropsValued at receiptOrdinary income at FMV on receipt
LP ILTracked as unrealized lossNot a taxable event until withdrawal
The ledger in
scripts/trading_ledger.py
tracks realized gains using FIFO by default. For trading P&L, you can overlay mark-to-market valuations on open positions.
See
references/planned_features.md
for detailed worked examples of how the same trades produce different P&L under FIFO vs average cost.

这是两组不同的数字,用途也不同:
对比项交易 P&L税务 P&L
用途策略评估合规与申报
未实现收益包含(按市值计价)不包含(实现前)
成本基础方法平均成本法(简单)FIFO、LIFO 或具体认定法(specific ID,取决于司法辖区)
确认时点实时发生处置时
空投按收到时的价值计量收到时按 FMV 计入普通收入
LP IL作为未实现亏损跟踪提款前不构成应税事件
scripts/trading_ledger.py
中的账本默认使用 FIFO 跟踪已实现收益。对于交易 P&L,你可以为未平仓头寸叠加按市值计价估值。
有关同一组交易在 FIFO 与平均成本法下产生不同 P&L 的详细示例,请参阅
references/planned_features.md
。

Entity Considerations

实体账户考量

Traders operating through an LLC or S-Corp should track additional accounts:
  • Management fees — if the entity charges a management fee
  • Distributions — payments from entity to owner (not the same as withdrawals from a trading account)
  • Payroll expenses — S-Corp officer salary
  • Tax provisions — estimated quarterly tax payments
The accounting principles are identical; the chart of accounts simply expands. The scripts in this skill focus on the trading-level ledger, which is the foundation for entity-level reporting.

通过 LLC 或 S-Corp 运营的交易者还应跟踪以下额外账户:
  • 管理费——实体收取管理费时
  • 分配——实体向所有者支付的款项(与从交易账户提款不同)
  • 工资费用——S-Corp 高管薪资
  • 税费计提——预估季度税款
会计原则完全相同,只是科目表会扩展。本 skill 中的脚本侧重于交易层级的账本,这是实体层级报告的基础。

Quick Start

快速开始

python
from trading_ledger import Ledger, Amount

ledger = Ledger(base_currency="SOL")
python
from trading_ledger import Ledger, Amount

ledger = Ledger(base_currency="SOL")

Fund the account

Fund the account

ledger.record_funding(amount=50.0, memo="Initial capital")
ledger.record_funding(amount=50.0, memo="Initial capital")

Buy a token

Buy a token

ledger.record_buy( token="BONK", quantity=100_000, cost_sol=0.5, fee_sol=0.001, memo="Entry on volume spike" )
ledger.record_buy( token="BONK", quantity=100_000, cost_sol=0.5, fee_sol=0.001, memo="Entry on volume spike" )

Sell for profit

Sell for profit

ledger.record_sell( token="BONK", quantity=100_000, proceeds_sol=0.8, fee_sol=0.001, memo="Target hit" )
ledger.record_sell( token="BONK", quantity=100_000, proceeds_sol=0.8, fee_sol=0.001, memo="Target hit" )

Record staking reward

Record staking reward

ledger.record_income( income_type="staking", amount_sol=0.05, memo="Epoch 580 rewards" )
ledger.record_income( income_type="staking", amount_sol=0.05, memo="Epoch 580 rewards" )

Generate reports

Generate reports

ledger.print_pnl(start="2026-02-01", end="2026-02-28") ledger.print_balance_sheet(as_of="2026-02-28")

Run the demo script to see a full month of trading activity with all report types:

```bash
python scripts/trading_ledger.py --demo

ledger.print_pnl(start="2026-02-01", end="2026-02-28") ledger.print_balance_sheet(as_of="2026-02-28")

运行演示脚本,查看包含所有报告类型的完整月度交易活动:

```bash
python scripts/trading_ledger.py --demo

Use Cases

使用场景

  1. Track real P&L — Know exactly how much you made after all fees, not just entry/exit prices
  2. Tax preparation — Hand your accountant a clean ledger with cost basis and realized gains
  3. Fee analysis — Discover that gas and priority fees are eating 3% of your gross profits
  4. Strategy comparison — Compare net P&L across strategies, not just win rates
  5. Cash flow planning — Know if you have enough liquid SOL for the next trade
  6. Audit trail — Every number traces back to a dated, memo-tagged journal entry

  1. 跟踪实际 P&L——准确了解扣除全部费用后赚了多少,而不只是看买入/卖出价格
  2. 税务准备——向你的会计师提供一份包含成本基础和已实现收益的清晰账本
  3. 费用分析——发现 gas 和优先费正在吞噬毛利润的 3%
  4. 策略比较——比较不同策略的净 P&L,而不只是胜率
  5. 现金流规划——了解是否拥有足够的流动 SOL 进行下一笔交易
  6. 审计轨迹——每个数字都可追溯到一笔带日期和备注标签的日记账分录

Prerequisites

先决条件

  • Python 3.10+
  • No external dependencies (the ledger uses only the standard library)

  • Python 3.10+
  • 无外部依赖(账本仅使用标准库)

Files

文件

FileDescription
references/planned_features.md
Chart of accounts, double-entry examples, report formats, trading vs tax P&L
scripts/trading_ledger.py
Double-entry ledger with P&L, balance sheet, and demo mode

Disclaimer: This skill provides accounting structure and calculations for informational and organizational purposes only. It is not tax advice, legal advice, or financial advice. Consult a qualified tax professional or CPA for guidance on your specific tax obligations. Cryptocurrency tax treatment varies by jurisdiction and changes frequently.
文件描述
references/planned_features.md
科目表、复式记账示例、报告格式、交易 P&L 与税务 P&L 对比
scripts/trading_ledger.py
包含 P&L、资产负债表和演示模式的复式记账账本

免责声明:本 skill 仅供信息参考和组织管理用途,提供会计结构和计算。其内容不构成税务建议、法律建议或财务建议。请咨询合格的税务专业人士或 CPA,以获得针对你具体税务义务的指导。加密货币税务处理因司法辖区而异,并且经常发生变化。