Last active
February 22, 2021 01:12
-
-
Save markholdt/099fff06d515a39964932e6eafded243 to your computer and use it in GitHub Desktop.
AlphaVantage - Retrieve Prices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using ServiceStack; | |
using ServiceStack.Text; | |
public class AlphaVantageData | |
{ | |
public DateTime Timestamp { get; set; } | |
public decimal Open { get; set; } | |
public decimal High { get; set; } | |
public decimal Low { get; set; } | |
public decimal Close { get; set; } | |
public decimal Volume { get; set; } | |
} | |
// retrieve monthly prices for Microsoft | |
var symbol = "MSFT"; | |
var apiKey = "demo"; // retrieve your api key from https://www.alphavantage.co/support/#api-key | |
var monthlyPrices = $"https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol={symbol}&apikey={apiKey}&datatype=csv" | |
.GetStringFromUrl().FromCsv<List<AlphaVantageData>>(); | |
monthlyPrices.PrintDump(); | |
// some simple stats | |
var maxPrice = monthlyPrices.Max(u => u.Close); | |
var minPrice = monthlyPrices.Min(u => u.Close); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="System.Memory" version="4.5.2" targetFramework="net45" /> | |
<package id="ServiceStack.Text" version="5.5.0" targetFramework="net45" /> | |
<package id="ServiceStack.Client" version="5.5.0" targetFramework="net45" /> | |
<package id="ServiceStack.Interfaces" version="5.5.0" targetFramework="net45" /> | |
</packages> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment