Get stock price

Everything else that doesn't fall into one of the other PB categories.
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Get stock price

Post by WilliamL »

I see that there has been other threads about this but no easy answers.

I just need to get a stock price and I've been using this.

Code: Select all

Filename$ = SaveFileRequester("Where to save txt file", "", "", 0)
  If ReceiveHTTPFile("http://finance.yahoo.com/q?s=%5EDJI", Filename$)
    Debug "File recieved and written to disk. If the remote file was not found, it will contains the webserver error."
  Else
    Debug "No file recieved (network error)."
  EndIf
I get a lot of text and it is a pain to filter out all the text and find the price.

Is there an easier way to get the stock price without all the other text?
Last edited by WilliamL on Sat Jun 01, 2024 11:53 pm, edited 2 times in total.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
Fips
User
User
Posts: 35
Joined: Sun Feb 20, 2022 1:03 pm

Re: Get stock price

Post by Fips »

I doubt that you actually retrieve the information you are looking for. You probably get a HTML document with some javascript functions but not your stock price.

Yahoo finance used to be cool but it seems they shut down their api some years ago. Some claim that in the US this might still work (cant test). Some python libraries also still seem to be working.

I think the request would be something like

Code: Select all

https://query1.finance.yahoo.com/v11/finance/quoteSummary/DTG.DE
You would get a JSON as an answer.

I then started to use alphavantage. But you need to get an api key. It is free but limited to a certain amount of request per day. I guess they are offering some kind of premium as well. I haven't been using it for a while. Was ok for my needs back then.

The request would be something like:

Code: Select all

https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=Dai.de&apikey=XXXXXX
PB400
New User
New User
Posts: 5
Joined: Wed Feb 08, 2017 10:21 pm

Re: Get stock price

Post by PB400 »

Hi,

The Yahoo stock APIs work fine but it is difficult to find what version actually works as they provide zero support. Here are some examples you may find useful though:

; Company Search and Details (Sector etc)
https://query1.finance.yahoo.com/v1/fin ... rch?q=AVON

; News
https://query1.finance.yahoo.com/ws/ins ... bol=AVON.L

; Historic Price Download
https://query1.finance.yahoo.com/v7/fin ... ts=history

; Dividends
https://query1.finance.yahoo.com/v7/fin ... Close=true

;The following is also a useful link that give more info on some of the APIs, its not up to date but it is useful.
https://cryptocointracker.com/yahoo-fin ... inance-api

You are going to have to do some leg work working out each of the parameters and formatting the returned data but UK Price info is 15 minute delayed but US data is much less, it amazing what they provide for free really.
Post Reply