-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulateur_csv.py
More file actions
47 lines (38 loc) · 1.46 KB
/
simulateur_csv.py
File metadata and controls
47 lines (38 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# simulateur_csv.py
import csv
import os
from datetime import date
FICHIER_CSV = "journal_simulation.csv"
def deja_journalise_aujourdhui(pool_id: str) -> bool:
"""
Vérifie si un résultat pour cette pool a déjà été enregistré aujourd'hui.
:param pool_id: Identifiant unique de la pool.
:return: True si déjà enregistré aujourd'hui, sinon False.
"""
if not os.path.exists(FICHIER_CSV):
return False
with open(FICHIER_CSV, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row.get('date') == str(date.today()) and row.get('pool_id') == pool_id:
return True
return False
def journaliser_resultats(pool: dict, gain: float) -> None:
"""
Enregistre le résultat simulé dans un fichier CSV.
:param pool: Dictionnaire contenant les infos de la pool.
:param gain: Gain simulé en USDC.
"""
fichier_existe = os.path.exists(FICHIER_CSV)
with open(FICHIER_CSV, 'a', newline='') as csvfile:
champs = ['date', 'pool_id', 'nom', 'plateforme', 'gain_usdc']
writer = csv.DictWriter(csvfile, fieldnames=champs)
if not fichier_existe:
writer.writeheader()
writer.writerow({
'date': str(date.today()),
'pool_id': pool.get('id', 'inconnu'),
'nom': pool.get('symbol', 'N/A'),
'plateforme': pool.get('dex', 'N/A'),
'gain_usdc': round(gain, 2)
})