}
}
+
+// CHARGER LES STRATÉGIES DE SACHA
+async function loadStrategies() {
+ try {
+ const res = await fetch(`${SERVER_URL}/api/strategy?userId=${userId}`);
+ const data = await res.json();
+
+ const select = document.getElementById('strategySelect');
+ if (!select) return;
+
+ select.innerHTML = '';
+
+ // Si le backend renvoie un tableau direct
+ const strategies = Array.isArray(data) ? data : (data.strategies || []);
+
+ if (!strategies.length) {
+ const opt = document.createElement('option');
+ opt.value = '';
+ opt.textContent = 'Aucune stratégie disponible';
+ select.appendChild(opt);
+ return;
+ }
+
+ strategies.forEach(strategy => {
+ const opt = document.createElement('option');
+ opt.value = strategy.id || strategy.name;
+ opt.textContent = strategy.name || strategy.id;
+ select.appendChild(opt);
+ });
+
+ } catch (err) {
+ console.error("Erreur chargement stratégies :", err);
+ }
+}
+
+
+// Appliquer la stratégie sélectionnée
+async function applySelectedStrategy() {
+ try {
+ const select = document.getElementById('strategySelect');
+ if (!select) return;
+
+ const strategyId = select.value;
+ if (!strategyId) {
+ alert("Choisis une stratégie.");
+ return;
+ }
+
+ const res = await fetch(`${SERVER_URL}/api/strategy/apply`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ userId, strategyId })
+ });
+
+ if (!res.ok) {
+ throw new Error("Erreur serveur");
+ }
+
+ alert("Stratégie appliquée ✅");
+
+ } catch (err) {
+ console.error("Erreur application stratégie :", err);
+ alert("Impossible d'appliquer la stratégie.");
+ }
+}
+
+
// socket -------------------------------------------------------------------------------------------------------
// Quand une alerte arrive, l'ajouter dans la liste #alertList
function handleIncomingAlert(alert) {
document.getElementById("connStatus").textContent = "Statut : off";
});
+//button stratégie
+
+(function bindStrategyButton() {
+ const select = document.getElementById('strategySelect');
+ if (!select) return;
+
+ const card = select.closest('.card');
+ const button = card ? card.querySelector('button.btn-primary') : null;
+
+ if (button) {
+ button.addEventListener('click', applySelectedStrategy);
+ }
+})();
+
+loadStrategies();
loadAlertHistory();
loadCurrentPrice();
loadWallet();