Yahoo Finance API

Q. Yahoo fournit-il une API de finance? Si oui, quel est le lien vers cette API.

    IMHO le meilleur endroit pour trouver cette information est: http://code.google.com/p/yahoo-finance-managed/

    J’avais l’habitude d’utiliser le “gummy-stuff” mais j’ai trouvé cette page qui est beaucoup plus organisée et remplie d’exemples faciles à utiliser. Je l’utilise maintenant pour récupérer les données dans des fichiers CSV et utiliser les fichiers de mon projet C ++ / Qt.

    Voici un simple racloir que j’ai créé en c # pour imprimer des données de devis en streaming sur une console. Il devrait être facilement converti en Java. Basé sur le post suivant:

    http://blog.underdog-projects.net/2009/02/bringing-the-yahoo-finance-stream-to-the-shell/

    Pas trop sophistiqué (pas de regex, etc.), juste une solution rapide et sale.

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web.Script.Serialization; namespace WebDataAddin { public class YahooConstants { public const ssortingng AskPrice = "a00"; public const ssortingng BidPrice = "b00"; public const ssortingng DayRangeLow = "g00"; public const ssortingng DayRangeHigh = "h00"; public const ssortingng MarketCap = "j10"; public const ssortingng Volume = "v00"; public const ssortingng AskSize = "a50"; public const ssortingng BidSize = "b60"; public const ssortingng EcnBid = "b30"; public const ssortingng EcnBidSize = "o50"; public const ssortingng EcnExtHrBid = "z03"; public const ssortingng EcnExtHrBidSize = "z04"; public const ssortingng EcnAsk = "b20"; public const ssortingng EcnAskSize = "o40"; public const ssortingng EcnExtHrAsk = "z05"; public const ssortingng EcnExtHrAskSize = "z07"; public const ssortingng EcnDayHigh = "h01"; public const ssortingng EcnDayLow = "g01"; public const ssortingng EcnExtHrDayHigh = "h02"; public const ssortingng EcnExtHrDayLow = "g11"; public const ssortingng LastTradeTimeUnixEpochformat = "t10"; public const ssortingng EcnQuoteLastTime = "t50"; public const ssortingng EcnExtHourTime = "t51"; public const ssortingng RtQuoteLastTime = "t53"; public const ssortingng RtExtHourQuoteLastTime = "t54"; public const ssortingng LastTrade = "l10"; public const ssortingng EcnQuoteLastValue = "l90"; public const ssortingng EcnExtHourPrice = "l91"; public const ssortingng RtQuoteLastValue = "l84"; public const ssortingng RtExtHourQuoteLastValue = "l86"; public const ssortingng QuoteChangeAbsolute = "c10"; public const ssortingng EcnQuoteAfterHourChangeAbsolute = "c81"; public const ssortingng EcnQuoteChangeAbsolute = "c60"; public const ssortingng EcnExtHourChange1 = "z02"; public const ssortingng EcnExtHourChange2 = "z08"; public const ssortingng RtQuoteChangeAbsolute = "c63"; public const ssortingng RtExtHourQuoteAfterHourChangeAbsolute = "c85"; public const ssortingng RtExtHourQuoteChangeAbsolute = "c64"; public const ssortingng QuoteChangePercent = "p20"; public const ssortingng EcnQuoteAfterHourChangePercent = "c82"; public const ssortingng EcnQuoteChangePercent = "p40"; public const ssortingng EcnExtHourPercentChange1 = "p41"; public const ssortingng EcnExtHourPercentChange2 = "z09"; public const ssortingng RtQuoteChangePercent = "p43"; public const ssortingng RtExtHourQuoteAfterHourChangePercent = "c86"; public const ssortingng RtExtHourQuoteChangePercent = "p44"; public static readonly IDictionary CodeMap = typeof(YahooConstants).GetFields(). Where(field => field.FieldType == typeof(ssortingng)). ToDictionary(field => ((ssortingng)field.GetValue(null)).ToUpper(), field => field.Name); } public static class SsortingngBuilderExtensions { public static bool HasPrefix(this SsortingngBuilder builder, ssortingng prefix) { return ContainsAtIndex(builder, prefix, 0); } public static bool HasSuffix(this SsortingngBuilder builder, ssortingng suffix) { return ContainsAtIndex(builder, suffix, builder.Length - suffix.Length); } private static bool ContainsAtIndex(this SsortingngBuilder builder, ssortingng str, int index) { if (builder != null && !ssortingng.IsNullOrEmpty(str) && index >= 0 && builder.Length >= str.Length + index) { return !str.Where((t, i) => builder[index + i] != t).Any(); } return false; } } public class WebDataAddin { public const ssortingng ScriptStart = ""; public const ssortingng MessageStart = "try{parent.yfs_"; public const ssortingng MessageEnd = ");}catch(e){}"; public const ssortingng DataMessage = "u1f("; public const ssortingng InfoMessage = "mktmcb("; protected static T ParseJson(ssortingng json) { // parse json - max acceptable value resortingeved from //http://forums.asp.net/t/1343461.aspx var deserializer = new JavaScriptSerializer { MaxJsonLength = 2147483647 }; return deserializer.Deserialize(json); } public static void Main() { const ssortingng symbols = "GBPUSD=X,SPY,MSFT,BAC,QQQ,GOOG"; // these are constants in the YahooConstants enum above const ssortingng attrs = "b00,b60,a00,a50"; const ssortingng url = "http://streamerapi.finance.yahoo.com/streamer/1.0?s={0}&k={1}&r=0&callback=parent.yfs_u1f&mktmcb=parent.yfs_mktmcb&gencallback=parent.yfs_gencb&region=US&lang=en-US&localize=0&mu=1"; var req = WebRequest.Create(ssortingng.Format(url, symbols, attrs)); req.Proxy.Credentials = CredentialCache.DefaultCredentials; var missingCodes = new HashSet(); var response = req.GetResponse(); if(response != null) { var stream = response.GetResponseStream(); if (stream != null) { using (var reader = new StreamReader(stream)) { var builder = new SsortingngBuilder(); var initialPayloadReceived = false; while (!reader.EndOfStream) { var c = (char)reader.Read(); builder.Append(c); if(!initialPayloadReceived) { if (builder.HasSuffix(ScriptStart)) { // chop off the first part, and re-append the // script tag (this is all we care about) builder.Clear(); builder.Append(ScriptStart); initialPayloadReceived = true; } } else { // check if we have a fully formed message // (check suffix first to avoid re-checking // the prefix over and over) if (builder.HasSuffix(ScriptEnd) && builder.HasPrefix(ScriptStart)) { var chop = ScriptStart.Length + MessageStart.Length; var javascript = builder.ToSsortingng(chop, builder.Length - ScriptEnd.Length - MessageEnd.Length - chop); if (javascript.StartsWith(DataMessage)) { var json = ParseJson>( javascript.Subssortingng(DataMessage.Length)); // parse out the data. key should be the symbol foreach(var symbol in json) { Console.WriteLine("Symbol: {0}", symbol.Key); var symbolData = (Dictionary) symbol.Value; foreach(var dataAttr in symbolData) { var codeKey = dataAttr.Key.ToUpper(); if (YahooConstants.CodeMap.ContainsKey(codeKey)) { Console.WriteLine("\t{0}: {1}", YahooConstants. CodeMap[codeKey], dataAttr.Value); } else { missingCodes.Add(codeKey); Console.WriteLine("\t{0}: {1} (Warning! No Code Mapping Found)", codeKey, dataAttr.Value); } } Console.WriteLine(); } } else if(javascript.StartsWith(InfoMessage)) { var json = ParseJson>( javascript.Subssortingng(InfoMessage.Length)); foreach (var dataAttr in json) { Console.WriteLine("\t{0}: {1}", dataAttr.Key, dataAttr.Value); } Console.WriteLine(); } else { throw new Exception("Cannot recognize the message type"); } builder.Clear(); } } } } } } } } } 

    Vous pouvez utiliser YQL cependant les tables yahoo.finance. * Ne sont pas les tables yahoo de base. C’est une table de données ouverte qui utilise le «csv api» et le convertit au format json ou xml. Il est plus pratique à utiliser mais ce n’est pas toujours fiable. Je ne pouvais pas l’utiliser il y a un moment car la table atteint sa limite de stockage ou quelque chose comme ça …

    Vous pouvez utiliser cette bibliothèque php pour obtenir des données / citations historiques en utilisant YQL https://github.com/aygee/php-yql-finance

    Yahoo est très facile à utiliser et fournit des données personnalisées. Utilisez la page suivante pour en savoir plus.

    finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT=pder=.csv

    AVERTISSEMENT – il existe quelques didacticiels sur le Web qui vous indiquent comment procéder, mais la région dans laquelle vous placez les symboles boursiers génère une erreur si vous l’utilisez comme publiée. Vous obtiendrez une “valeur de format manquante”. Les tutoriels que j’ai trouvés omettent le commentaire sur GOOG.

    Exemple d’URL pour GOOG: http://download.finance.yahoo.com/d/quotes.csv?s=%40%5EDJI,GOOG&f=nsl1op&e=.csv