0

I was inspired by the answer here and the function get_stock_historical_data in python module investpy to write in Powershell a function that retrieves all the daily prices of a stock between two dates :

$uri = 'https://www.investing.com/instruments/HistoricalDataAjax'

$params = @{
    'curr_id'= '951481'
    'smlID'= '2081817'
    'header'= 'STOXX 50 Volatility VSTOXX EUR Historical Data'
    'st_date'= '04/13/2021'
    'end_date'= '04/13/2002'
    'interval_sec'= 'Daily'
    'sort_col'= 'date'
    'sort_ord'= 'DESC'
    'action'= 'historical_data'
}

$headers = @{
    'User-Agent' = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0'
    'X-Requested-With'= 'XMLHttpRequest'
    'Accept'= 'text/html'
    'Accept-Encoding'= 'gzip, deflate'}

$res = Invoke-WebRequest -Method POST -Headers $headers  -Uri $uri -Body $params -ContentType application/x-www-form-urlencoded
$res.Content > .\test.txt

My issue is that the response contains

<td colspan="7" class="arial_11 blueFont center">No results found</td>

But it should return all the prices of the stock over a year

For information, when I send it directly from investing and inspect the page I get :

General

Form

Thanks for your help !

user438383
  • 5,716
  • 8
  • 28
  • 43
Alex
  • 217
  • 1
  • 17
  • 1
    From `'st_date'= '04/13/2021'` to `'end_date'= '04/13/2002'` doesn't make much sense. I'm guessing it'll work much better if you change `end_date` to any date after what you specified in `st_date`. – notjustme Apr 13 '22 at 11:03
  • 1
    It was just that ! I wanted to write 2022. I was looking for much more complicated explanations, thank you! – Alex Apr 13 '22 at 11:16

1 Answers1

1

The problem in this particular example is the start date ('st_date'='04/13/2021') being a date after the end date ('end_date'='04/13/2002'). The request is hence basically for data from after 2021 but before 2002, which doesn't quite make sense.

Changing the latter to any date after 04/13/2021 in this scenario should solve the problem.

notjustme
  • 2,376
  • 2
  • 20
  • 27