Git Product home page Git Product logo

yahooquotesapi's Introduction

YahooQuotesApi   Build status NuGet NuGet License: MIT Ukraine

Retrieves from Yahoo Finance: quote snapshots, historical quotes, dividends, splits, and modules

  • .NET 6.0 library
  • intellisense support for properties
  • simple and intuitive API
  • fault-tolerant
  • tested
  • dependencies: Polly, NodaTime

Installation

PM> Install-Package YahooQuotesApi

Examples

snapshot

using NodaTime;
using YahooQuotesApi;

YahooQuotes yahooQuotes = new YahooQuotesBuilder().Build();

Security? security = await yahooQuotes.GetAsync("AAPL");

if (security is null)
    throw new ArgumentException("Unknown symbol: AAPL.");

Assert.Equal("Apple Inc.", security.LongName);
Assert.True(security.RegularMarketPrice > 0);

snapshots

YahooQuotes yahooQuotes = new YahooQuotesBuilder().Build();

Dictionary<string,Security?> securities = await yahooQuotes.GetAsync(new[] { "AAPL", "BP.L", "USDJPY=X" });

Security security = securities["BP.L"] ?? throw new ArgumentException("Unknown symbol");

Assert.Equal("BP p.l.c.", security.LongName);
Assert.Equal("GBP", security.Currency, true);
Assert.Equal("LSE", security.Exchange);
Assert.True(security.RegularMarketPrice > 0);

snapshot with price history

YahooQuotes yahooQuotes = new YahooQuotesBuilder()
    .WithHistoryStartDate(Instant.FromUtc(2020, 1, 1, 0, 0))
    .Build();

Security security = await yahooQuotes.GetAsync("MSFT", HistoryFlags.PriceHistory)
    ?? throw new ArgumentException("Unknown symbol.");

Assert.Equal("NasdaqGS", security.FullExchangeName);

Assert.False(security.PriceHistory.HasError);
CandleTick[] priceHistory = security.PriceHistory.Value;
CandleTick tick = priceHistory[0];

Assert.Equal(new LocalDate(2020, 1, 2), tick.Date);
Assert.Equal(160.62, tick.Close);

snapshot with price history in base currency

YahooQuotes yahooQuotes = new YahooQuotesBuilder()
    .WithHistoryStartDate(Instant.FromUtc(2020, 7, 15, 0, 0))
    .WithCacheDuration(snapshotDuration: Duration.FromMinutes(30), historyDuration: Duration.FromHours(6))
    .Build();

Security security = await yahooQuotes
    .GetAsync("TSLA", HistoryFlags.PriceHistory, historyBase: "JPY=X")
        ?? throw new ArgumentException("Unknown symbol.");

Assert.Equal("Tesla, Inc.", security.ShortName);
Assert.Equal("USD", security.Currency);
Assert.Equal("America/New_York", security.ExchangeTimezone?.Id);

CandleTick tick = security.PriceHistory.Value[0];
Assert.Equal(new LocalDate(2020, 7, 15), tick.Date);
Assert.Equal(103.0673, tick.Close); // in USD

Instant instant = new LocalDateTime(2020, 7, 15, 16, 0, 0)
    .InZoneLeniently(security.ExchangeTimezone!).ToInstant();

ValueTick tickBase = security.PriceHistoryBase.Value[0];
Assert.Equal(instant, tickBase.Date);
Assert.Equal(11046, tickBase.Value, 0); // in JPY

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.