feat(watchlist): add company identity catalog
Embed a pinned FinanceDatabase equity snapshot, add authenticated company search and identity-based follows, preserve legacy assets, and map selected Yahoo symbols for collection. Refs #19 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
32
backend/internal/generation/company_symbols.go
Normal file
32
backend/internal/generation/company_symbols.go
Normal file
@ -0,0 +1,32 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var yahooTicker = regexp.MustCompile(`^[A-Za-z0-9^][A-Za-z0-9.^=\-]{0,31}$`)
|
||||
var figiIdentity = regexp.MustCompile(`^BBG[A-Z0-9]{9}$`)
|
||||
|
||||
// Only the Yahoo source gets the catalogue's Yahoo listing hint. Other feeds
|
||||
// retain the exact historical Symbol input. No guesses or Bloomberg conversion.
|
||||
func yahooSymbols(assets []models.UserAsset) []string {
|
||||
out := []string{}
|
||||
seen := map[string]bool{}
|
||||
for _, a := range assets {
|
||||
symbol := a.Symbol
|
||||
if a.CompanyID != nil {
|
||||
if a.YahooSymbol == nil {
|
||||
continue
|
||||
}
|
||||
symbol = *a.YahooSymbol
|
||||
}
|
||||
if !yahooTicker.MatchString(symbol) || figiIdentity.MatchString(strings.ToUpper(symbol)) || seen[symbol] {
|
||||
continue
|
||||
}
|
||||
seen[symbol] = true
|
||||
out = append(out, symbol)
|
||||
}
|
||||
return out
|
||||
}
|
||||
46
backend/internal/generation/company_symbols_test.go
Normal file
46
backend/internal/generation/company_symbols_test.go
Normal file
@ -0,0 +1,46 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func pointer(s string) *string { return &s }
|
||||
func TestYahooSymbolsUseResolvedPrimaryWithoutBloombergOrFIGI(t *testing.T) {
|
||||
assets := []models.UserAsset{
|
||||
{CompanyID: pointer("isin:KYG070341048"), Name: "Baidu, Inc.", Symbol: "OLD_BLOOMBERG", YahooSymbol: pointer("9888.HK")},
|
||||
{Symbol: "SSAAPL INDEX"}, {Symbol: "BBG000BBJQV0"}, {Symbol: "NVDA"}, {Symbol: "NVDA"},
|
||||
{CompanyID: pointer("isin:unknown"), Symbol: "CLIENT-SPOOF"},
|
||||
}
|
||||
if got := yahooSymbols(assets); !reflect.DeepEqual(got, []string{"9888.HK", "NVDA"}) {
|
||||
t.Fatalf("Yahoo input=%v", got)
|
||||
}
|
||||
}
|
||||
|
||||
type symbolFeed struct{ symbols []string }
|
||||
|
||||
func (f *symbolFeed) Name() string { return "fake" }
|
||||
func (f *symbolFeed) Scrape(_ context.Context, s []string) ([]scraper.Article, error) {
|
||||
f.symbols = s
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func TestPerSourceCompanyHintsDoNotChangeOtherFeeds(t *testing.T) {
|
||||
yahoo, bloomberg, watcher := &symbolFeed{}, &symbolFeed{}, &symbolFeed{}
|
||||
input := UserInput{Language: "fr", RankingMode: "title", GlobalLimit: 20, Assets: []models.UserAsset{{CompanyID: pointer("isin:company"), Name: "Company", Symbol: "HISTORIC INDEX", YahooSymbol: pointer("9888.HK")}}}
|
||||
for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceWatcherGuru} {
|
||||
key := key
|
||||
input.Sources = append(input.Sources, models.Source{ID: key, SourceKey: &key, Enabled: true, ArticleLimit: 20})
|
||||
}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"owner": input}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, LayaRanker: &contractRanker{}, Summarizer: &contractSummarizer{}, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: yahoo, models.SourceBloomberg: bloomberg, models.SourceWatcherGuru: watcher}})
|
||||
if _, err := uc.Generate(context.Background(), "owner"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(yahoo.symbols, []string{"9888.HK"}) || !reflect.DeepEqual(bloomberg.symbols, []string{"HISTORIC INDEX"}) || !reflect.DeepEqual(watcher.symbols, bloomberg.symbols) {
|
||||
t.Fatalf("Yahoo=%v Bloomberg=%v Watcher=%v", yahoo.symbols, bloomberg.symbols, watcher.symbols)
|
||||
}
|
||||
}
|
||||
@ -168,7 +168,11 @@ func (u *useCase) Generate(ctx context.Context, userID string) (Result, error) {
|
||||
if feed == nil {
|
||||
err = fmt.Errorf("unavailable")
|
||||
} else {
|
||||
articles, err = feed.Scrape(ctx, append([]string(nil), symbols...))
|
||||
sourceSymbols := symbols
|
||||
if *source.SourceKey == models.SourceYahooFinance {
|
||||
sourceSymbols = yahooSymbols(input.Assets)
|
||||
}
|
||||
articles, err = feed.Scrape(ctx, append([]string(nil), sourceSymbols...))
|
||||
}
|
||||
if err != nil {
|
||||
stat.Status = "failed"
|
||||
|
||||
Reference in New Issue
Block a user