karlwancl / YahooFinanceApi

A handy Yahoo! Finance api wrapper, based on .NET Standard 2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does one get the history data of a stock

EpEthan opened this issue · comments

I'm sorry if this is a redundant or stupid question. However, I copied the code given in the README.md file for getting historical data for a stock, yet the program did not display any data - rather, it simply terminated after the function Yahoo.GetHistoricalAsync().
Sorry again if this is a stupid question. I'm only a beginner and still trying to get the hang of coding...

This is the code by the way:

var history = await Yahoo.GetHistoricalAsync("AAPL", new DateTime(2016, 1, 1), 
    new DateTime(2016, 7, 1), Period.Daily);

foreach (var candle in history)
{
    Console.WriteLine($"DateTime: {candle.DateTime}, Open: {candle.Open}, High: {candle.High}, 
    Low: {candle.Low}, Close: {candle.Close}, Volume: {candle.Volume}, 
    AdjustedClose: {candle.AdjustedClose}");
}

Actually, no exception is thrown. That's what is weird: the program terminates without writing anything. Do you have any idea why it's happening?

Where can I find it?
Again, sorry if these are all dumb questions...

Hello everybody,

I have tested exactly the same code as EpEthan, in C# or vb.net but I always have this exception :
"Exception : Could not convert '2016-01-04,25.652500,26.342501,25.500000,26.337500,24.323219,270597600' to DateTime."
Do you know why ?

Thank you

Hello everybody,

Nobody have an idea about my problem ?
At the beginning I have :
`Option Strict On

Imports YahooFinanceApi
Imports System.IO
Imports System.Threading.Tasks
Imports System.Collections.Generic
Imports System`

And my sub is ;
`Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim dateDebut, dateFin As String
    dateDebut = "2021/01/01"
    dateFin = "2021/04/01"

    Dim dd As Date = DateTime.Parse(dateDebut)
    Dim df As Date = DateTime.Parse(dateFin)
    Dim prices As New List(Of String)
    Dim history = Await Yahoo.GetHistoricalAsync("AIR.PA", dd, df, Period.Daily)

    For Each candle In history
        prices.Add(candle.High.ToString)
        Label1.Text = candle.High.ToString
        Console.WriteLine($"DateTime: {candle.DateTime}, Open: {candle.Open}, High: {candle.High}, Low: {candle.Low}, Close: {candle.Close}, Volume: {candle.Volume}, AdjustedClose: {candle.AdjustedClose}")
    Next

End Sub`

I tried to read a value of historical in a List, in a Label, in the console but nothing wrong...
What am I doing wrong ?

I have no problem with ohter Yahoo functions like
'Dim securities = Await Yahoo. 'Symbols(txtTickers.Text.Split(","c)). 'Fields(Field.Symbol, Field.RegularMarketPrice, Field.RegularMarketTime, Field.Currency, Field.LongName, Field.RegularMarketDayHigh, Field.RegularMarketDayLow, Field.RegularMarketVolume). 'QueryAsync()

ok thank you I will have a look but I would have preferred to understand my mistakes

Problem solved after uninstall and install again all packages!