A NestJS-based Foreign Exchange Query Language (FXQL) Statement Parser that processes and stores currency exchange rate information.
- FXQL statement parsing and validation
- Singleton Design
- Response compression
- PostgreSQL database integration
- Rate limiting
- Comprehensive logging
- Docker support
- API documentation (Swagger)
- Unit tests
- Node.js (v18 or later)
- Docker and Docker Compose
- PostgreSQL (if running locally)
- Clone the repository:
git clone https://github.com/yourusername/fxql-parser.git
cd fxql-parser- Create a
.envfile based on the example:
cp .env.example .env- Start the application using Docker Compose:
docker-compose -f docker-compose.yml up --build -dThe application will be available at http://127.0.0.1:3000.
- Install dependencies:
npm install- Configure environment variables:
cp .env.example .env
# Edit .env with your local database credentials- Start the development server:
npm run start:devhttp://localhost:3000/api
- Endpoint:
http://localhost:3000/ - Method:
POST - Description: Parses, validates, and saves FXQL statements to the database.
- Content-Type:
application/json - Body:
Parses and stores FXQL statements.
{
"FXQL": "USD-GBP {\n BUY 100\n SELL 200\n CAP 93800\n}"
}{
"message": "FXQL Statement Parsed Successfully.",
"code": "FXQL-200",
"data": [
{
"EntryId": 1,
"SourceCurrency": "USD",
"DestinationCurrency": "GBP",
"SellPrice": 200,
"BuyPrice": 100,
"CapAmount": 93800
}
]
}-
Status Code:
400 Bad Request- Response Body:
{ "message": "Invalid FXQL Statement.", "code": "FXQL-400" } -
Status Code:
429 Too Many Requests- Response Body:
{ "message": "Rate limit exceeded.", "code": "FXQL-429" }
Run the test suite:
npm run testRun the end-to-end test:
npm run test:e2eRun tests with coverage:
npm run test:covThe API implements rate limiting with the following default settings:
- 100 requests per minute per IP
- Configurable via environment variables:
RATE_LIMIT_TTL: Time window in secondsRATE_LIMIT_LIMIT: Maximum number of requests per window
The application logs HTTP requests with the following information:
- Method
- URL
- Status code
- Response size
- Response time
- User agent
- IP address
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=fxql_db
RATE_LIMIT_TTL=60
RATE_LIMIT_LIMIT=100