trade-accounting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTrade 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:
| Category | Normal Balance | Examples |
|---|---|---|
| Assets | Debit | Cash (SOL/USDC), token holdings, LP positions, staking deposits, receivables |
| Liabilities | Credit | Margin borrowing, accrued taxes payable |
| Income | Credit | Realized trading gains, staking rewards, airdrop income, LP fee income |
| Expenses | Debit | Trading fees, gas/priority fees, subscription costs, data feeds |
| Equity | Credit | Owner capital contributions, retained earnings, withdrawals (contra) |
交易运营遵循标准会计原则,采用以下账户类别:
| 类别 | 正常余额 | 示例 |
|---|---|---|
| 资产 | 借方 | 现金(SOL/USDC)、代币持仓、LP 头寸、质押存款、应收款 |
| 负债 | 贷方 | 保证金借款、应计应付税款 |
| 收入 | 贷方 | 已实现交易收益、质押奖励、空投收入、LP 费用收入 |
| 费用 | 借方 | 交易手续费、gas/优先费、订阅成本、数据源 |
| 权益 | 贷方 | 所有者资本投入、留存收益、提款(权益抵减项) |
Chart of Accounts
科目表
See for a full chart of accounts. A minimal setup:
references/planned_features.md1000 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.md1000 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):
| Account | Debit | Credit |
|---|---|---|
| Token Holdings – BONK | 0.501 SOL | |
| Cash – SOL | 0.501 SOL |
Or with the fee broken out explicitly:
| Account | Debit | Credit |
|---|---|---|
| Token Holdings – BONK | 0.5 SOL | |
| Gas & Priority Fees | 0.001 SOL | |
| Cash – SOL | 0.501 SOL |
Sell 1000 BONK for 0.8 SOL (cost basis was 0.5 SOL, 0.001 SOL gas):
| Account | Debit | Credit |
|---|---|---|
| Cash – SOL | 0.799 SOL | |
| Gas & Priority Fees | 0.001 SOL | |
| Token Holdings – BONK | 0.5 SOL | |
| Realized Trading Gains | 0.3 SOL |
Receive staking rewards of 0.05 SOL:
| Account | Debit | Credit |
|---|---|---|
| Cash – SOL | 0.05 SOL | |
| Staking Rewards | 0.05 SOL |
Receive airdrop of 5000 JUP (valued at 2.1 SOL at receipt):
| Account | Debit | Credit |
|---|---|---|
| Token Holdings – JUP | 2.1 SOL | |
| Airdrop Income | 2.1 SOL |
Collect LP fees of 0.03 SOL:
| Account | Debit | Credit |
|---|---|---|
| Cash – SOL | 0.03 SOL | |
| LP Fee Income | 0.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:
| Account | Debit | Credit |
|---|---|---|
| Cash – SOL | 0.699 SOL | |
| Gas & Priority Fees | 0.001 SOL | |
| Token Holdings – BONK | 0.5 SOL | |
| Realized Trading Gains | 0.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):
| 账户 | 借方 | 贷方 |
|---|---|---|
| 代币持仓 – BONK | 0.501 SOL | |
| 现金 – SOL | 0.501 SOL |
或者将费用单独列明:
| 账户 | 借方 | 贷方 |
|---|---|---|
| 代币持仓 – BONK | 0.5 SOL | |
| gas 与优先费 | 0.001 SOL | |
| 现金 – SOL | 0.501 SOL |
卖出 1000 BONK,获得 0.8 SOL(成本基础为 0.5 SOL,gas 费为 0.001 SOL):
| 账户 | 借方 | 贷方 |
|---|---|---|
| 现金 – SOL | 0.799 SOL | |
| gas 与优先费 | 0.001 SOL | |
| 代币持仓 – BONK | 0.5 SOL | |
| 已实现交易收益 | 0.3 SOL |
收到 0.05 SOL 的质押奖励:
| 账户 | 借方 | 贷方 |
|---|---|---|
| 现金 – SOL | 0.05 SOL | |
| 质押奖励 | 0.05 SOL |
收到 5000 JUP 空投(收到时估值为 2.1 SOL):
| 账户 | 借方 | 贷方 |
|---|---|---|
| 代币持仓 – JUP | 2.1 SOL | |
| 空投收入 | 2.1 SOL |
收取 0.03 SOL 的 LP 费用:
| 账户 | 借方 | 贷方 |
|---|---|---|
| 现金 – SOL | 0.03 SOL | |
| LP 费用收入 | 0.03 SOL |
部分平仓——卖出一半头寸:
如果你持有 2000 BONK,成本基础为 1.0 SOL,并卖出 1000 个,获得 0.7 SOL:
| 账户 | 借方 | 贷方 |
|---|---|---|
| 现金 – SOL | 0.699 SOL | |
| gas 与优先费 | 0.001 SOL | |
| 代币持仓 – BONK | 0.5 SOL | |
| 已实现交易收益 | 0.2 SOL |
已卖出部分的成本基础(0.5 SOL,即 1.0 SOL 的一半)会从资产账户中扣除。
Transaction Types
交易类型
The ledger handles these trading flows:
| Flow | Accounts Touched |
|---|---|
| Fund account | Cash (debit), Owner Capital (credit) |
| Withdraw funds | Owner Withdrawals (debit), Cash (credit) |
| Buy token | Token Holdings (debit), Cash (credit), Gas Expense (debit) |
| Sell token | Cash (debit), Token Holdings (credit), Realized Gains (credit or debit for loss), Gas Expense (debit) |
| Partial close | Same as sell, pro-rated cost basis |
| Swap token for token | Token B (debit), Token A (credit), fees |
| Staking deposit | Staking Deposits (debit), Cash (credit) |
| Staking reward | Cash (debit), Staking Rewards (credit) |
| Airdrop received | Token Holdings (debit), Airdrop Income (credit) |
| LP fee collected | Cash (debit), LP Fee Income (credit) |
| Trading fee | Trading Fees (debit), Cash (credit) |
| Gas/priority fee | Gas & 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:
| Aspect | Trading P&L | Tax P&L |
|---|---|---|
| Purpose | Strategy evaluation | Compliance, filing |
| Unrealized gains | Included (mark-to-market) | Excluded (until realized) |
| Cost basis method | Average cost (simple) | FIFO, LIFO, or specific ID (jurisdiction-dependent) |
| Timing | Real-time | At disposal event |
| Airdrops | Valued at receipt | Ordinary income at FMV on receipt |
| LP IL | Tracked as unrealized loss | Not a taxable event until withdrawal |
The ledger in tracks realized gains using FIFO by default. For trading P&L, you can overlay mark-to-market valuations on open positions.
scripts/trading_ledger.pySee for detailed worked examples of how the same trades produce different P&L under FIFO vs average cost.
references/planned_features.md这是两组不同的数字,用途也不同:
| 对比项 | 交易 P&L | 税务 P&L |
|---|---|---|
| 用途 | 策略评估 | 合规与申报 |
| 未实现收益 | 包含(按市值计价) | 不包含(实现前) |
| 成本基础方法 | 平均成本法(简单) | FIFO、LIFO 或具体认定法(specific ID,取决于司法辖区) |
| 确认时点 | 实时 | 发生处置时 |
| 空投 | 按收到时的价值计量 | 收到时按 FMV 计入普通收入 |
| LP IL | 作为未实现亏损跟踪 | 提款前不构成应税事件 |
scripts/trading_ledger.py有关同一组交易在 FIFO 与平均成本法下产生不同 P&L 的详细示例,请参阅 。
references/planned_features.mdEntity 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 --demoledger.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 --demoUse Cases
使用场景
- Track real P&L — Know exactly how much you made after all fees, not just entry/exit prices
- Tax preparation — Hand your accountant a clean ledger with cost basis and realized gains
- Fee analysis — Discover that gas and priority fees are eating 3% of your gross profits
- Strategy comparison — Compare net P&L across strategies, not just win rates
- Cash flow planning — Know if you have enough liquid SOL for the next trade
- Audit trail — Every number traces back to a dated, memo-tagged journal entry
- 跟踪实际 P&L——准确了解扣除全部费用后赚了多少,而不只是看买入/卖出价格
- 税务准备——向你的会计师提供一份包含成本基础和已实现收益的清晰账本
- 费用分析——发现 gas 和优先费正在吞噬毛利润的 3%
- 策略比较——比较不同策略的净 P&L,而不只是胜率
- 现金流规划——了解是否拥有足够的流动 SOL 进行下一笔交易
- 审计轨迹——每个数字都可追溯到一笔带日期和备注标签的日记账分录
Prerequisites
先决条件
- Python 3.10+
- No external dependencies (the ledger uses only the standard library)
- Python 3.10+
- 无外部依赖(账本仅使用标准库)
Files
文件
| File | Description |
|---|---|
| Chart of accounts, double-entry examples, report formats, trading vs tax P&L |
| 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.
| 文件 | 描述 |
|---|---|
| 科目表、复式记账示例、报告格式、交易 P&L 与税务 P&L 对比 |
| 包含 P&L、资产负债表和演示模式的复式记账账本 |
免责声明:本 skill 仅供信息参考和组织管理用途,提供会计结构和计算。其内容不构成税务建议、法律建议或财务建议。请咨询合格的税务专业人士或 CPA,以获得针对你具体税务义务的指导。加密货币税务处理因司法辖区而异,并且经常发生变化。