Updated to point to new rest api for stock info

This commit is contained in:
dfinke
2019-02-02 16:58:51 -05:00
parent 37b076706e
commit e7afe166a4
2 changed files with 20 additions and 18 deletions

View File

@@ -1,25 +1,24 @@
<#
Revisit I think yahoo deprecated their service
#>
function Get-StockInfo {
param(
$stock,
[datetime]$startDate,
[datetime]$endDate
[Parameter(Mandatory)]
$symbols,
[ValidateSet('open', 'close', 'high', 'low', 'avgTotalVolume')]
$dataPlot = "close"
)
Process {
$xlfile = "$env:TEMP\stocks.xlsx"
rm $xlfile -ErrorAction Ignore
if (!$endDate) { $endDate = $startDate}
$result = Invoke-RestMethod "https://api.iextrading.com/1.0/stock/market/batch?symbols=$($symbols)&types=quote&last=1"
$baseUrl = "http://query.yahooapis.com/v1/public/yql?q="
$q = @"
select * from yahoo.finance.historicaldata where symbol = "$($stock)" and startDate = "$($startDate.ToString('yyyy-MM-dd'))" and endDate = "$($endDate.ToString('yyyy-MM-dd'))"
"@
$suffix = "&env=store://datatables.org/alltableswithkeys&format=json"
$r = Invoke-RestMethod ($baseUrl + $q + $suffix)
$r.query.results.quote
$symbolCount = $symbols.Split(",").count
}
}
$ecd = New-ExcelChartDefinition -Row 1 -Column 1 -SeriesHeader $dataPlot `
-XRange symbol -YRange $dataPlot `
-Title "$($dataPlot)`r`n As Of $((Get-Date).ToShortDateString())"
$(foreach ($name in $result.psobject.Properties.name) {
$result.$name.quote
}) | Export-Excel $xlfile -AutoNameRange -AutoSize -Show -ExcelChartDefinition $ecd -StartRow 21 -StartColumn 2
}

View File

@@ -0,0 +1,3 @@
. $PSScriptRoot\Get-StockInfo.ps1
Get-StockInfo -symbols "msft,ibm,ge,xom,aapl" -dataPlot avgTotalVolume