Skip to content

Extract applyImportedTrades into 18b-chain-apply.js#67

Merged
heyitsStylez merged 1 commit into
mainfrom
extract-chain-apply
May 16, 2026
Merged

Extract applyImportedTrades into 18b-chain-apply.js#67
heyitsStylez merged 1 commit into
mainfrom
extract-chain-apply

Conversation

@heyitsStylez
Copy link
Copy Markdown
Owner

Summary

  • Extracts dedup-by-txHash, open/close split, close-trade matching, and OPEN→EXPIRED outcome correction out of syncRysk / syncHypersurface into two pure, dual-exported functions in a new src/js/18b-chain-apply.js module
  • applyCloseTrade(tradesArray, closeTrade) — parameterised on tradesArray instead of closing over the global, returns boolean
  • applyImportedTrades(tradesArray, openTrades, closeTrades, synced){ added, closedCount, corrected } — handles dedup, pushes open trades (stripping isClose), applies close trades, runs OPEN→EXPIRED correction across the full array
  • Outcome correction now covers both RYSK and HSFC trades on every sync (previously each sync only corrected its own platform's trades)
  • syncRysk and syncHypersurface become thin wrappers: fetch → parse → applyImportedTrades → save/render if anything changed

Test plan

  • test/unit/chain-apply.test.js added — 10 pure-Node tests (no jsdom) covering all acceptance criteria:
    • already-synced txHash is skipped
    • close trade matches open trade → CLOSED + closeCost set
    • unknown close trade → closedCount: 0
    • OPEN trade with past expiry → EXPIRED
    • correction applies to both RYSK and HSFC platform trades
    • isClose absent from pushed trades
  • All 120 existing tests pass (npm test)
  • python3 build.py --check passes (26 JS modules, syntax OK)
  • Pre-commit hook passed (build + test)

Closes #59

🤖 Generated with Claude Code

Moves dedup-by-txHash, open/close split, close-trade matching, and
OPEN→EXPIRED outcome correction out of syncRysk/syncHypersurface into
two pure, dual-exported functions in a new module:

  applyCloseTrade(tradesArray, closeTrade) → boolean
  applyImportedTrades(tradesArray, openTrades, closeTrades, synced)
    → { added, closedCount, corrected }

Outcome correction now runs across the full trades array on every sync,
covering both RYSK and HSFC trades (previously each sync only corrected
its own platform). syncRysk and syncHypersurface become thin wrappers:
fetch → parse → applyImportedTrades → save/render if changed.

Adds test/unit/chain-apply.test.js (10 pure-Node tests, no jsdom).

Closes #59

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hyperwheel Ready Ready Preview, Comment May 16, 2026 0:00am

@heyitsStylez heyitsStylez merged commit 895a86f into main May 16, 2026
4 checks passed
@heyitsStylez heyitsStylez deleted the extract-chain-apply branch May 16, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract applyImportedTrades from chain-sync into 18b-chain-apply.js

1 participant