ooples / OoplesFinance.YahooFinanceAPI

A .NET API wrapper for Yahoo Finance that allows users to get top trending stocks, historical stock data, stock splits, dividends, capital gains, and much much more!
Apache License 2.0
47 stars 10 forks source link

Splits #4

Closed ElDuderinoBerlin closed 1 year ago

ElDuderinoBerlin commented 1 year ago

Hi,

splits shall be numerator / denominator, not a string.

In most cases ppl must parse the string and build the ratio to calculate adjusted prices.

Just a hint.

Regards Martin

ooples commented 1 year ago

@maddinthegreat I purposely kept it this way to allow users to decide what to do with the data themselves. I'm open to suggestions of course

ElDuderinoBerlin commented 1 year ago

Hi,

where do you get the URLs from? Is there an API documentation for the Yahoo-API? Didn't find something.

Regards Martin

ElDuderinoBerlin commented 1 year ago

I made this that way:

public sealed class StockSplitData { public DateTime Date { get; set; } = default!; public string StockSplit { get; set; } = default!;

private void Parse(out double before, out double after)
{
    var splitted = StockSplit.Split(':');
    if (splitted.Length != 2 || !double.TryParse(splitted[0], out after) || !double.TryParse(splitted[1], out before))
    {
        throw new FormatException($"{nameof(StockSplit)} has incorrect format!");
    }
}

public double Before
{
    get
    {
        Parse(out var before, out var after);
        return before;
    }
}

public double After
{
    get
    {
        Parse(out var before, out var after);
        return after;
    }
}

public override string ToString()
{
    return $"Date: {Date:dd.MM.yyyy} - Before: {Before:#.#}, After:{After:#.#}";
}

}

ooples commented 1 year ago

@maddinthegreat These urls were compiled mostly by a good friend of mine who managed to analyze the internal data network that Yahoo uses to populate their website. These are not meant to be public at all so you won't find any documentation for any of them. As far as your code goes, I will use something similar to return a StockSplit object that will have the converted values. Or if you want, you could contribute to this project and add some of your code instead. Let me know

github-actions[bot] commented 1 year ago

Stale issue message