feat: company names for tickers (Alpaca backfill + subtle display)
Store an optional company name on Ticker (migration 014) and backfill it from Alpaca's asset list in a single Trading-API call for the whole universe — no per-ticker fetch. Runs automatically at the end of universe bootstrap and via a manual "Backfill Names" button (admin) / POST /admin/tickers/backfill-names. The name ships on /tickers; a shared symbol→name map (useTickerNames) lets any view show it without its own request. Displayed subtly next to the symbol — in the global search, the ticker header, and as a small muted line under the symbol in Top Setups and Open Trades (no extra column, truncated so it never widens the table). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -283,6 +283,22 @@ export function useBootstrapTickers() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useBackfillTickerNames() {
|
||||
const qc = useQueryClient();
|
||||
const { addToast } = useToast();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => adminApi.backfillTickerNames(),
|
||||
onSuccess: (result) => {
|
||||
qc.invalidateQueries({ queryKey: ['tickers'] });
|
||||
addToast('success', `Company names: +${result.updated} filled (${result.unmatched} unmatched)`);
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
addToast('error', error.message || 'Failed to backfill company names');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ── Jobs ──
|
||||
|
||||
export function useJobs() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import * as tickersApi from '../api/tickers';
|
||||
import { useToast } from '../components/ui/Toast';
|
||||
@@ -9,6 +10,19 @@ export function useTickers() {
|
||||
});
|
||||
}
|
||||
|
||||
/** symbol (upper) → company name, from the tracked-ticker list. Shared lookup so
|
||||
* any view can show the company behind a symbol without its own request. */
|
||||
export function useTickerNames(): Map<string, string> {
|
||||
const { data } = useTickers();
|
||||
return useMemo(() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const t of data ?? []) {
|
||||
if (t.name) map.set(t.symbol.toUpperCase(), t.name);
|
||||
}
|
||||
return map;
|
||||
}, [data]);
|
||||
}
|
||||
|
||||
export function useAddTicker() {
|
||||
const qc = useQueryClient();
|
||||
const { addToast } = useToast();
|
||||
|
||||
Reference in New Issue
Block a user