wash-sale-detection
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWash Sale Detection
洗售检测
Detect wash sales under current US crypto tax rules (effective 2025), monitor the 61-day window around realized losses, track disallowed losses with basis adjustments, and compute safe re-entry countdowns.
Disclaimer: This skill provides informational analysis only. It is NOT tax advice. Consult a qualified tax professional or CPA for guidance on your specific situation. Tax law is complex, and the application of wash sale rules to cryptocurrency may vary based on individual circumstances, IRS guidance updates, and court rulings.
依据当前美国加密货币税收规则(2025年生效)检测洗售行为,监控已实现损失前后的61天窗口期,追踪涉及成本基准调整的禁止抵扣损失,并计算安全重新入场倒计时。
免责声明:本工具仅提供信息分析服务,不构成税务建议。请咨询合格的税务专业人士或注册会计师(CPA)获取针对您具体情况的指导。税法十分复杂,洗售规则在加密货币中的应用可能因个人情况、IRS指导更新及法院裁决而有所不同。
Background
背景
Before 2025, cryptocurrency was not subject to the wash sale rule because digital assets were classified as property rather than securities. The Infrastructure Investment and Jobs Act and subsequent IRS rulemaking extended wash sale treatment to digital assets beginning January 1, 2025.
Under IRC Section 1091 (as amended for digital assets), if you sell or dispose of a cryptocurrency at a loss and acquire a substantially identical asset within a 61-day window (30 days before the sale through 30 days after), the loss is disallowed for tax purposes. The disallowed loss is added to the cost basis of the replacement position.
2025年之前,加密货币不受洗售规则约束,因为数字资产被归类为财产而非证券。《基础设施投资与就业法案》及后续IRS规则制定将洗售规则的适用范围扩展至数字资产,自2025年1月1日起生效。
根据IRC第1091条(针对数字资产修订版),如果您以亏损价格出售或处置加密货币,并在61天窗口期(出售前30天至出售后30天)内购入实质相同的资产,该损失在税务上会被禁止抵扣。禁止抵扣的损失将被添加至替代持仓的成本基准中。
Key Concepts
核心概念
The 61-Day Window
61天窗口期
Day -30 ................. Day 0 ................. Day +30
|--- 30 days before ---|--- sale day ---|--- 30 days after ---|
^ ^ ^
Window opens Loss realized Window closes- Day 0: The day you sell a position at a realized loss
- Days -30 to -1: Purchases in this range trigger a wash sale retroactively
- Days +1 to +30: Purchases in this range trigger a wash sale prospectively
- The window is calendar days, not trading days
Day -30 ................. Day 0 ................. Day +30
|--- 30 days before ---|--- sale day ---|--- 30 days after ---|
^ ^ ^
Window opens Loss realized Window closes- Day 0:您以已实现亏损价格出售持仓的日期
- Days -30至-1:此时间段内的买入操作会追溯触发洗售
- Days +1至+30:此时间段内的买入操作会前瞻性触发洗售
- 窗口期按自然日计算,而非交易日
Substantially Identical Assets
实质相同资产
For crypto, "substantially identical" generally means the same token. Selling SOL at a loss and buying SOL within 30 days is a wash sale. Selling SOL and buying ETH is not (they are different assets).
Edge cases that may be scrutinized:
- Wrapped vs unwrapped versions of the same token (e.g., SOL vs wSOL)
- Tokens across different chains (e.g., USDC on Solana vs USDC on Ethereum)
- Derivative tokens that track the same underlying (e.g., stSOL and SOL)
对于加密货币而言,“实质相同”通常指同一代币。以亏损价格出售SOL并在30天内买入SOL属于洗售行为。出售SOL并买入ETH则不属于(二者为不同资产)。
可能受到严格审查的边缘案例:
- 同一代币的包装版与非包装版(如SOL与wSOL)
- 不同链上的同一代币(如Solana链上的USDC与以太坊链上的USDC)
- 追踪同一标的的衍生代币(如stSOL与SOL)
Disallowed Loss and Basis Adjustment
禁止抵扣损失与成本基准调整
When a wash sale occurs:
- The realized loss is disallowed — you cannot deduct it in the current tax year
- The disallowed loss is added to the cost basis of the replacement position
- The holding period of the original position may carry over to the replacement
Example:
- Buy 10 SOL at $100 each (cost basis: $1,000)
- Sell 10 SOL at $80 each (proceeds: $800, loss: $200)
- Buy 10 SOL at $85 within 15 days (wash sale triggered)
- New cost basis: $850 + $200 disallowed loss = $1,050
- The $200 loss is not gone — it is deferred into the new position
发生洗售行为时:
- 已实现损失被禁止抵扣——您无法在当前纳税年度扣除该损失
- 禁止抵扣的损失被添加至替代持仓的成本基准中
- 原持仓的持有期可能延续至替代持仓
示例:
- 以每个100美元买入10枚SOL(成本基准:1000美元)
- 以每个80美元卖出10枚SOL(收益:800美元,亏损:200美元)
- 15天内以每个85美元买入10枚SOL(触发洗售)
- 新成本基准:850美元 + 200美元禁止抵扣损失 = 1050美元
- 200美元的损失并未消失——而是递延至新持仓中
Prerequisites
前提条件
- Python 3.10+
- No external dependencies required (standard library only)
- Trade history data in CSV or structured format with: date, action (buy/sell), token, quantity, price, proceeds, cost basis
- Python 3.10+
- 无需外部依赖(仅使用标准库)
- CSV或结构化格式的交易历史数据,包含:日期、操作(买入/卖出)、代币、数量、价格、收益、成本基准
Capabilities
功能
- Wash Sale Scanning — Analyze a trade history and flag all wash sale violations
- 61-Day Window Monitoring — Track open windows for recent loss-generating sales
- Disallowed Loss Calculation — Compute the exact disallowed amount per wash sale
- Basis Adjustment Tracking — Show adjusted cost basis for replacement positions
- Safe Re-Entry Countdown — For each token sold at a loss, show days remaining until safe to re-enter
- Automation Hazard Detection — Flag copy-trade systems or bot strategies that may inadvertently trigger wash sales
- 洗售扫描——分析交易历史并标记所有洗售违规行为
- 61天窗口期监控——追踪近期产生亏损的出售操作的开放窗口期
- 禁止抵扣损失计算——计算每笔洗售的准确禁止抵扣金额
- 成本基准调整追踪——展示替代持仓的调整后成本基准
- 安全重新入场倒计时——针对每枚以亏损价格出售的代币,展示可安全重新入场的剩余天数
- 自动化风险检测——标记可能无意中触发洗售的复制交易系统或机器人策略
Quick Start
快速开始
python
from datetime import datepython
from datetime import dateDefine your trade history
Define your trade history
trades = [
{"date": date(2025, 3, 1), "action": "buy", "token": "SOL", "qty": 10, "price": 100.0},
{"date": date(2025, 3, 15), "action": "sell", "token": "SOL", "qty": 10, "price": 80.0},
{"date": date(2025, 3, 25), "action": "buy", "token": "SOL", "qty": 10, "price": 85.0},
]
trades = [
{"date": date(2025, 3, 1), "action": "buy", "token": "SOL", "qty": 10, "price": 100.0},
{"date": date(2025, 3, 15), "action": "sell", "token": "SOL", "qty": 10, "price": 80.0},
{"date": date(2025, 3, 25), "action": "buy", "token": "SOL", "qty": 10, "price": 85.0},
]
Check for wash sales
Check for wash sales
from scripts.wash_sale_scanner import WashSaleScanner
scanner = WashSaleScanner(trades)
results = scanner.scan()
for ws in results.wash_sales:
print(f"WASH SALE: {ws.token} — Loss ${ws.disallowed_loss:.2f} disallowed")
print(f" Sale: {ws.sale_date} | Re-entry: {ws.replacement_date}")
print(f" Adjusted basis: ${ws.adjusted_basis:.2f}")
from scripts.wash_sale_scanner import WashSaleScanner
scanner = WashSaleScanner(trades)
results = scanner.scan()
for ws in results.wash_sales:
print(f"WASH SALE: {ws.token} — Loss ${ws.disallowed_loss:.2f} disallowed")
print(f" Sale: {ws.sale_date} | Re-entry: {ws.replacement_date}")
print(f" Adjusted basis: ${ws.adjusted_basis:.2f}")
Check safe re-entry countdowns
Check safe re-entry countdowns
for countdown in results.countdowns:
print(f"{countdown.token}: {countdown.days_remaining} days until safe re-entry")
undefinedfor countdown in results.countdowns:
print(f"{countdown.token}: {countdown.days_remaining} days until safe re-entry")
undefinedUse Cases
使用场景
1. End-of-Year Tax Review
1. 年末税务复核
Scan your full year of trading activity to identify all wash sales before filing taxes. Generate a report showing total disallowed losses and adjusted cost bases.
在报税之前扫描您全年的交易活动,识别所有洗售行为。生成一份报告,展示总禁止抵扣损失和调整后的成本基准。
2. Real-Time Monitoring
2. 实时监控
Before placing a buy order, check whether the token has an open wash sale window from a recent loss. Avoid inadvertent wash sales by waiting for the countdown to expire.
下达买入订单前,检查该代币是否因近期亏损存在开放的洗售窗口期。等待倒计时结束,避免无意中触发洗售。
3. Copy-Trade and Bot Audit
3. 复制交易与机器人审计
Automated trading systems (copy-trading bots, DCA bots, grid bots) frequently trigger wash sales because they buy and sell the same tokens repeatedly. Run this scanner on bot trade exports to quantify the tax impact.
自动化交易系统(复制交易机器人、DCA机器人、网格机器人)频繁触发洗售,因为它们反复买卖同一代币。在机器人交易导出数据上运行此扫描器,量化税务影响。
4. Tax-Loss Harvesting Coordination
4. 税损收割协调
When executing a tax-loss harvesting strategy, use the safe re-entry countdown to plan when you can re-enter positions. Swap into a non-identical asset during the 30-day window if you want to maintain market exposure.
执行税损收割策略时,使用安全重新入场倒计时规划重新入场的时间。如果您想维持市场敞口,可在30天窗口期内切换至非同类资产。
5. Multi-Account Wash Sale Detection
5. 多账户洗售检测
The wash sale rule applies across all accounts controlled by the same taxpayer. If you trade SOL on multiple exchanges or wallets, aggregate the trade history before scanning.
洗售规则适用于同一纳税人控制的所有账户。如果您在多个交易所或钱包交易SOL,请在扫描前汇总交易历史。
Edge Cases and Automation Hazards
边缘案例与自动化风险
DCA Bots and Grid Bots
DCA机器人与网格机器人
Dollar-cost averaging bots that buy a token weekly will almost certainly trigger wash sales if the token is also sold at a loss during the same period. The scanner flags overlapping buy/sell patterns within the 61-day window.
每周买入某代币的美元成本平均机器人,如果同期该代币也被以亏损价格卖出,几乎肯定会触发洗售。扫描器会标记61天窗口期内重叠的买卖模式。
Copy-Trading
复制交易
If a copy-trade system sells a token at a loss and the leader re-enters within 30 days, your copied trades inherit the wash sale. There is no "I didn't place the trade" exception.
如果复制交易系统以亏损价格出售代币,且交易领导者在30天内重新入场,您的复制交易将继承洗售后果。不存在“我没有下达该交易”的例外情况。
Partial Fills and Multiple Lots
部分成交与多批次持仓
When a sale at a loss is followed by multiple smaller purchases, the wash sale applies to each purchase up to the quantity of the loss-generating sale. The scanner handles partial matching.
以亏损价格出售后进行多次小额买入时,洗售规则适用于每笔买入,直至达到产生亏损的出售数量。扫描器支持部分匹配处理。
Cross-Wallet Transfers
跨钱包转账
Transferring tokens to another wallet you control and selling there does not avoid the wash sale rule. The rule follows the taxpayer, not the account.
将代币转移至您控制的另一个钱包并在那里出售,无法规避洗售规则。规则针对的是纳税人,而非账户。
Safe Re-Entry Strategy
安全重新入场策略
After selling a token at a loss:
- Wait 31 calendar days before repurchasing the same token
- During the waiting period, consider holding a non-identical substitute (e.g., sell SOL, hold ETH for exposure to crypto broadly)
- Use the countdown timer to know exactly when re-entry is safe
- Set calendar reminders for window expiration dates
Token: SOL
Sale Date: 2025-03-15
Loss: $200.00
Window Closes: 2025-04-14
Days Remaining: 12
Status: DO NOT BUY — wash sale window active以亏损价格出售代币后:
- 等待31个自然日再回购同一代币
- 等待期间,考虑持有非同类替代资产(如出售SOL,持有ETH以维持整体加密货币敞口)
- 使用倒计时器准确了解何时可安全重新入场
- 设置日历提醒,标记窗口期到期日期
Token: SOL
Sale Date: 2025-03-15
Loss: $200.00
Window Closes: 2025-04-14
Days Remaining: 12
Status: DO NOT BUY — wash sale window activeBasis Adjustment Walkthrough
成本基准调整演练
Detailed step-by-step basis adjustment example:
TRADE 1: Buy 100 SOL @ $150.00 → Basis: $15,000.00
TRADE 2: Sell 100 SOL @ $120.00 → Proceeds: $12,000.00, Loss: $3,000.00
TRADE 3: Buy 100 SOL @ $125.00 → Basis before adjustment: $12,500.00
(within 30 days of Trade 2)
WASH SALE TRIGGERED:
Disallowed loss: $3,000.00
Adjusted basis: $12,500.00 + $3,000.00 = $15,500.00
Effective price: $155.00 per SOL (not $125.00)
Later sale at $160.00:
Proceeds: $16,000.00
Adj. basis: $15,500.00
Gain: $500.00 (not $3,500.00)
The $3,000 loss is recovered through the higher basis.详细的分步成本基准调整示例:
TRADE 1: Buy 100 SOL @ $150.00 → Basis: $15,000.00
TRADE 2: Sell 100 SOL @ $120.00 → Proceeds: $12,000.00, Loss: $3,000.00
TRADE 3: Buy 100 SOL @ $125.00 → Basis before adjustment: $12,500.00
(within 30 days of Trade 2)
WASH SALE TRIGGERED:
Disallowed loss: $3,000.00
Adjusted basis: $12,500.00 + $3,000.00 = $15,500.00
Effective price: $155.00 per SOL (not $125.00)
Later sale at $160.00:
Proceeds: $16,000.00
Adj. basis: $15,500.00
Gain: $500.00 (not $3,500.00)
The $3,000 loss is recovered through the higher basis.Files
文件
References
参考资料
- — Wash sale rules in depth, 61-day window mechanics, basis adjustment examples, automation edge cases, IRS guidance references
references/planned_features.md
- — 深入介绍洗售规则、61天窗口期机制、成本基准调整示例、自动化边缘案例、IRS指导参考
references/planned_features.md
Scripts
脚本
- — Complete wash sale scanner: loads trade history, identifies wash sales, computes disallowed losses and basis adjustments, shows safe re-entry countdowns. Run with
scripts/wash_sale_scanner.pyfor example scenarios.--demo
- — 完整的洗售扫描器:加载交易历史、识别洗售行为、计算禁止抵扣损失与成本基准调整、展示安全重新入场倒计时。使用
scripts/wash_sale_scanner.py参数运行可查看示例场景。--demo
Limitations
局限性
- This tool implements a simplified interpretation of wash sale rules as applied to crypto
- "Substantially identical" determination for wrapped tokens and derivatives may require professional judgment
- The scanner does not handle options, futures, or other derivative instruments on crypto
- Multi-account detection requires you to aggregate trade data manually
- Rules may change as IRS issues further guidance on digital asset wash sales
- State tax rules may differ from federal treatment
- 本工具对适用于加密货币的洗售规则采用简化解读
- 包装代币和衍生代币的“实质相同”判定可能需要专业判断
- 扫描器不处理加密货币的期权、期货或其他衍生工具
- 多账户检测需要您手动汇总交易数据
- 随着IRS发布更多关于数字资产洗售的指导,规则可能发生变化
- 州级税收规则可能与联邦待遇不同