{"id":89,"date":"2025-04-23T19:44:38","date_gmt":"2025-04-23T17:44:38","guid":{"rendered":"https:\/\/quantifier.fr\/?p=89"},"modified":"2025-05-02T11:15:46","modified_gmt":"2025-05-02T09:15:46","slug":"telecharger-les-cotations-sur-yahoo-finance","status":"publish","type":"post","link":"https:\/\/quantifier.fr\/index.php\/2025\/04\/23\/telecharger-les-cotations-sur-yahoo-finance\/","title":{"rendered":"T\u00e9l\u00e9charger les cotations sur Yahoo Finance"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/quantifier.fr\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-23-2025-07_42_17-PM.png\" alt=\"\" class=\"wp-image-90\" style=\"width:442px;height:auto\" srcset=\"https:\/\/quantifier.fr\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-23-2025-07_42_17-PM.png 1024w, https:\/\/quantifier.fr\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-23-2025-07_42_17-PM-300x300.png 300w, https:\/\/quantifier.fr\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-23-2025-07_42_17-PM-150x150.png 150w, https:\/\/quantifier.fr\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-23-2025-07_42_17-PM-768x768.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Attention ! l&#8217;API Yahoo Finance n&#8217;est pas officielle et peut \u00e9voluer ou s&#8217;interrompre sans pr\u00e9avis.<\/p>\n\n\n\n<p>Ci dessous un petit code javascript pour t\u00e9l\u00e9charger les cours quotidiens : <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nasync function getQuotesHistory(ticker) {\n\n  \/\/plages de donn\u00e9es disponibles :&#x5B;&quot;1d&quot;,&quot;5d&quot;,&quot;1mo&quot;,&quot;3mo&quot;,&quot;6mo&quot;,&quot;1y&quot;,&quot;2y&quot;,&quot;5y&quot;,&quot;10y&quot;,&quot;ytd&quot;,&quot;max&quot;]\n  url = `https:\/\/query1.finance.yahoo.com\/v8\/finance\/chart\/${ticker}?range=1mo&amp;interval=1d&amp;includePrePost=true&amp;events=div%7Csplit%7Cearn&amp;corsDomain=finance.yahoo.com`;\n\n  \/\/ R\u00e9cup\u00e8re les donn\u00e9es \u00e0 partir de l'API Yahoo finance\n  try{\n    response = await fetch(url);\n  }catch (err){\n    console.log(`fetch ko :  ${ticker}`);\n  }\n  try {\n    data = await response.json();\n    \/\/ extraction des donn\u00e9es\n    const open = data.chart.result&#x5B;0].indicators.quote&#x5B;0].open;\n    const high = data.chart.result&#x5B;0].indicators.quote&#x5B;0].high;\n    const low = data.chart.result&#x5B;0].indicators.quote&#x5B;0].low;\n    const close = data.chart.result&#x5B;0].indicators.quote&#x5B;0].close;\n    const volume = data.chart.result&#x5B;0].indicators.quote&#x5B;0].volume;\n    const dates = data.chart.result&#x5B;0].timestamp.map((ts) =&gt; new Date(ts * 1000).toLocaleDateString('en-ZA'));\n\n    \/\/ Boucle pour parser les donn\u00e9es de chaque jour et les loguer dans la console \n    for (let i = 0; i &lt; open.length; i++) {\n      console.log(`${ticker};${dates&#x5B;i]};${open&#x5B;i]};${high&#x5B;i]};${low&#x5B;i]};${close&#x5B;i]};${volume&#x5B;i]}`);\n    }\n  } catch(err){\n    console.log(`erreur :  ${ticker}`);\n    console.log(err.message);\n  }\n}\n\ngetQuotesHistory('^GSPC'); \/\/cours de l'indice SP500\ngetQuotesHistory('AAPL');  \/\/cours de l'action Apple\ngetQuotesHistory('ajouter ici votre ticker');\n<\/pre><\/div>\n\n\n<p><\/p>\n\n\n\n<p>code d&#8217;appel dans le terminal pour g\u00e9n\u00e9rer un fichier .csv  : <\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-accent-6-background-color has-background\">node yfinance.js &gt; c:\\temp\\cotations.csv<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Attention ! l&#8217;API Yahoo Finance n&#8217;est pas officielle et peut \u00e9voluer ou s&#8217;interrompre sans pr\u00e9avis. Ci dessous un petit code javascript pour t\u00e9l\u00e9charger les cours quotidiens : code d&#8217;appel dans le terminal pour g\u00e9n\u00e9rer un fichier .csv : node yfinance.js &gt; c:\\temp\\cotations.csv<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":2,"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/quantifier.fr\/index.php\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}