Skip to content

Instantly share code, notes, and snippets.

@ptrelford
Created July 17, 2014 13:03
Show Gist options
  • Save ptrelford/4b31b3a6b9cb12bf4222 to your computer and use it in GitHub Desktop.
Save ptrelford/4b31b3a6b9cb12bf4222 to your computer and use it in GitHub Desktop.
Yahoo reade
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
namespace DashboardApp
{
public static class Yahoo
{
public static IEnumerable<object> GetPrices(string stock)
{
var url = "http://ichart.finance.yahoo.com/table.csv?s=" + stock;
var request = HttpWebRequest.Create(url);
var response = request.GetResponse();
var stream = response.GetResponseStream();
var reader = new StreamReader(stream);
var first = true;
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var fields = line.Split(',');
if (!first)
yield return new {
Date = DateTime.Parse(fields[0]),
Open = Decimal.Parse(fields[1]),
High = Decimal.Parse(fields[2]),
Low = Decimal.Parse(fields[3]),
Close = Decimal.Parse(fields[4]),
Volume = Decimal.Parse(fields[5])
};
first = false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment