--- /dev/null
+const PAIR_CODE = process.env.PRICE_PAIR_CODE || "BTC/EUR";
+const REFRESH_EVERY_MS = Number(process.env.PRICE_REFRESH_EVERY_MS || 300000);
+const PORT = process.env.PRICE_PORT || 3001;
+const BASE_URL = `http://127.0.0.1:${PORT}`;
+
+let refreshing = false;
+
+async function refreshPrice() {
+ if (refreshing) return;
+ refreshing = true;
+ try {
+ const url = `${BASE_URL}/api/price/refresh?pair=${encodeURIComponent(PAIR_CODE)}`;
+ const res = await fetch(url, { method: "POST" });
+ const data = await res.json().catch(() => null);
+ console.log(`[auto-refresh] OK ${PAIR_CODE}`, data?.data?.current_price ?? "");
+ } catch (err) {
+ console.log("[auto-refresh] exception:", err?.message || err);
+ } finally {
+ refreshing = false;
+ }
+}
+
+refreshPrice();
+setInterval(refreshPrice, REFRESH_EVERY_MS);
+console.log(`[auto-refresh] Prix ${PAIR_CODE} toutes les ${REFRESH_EVERY_MS/60000} min`);
--- /dev/null
+// =========================================================
+// PRICE SERVICE - Serveur standalone
+// =========================================================
+// Ce fichier encapsule le module price
+// en microservice Express indépendant sur port 3001.
+//
+// USAGE : node modules/price/server.js (depuis Wallette/server/)
+// PORT : process.env.PRICE_PORT || 3001
+// =========================================================
+
+import cors from 'cors';
+import dotenv from 'dotenv';
+import express from 'express';
+import path from 'path';
+import { fileURLToPath } from 'url';
+
+// Charger .env depuis Wallette/server/.env
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+dotenv.config({ path: path.resolve(__dirname, '../../.env') });
+
+// IMPORTANT : dotenv doit être chargé AVANT l'import du router
+// car db.js lit process.env au moment de l'import
+const { default: priceApiRouter } = await import('./routes/api.router.js');
+
+const PORT = process.env.PRICE_PORT || 3001;
+
+const app = express();
+app.use(cors());
+app.use(express.json());
+app.use(express.static(path.join(__dirname, 'public')));
+
+// ─── Health check (requis par le gateway) ────────────────
+app.get('/health', (req, res) => {
+ res.json({ ok: true, service: 'price-service', port: PORT });
+});
+
+// ─── Routes API price ─────────────────────────────────────
+// Le router expose /price/current, /price/history...
+// On le monte sur /api pour que le gateway route /api/price/* correctement
+app.use('/api', priceApiRouter);
+
+// ─── 404 ─────────────────────────────────────────────────
+app.use((req, res) => {
+ res.status(404).json({ ok: false, error: { code: 'NOT_FOUND', message: 'Route non trouvée' } });
+});
+
+// ─── Démarrage ────────────────────────────────────────────
+app.listen(PORT, () => {
+ console.log(`
+ ╔══════════════════════════════════════════╗
+ ║ PRICE SERVICE ║
+ ║ HTTP : http://localhost:${PORT} ║
+ ║ → /health = OK ║
+ ║ → /api/price/current?pair= = prix ║
+ ║ → /api/price/history?pair= = historique ║
+ ╚══════════════════════════════════════════╝`);
+});