extensions icon indicating copy to clipboard operation
extensions copied to clipboard

[Stock Tracker] ... Error fetching stock data

Open MeleMannen opened this issue 1 year ago • 22 comments

Extension

https://www.raycast.com/hmarr/stock-tracker

Raycast Version

1.98.4

macOS Version

15.5

Description

Hi! I just downloaded your extension Stock Tracker, but i cant seem to get it to work. I have tried to reinstall it, but it did nothing. When i try to search for a Stock like AAPL or something like that, i get this error:

Image

Steps To Reproduce

  1. Activate raycast
  2. Run the View Stocks command.
  3. Search for something, like AAPL
  4. Get the error in the image below.

Current Behaviour

Does not receive anything back from Yahoo by the looks of it.

Expected Behaviour

See some info about the Stock.

MeleMannen avatar May 14 '25 00:05 MeleMannen

Thank you for opening this issue!

🔔 @hmarr @ericchernuka you might want to have a look.

💡 Author and Contributors commands

The author and contributors of hmarr/stock-tracker can trigger bot actions by commenting:

  • @raycastbot close this issue Closes the issue.
  • @raycastbot close as not planned Closes the issue as not planned.
  • @raycastbot rename this issue to "Awesome new title" Renames the issue.
  • @raycastbot reopen this issue Reopens the issue.
  • @raycastbot assign me Assigns yourself to the issue.
  • @raycastbot good first issue Adds the "Good first issue" label to the issue.
  • @raycastbot keep this issue open Make sure the issue won't go stale and will be kept open by the bot.

raycastbot avatar May 14 '25 00:05 raycastbot

I recently saw this and haven't had a chance to look into it. Seems like Yahoo may have changed something on their end for how they validate the cookie so I'll look to investigate if there's a workaround.

ericchernuka avatar May 14 '25 01:05 ericchernuka

Ahhh i see, but do you actually need the Cookie? Because i made an iOS app with the same API, and i didn't touch any Cookie things? Is there a reason you need it or could you maybe just remove that part? Thanks anyway for the update and good luck!

MeleMannen avatar May 14 '25 16:05 MeleMannen

Oh interesting! It was there previously and from all the googling it seemed like the way most were doing it.

In your app did you need a API token to leverage it? I think this one is just scrapping the web thus the cookie technique.

ericchernuka avatar May 14 '25 17:05 ericchernuka

Same here 🤚

rafaell-lycan avatar May 14 '25 17:05 rafaell-lycan

Ahhh sike, i just looked at how i did it and i was using a cromb, but only for this call: https://query1.finance.yahoo.com/v6/finance/options/(symbol)?cromb=(cromb), whitch no longer works for my either.

MeleMannen avatar May 14 '25 17:05 MeleMannen

Witch API's are you using for the extension and witch is the culprit?

MeleMannen avatar May 14 '25 18:05 MeleMannen

https://github.com/raycast/extensions/blob/main/extensions/stock-tracker/src/yahoo-finance/client.ts

This would be it

ericchernuka avatar May 14 '25 23:05 ericchernuka

I think i found the issue. You just need to add this in HEADERS: "Host": "query2.finance.yahoo.com", in this file: https://github.com/raycast/extensions/blob/main/extensions/stock-tracker/src/yahoo-finance/client.ts.

MeleMannen avatar May 25 '25 13:05 MeleMannen

@MeleMannen quickly tossed that in, but I still get the error. I wonder if the best approach here might be to leverage https://github.com/gadicc/node-yahoo-finance2 to keep pace with updates due to Yahoo's unauthorized detection techniques.

A quick patch to leverage it seemed to get it working again, but I haven't had a chance to really battle test it.

ericchernuka avatar May 25 '25 16:05 ericchernuka

@ericchernuka Yeah that could maybe be smart, but i actually managed to fix it. On my machine at least😅. I just replaced the User-Agent with another one. Very weird and took me a long time to figure out, as i don't have any experience in TypeScript. I just published the fix pending review.

MeleMannen avatar May 26 '25 00:05 MeleMannen

I'll have a look!

I had been playing with randomly selecting a user agent string in order to provide some variability. Shamelessly taken from the python library for Yahoo finance.

ericchernuka avatar May 26 '25 00:05 ericchernuka

Nice! I had to fix a quick format issue, but it should hopefully pass the tests now.

Haha nice. Yeah that could be cool, but some of them obviously don't work. I tried like 3 different ones, before the one that worked. But if one could find more than one that works, it would probably be smart as more people would be using different User-Agent, and therefore a smaller chance for yahoo to block them.

MeleMannen avatar May 26 '25 00:05 MeleMannen

There's some interesting techniques for sure. Just found this in the node one. https://github.com/gadicc/node-yahoo-finance2/blob/devel/src/lib/getCrumb.ts#L303C5-L303C29

ericchernuka avatar May 26 '25 00:05 ericchernuka

Wow! That is genius! That could definitely be worth looking into, especially if it fails again!

MeleMannen avatar May 26 '25 00:05 MeleMannen

I found a problem, witch i am not sure how to fix. The problem is that the stored Crumb is bad, so when it updates, it does not fix the issue. The user will have to reinstall the extension, before it will work. But i am not sure what would be the best fix for this. Is there a way to remove all LocalStorage for that extension when updating it or something like that?

MeleMannen avatar May 26 '25 11:05 MeleMannen

One solution could perhaps be to check if the LocalStorage, of the crumb value, is equal to "Too Many Requests" or something like that, and then delete it if it is.

MeleMannen avatar May 26 '25 13:05 MeleMannen

Or even if the crumb just includes a letter.

MeleMannen avatar May 26 '25 13:05 MeleMannen

Sorry. Haven't had a chance to look yet, but we could probably check the status of the request is over 400 not save it. If we had a previous one, but it's since been invalidated. We should probably clear it, then retry the cookie flow.

ericchernuka avatar May 26 '25 13:05 ericchernuka

Smart! I tried to implement a version of that solution and an attempt at the cool User-Agent. I only included the name as i did not find any version number i could use.

MeleMannen avatar May 26 '25 15:05 MeleMannen