Implement Phase 4: TWAP and ICEBERG algorithm execution with goroutine scheduler#19
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/JetSquirrel/longbridge-fs/sessions/616280be-08f3-4e0a-bd41-0c057ae4e0e7 Co-authored-by: JetSquirrel <20291255+JetSquirrel@users.noreply.github.com>
JetSquirrel
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements algorithmic order execution for splitting large orders to reduce market impact. Adds TWAP (time-weighted) and ICEBERG (visibility-based) algorithms with full audit trail support.
Implementation
Core Components
AlgoScheduler: Manages concurrent algorithm tasks via goroutines with context-based cancellationAlgoTask: Tracks execution state per order (slices, timing, completion)Data Model Extensions
Beancount Order Format
Slice Execution Output
Integration
ProcessLedgerWithScheduler(): Routes algo orders to scheduler instead of direct executionAppendExecutionWithMeta(): Writes slice metadata to beancount ledgerFiles Changed
New
internal/broker/algo.go- Scheduler and task management (210 lines)internal/broker/algo_twap.go- TWAP implementation (65 lines)internal/broker/algo_iceberg.go- ICEBERG implementation (70 lines)internal/broker/algo_test.go- Test coverage (163 lines)Modified
internal/model/types.go- Added algo fields to ParsedOrderinternal/ledger/parser.go- Parse algo metadata from beancountinternal/broker/broker.go- Added scheduler integrationinternal/audit/audit.go- Track algo_tasks_active metriccmd/longbridge-fs/main.go- Initialize scheduler in controllertask.md- Mark Phase 4 completeTesting
Tests verify correct slice count, timing, and ledger writes for both algorithms:
TestTWAPExecution: 5 slices with time-based distributionTestICEBERGExecution: 3 slices with sequential submission