A reliable backend service that eternally listens to the LetsExchange Fiat API WebSocket and stores every incoming message into a MongoDB collection.
This service is designed for long-running production environments, ensuring that any WebSocket disconnect or error triggers an immediate automatic reconnection.
-
Eternal WebSocket Listener
Automatically listens to the LetsExchange transaction feed at:
=wss://fiat-api.letsexchange.io/transaction/?EIO=3&transport=websocket -
Automatic Reconnection
Instantly reconnects when:- The WebSocket drops
- A network error occurs
- A timeout or server disconnect happens
-
MongoDB Storage
Stores every message in a configurable MongoDB collection. -
Fully Configurable
MongoDB URI, delays, log level, WebSocket URL, etc., are set via.env. -
Graceful Shutdown
Cleanly closes WebSocket and DB connections. -
Docker Support
Run the entire service inside a container.
letsexchange-ws-listener/
├─ src/
│ ├─ index.js # Entry point
│ ├─ config.js # Loads & validates environment variables
│ ├─ logger.js # Logging utility
│ ├─ mongo.js # MongoDB connection helper
│ ├─ websocketClient.js # WebSocket connection + reconnection logic
│ └─ messageHandler.js # Processes & stores messages
│
├─ .env.example # Example environment variables
├─ .gitignore # Ignore rules
├─ Dockerfile # Docker support
├─ package.json # Dependencies & scripts
├─ package-lock.json # Auto-generated lock file
└─ README.md # Documentation
---
🚀 Setup Instructions
1. Clone the Repository
git clone https://github.com/Arsenic-23/exchangeservice.git
cd exchangeservice
2. Install Dependencies
npm install
3. Create Your .env File
cp .env.example .env
Fill .env with:
WS_URL==wss://fiat-api.letsexchange.io/transaction/?EIO=3&transport=websocket
MONGODB_URI=mongodb://localhost:27017
MONGODB_DB_NAME=exchangeservice
MONGODB_COLLECTION=transactions
RECONNECT_DELAY_MS=5000
MAX_RECONNECT_DELAY_MS=60000
LOG_LEVEL=info
---
▶️ Run the Service
npm start
Expected output:
> letsexchange-ws-listener@1.0.2 start
> node src/index.js
{"level":"info","timestamp":"2025-11-22T16:38:30.477Z","message":"Starting LetsExchange WebSocket Listener Service..."}
{"level":"info","timestamp":"2025-11-22T16:38:30.479Z","message":"Connecting to MongoDB..."}
{"level":"info","timestamp":"2025-11-22T16:38:32.033Z","message":"MongoDB connection established."}
{"level":"info","timestamp":"2025-11-22T16:38:32.307Z","message":"MongoDB indexes ensured."}
{"level":"info","timestamp":"2025-11-22T16:38:32.308Z","message":"Connecting to Socket.IO","meta":{"url":"wss://fiat-api.letsexchange.io/transaction/?EIO=3&transport=websocket"}}
{"level":"info","timestamp":"2025-11-22T16:38:32.315Z","message":"Service running."}
{"level":"info","timestamp":"2025-11-22T16:38:35.392Z","message":"Socket.IO connected"}
{"level":"info","timestamp":"2025-11-22T16:38:35.393Z","message":"Subscription frame sent","meta":{"frame":"42[\"subscribe\",\"transaction\"]"}}
{"level":"info","timestamp":"2025-11-22T16:38:30.477Z","message":"Starting LetsExchange WebSocket Listener Service..."}
{"level":"info","timestamp":"2025-11-22T16:38:30.479Z","message":"Connecting to MongoDB..."}
{"level":"info","timestamp":"2025-11-22T16:38:32.033Z","message":"MongoDB connection established."}
{"level":"info","timestamp":"2025-11-22T16:38:32.307Z","message":"MongoDB indexes ensured."}
{"