feat(tickers): finnhub_token alias + auto-map crypto symbols (BTC-USD)#41
Merged
Conversation
- config.rs: FINNHUB_API_KEY falls back to FINNHUB_TOKEN / finnhub_token (matches the key name already used in env files). - routes.rs: finnhub_symbol() maps Yahoo-style crypto (BTC-USD) to Finnhub's COINBASE:BTC-USD so existing BTC-USD tickers keep working; display keeps the user's symbol. Verified live: INTC/TSLA + BTC-USD all return quotes. - frontend hint + README + .env.example: crypto is supported again (BTC-USD). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ef927ec to
34df6a3
Compare
There was a problem hiding this comment.
Pull request overview
This PR is a follow-up to the Finnhub ticker switch, aiming to (1) read the Finnhub API key from the env var names users actually have configured, and (2) restore crypto ticker support by mapping Yahoo-style symbols (e.g. BTC-USD) to an exchange-prefixed Finnhub symbol for quote fetches.
Changes:
- Add
FINNHUB_API_KEYfallbacks toFINNHUB_TOKEN/finnhub_tokenin server config loading. - Auto-map
*-USDcrypto tickers (e.g.BTC-USD) toCOINBASE:*for Finnhub/quoterequests while keeping the displayed label unchanged. - Update docs and UI hints/examples to reflect Finnhub + crypto support.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/routes.rs |
Adds finnhub_symbol() helper and uses it when fetching Finnhub quotes for tickers. |
src/config.rs |
Adds env var aliasing for the Finnhub API key. |
README.md |
Documents key aliases and crypto symbol mapping behavior. |
frontend/actions.ts |
Updates settings editor placeholder/hint to include crypto example. |
public/actions.js |
Updates built JS placeholder/hint to include crypto example. |
.env.example |
Updates ticker/key guidance for Finnhub + crypto and key aliases. |
.gitignore |
Ignores .opencode/ directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+156
to
+159
| finnhub_api_key: env::var("FINNHUB_API_KEY") | ||
| .or_else(|_| env::var("FINNHUB_TOKEN")) | ||
| .or_else(|_| env::var("finnhub_token")) | ||
| .unwrap_or_default(), |
| overlay.id = 'settingsEditor'; | ||
| const panels = dashboardSettings.panels; | ||
| overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label>Tickers</label><div class="ticker-editor"><div class="ticker-chips" id="tickerChips"></div><div class="ticker-add"><input id="tickerInput" type="text" spellcheck="false" autocapitalize="characters" placeholder="Add symbol — e.g. NVDA, TSLA"><button type="button" id="addTickerBtn"><span class="ticker-add-plus">+</span> Add</button></div><p class="muted ticker-hint">Enter to add · Finnhub symbols (US stocks) · max 16</p></div><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`; | ||
| overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label>Tickers</label><div class="ticker-editor"><div class="ticker-chips" id="tickerChips"></div><div class="ticker-add"><input id="tickerInput" type="text" spellcheck="false" autocapitalize="characters" placeholder="Add symbol — e.g. NVDA, TSLA, BTC-USD"><button type="button" id="addTickerBtn"><span class="ticker-add-plus">+</span> Add</button></div><p class="muted ticker-hint">Enter to add · Finnhub symbols · US stocks + crypto (BTC-USD) · max 16</p></div><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`; |
| overlay.id = 'settingsEditor'; | ||
| const panels = dashboardSettings.panels; | ||
| overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label>Tickers</label><div class="ticker-editor"><div class="ticker-chips" id="tickerChips"></div><div class="ticker-add"><input id="tickerInput" type="text" spellcheck="false" autocapitalize="characters" placeholder="Add symbol — e.g. NVDA, TSLA"><button type="button" id="addTickerBtn"><span class="ticker-add-plus">+</span> Add</button></div><p class="muted ticker-hint">Enter to add · Finnhub symbols (US stocks) · max 16</p></div><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`; | ||
| overlay.innerHTML = `<form class="links-editor-box settings-editor-box"><div class="links-editor-head"><div><h2>Configure</h2><p class="muted">Sidebar widgets and stock tickers are saved in dashboard-config.json.</p></div><button type="button" class="ghost" data-close-settings>Cancel</button></div><div class="settings-grid"><label><input type="checkbox" name="machine" ${panels.machine ? 'checked' : ''}> Machine</label><label class="settings-subsetting"><input type="checkbox" name="machineSensors" ${panels.machineSensors ? 'checked' : ''}> Thermal sensors</label><label><input type="checkbox" name="remoteHosts" ${panels.remoteHosts ? 'checked' : ''}> Remote hosts</label><label><input type="checkbox" name="containers" ${panels.containers ? 'checked' : ''}> Local containers</label><label><input type="checkbox" name="links" ${panels.links ? 'checked' : ''}> Links</label><label><input type="checkbox" name="tickers" ${panels.tickers ? 'checked' : ''}> Ticker bar</label><label><input type="checkbox" name="expandLists" ${panels.expandLists ? 'checked' : ''}> Expand lists (no scrollbars)</label></div><label>Tickers</label><div class="ticker-editor"><div class="ticker-chips" id="tickerChips"></div><div class="ticker-add"><input id="tickerInput" type="text" spellcheck="false" autocapitalize="characters" placeholder="Add symbol — e.g. NVDA, TSLA, BTC-USD"><button type="button" id="addTickerBtn"><span class="ticker-add-plus">+</span> Add</button></div><p class="muted ticker-hint">Enter to add · Finnhub symbols · US stocks + crypto (BTC-USD) · max 16</p></div><div class="links-editor-actions"><button type="submit" class="primary">${icon('settings')}<span>Save config</span></button></div></form>`; |
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.
Follow-up to #40. Two fixes so the Finnhub ticker works with the key as it's actually stored, and so crypto keeps working after the Yahoo→Finnhub switch.
FINNHUB_API_KEYnow falls back toFINNHUB_TOKEN/finnhub_token(the name used in the env files).finnhub_symbol()maps a Yahoo-styleBTC-USD→COINBASE:BTC-USD(Finnhub returns{c:0}for a bareBTC-USD). Stocks never end in-USD, and explicitBINANCE:…symbols pass through. The displayed label keeps the user's symbol..env.exampleupdated — crypto (BTC-USD) is supported again.Verified live (release binary, real key):
/api/tickers→INTC $111.78 −0.83%,TSLA $418.45 −1.24%,BTC-USD $62,894 −1.43%. Browser: 3 ticks, no overflow, 0 console errors.tsc+cargo build --releasegreen.🤖 Generated with Claude Code