USER
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"### Bienvenue dans mon projet pour conquerir le monde\n",
"\n",
"\n",
"---Nos objectif \\\n",
"Devenir riche \\\n",
"Conquerire le monde \\\n",
"Devenir immortel \\\n",
"\n",
"---Plan \\\n",
"créé un ia de trading pour avoir les première liquidité \\\n",
"la revendre\n",
"\n",
"\n",
"--- Ce qui nous empèche de conquèrir le monde : \\\n",
"les heures d'hiver et d'automne0"
],
"metadata": {
"id": "qnQm2vcsgDsv"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"import requests\n",
"import re\n",
"import subprocess\n",
"from datetime import datetime, timedelta\n",
"from pathlib import Path\n"
],
"metadata": {
"id": "zOseKr_vSvoa"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"| Option | Alias | Default | Description |\n",
"| ------ | ----- | ----- | ----- |\n",
"| --instrument | -i | | Trading instrument id. View list |\n",
"| --date-from | -from | | From date (yyyy-mm-dd) |\n",
"| --date-to | -to | now | To date (yyyy-mm-dd or 'now') |\n",
"| --timeframe | -t | d1 | Timeframe aggregation (tick, s1, m1, m5, m15, m30, h1, h4, d1, mn1) |\n",
"| --price-type | -p | bid | Price type: (bid, ask) |\n",
"| --utc-offset | -utc | 0 | UTC offset in minutes |\n",
"| --volumes | -v | false | Include volumes |\n",
"| --volume-units | -vu | millions | Volume units (millions, thousands, units) |\n",
"| --flats | -fl | false | Include flats (0 volumes) |\n",
"| --format | -f | json | Output format (csv, json, array). View output examples |\n",
"| --directory | -dir | ./download | Download directory |\n",
"| --batch-size | -bs | 10 | Batch size of downloaded artifacts |\n",
"| --batch-pause | -bp | 1000 | Pause between batches in ms |\n",
"| --cache | -ch | false | Use cache |\n",
"| --cache-path | -chpath | ./dukascopy-cache | Folder path for cache data |\n",
"| --retries | -r | 0 | Number of retries for a failed artifact download |\n",
"| --retry-on-empty | -re | false | A flag indicating whether requests with successful but empty (0 Bytes) responses should be retried. If retries is 0, this parameter will be ignored |\n",
"| --no-fail-after-retries | -fr | false | A flag indicating whether the process should fail after all retries have been exhausted. If retries is 0, this parameter will be ignored |\n",
"| --retry-pause | -rp | 500 | Pause between retries in milliseconds |\n",
"| --debug | -d | false | Output extra debugging |\n",
"| --silent | -s | false | Hides the search config in the CLI output |\n",
"| --inline | -in | false | Makes files smaller in size by removing new lines in the output (works only with json and array formats) |\n",
"| --file-name | -fn | | Custom file name for the generated file |\n",
"| --help | -h | | display help for command |"
],
"metadata": {
"id": "F7iDYaeVQYh1"
}
},
{
"cell_type": "code",
"source": [
"# Paramètres de la commande\n",
"instrument = \"eurusd\"\n",
"type_de_donnees = \"m1\"\n",
"format_fichier = \"csv\"\n",
"debut = pd.Timestamp(2024, 1, 1)\n",
"fin = pd.Timestamp(2024, 2, 13)\n",
"\n",
"# Générer le chemin du répertoire de contenu et construire la commande\n",
"content_dir = Path(\"/content\")\n",
"commande = f\"npx dukascopy-node -i {instrument} -from {debut:%Y-%m-%d} -to {fin:%Y-%m-%d} -v {True} -t {type_de_donnees} -f {format_fichier}\"\n",
"\n",
"# Exécution de la commande et capture de la sortie\n",
"try:\n",
" resultat = subprocess.run(commande, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)\n",
" sortie_commande = resultat.stdout\n",
" print(sortie_commande)\n",
"\n",
" # Extraction du nom du fichier CSV et traitement des données\n",
" match = re.search(r\"File saved: (\\S+)\", sortie_commande)\n",
" if match:\n",
" chemin_fichier_csv = match.group(1)\n",
" chemin_fichier_csv = content_dir / chemin_fichier_csv # Avec pathlib, nous assurons l’uniformité du chemin\n",
" print(\"Chemin du fichier CSV:\", chemin_fichier_csv)\n",
"\n",
" # Lecture et traitement du fichier CSV\n",
" try:\n",
" donnees = pd.read_csv(chemin_fichier_csv)\n",
" donnees['timestamp'] = pd.to_datetime(donnees['timestamp'], unit='ms').dt.strftime('%Y-%m-%d %H:%M')\n",
" donnees = donnees.rename(columns={'timestamp': 'timestamp'})\n",
" donnees.to_csv(chemin_fichier_csv, index=False)\n",
" print(f\"Le fichier CSV a été mis à jour avec les timestamps formatés : {chemin_fichier_csv}\")\n",
" print(donnees.head())\n",
" except Exception as e:\n",
" print(\"Erreur lors de la lecture ou de la conversion du fichier CSV:\", e)\n",
" else:\n",
" print(\"Le nom du fichier n’a pas pu être extrait.\")\n",
"except subprocess.CalledProcessError as e:\n",
" print(\"Erreur lors de l’exécution de la commande:\", e)\n"
],
"metadata": {
"id": "9f05Bp4AslcA",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "62390ad0-8f52-4e70-ad36-d8dd23e6f55e"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"npx: installed 30 in 7.213s\n",
"----------------------------------------------------\n",
"Downloading historical price data for:\n",
"----------------------------------------------------\n",
"Instrument: Euro vs US Dollar\n",
"Timeframe: m1\n",
"From date: Jan 1, 2024, 12:00 AM\n",
"To date: Feb 13, 2024, 12:00 AM\n",
"Price type: bid\n",
"Volumes: true\n",
"UTC Offset: 0\n",
"Include flats: false\n",
"Format: csv\n",
"----------------------------------------------------\n",
"----------------------------------------------------\n",
"√ File saved: download/eurusd-m1-bid-2024-01-01-2024-02-13.csv (2.6 MB)\n",
"\n",
"Download time: 14.9s\n",
"\n",
"\n",
"Chemin du fichier CSV: /content/download/eurusd-m1-bid-2024-01-01-2024-02-13.csv\n",
"Le fichier CSV a été mis à jour avec les timestamps formatés : /content/download/eurusd-m1-bid-2024-01-01-2024-02-13.csv\n",
" timestamp open high low close volume\n",
"0 2024-01-01 22:00 1.10427 1.10429 1.10425 1.10429 5.9\n",
"1 2024-01-01 22:01 1.10429 1.10429 1.10429 1.10429 8.1\n",
"2 2024-01-01 22:02 1.10429 1.10429 1.10429 1.10429 9.9\n",
"3 2024-01-01 22:03 1.10429 1.10429 1.10426 1.10426 18.9\n",
"4 2024-01-01 22:04 1.10426 1.10431 1.10424 1.10425 18.0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"def Data(chemin_fichier_csv, date_heure_str):\n",
" try:\n",
" # Chargement du fichier CSV dans un DataFrame pandas\n",
" donnees = pd.read_csv(chemin_fichier_csv)\n",
"\n",
" # Assurer que la colonne 'timestamp' est au bon format de date-heure\n",
" donnees['timestamp'] = pd.to_datetime(donnees['timestamp'])\n",
"\n",
" # Formatage de la date-heure de la requête pour correspondre au format du DataFrame\n",
" date_heure_requise = pd.to_datetime(date_heure_str)\n",
"\n",
" # Filtrer pour obtenir les données de la minute spécifiée\n",
" info_minute = donnees[\n",
" (donnees['timestamp'] >= date_heure_requise) &\n",
" (donnees['timestamp'] < date_heure_requise + pd.Timedelta(minutes=1))\n",
" ]\n",
"\n",
" # Vérifier si des données ont été trouvées et les retourner\n",
" if not info_minute.empty:\n",
" # On utilise iloc[0] pour obtenir le premier enregistrement correspondant\n",
" return info_minute.iloc[0].to_dict()\n",
" else:\n",
" # Aucune donnée correspondante n’a été trouvée\n",
" return None\n",
" except Exception as e:\n",
" print(f\"Erreur lors de la lecture du fichier CSV ou de la recherche des données: {e}\")\n",
" return None\n"
],
"metadata": {
"id": "ZiyMguNXIv5M"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"date_heure_str = \"2024-01-05 11:59\"\n",
"\n",
"# Utilisation de la fonction pour récupérer les informations\n",
"informations = Data(chemin_fichier_csv, date_heure_str)\n",
"\n",
"# Affichage des informations récupérées\n",
"if informations:\n",
" print(f\"Informations pour {date_heure_str}:\")\n",
" print(f\"Open: {informations['open']}\")\n",
" print(f\"High: {informations['high']}\")\n",
" print(f\"Low: {informations['low']}\")\n",
" print(f\"Close: {informations['close']}\")\n",
" print(f\"Volume: {informations['volume']}\")\n",
"else:\n",
" print(\"Aucune information trouvée pour la minute spécifiée.\")\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "MsTWF5PjI5_Z",
"outputId": "54d8af17-5876-4929-bce6-84a1af418ece"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Informations pour 2024-01-05 11:59:\n",
"Open: 1.09132\n",
"High: 1.09143\n",
"Low: 1.09132\n",
"Close: 1.09142\n",
"Volume: 104.55999755859376\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"api_key = 'cnguep9r01qhlsli99igcnguep9r01qhlsli99j0'\n",
"symbol = 'EUR/USD'\n",
"interval = '1min'\n",
"count = 10\n",
"\n",
"url = f'https://finnhub.io/api/v1/forex/candles?symbol={symbol}&resolution={interval}&count={count}'\n",
"headers = {'X-Finnhub-Token': api_key}\n",
"\n",
"response = requests.get(url, headers=headers)\n",
"\n",
"# Imprimez la réponse brute de l'API\n",
"print(response.text)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Nk5vmJ1icz_T",
"outputId": "3d272585-e3c1-4ca7-b736-323660248f5a"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"<!DOCTYPE html>\n",
"<html lang=\"en\">\n",
"<head>\n",
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n",
" <meta name=\"author\" content=\"Finnhub.io\"/>\n",
"\n",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=5\">\n",
" <link rel=\"shortcut icon\"\n",
" href=\"/static/img/webp/finnhub-logo.webp\"/>\n",
"\n",
" \n",
" <script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-64068110-3\"></script>\n",
" <script>\n",
" window.dataLayer = window.dataLayer || [];\n",
"\n",
" function gtag() {\n",
" dataLayer.push(arguments);\n",
" }\n",
"\n",
" gtag('js', new Date());\n",
"\n",
" gtag('config', 'UA-64068110-3');\n",
" </script>\n",
"\n",
" <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css\">\n",
"\n",
" <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\n",
" <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js'></script>\n",
"\n",
" <script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js\"></script>\n",
" <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js\"></script>\n",
"\n",
" <script src=\"https://cdnjs.cloudflare.com/ajax/libs/react/16.8.0/umd/react.production.min.js\"></script>\n",
" <script src=\"https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.0/umd/react-dom.production.min.js\"></script>\n",
"\n",
" <link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v6.0.0/css/all.css\">\n",
"\n",
" <script src=\"https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.min.js\"></script>\n",
" <script src=\"https://cdnjs.cloudflare.com/ajax/libs/redux/3.3.1/redux.min.js\"></script>\n",
" <script src=\"https://unpkg.com/react-redux@5.0.7/dist/react-redux.min.js\"></script>\n",
" <script type=\"text/javascript\">\n",
"\n",
" var protocol = location.protocol;\n",
" var wsprotocol\n",
" if (protocol === \"https:\") {\n",
" wsprotocol = \"wss:\";\n",
" } else {\n",
" wsprotocol = \"ws:\";\n",
" }\n",
" var slashes = protocol.concat(\"//\");\n",
" var host = slashes.concat(window.location.host);\n",
"\n",
" window.wsUrl = \"\"\n",
" if (window.wsUrl === '') {\n",
" window.wsUrl = window.location.host\n",
" }\n",
"\n",
" window.getCookie = function getcookie(cname) {\n",
" var name = cname + \"=\";\n",
" var decodedCookie = decodeURIComponent(document.cookie);\n",
" var ca = decodedCookie.split(';');\n",
" for (var i = 0; i < ca.length; i++) {\n",
" var c = ca[i];\n",
" while (c.charAt(0) == ' ') {\n",
" c = c.substring(1);\n",
" }\n",
" if (c.indexOf(name) == 0) {\n",
" return c.substring(name.length, c.length);\n",
" }\n",
" }\n",
" return \"\";\n",
" }\n",
"\n",
" window.setCookie = function setcookie(cname, cvalue, exdays) {\n",
" var d = new Date();\n",
" d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));\n",
" var expires = \"expires=\" + d.toUTCString();\n",
" document.cookie = cname + \"=\" + cvalue + \";\" + expires + \";path=/\";\n",
" }\n",
"\n",
" window.toTitle = function toTitleCase(str) {\n",
" return str.replace(/\\w\\S*/g, function (txt) {\n",
" return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();\n",
" });\n",
" }\n",
"\n",
" window.getUrlParams = function (key) {\n",
" let url = location.href\n",
" var params = {};\n",
" (url + '?').split('?')[1].split('&').forEach(function (pair) {\n",
" pair = (pair + '=').split('=').map(decodeURIComponent);\n",
" if (pair[0].length) {\n",
" params[pair[0]] = pair[1];\n",
" }\n",
" });\n",
" return params[key];\n",
" };\n",
"\n",
" window.stripHtml = function (html) {\n",
" let tmp = document.createElement(\"DIV\");\n",
" tmp.innerHTML = html;\n",
" return tmp.textContent || tmp.innerText || \"\";\n",
" }\n",
"\n",
" window.timeConverter = function tConverter(UNIX_timestamp) {\n",
" var a = new Date(UNIX_timestamp * 1000);\n",
" var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n",
" var dates = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']\n",
" var month = months[a.getMonth()];\n",
" var date = a.getDate();\n",
" var time = dates[a.getDay()] + ' ' + month + ' ' + date\n",
" return time;\n",
" }\n",
"\n",
" window.roundToX = function (num, X) {\n",
" return +(Math.round(num + \"e+\" + X) + \"e-\" + X);\n",
" }\n",
" </script>\n",
"\n",
"\n",
" <meta name=\"description\"\n",
" content=\"Finnhub - Free stock API for realtime market data, global company fundamentals, economic data, and alternative data.\"/>\n",
"<meta name=\"keywords\"\n",
" content=\"stock api,realtime,stock,equity,forex,crypto,fundamental data,economic data,alternative data\">\n",
"<meta property=\"og:title\" content=\"Finnhub - Free realtime APIs for stock, forex and cryptocurrency.\">\n",
"<meta property=\"og:type\" content=\"website\">\n",
"<meta property=\"og:url\" content=\"https://finnhub.io/\">\n",
"<meta property=\"og:image\"\n",
" content=\"https://static.finnhub.io/img/finnhub_2020-05-09_20_51/logo/logo-transparent-thumbnail.png\">\n",
"<meta property=\"og:description\"\n",
" content=\"Finnhub - Free APIs for realtime stock, forex, and cryptocurrency. Company fundamentals, Economic data, and Alternative data.\">\n",
"<meta name=\"twitter:card\" content=\"summary\">\n",
"<meta name=\"twitter:title\"\n",
" content=\"Finnhub - Free realtime APIs for stock, forex and cryptocurrency.\">\n",
"<meta name=\"twitter:image\"\n",
" content=\"https://static.finnhub.io/img/finnhub_2020-05-09_20_51/logo/logo-transparent-thumbnail.png\">\n",
"<meta name=\"twitter:description\"\n",
" content=\"Finnhub - Free APIs for realtime stock, forex, and cryptocurrency. Company fundamentals, Economic data, and Alternative data.\">\n",
"<meta charset=\"UTF-8\">\n",
"\n",
" <title>Finnhub Stock APIs - Real-time stock prices, Company fundamentals, Estimates, and Alternative data.</title>\n",
"\n",
" <script type=\"text/javascript\">\n",
" window.serverData = {\"announcement\":\"Global Filings Search is now available on Finnhub. Check out \\u003ca href=\\\"/docs/api/global-filings-search\\\"\\u003ehere\\u003c/a\\u003e\"}\n",
" window.login = false \n",
" window.isSubscribe = null \n",
" </script>\n",
"</head>\n",
"<body>\n",
"<div id=\"root\"></div>\n",
"<script type=\"text/javascript\" src=\"/static/js/webpack/dist/main-index.bundle.357882d13b93982f42b7.js\"></script></body>\n",
"</html>\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"### Après le fichier\n",
"\n",
"Maintenant que l'on a récupéré ce petit csv de merde\n",
"- 30 dernière minute : open + high + low + volume = 150 (on commence de la plus recent a la plus ancienne)\n",
"- 30 dernière : pareil = 150\n",
"- 30 dernier jours : pareil = 150\n",
"- 7 jour de la semaine = 7 (de lundi a dimanche)\n",
"- 31 jour du mois = 31\n",
"- 12 mois de l'anéee = 12\n"
],
"metadata": {
"id": "eOP-2yDs6cBk"
}
},
{
"cell_type": "markdown",
"source": [
"# Liste pour les 30 derniers minutes"
],
"metadata": {
"id": "76Amy6xU7YuB"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"\n",
"# Fonction Data donnée dans la question initiale.\n",
"def Data(chemin_fichier_csv, date_heure_str):\n",
" try:\n",
" # Chargement du fichier CSV dans un DataFrame pandas.\n",
" donnees = pd.read_csv(chemin_fichier_csv)\n",
"\n",
" # Assurer que la colonne timestamp est au bon format de date-heure.\n",
" donnees['timestamp'] = pd.to_datetime(donnees['timestamp'])\n",
"\n",
" # Formatage de la date-heure de la requête pour correspondre au format du DataFrame.\n",
" date_heure_requise = pd.to_datetime(date_heure_str)\n",
"\n",
" # Filtrer pour obtenir les données de la minute spécifiée.\n",
" info_minute = donnees[\n",
" (donnees['timestamp'] >= date_heure_requise) &\n",
" (donnees['timestamp'] < date_heure_requise + pd.Timedelta(minutes=1))\n",
" ]\n",
"\n",
" # Vérifier si des données ont été trouvées et les retourner.\n",
" if not info_minute.empty:\n",
" # On utilise iloc[0] pour obtenir le premier enregistrement correspondant.\n",
" return info_minute.iloc[0].to_dict()\n",
" else:\n",
" # Aucune donnée correspondante n’a été trouvée.\n",
" return None\n",
" except Exception as e:\n",
" print(f\"Erreur lors de la lecture du fichier CSV ou de la recherche des données: {e}\")\n",
" return None\n",
"\n",
"# Fonction pour lister les données sur les 30 dernières minutes.\n",
"def liste_donnees_30min(chemin_fichier_csv, date_heure_str):\n",
" liste_donnees = []\n",
" # Convertir la date_heure_str en objet datetime.\n",
" date_heure_finale = pd.to_datetime(date_heure_str)\n",
"\n",
" # Boucle pour récupérer les données minute par minute de la plus récente à la plus vieille.\n",
" for i in range(31):\n",
" # Le point de départ pour chaque minute.\n",
" minute_debut = date_heure_finale - pd.Timedelta(minutes=i)\n",
" # Convertir en chaîne de caractères ISO pour l’appel de fonction.\n",
" minute_debut_str = minute_debut.strftime('%Y-%m-%d %H:%M:%S')\n",
" # Utiliser la fonction Data pour obtenir les données.\n",
" donnee_minute = Data(chemin_fichier_csv, minute_debut_str)\n",
" # Si des données sont trouvées, les ajouter à la liste.\n",
" if donnee_minute:\n",
" liste_donnees.append(donnee_minute)\n",
"\n",
" # Renvoyer la liste complète des données des 30 dernières minutes.\n",
" return liste_donnees\n",
"\n",
"# Exemple d’utilisation.\n",
"\n",
"date_heure_str = \"2024-02-01 12:45:00\" # Ajustez cette date-heure au format correspondant à vos données.\n",
"\n",
"# Appel de la fonction.\n",
"donnees_30_dernieres_minutes = liste_donnees_30min(chemin_fichier_csv, date_heure_str)\n",
"\n",
"# Affichage des résultats.\n",
"for donnee in donnees_30_dernieres_minutes:\n",
" print(donnee)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "nFmUPW6NN00u",
"outputId": "5b1ab0c1-502d-4dff-9d43-ccf20d822d23"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'timestamp': Timestamp('2024-02-01 12:45:00'), 'open': 1.08178, 'high': 1.08184, 'low': 1.08173, 'close': 1.08174, 'volume': 240.8699951171875}\n",
"{'timestamp': Timestamp('2024-02-01 12:44:00'), 'open': 1.08143, 'high': 1.08178, 'low': 1.08142, 'close': 1.08178, 'volume': 524.3599853515625}\n",
"{'timestamp': Timestamp('2024-02-01 12:43:00'), 'open': 1.08143, 'high': 1.0815, 'low': 1.08139, 'close': 1.08142, 'volume': 476.7699890136719}\n",
"{'timestamp': Timestamp('2024-02-01 12:42:00'), 'open': 1.08155, 'high': 1.08157, 'low': 1.08142, 'close': 1.08145, 'volume': 553.02001953125}\n",
"{'timestamp': Timestamp('2024-02-01 12:41:00'), 'open': 1.08146, 'high': 1.08152, 'low': 1.08141, 'close': 1.08151, 'volume': 171.00999450683594}\n",
"{'timestamp': Timestamp('2024-02-01 12:40:00'), 'open': 1.0813, 'high': 1.08147, 'low': 1.08125, 'close': 1.08147, 'volume': 460.5700073242188}\n",
"{'timestamp': Timestamp('2024-02-01 12:39:00'), 'open': 1.08118, 'high': 1.08131, 'low': 1.08116, 'close': 1.08131, 'volume': 339.1099853515625}\n",
"{'timestamp': Timestamp('2024-02-01 12:38:00'), 'open': 1.08107, 'high': 1.08118, 'low': 1.08107, 'close': 1.08117, 'volume': 337.29998779296875}\n",
"{'timestamp': Timestamp('2024-02-01 12:37:00'), 'open': 1.08111, 'high': 1.08126, 'low': 1.08106, 'close': 1.08106, 'volume': 223.5}\n",
"{'timestamp': Timestamp('2024-02-01 12:36:00'), 'open': 1.08101, 'high': 1.08117, 'low': 1.081, 'close': 1.08111, 'volume': 184.509994506836}\n",
"{'timestamp': Timestamp('2024-02-01 12:35:00'), 'open': 1.08092, 'high': 1.08104, 'low': 1.08078, 'close': 1.08104, 'volume': 401.8900146484375}\n",
"{'timestamp': Timestamp('2024-02-01 12:34:00'), 'open': 1.08102, 'high': 1.08106, 'low': 1.08093, 'close': 1.08093, 'volume': 187.9900054931641}\n",
"{'timestamp': Timestamp('2024-02-01 12:33:00'), 'open': 1.08118, 'high': 1.08119, 'low': 1.08096, 'close': 1.08102, 'volume': 492.9599914550781}\n",
"{'timestamp': Timestamp('2024-02-01 12:32:00'), 'open': 1.08124, 'high': 1.08126, 'low': 1.08097, 'close': 1.08117, 'volume': 396.239990234375}\n",
"{'timestamp': Timestamp('2024-02-01 12:31:00'), 'open': 1.08153, 'high': 1.08155, 'low': 1.08122, 'close': 1.08123, 'volume': 237.1199951171875}\n",
"{'timestamp': Timestamp('2024-02-01 12:30:00'), 'open': 1.08145, 'high': 1.08159, 'low': 1.08144, 'close': 1.08153, 'volume': 235.19000244140625}\n",
"{'timestamp': Timestamp('2024-02-01 12:29:00'), 'open': 1.08128, 'high': 1.08144, 'low': 1.08126, 'close': 1.08144, 'volume': 298.2900085449219}\n",
"{'timestamp': Timestamp('2024-02-01 12:28:00'), 'open': 1.08111, 'high': 1.0813, 'low': 1.08109, 'close': 1.08128, 'volume': 151.35000610351562}\n",
"{'timestamp': Timestamp('2024-02-01 12:27:00'), 'open': 1.08116, 'high': 1.08119, 'low': 1.08111, 'close': 1.08112, 'volume': 168.67999267578125}\n",
"{'timestamp': Timestamp('2024-02-01 12:26:00'), 'open': 1.08121, 'high': 1.08122, 'low': 1.08116, 'close': 1.08117, 'volume': 314.760009765625}\n",
"{'timestamp': Timestamp('2024-02-01 12:25:00'), 'open': 1.08108, 'high': 1.08131, 'low': 1.08108, 'close': 1.08122, 'volume': 277.32000732421875}\n",
"{'timestamp': Timestamp('2024-02-01 12:24:00'), 'open': 1.08122, 'high': 1.08132, 'low': 1.08107, 'close': 1.08109, 'volume': 328.8699951171875}\n",
"{'timestamp': Timestamp('2024-02-01 12:23:00'), 'open': 1.08118, 'high': 1.08129, 'low': 1.08117, 'close': 1.08121, 'volume': 426.1099853515625}\n",
"{'timestamp': Timestamp('2024-02-01 12:22:00'), 'open': 1.08124, 'high': 1.08128, 'low': 1.08116, 'close': 1.08117, 'volume': 388.7900085449219}\n",
"{'timestamp': Timestamp('2024-02-01 12:21:00'), 'open': 1.08123, 'high': 1.08134, 'low': 1.08121, 'close': 1.08123, 'volume': 447.4100036621094}\n",
"{'timestamp': Timestamp('2024-02-01 12:20:00'), 'open': 1.08167, 'high': 1.08167, 'low': 1.08122, 'close': 1.08122, 'volume': 224.88999938964844}\n",
"{'timestamp': Timestamp('2024-02-01 12:19:00'), 'open': 1.08143, 'high': 1.0817, 'low': 1.08143, 'close': 1.08168, 'volume': 90.05000305175781}\n",
"{'timestamp': Timestamp('2024-02-01 12:18:00'), 'open': 1.08117, 'high': 1.08143, 'low': 1.08113, 'close': 1.08143, 'volume': 273.9599914550781}\n",
"{'timestamp': Timestamp('2024-02-01 12:17:00'), 'open': 1.08108, 'high': 1.08119, 'low': 1.08108, 'close': 1.08117, 'volume': 269.0400085449219}\n",
"{'timestamp': Timestamp('2024-02-01 12:16:00'), 'open': 1.08123, 'high': 1.08127, 'low': 1.08106, 'close': 1.08108, 'volume': 401.4700012207031}\n",
"{'timestamp': Timestamp('2024-02-01 12:15:00'), 'open': 1.08122, 'high': 1.08138, 'low': 1.08118, 'close': 1.08124, 'volume': 482.1799926757813}\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# 30 derniers jours"
],
"metadata": {
"id": "7YxteF4kN32H"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"\n",
"# Fonction Data donnée.\n",
"def Data(chemin_fichier_csv, date_heure_str):\n",
" try:\n",
" donnees = pd.read_csv(chemin_fichier_csv)\n",
" donnees['timestamp'] = pd.to_datetime(donnees['timestamp'])\n",
" date_heure_requise = pd.to_datetime(date_heure_str)\n",
" info_jour = donnees[\n",
" (donnees['timestamp'] >= date_heure_requise) &\n",
" (donnees['timestamp'] < date_heure_requise + pd.Timedelta(days=1))\n",
" ]\n",
" if not info_jour.empty:\n",
" return info_jour.iloc[0].to_dict()\n",
" else:\n",
" return None\n",
" except Exception as e:\n",
" print(f\"Erreur lors de la lecture du fichier CSV ou de la recherche des données: {e}\")\n",
" return None\n",
"\n",
"# Fonction pour lister les données sur les 7 derniers jours.\n",
"def liste_donnees_7jours(chemin_fichier_csv, date_heure_str):\n",
" liste_donnees = []\n",
" date_heure_finale = pd.to_datetime(date_heure_str)\n",
"\n",
" # Nous parcourons maintenant seulement 7 jours, donc range(7)\n",
" for i in range(30, -1, -1):\n",
" jour_debut = date_heure_finale - pd.Timedelta(days=i)\n",
" jour_debut_str = jour_debut.strftime('%Y-%m-%d %H:%M:%S')\n",
" donnee_jour = Data(chemin_fichier_csv, jour_debut_str)\n",
" if donnee_jour:\n",
" liste_donnees.append(donnee_jour)\n",
"\n",
" return liste_donnees\n",
"\n",
"\n",
"date_heure_str = \"2024-02-01 12:45:00\" # Ajustez cette date-heure.\n",
"\n",
"donnees_30_derniers_jours_liste = liste_donnees_7jours(chemin_fichier_csv, date_heure_str)\n",
"\n",
"# Affichage de la liste finale contenant toutes les données.\n",
"print(\"Liste des données des 7 derniers jours :\")\n",
"print(donnees_30_derniers_jours_liste)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "VwDg9tVROFQK",
"outputId": "9202db03-19d2-4f5b-b84c-87f6e6fd3e35"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Liste des données des 7 derniers jours :\n",
"[{'timestamp': Timestamp('2024-01-02 12:45:00'), 'open': 1.09608, 'high': 1.09619, 'low': 1.09607, 'close': 1.09615, 'volume': 192.1300048828125}, {'timestamp': Timestamp('2024-01-03 12:45:00'), 'open': 1.09205, 'high': 1.09217, 'low': 1.09192, 'close': 1.09208, 'volume': 380.6900024414063}, {'timestamp': Timestamp('2024-01-04 12:45:00'), 'open': 1.0955, 'high': 1.0955, 'low': 1.0952, 'close': 1.09534, 'volume': 107.33999633789062}, {'timestamp': Timestamp('2024-01-05 12:45:00'), 'open': 1.09184, 'high': 1.09196, 'low': 1.09182, 'close': 1.09195, 'volume': 105.77999877929688}, {'timestamp': Timestamp('2024-01-07 22:04:00'), 'open': 1.09386, 'high': 1.0939, 'low': 1.09376, 'close': 1.0939, 'volume': 28.600000381469727}, {'timestamp': Timestamp('2024-01-08 12:45:00'), 'open': 1.0942, 'high': 1.09436, 'low': 1.0942, 'close': 1.0943, 'volume': 109.26000213623048}, {'timestamp': Timestamp('2024-01-09 12:45:00'), 'open': 1.09324, 'high': 1.09341, 'low': 1.09319, 'close': 1.09338, 'volume': 175.22999572753906}, {'timestamp': Timestamp('2024-01-10 12:45:00'), 'open': 1.09447, 'high': 1.09448, 'low': 1.09439, 'close': 1.09442, 'volume': 248.8500061035156}, {'timestamp': Timestamp('2024-01-11 12:45:00'), 'open': 1.09844, 'high': 1.09862, 'low': 1.09841, 'close': 1.0986, 'volume': 214.6000061035156}, {'timestamp': Timestamp('2024-01-12 12:45:00'), 'open': 1.09432, 'high': 1.09432, 'low': 1.09412, 'close': 1.09416, 'volume': 160.11000061035156}, {'timestamp': Timestamp('2024-01-14 22:00:00'), 'open': 1.0948, 'high': 1.09484, 'low': 1.09476, 'close': 1.09476, 'volume': 10.399999618530272}, {'timestamp': Timestamp('2024-01-15 12:45:00'), 'open': 1.09546, 'high': 1.0956, 'low': 1.09541, 'close': 1.09541, 'volume': 139.64999389648438}, {'timestamp': Timestamp('2024-01-16 12:45:00'), 'open': 1.0885, 'high': 1.08852, 'low': 1.08844, 'close': 1.08846, 'volume': 153.57000732421875}, {'timestamp': Timestamp('2024-01-17 12:45:00'), 'open': 1.0872, 'high': 1.0872, 'low': 1.0871, 'close': 1.08715, 'volume': 216.75}, {'timestamp': Timestamp('2024-01-18 12:45:00'), 'open': 1.08786, 'high': 1.08798, 'low': 1.08786, 'close': 1.08798, 'volume': 135.25999450683594}, {'timestamp': Timestamp('2024-01-19 12:45:00'), 'open': 1.08825, 'high': 1.08825, 'low': 1.08815, 'close': 1.08816, 'volume': 176.00999450683594}, {'timestamp': Timestamp('2024-01-21 22:00:00'), 'open': 1.08906, 'high': 1.08918, 'low': 1.08905, 'close': 1.08909, 'volume': 5.5}, {'timestamp': Timestamp('2024-01-22 12:45:00'), 'open': 1.08977, 'high': 1.08981, 'low': 1.08958, 'close': 1.08962, 'volume': 271.3900146484375}, {'timestamp': Timestamp('2024-01-23 12:45:00'), 'open': 1.08625, 'high': 1.08627, 'low': 1.08616, 'close': 1.08621, 'volume': 221.3300018310547}, {'timestamp': Timestamp('2024-01-24 12:45:00'), 'open': 1.08952, 'high': 1.08956, 'low': 1.0895, 'close': 1.08954, 'volume': 150.52999877929688}, {'timestamp': Timestamp('2024-01-25 12:45:00'), 'open': 1.08919, 'high': 1.08925, 'low': 1.08919, 'close': 1.08921, 'volume': 94.7699966430664}, {'timestamp': Timestamp('2024-01-26 12:45:00'), 'open': 1.08699, 'high': 1.08717, 'low': 1.08693, 'close': 1.08716, 'volume': 134.00999450683594}, {'timestamp': Timestamp('2024-01-28 22:00:00'), 'open': 1.08468, 'high': 1.08484, 'low': 1.08428, 'close': 1.0843, 'volume': 28.0}, {'timestamp': Timestamp('2024-01-29 12:45:00'), 'open': 1.08352, 'high': 1.08364, 'low': 1.08352, 'close': 1.08358, 'volume': 98.5199966430664}, {'timestamp': Timestamp('2024-01-30 12:45:00'), 'open': 1.08428, 'high': 1.08439, 'low': 1.08425, 'close': 1.08439, 'volume': 47.70000076293945}, {'timestamp': Timestamp('2024-01-31 12:45:00'), 'open': 1.08375, 'high': 1.08379, 'low': 1.08366, 'close': 1.08376, 'volume': 199.2100067138672}, {'timestamp': Timestamp('2024-02-01 12:45:00'), 'open': 1.08178, 'high': 1.08184, 'low': 1.08173, 'close': 1.08174, 'volume': 240.8699951171875}]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# 7 derniers jours"
],
"metadata": {
"id": "HeT4Hg1pP0H1"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"\n",
"# Fonction Data donnée.\n",
"def Data(chemin_fichier_csv, date_heure_str):\n",
" try:\n",
" donnees = pd.read_csv(chemin_fichier_csv)\n",
" donnees['timestamp'] = pd.to_datetime(donnees['timestamp'])\n",
" date_heure_requise = pd.to_datetime(date_heure_str)\n",
" info_jour = donnees[\n",
" (donnees['timestamp'] >= date_heure_requise) &\n",
" (donnees['timestamp'] < date_heure_requise + pd.Timedelta(days=1))\n",
" ]\n",
" if not info_jour.empty:\n",
" return info_jour.iloc[0].to_dict()\n",
" else:\n",
" return None\n",
" except Exception as e:\n",
" print(f\"Erreur lors de la lecture du fichier CSV ou de la recherche des données: {e}\")\n",
" return None\n",
"\n",
"# Fonction pour lister les données sur les 7 derniers jours.\n",
"def liste_donnees_7jours(chemin_fichier_csv, date_heure_str):\n",
" liste_donnees = []\n",
" date_heure_finale = pd.to_datetime(date_heure_str)\n",
"\n",
" # Nous parcourons maintenant seulement 7 jours, donc range(7)\n",
" for i in range(7, -1, -1):\n",
" jour_debut = date_heure_finale - pd.Timedelta(days=i)\n",
" jour_debut_str = jour_debut.strftime('%Y-%m-%d %H:%M:%S')\n",
" donnee_jour = Data(chemin_fichier_csv, jour_debut_str)\n",
" if donnee_jour:\n",
" liste_donnees.append(donnee_jour)\n",
"\n",
" return liste_donnees\n",
"\n",
"\n",
"date_heure_str = \"2024-02-01 12:45:00\" # Ajustez cette date-heure.\n",
"\n",
"donnees_7_derniers_jours_liste = liste_donnees_7jours(chemin_fichier_csv, date_heure_str)\n",
"\n",
"# Affichage de la liste finale contenant toutes les données.\n",
"print(\"Liste des données des 7 derniers jours :\")\n",
"print(donnees_7_derniers_jours_liste)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "C9t40s2GP4PW",
"outputId": "0aa142c2-ec45-439e-a342-e4be3c7da950"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Liste des données des 7 derniers jours :\n",
"[{'timestamp': Timestamp('2024-01-25 12:45:00'), 'open': 1.08919, 'high': 1.08925, 'low': 1.08919, 'close': 1.08921, 'volume': 94.7699966430664}, {'timestamp': Timestamp('2024-01-26 12:45:00'), 'open': 1.08699, 'high': 1.08717, 'low': 1.08693, 'close': 1.08716, 'volume': 134.00999450683594}, {'timestamp': Timestamp('2024-01-28 22:00:00'), 'open': 1.08468, 'high': 1.08484, 'low': 1.08428, 'close': 1.0843, 'volume': 28.0}, {'timestamp': Timestamp('2024-01-29 12:45:00'), 'open': 1.08352, 'high': 1.08364, 'low': 1.08352, 'close': 1.08358, 'volume': 98.5199966430664}, {'timestamp': Timestamp('2024-01-30 12:45:00'), 'open': 1.08428, 'high': 1.08439, 'low': 1.08425, 'close': 1.08439, 'volume': 47.70000076293945}, {'timestamp': Timestamp('2024-01-31 12:45:00'), 'open': 1.08375, 'high': 1.08379, 'low': 1.08366, 'close': 1.08376, 'volume': 199.2100067138672}, {'timestamp': Timestamp('2024-02-01 12:45:00'), 'open': 1.08178, 'high': 1.08184, 'low': 1.08173, 'close': 1.08174, 'volume': 240.8699951171875}]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# 31 derniers jours"
],
"metadata": {
"id": "Vi2YecL_SBAW"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"\n",
"# Fonction Data donnée.\n",
"def Data(chemin_fichier_csv, date_heure_str):\n",
" try:\n",
" donnees = pd.read_csv(chemin_fichier_csv)\n",
" donnees['timestamp'] = pd.to_datetime(donnees['timestamp'])\n",
" date_heure_requise = pd.to_datetime(date_heure_str)\n",
" info_jour = donnees[\n",
" (donnees['timestamp'] >= date_heure_requise) &\n",
" (donnees['timestamp'] < date_heure_requise + pd.Timedelta(days=1))\n",
" ]\n",
" if not info_jour.empty:\n",
" return info_jour.iloc[0].to_dict()\n",
" else:\n",
" return None\n",
" except Exception as e:\n",
" print(f\"Erreur lors de la lecture du fichier CSV ou de la recherche des données: {e}\")\n",
" return None\n",
"\n",
"\n",
"def liste_donnees_7jours(chemin_fichier_csv, date_heure_str):\n",
" liste_donnees = []\n",
" date_heure_finale = pd.to_datetime(date_heure_str)\n",
"\n",
"\n",
" for i in range(31, -1, -1):\n",
" jour_debut = date_heure_finale - pd.Timedelta(days=i)\n",
" jour_debut_str = jour_debut.strftime('%Y-%m-%d %H:%M:%S')\n",
" donnee_jour = Data(chemin_fichier_csv, jour_debut_str)\n",
" if donnee_jour:\n",
" liste_donnees.append(donnee_jour)\n",
"\n",
" return liste_donnees\n",
"\n",
"\n",
"date_heure_str = \"2024-02-01 12:45:00\" # Ajustez cette date-heure.\n",
"\n",
"donnees_31_derniers_jours_liste = liste_donnees_7jours(chemin_fichier_csv, date_heure_str)\n",
"\n",
"# Affichage de la liste finale contenant toutes les données.\n",
"print(\"Liste des données des 31 derniers jours :\")\n",
"print(donnees_31_derniers_jours_liste)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "4mA8CQjNSFQA",
"outputId": "0d728b04-ab3a-4a02-d7c4-d7364527ffdc"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Liste des données des 31 derniers jours :\n",
"[{'timestamp': Timestamp('2024-01-01 22:00:00'), 'open': 1.10427, 'high': 1.10429, 'low': 1.10425, 'close': 1.10429, 'volume': 5.900000095367432}, {'timestamp': Timestamp('2024-01-02 12:45:00'), 'open': 1.09608, 'high': 1.09619, 'low': 1.09607, 'close': 1.09615, 'volume': 192.1300048828125}, {'timestamp': Timestamp('2024-01-03 12:45:00'), 'open': 1.09205, 'high': 1.09217, 'low': 1.09192, 'close': 1.09208, 'volume': 380.6900024414063}, {'timestamp': Timestamp('2024-01-04 12:45:00'), 'open': 1.0955, 'high': 1.0955, 'low': 1.0952, 'close': 1.09534, 'volume': 107.33999633789062}, {'timestamp': Timestamp('2024-01-05 12:45:00'), 'open': 1.09184, 'high': 1.09196, 'low': 1.09182, 'close': 1.09195, 'volume': 105.77999877929688}, {'timestamp': Timestamp('2024-01-07 22:04:00'), 'open': 1.09386, 'high': 1.0939, 'low': 1.09376, 'close': 1.0939, 'volume': 28.600000381469727}, {'timestamp': Timestamp('2024-01-08 12:45:00'), 'open': 1.0942, 'high': 1.09436, 'low': 1.0942, 'close': 1.0943, 'volume': 109.26000213623048}, {'timestamp': Timestamp('2024-01-09 12:45:00'), 'open': 1.09324, 'high': 1.09341, 'low': 1.09319, 'close': 1.09338, 'volume': 175.22999572753906}, {'timestamp': Timestamp('2024-01-10 12:45:00'), 'open': 1.09447, 'high': 1.09448, 'low': 1.09439, 'close': 1.09442, 'volume': 248.8500061035156}, {'timestamp': Timestamp('2024-01-11 12:45:00'), 'open': 1.09844, 'high': 1.09862, 'low': 1.09841, 'close': 1.0986, 'volume': 214.6000061035156}, {'timestamp': Timestamp('2024-01-12 12:45:00'), 'open': 1.09432, 'high': 1.09432, 'low': 1.09412, 'close': 1.09416, 'volume': 160.11000061035156}, {'timestamp': Timestamp('2024-01-14 22:00:00'), 'open': 1.0948, 'high': 1.09484, 'low': 1.09476, 'close': 1.09476, 'volume': 10.399999618530272}, {'timestamp': Timestamp('2024-01-15 12:45:00'), 'open': 1.09546, 'high': 1.0956, 'low': 1.09541, 'close': 1.09541, 'volume': 139.64999389648438}, {'timestamp': Timestamp('2024-01-16 12:45:00'), 'open': 1.0885, 'high': 1.08852, 'low': 1.08844, 'close': 1.08846, 'volume': 153.57000732421875}, {'timestamp': Timestamp('2024-01-17 12:45:00'), 'open': 1.0872, 'high': 1.0872, 'low': 1.0871, 'close': 1.08715, 'volume': 216.75}, {'timestamp': Timestamp('2024-01-18 12:45:00'), 'open': 1.08786, 'high': 1.08798, 'low': 1.08786, 'close': 1.08798, 'volume': 135.25999450683594}, {'timestamp': Timestamp('2024-01-19 12:45:00'), 'open': 1.08825, 'high': 1.08825, 'low': 1.08815, 'close': 1.08816, 'volume': 176.00999450683594}, {'timestamp': Timestamp('2024-01-21 22:00:00'), 'open': 1.08906, 'high': 1.08918, 'low': 1.08905, 'close': 1.08909, 'volume': 5.5}, {'timestamp': Timestamp('2024-01-22 12:45:00'), 'open': 1.08977, 'high': 1.08981, 'low': 1.08958, 'close': 1.08962, 'volume': 271.3900146484375}, {'timestamp': Timestamp('2024-01-23 12:45:00'), 'open': 1.08625, 'high': 1.08627, 'low': 1.08616, 'close': 1.08621, 'volume': 221.3300018310547}, {'timestamp': Timestamp('2024-01-24 12:45:00'), 'open': 1.08952, 'high': 1.08956, 'low': 1.0895, 'close': 1.08954, 'volume': 150.52999877929688}, {'timestamp': Timestamp('2024-01-25 12:45:00'), 'open': 1.08919, 'high': 1.08925, 'low': 1.08919, 'close': 1.08921, 'volume': 94.7699966430664}, {'timestamp': Timestamp('2024-01-26 12:45:00'), 'open': 1.08699, 'high': 1.08717, 'low': 1.08693, 'close': 1.08716, 'volume': 134.00999450683594}, {'timestamp': Timestamp('2024-01-28 22:00:00'), 'open': 1.08468, 'high': 1.08484, 'low': 1.08428, 'close': 1.0843, 'volume': 28.0}, {'timestamp': Timestamp('2024-01-29 12:45:00'), 'open': 1.08352, 'high': 1.08364, 'low': 1.08352, 'close': 1.08358, 'volume': 98.5199966430664}, {'timestamp': Timestamp('2024-01-30 12:45:00'), 'open': 1.08428, 'high': 1.08439, 'low': 1.08425, 'close': 1.08439, 'volume': 47.70000076293945}, {'timestamp': Timestamp('2024-01-31 12:45:00'), 'open': 1.08375, 'high': 1.08379, 'low': 1.08366, 'close': 1.08376, 'volume': 199.2100067138672}, {'timestamp': Timestamp('2024-02-01 12:45:00'), 'open': 1.08178, 'high': 1.08184, 'low': 1.08173, 'close': 1.08174, 'volume': 240.8699951171875}]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"12 dernier mois"
],
"metadata": {
"id": "APxPvhVTT2OZ"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"\n",
"# Fonction Data donnée.\n",
"def Data(chemin_fichier_csv, date_heure_str):\n",
" try:\n",
" donnees = pd.read_csv(chemin_fichier_csv)\n",
" donnees['timestamp'] = pd.to_datetime(donnees['timestamp'])\n",
" date_heure_requise = pd.to_datetime(date_heure_str)\n",
" info_jour = donnees[\n",
" (donnees['timestamp'] >= date_heure_requise) &\n",
" (donnees['timestamp'] < date_heure_requise + pd.Timedelta(days=1))\n",
" ]\n",
" if not info_jour.empty:\n",
" return info_jour.iloc[0].to_dict()\n",
" else:\n",
" return None\n",
" except Exception as e:\n",
" print(f\"Erreur lors de la lecture du fichier CSV ou de la recherche des données: {e}\")\n",
" return None\n",
"\n",
"\n",
"def liste_donnees_7jours(chemin_fichier_csv, date_heure_str):\n",
" liste_donnees = []\n",
" date_heure_finale = pd.to_datetime(date_heure_str)\n",
"\n",
"\n",
" for i in range(365, -1, -1):\n",
" jour_debut = date_heure_finale - pd.Timedelta(days=i)\n",
" jour_debut_str = jour_debut.strftime('%Y-%m-%d %H:%M:%S')\n",
" donnee_jour = Data(chemin_fichier_csv, jour_debut_str)\n",
" if donnee_jour:\n",
" liste_donnees.append(donnee_jour)\n",
"\n",
" return liste_donnees\n",
"\n",
"\n",
"date_heure_str = \"2024-02-01 12:45:00\" # Ajustez cette date-heure.\n",
"\n",
"donnees_365_derniers_jours_liste = liste_donnees_7jours(chemin_fichier_csv, date_heure_str)\n",
"\n",
"# Affichage de la liste finale contenant toutes les données.\n",
"print(\"Liste des données des 12 derniers mois :\")\n",
"print(donnees_365_derniers_jours_liste)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hQ1WARdpT6c8",
"outputId": "778ba183-29d3-405d-b6a8-6c01620da107"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Liste des données des 12 derniers mois :\n",
"[{'timestamp': Timestamp('2024-01-01 22:00:00'), 'open': 1.10427, 'high': 1.10429, 'low': 1.10425, 'close': 1.10429, 'volume': 5.900000095367432}, {'timestamp': Timestamp('2024-01-02 12:45:00'), 'open': 1.09608, 'high': 1.09619, 'low': 1.09607, 'close': 1.09615, 'volume': 192.1300048828125}, {'timestamp': Timestamp('2024-01-03 12:45:00'), 'open': 1.09205, 'high': 1.09217, 'low': 1.09192, 'close': 1.09208, 'volume': 380.6900024414063}, {'timestamp': Timestamp('2024-01-04 12:45:00'), 'open': 1.0955, 'high': 1.0955, 'low': 1.0952, 'close': 1.09534, 'volume': 107.33999633789062}, {'timestamp': Timestamp('2024-01-05 12:45:00'), 'open': 1.09184, 'high': 1.09196, 'low': 1.09182, 'close': 1.09195, 'volume': 105.77999877929688}, {'timestamp': Timestamp('2024-01-07 22:04:00'), 'open': 1.09386, 'high': 1.0939, 'low': 1.09376, 'close': 1.0939, 'volume': 28.600000381469727}, {'timestamp': Timestamp('2024-01-08 12:45:00'), 'open': 1.0942, 'high': 1.09436, 'low': 1.0942, 'close': 1.0943, 'volume': 109.26000213623048}, {'timestamp': Timestamp('2024-01-09 12:45:00'), 'open': 1.09324, 'high': 1.09341, 'low': 1.09319, 'close': 1.09338, 'volume': 175.22999572753906}, {'timestamp': Timestamp('2024-01-10 12:45:00'), 'open': 1.09447, 'high': 1.09448, 'low': 1.09439, 'close': 1.09442, 'volume': 248.8500061035156}, {'timestamp': Timestamp('2024-01-11 12:45:00'), 'open': 1.09844, 'high': 1.09862, 'low': 1.09841, 'close': 1.0986, 'volume': 214.6000061035156}, {'timestamp': Timestamp('2024-01-12 12:45:00'), 'open': 1.09432, 'high': 1.09432, 'low': 1.09412, 'close': 1.09416, 'volume': 160.11000061035156}, {'timestamp': Timestamp('2024-01-14 22:00:00'), 'open': 1.0948, 'high': 1.09484, 'low': 1.09476, 'close': 1.09476, 'volume': 10.399999618530272}, {'timestamp': Timestamp('2024-01-15 12:45:00'), 'open': 1.09546, 'high': 1.0956, 'low': 1.09541, 'close': 1.09541, 'volume': 139.64999389648438}, {'timestamp': Timestamp('2024-01-16 12:45:00'), 'open': 1.0885, 'high': 1.08852, 'low': 1.08844, 'close': 1.08846, 'volume': 153.57000732421875}, {'timestamp': Timestamp('2024-01-17 12:45:00'), 'open': 1.0872, 'high': 1.0872, 'low': 1.0871, 'close': 1.08715, 'volume': 216.75}, {'timestamp': Timestamp('2024-01-18 12:45:00'), 'open': 1.08786, 'high': 1.08798, 'low': 1.08786, 'close': 1.08798, 'volume': 135.25999450683594}, {'timestamp': Timestamp('2024-01-19 12:45:00'), 'open': 1.08825, 'high': 1.08825, 'low': 1.08815, 'close': 1.08816, 'volume': 176.00999450683594}, {'timestamp': Timestamp('2024-01-21 22:00:00'), 'open': 1.08906, 'high': 1.08918, 'low': 1.08905, 'close': 1.08909, 'volume': 5.5}, {'timestamp': Timestamp('2024-01-22 12:45:00'), 'open': 1.08977, 'high': 1.08981, 'low': 1.08958, 'close': 1.08962, 'volume': 271.3900146484375}, {'timestamp': Timestamp('2024-01-23 12:45:00'), 'open': 1.08625, 'high': 1.08627, 'low': 1.08616, 'close': 1.08621, 'volume': 221.3300018310547}, {'timestamp': Timestamp('2024-01-24 12:45:00'), 'open': 1.08952, 'high': 1.08956, 'low': 1.0895, 'close': 1.08954, 'volume': 150.52999877929688}, {'timestamp': Timestamp('2024-01-25 12:45:00'), 'open': 1.08919, 'high': 1.08925, 'low': 1.08919, 'close': 1.08921, 'volume': 94.7699966430664}, {'timestamp': Timestamp('2024-01-26 12:45:00'), 'open': 1.08699, 'high': 1.08717, 'low': 1.08693, 'close': 1.08716, 'volume': 134.00999450683594}, {'timestamp': Timestamp('2024-01-28 22:00:00'), 'open': 1.08468, 'high': 1.08484, 'low': 1.08428, 'close': 1.0843, 'volume': 28.0}, {'timestamp': Timestamp('2024-01-29 12:45:00'), 'open': 1.08352, 'high': 1.08364, 'low': 1.08352, 'close': 1.08358, 'volume': 98.5199966430664}, {'timestamp': Timestamp('2024-01-30 12:45:00'), 'open': 1.08428, 'high': 1.08439, 'low': 1.08425, 'close': 1.08439, 'volume': 47.70000076293945}, {'timestamp': Timestamp('2024-01-31 12:45:00'), 'open': 1.08375, 'high': 1.08379, 'low': 1.08366, 'close': 1.08376, 'volume': 199.2100067138672}, {'timestamp': Timestamp('2024-02-01 12:45:00'), 'open': 1.08178, 'high': 1.08184, 'low': 1.08173, 'close': 1.08174, 'volume': 240.8699951171875}]\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"# ducoup voici ce que nous récupéront les quoicoupote"
],
"metadata": {
"id": "m2vVLZQEUW8P"
}
},
{
"cell_type": "code",
"source": [
"donnees_365_derniers_jours_liste\n",
"donnees_31_derniers_jours_liste\n",
"donnees_7_derniers_jours_liste\n",
"donnees_30_derniers_jours_liste\n",
"donnees_30_dernieres_minutes"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 193
},
"id": "G3RqMOdVUbdG",
"outputId": "d566ad25-4667-42bd-f882-2b5fbbe4ab5a"
},
"execution_count": null,
"outputs": [
{
"output_type": "error",
"ename": "NameError",
"evalue": "name 'donnees_30_derniers_jours' is not defined",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-14-7bb42c6ad7cd>\u001b[0m in \u001b[0;36m<cell line: 4>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mdonnees_31_derniers_jours_liste\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mdonnees_7_derniers_jours_liste\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mdonnees_30_derniers_jours\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mdonnees_30_dernieres_minutes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'donnees_30_derniers_jours' is not defined"
]
}
]
}
]
}