Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

kirlut/AlphaVantage.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GitHub

This project is in the archive.

Unfortunately, I don't have time to contribute to this repo anymore and publish updates. Feel free to fork and use it however you need to. If you would like to continue development and want to hold ownership of NuGet packages, please email me: lutkir@pm.me

AlphaVantage.Net

The most popular .Net client library for Alpha Vantage API.

Release notes for version 2:

  • Most of the library classes were rewritten from scratch, keeping in mind all issues that were opened for the previous release.
  • New client works with System.Text.Json under the hood which is faster than classic Newtonsoft Json
  • Now you can create client's instances with 6 different constructors. It gives you access to underlying HttpClient + allow you to create wrappers around it if needed.
  • All packages were written using newest C# Nullable reference types feature, to reduce possible bugs

Packages:

  • AlphaVantage.Net.Core - low-level client for Alpha Vantage API based on HttpClient and System.Text.Json

Fully typed clients:

Documentation

AlphaVantage.Net.Core

Nuget (with prereleases) Nuget
This package allow you to request any available data from API, but you have to manually set all query parameters and retrieve information you need from the result

Installation:

  • Package Manager:
    Install-Package AlphaVantage.Net.Core -Version 2.0.1
  • .NET CLI:
    dotnet add package AlphaVantage.Net.Core --version 2.0.1

Usage:

using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using AlphaVantage.Net.Common;
using AlphaVantage.Net.Core.Client;

.....

public static async Task CoreDemo()
{
    // use your AlphaVantage API key
    string apiKey = "1";
    // there's 5 more constructors available
    using var client = new AlphaVantageClient(apiKey);

    // query for intraday time series for Apple Inc:
    var query = new Dictionary<string, string>()
    {
        {"symbol", "AAPL"},
        {"interval", "15min"}
    };
    
    // retrieve response as pure JSON string
    string stringResult = await client.RequestPureJsonAsync(ApiFunction.TIME_SERIES_INTRADAY, query);

    // retrieve response as parsed JsonDocument from System.Text.Json
    JsonDocument parsedResult = await client.RequestParsedJsonAsync(ApiFunction.TIME_SERIES_INTRADAY, query);
}

AlphaVantage.Net.Stocks

Nuget (with prereleases) Nuget

Installation:

  • Package Manager:
    Install-Package AlphaVantage.Net.Stocks -Version 2.0.1
  • .NET CLI:
    dotnet add package AlphaVantage.Net.Stocks --version 2.0.1

Usage:

using System.Collections.Generic;
using System.Threading.Tasks;
using AlphaVantage.Net.Common.Intervals;
using AlphaVantage.Net.Common.Size;
using AlphaVantage.Net.Core.Client;
using AlphaVantage.Net.Stocks;
using AlphaVantage.Net.Stocks.Client;

.....

public static async Task StocksDemo()
{
    // use your AlphaVantage API key
    string apiKey = "1";
    // there are 5 more constructors available
    using var client = new AlphaVantageClient(apiKey);
    using var stocksClient = client.Stocks();

    StockTimeSeries stockTs = await stocksClient.GetTimeSeriesAsync("AAPL", Interval.Daily, OutputSize.Compact, isAdjusted: true);

    GlobalQuote globalQuote = await stocksClient.GetGlobalQuoteAsync("AAPL");

    ICollection<SymbolSearchMatch> searchMatches = await stocksClient.SearchSymbolAsync("BA");
}

AlphaVantage.Net.Forex

Nuget (with prereleases) Nuget

Installation:

  • Package Manager:
    Install-Package AlphaVantage.Net.Forex -Version 2.0.1
  • .NET CLI:
    dotnet add package AlphaVantage.Net.Forex --version 2.0.1

Usage:

using System.Threading.Tasks;
using AlphaVantage.Net.Common.Currencies;
using AlphaVantage.Net.Common.Intervals;
using AlphaVantage.Net.Common.Size;
using AlphaVantage.Net.Core.Client;
using AlphaVantage.Net.Forex;
using AlphaVantage.Net.Forex.Client;

.....

public static async Task ForexDemo()
{
    // use your AlphaVantage API key
    string apiKey = "1";
    // there are 5 more constructors available
    using var client = new AlphaVantageClient(apiKey);
    using var forexClient = client.Forex();

    ForexTimeSeries forexTimeSeries = await forexClient.GetTimeSeriesAsync(
        PhysicalCurrency.USD, 
        PhysicalCurrency.ILS,
        Interval.Daily, 
        OutputSize.Compact);
            
    ForexExchangeRate forexExchangeRate = await forexClient.GetExchangeRateAsync(PhysicalCurrency.USD, PhysicalCurrency.ILS);
}

AlphaVantage.Net.Crypto

Nuget (with prereleases) Nuget

Installation:

  • Package Manager:
    Install-Package AlphaVantage.Net.Crypto -Version 2.0.1
  • .NET CLI:
    dotnet add package AlphaVantage.Net.Crypto --version 2.0.1

Usage:

using System.Threading.Tasks;
using AlphaVantage.Net.Common.Currencies;
using AlphaVantage.Net.Common.Intervals;
using AlphaVantage.Net.Core.Client;
using AlphaVantage.Net.Crypto;
using AlphaVantage.Net.Crypto.Client;

.....

public static async Task CryptoDemo()
{
    // use your AlphaVantage API key
    string apiKey = "1";
    // there are 5 more constructors available
    using var client = new AlphaVantageClient(apiKey);
    using var cryptoClient = client.Crypto();

    CryptoTimeSeries cryptoTimeSeries =
        await cryptoClient.GetTimeSeriesAsync(DigitalCurrency.BTC, PhysicalCurrency.ILS, Interval.Weekly);

    CryptoRating cryptoRating = await cryptoClient.GetCryptoRatingAsync(DigitalCurrency.BTC);

    CryptoExchangeRate exchangeRate =
        await cryptoClient.GetExchangeRateAsync(DigitalCurrency.BTC, PhysicalCurrency.ILS);
}

AlphaVantage.Net.TechnicalIndicators

Nuget (with prereleases) Nuget
Since API endpoints from this section have many different additional parameters, you still need to check Alpha Vantage documentation in order to use it.

Installation:

  • Package Manager:
    Install-Package AlphaVantage.Net.TechnicalIndicators -Version 2.0.1
  • .NET CLI:
    dotnet add package AlphaVantage.Net.TechnicalIndicators --version 2.0.1

Usage:

using System.Collections.Generic;
using System.Threading.Tasks;
using AlphaVantage.Net.Common.Intervals;
using AlphaVantage.Net.Core.Client;
using AlphaVantage.Net.TechnicalIndicators;
using AlphaVantage.Net.TechnicalIndicators.Client;

.....

public static async Task TechIndicatorsDemo()
{
    // use your AlphaVantage API key
    string apiKey = "1";
    // there are 5 more constructors available
    using var client = new AlphaVantageClient(apiKey);

    var symbol = "IBM";
    var indicatorType = TechIndicatorType.SMA;
    var query = new Dictionary<string, string>()
    {
        {"time_period", "20"},
        {"series_type", "close"}
    };

    TechIndicatorTimeSeries result = await client.GetTechIndicatorTimeSeriesAsync(symbol, indicatorType, Interval.Min15, query);
}