rapitidyquant

How do you count the number of api calls in tidyquant?


For example, I'm getting stock prices from yahoo finance using tidyquant in r.

library(tidyquant)
tq_get(c("AAPL","AMD"), from = '20222-03-01', to = '2022-03-02')

This will result in 4 rows.

How many api calls does this result in?


Solution

  • 2 api calls.

    Each ticker and date combination (from, to) and daily, weekly or monthly data is one api call. The api call is based on quantmod's getSymbols.yahoo which builds the query via .yahooURL. This url is a combination of the ticker, from, to, period (daily, weekly, monthly), event (historical data, dividend data or split data).

    You can see this in action if you look at the yahoo finance historical data and then look at the download link. E.g. for MSFT: https://finance.yahoo.com/quote/MSFT/history?p=MSFT

    1 api call for historical MSFT data:

    https://query1.finance.yahoo.com/v7/finance/download/MSFT?period1=1617621728&period2=1649157728&interval=1d&events=history&includeAdjustedClose=true

    So in your example, 2 queries will be sent to the yahoo servers.