Implement Phase 2 portfolio construction and Phase 3 research integration#12
Merged
Conversation
…tion - Add portfolio package with target/current/diff calculation - Implement rebalance pending.json to ORDER conversion - Add portfolio history snapshot archiving - Create research package with watchlist parser - Integrate Content API for news/topics feeds - Add portfolio sync and research refresh to controller loop - All code compiles successfully Agent-Logs-Url: https://github.com/JetSquirrel/longbridge-fs/sessions/a34a13a5-3680-43d6-8fe1-ba91755dc2cb Co-authored-by: JetSquirrel <20291255+JetSquirrel@users.noreply.github.com>
JetSquirrel
approved these changes
Mar 31, 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 portfolio rebalancing pipeline and Content API research feeds as specified in the five-layer harness architecture (spec.md Phase 2 & 3).
Portfolio Construction (
internal/portfolio/)Core logic (463 LOC):
SyncCurrent()- Computes current portfolio from account state + quotes with position weightsComputeDiff()- Calculates target vs current delta, generates rebalance actions with quantity estimatesProcessRebalance()- Convertsportfolio/rebalance/pending.jsonto ORDER entries in beancount ledgerValidateTarget()- Ensures target weights sum to 1.0, validates allocationsData flow:
Threshold-based rebalancing ignores adjustments <1% or $100 to reduce churn.
Research Feeds (
internal/research/)Content API integration (267 LOC):
RefreshFeeds()- Readsresearch/watchlist.json, fetches news/topics via Content APIGenerateSummary()- Scans feeds and quotes, producesresearch/summary.jsonavailability indexWrites structured feeds to:
research/feeds/news/{SYMBOL}/latest.jsonresearch/feeds/topics/{SYMBOL}/latest.jsonController Integration
Added to polling loop (
cmd/longbridge-fs/main.go):All operations are non-blocking - failures logged but don't halt the controller.
Type Definitions
Extended
internal/model/types.gowith:TargetPortfolio,CurrentPortfolio,PortfolioDiff,AdjustmentRebalancePending,RebalanceOrderWatchlist,NewsFeed,TopicsFeed,ResearchSummaryMaps directly to file structures defined in spec.md sections 6 & 4.
Deferred
--auto-rebalancemode intentionally omitted - manual approval viapending.jsonis safer for production. Current workflow requires explicit user/agent confirmation before ORDER generation.