Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stock-tracker extension - Fix yahoo finance rate limiting #16658

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/stock-tracker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Stock Tracker Changelog

## [Fix] - 2025-01-27

- Fix the integration with the Yahoo Finance API by adding a browser header

## [Fix] - 2023-06-03

- Fix the integration with the Yahoo Finance API by providing a cookie
Expand Down
3 changes: 3 additions & 0 deletions extensions/stock-tracker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"description": "Shows stock market data for individual stocks or your portfolio by using Yahoo Finance.",
"icon": "extension-icon.png",
"author": "hmarr",
"contributors": [
"ericchernuka"
],
"categories": [
"Finance"
],
Expand Down
6 changes: 2 additions & 4 deletions extensions/stock-tracker/src/favorites-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ function FavouritesActions({ favorites, quote, favoritesStore }: FavouritesActio
<Action
title="Move Up in Favorites"
icon={Icon.ArrowUp}
// TODO: switch to cmd+opt+up, but that doesn't work for some reason. Raycast bug?
shortcut={{ modifiers: ["opt"], key: "k" }}
shortcut={{ modifiers: ["cmd", "opt"], key: "arrowUp" }}
onAction={() => favoritesStore.moveUp(quote.symbol!)}
/>
<Action
title="Move Down in Favorites"
icon={Icon.ArrowDown}
// TODO: switch to cmd+opt+down, but that doesn't work for some reason. Raycast bug?
shortcut={{ modifiers: ["opt"], key: "j" }}
shortcut={{ modifiers: ["cmd", "opt"], key: "arrowDown" }}
onAction={() => favoritesStore.moveDown(quote.symbol!)}
/>
<FavoritesAddRemoveAction favorites={favorites} favoritesStore={favoritesStore} symbol={quote.symbol!} />
Expand Down
8 changes: 7 additions & 1 deletion extensions/stock-tracker/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ export default function Command() {
const isLoading = searchText.length > 0 ? searchIsLoading : favoritesIsLoading;

return (
<List onSearchTextChange={setSearchText} searchText={searchText} throttle isShowingDetail isLoading={isLoading}>
<List
onSearchTextChange={setSearchText}
searchText={searchText}
throttle={true}
isShowingDetail
isLoading={isLoading}
>
{searchText.length > 0 ? (
<SearchList searchText={searchText} handleLoading={setSearchIsLoading} />
) : (
Expand Down
11 changes: 8 additions & 3 deletions extensions/stock-tracker/src/yahoo-finance/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { LocalStorage } from "@raycast/api";
import fetch from "cross-fetch";

const HEADERS = {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
} as const;

export async function get<T>(path: string, params: { [key: string]: string }, signal: AbortSignal): Promise<T> {
// Requests to Yahoo Finance require a cookie (header) and a crumb (query param).
const { cookie, crumb } = await cookieCrumb();
Expand Down Expand Up @@ -30,7 +35,7 @@ async function request<T>(
}

const response = await fetch(url.toString(), {
headers: { cookie },
headers: { cookie, ...HEADERS },
signal,
});
if (response.status !== 200) {
Expand Down Expand Up @@ -69,7 +74,7 @@ export async function cookieCrumb(): Promise<CookieCrumb> {
}

async function getCookie(): Promise<string> {
const response = await fetch("https://fc.yahoo.com");
const response = await fetch("https://fc.yahoo.com", { headers: HEADERS });
const cookie = response.headers.get("set-cookie");
if (!cookie) {
throw new Error("Failed to fetch cookie");
Expand All @@ -79,7 +84,7 @@ async function getCookie(): Promise<string> {

async function getCrumb(cookie: string): Promise<string> {
const response = await fetch("https://query1.finance.yahoo.com/v1/test/getcrumb", {
headers: { cookie },
headers: { cookie, ...HEADERS },
});
const crumb = await response.text();
if (!crumb) {
Expand Down
Loading