mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-11-15 03:00:23 +00:00
what is going on
This commit is contained in:
commit
29fe11504e
5 changed files with 8 additions and 3021 deletions
|
@ -43,6 +43,7 @@
|
||||||
<Compile Include="DictionaryExtensions.cs" />
|
<Compile Include="DictionaryExtensions.cs" />
|
||||||
<Compile Include="AndroidSqliteBase.cs" />
|
<Compile Include="AndroidSqliteBase.cs" />
|
||||||
<Compile Include="EnumExtensions.cs" />
|
<Compile Include="EnumExtensions.cs" />
|
||||||
|
<Compile Include="AndroidSqliteBase.cs" />
|
||||||
<Compile Include="PortfolioRepositories\AndroidSqlitePortfolioRepository.cs" />
|
<Compile Include="PortfolioRepositories\AndroidSqlitePortfolioRepository.cs" />
|
||||||
<Compile Include="PortfolioRepositories\IPortfolioRepository.cs" />
|
<Compile Include="PortfolioRepositories\IPortfolioRepository.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
using FileHelpers;
|
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Core.StockData
|
|
||||||
{
|
|
||||||
[DelimitedRecord(",")]
|
|
||||||
public class YahooFinanceStockData
|
|
||||||
{
|
|
||||||
[FieldQuoted(QuoteMode.OptionalForBoth)]
|
|
||||||
public string Ticker;
|
|
||||||
|
|
||||||
public decimal LastTradePrice;
|
|
||||||
|
|
||||||
[FieldQuoted(QuoteMode.OptionalForBoth)]
|
|
||||||
public string Name;
|
|
||||||
|
|
||||||
public string Volume;
|
|
||||||
|
|
||||||
public decimal Change;
|
|
||||||
|
|
||||||
[FieldQuoted(QuoteMode.OptionalForBoth)]
|
|
||||||
public string LastTradeTime;
|
|
||||||
|
|
||||||
[FieldQuoted(QuoteMode.OptionalForBoth)]
|
|
||||||
public string RealTimeLastTradeWithTime;
|
|
||||||
|
|
||||||
[FieldQuoted(QuoteMode.OptionalForBoth)]
|
|
||||||
public string ChangeRealTime;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using Android.Util;
|
|
||||||
using FileHelpers;
|
|
||||||
using MonoStockPortfolio.Entities;
|
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Core.StockData
|
|
||||||
{
|
|
||||||
public class YahooStockDataProvider : IStockDataProvider
|
|
||||||
{
|
|
||||||
private const string LAST_TRADE_PRICE_ONLY = "l1";
|
|
||||||
private const string NAME = "n";
|
|
||||||
private const string VOLUME = "v";
|
|
||||||
private const string TICKER_SYMBOL = "s";
|
|
||||||
private const string CHANGE = "c1";
|
|
||||||
private const string LAST_TRADE_TIME = "t1";
|
|
||||||
private const string REAL_TIME_LAST_TRADE_WITH_TIME = "k1";
|
|
||||||
private const string REAL_TIME_CHANGE = "c6";
|
|
||||||
|
|
||||||
// http://www.gummy-stuff.org/Yahoo-data.htm
|
|
||||||
// http://finance.yahoo.com/d/quotes.csv?s= a BUNCH of
|
|
||||||
// STOCK SYMBOLS separated by "+" &f=a bunch of special tags
|
|
||||||
public IEnumerable<StockQuote> GetStockQuotes(IEnumerable<string> tickers)
|
|
||||||
{
|
|
||||||
string url = "http://finance.yahoo.com/d/quotes.csv?s=";
|
|
||||||
url += string.Join("+", tickers.ToArray());
|
|
||||||
url += "&f=";
|
|
||||||
url += TICKER_SYMBOL;
|
|
||||||
url += LAST_TRADE_PRICE_ONLY;
|
|
||||||
url += NAME;
|
|
||||||
url += VOLUME;
|
|
||||||
url += CHANGE;
|
|
||||||
url += LAST_TRADE_TIME;
|
|
||||||
url += REAL_TIME_LAST_TRADE_WITH_TIME;
|
|
||||||
url += REAL_TIME_CHANGE;
|
|
||||||
|
|
||||||
string resultCsv = ScrapeUrl(url);
|
|
||||||
|
|
||||||
var yahooQuoteData = ParseCsvIntoStockQuotes(resultCsv);
|
|
||||||
|
|
||||||
foreach (var quote in yahooQuoteData)
|
|
||||||
{
|
|
||||||
yield return MapYahooData(quote);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static StockQuote MapYahooData(YahooFinanceStockData data)
|
|
||||||
{
|
|
||||||
if(data == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var stock = new StockQuote();
|
|
||||||
stock.Name = data.Name;
|
|
||||||
stock.LastTradePrice = data.LastTradePrice;
|
|
||||||
stock.Ticker = data.Ticker;
|
|
||||||
stock.Volume = data.Volume;
|
|
||||||
stock.Change = data.Change;
|
|
||||||
stock.LastTradeTime = data.LastTradeTime;
|
|
||||||
stock.RealTimeLastTradePrice = decimal.Parse(data.RealTimeLastTradeWithTime
|
|
||||||
.Replace("<b>", "")
|
|
||||||
.Replace("</b>", "")
|
|
||||||
.Replace("N/A -", "")
|
|
||||||
.Trim()
|
|
||||||
);
|
|
||||||
stock.ChangeRealTime = data.ChangeRealTime;
|
|
||||||
return stock;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IList<YahooFinanceStockData> ParseCsvIntoStockQuotes(string csv)
|
|
||||||
{
|
|
||||||
var engine = new FileHelperEngine(typeof(YahooFinanceStockData));
|
|
||||||
var stockQuotes = engine.ReadString(csv) as YahooFinanceStockData[];
|
|
||||||
if(stockQuotes == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Could not parse CSV input");
|
|
||||||
}
|
|
||||||
return stockQuotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string ScrapeUrl(string url)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string resultCsv;
|
|
||||||
var req = WebRequest.Create(url);
|
|
||||||
var resp = req.GetResponse();
|
|
||||||
using (var sr = new StreamReader(resp.GetResponseStream()))
|
|
||||||
{
|
|
||||||
resultCsv = sr.ReadToEnd();
|
|
||||||
sr.Close();
|
|
||||||
}
|
|
||||||
return resultCsv;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.E("ScrapeUrlException", ex.ToString());
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,10 +4,17 @@ using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Android.Preferences;
|
using Android.Preferences;
|
||||||
|
<<<<<<< HEAD
|
||||||
using MonoStockPortfolio.Core;
|
using MonoStockPortfolio.Core;
|
||||||
using MonoStockPortfolio.Core.Config;
|
using MonoStockPortfolio.Core.Config;
|
||||||
using MonoStockPortfolio.Entities;
|
using MonoStockPortfolio.Entities;
|
||||||
using MonoStockPortfolio.Framework;
|
using MonoStockPortfolio.Framework;
|
||||||
|
=======
|
||||||
|
using MonoStockPortfolio.Core.Config;
|
||||||
|
using MonoStockPortfolio.Entities;
|
||||||
|
using MonoStockPortfolio.Framework;
|
||||||
|
using MonoStockPortfolio.Core;
|
||||||
|
>>>>>>> develop
|
||||||
|
|
||||||
namespace MonoStockPortfolio.Activites
|
namespace MonoStockPortfolio.Activites
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue