Service for obtaining currency exchange rates.
- Requirements
- Deployment
- CLI
- Environment Variables
- API
- Service configuration for docker-compose stack
- Node.js (>=16.0)
- Redis (>=6.2.6)
- PostgreSQL (>=14.1) with TimescaleDB (>= 2.5.1)
- Install dependencies:
npm install
. - Run migrations:
npm run migration:run
withDATABASE_URL
environment variable. - Run project:
npm run start:dev
with environment variables.
docker-compose -f docker/application.yml up
More configurations see here.
npm run prebuild
- Cleardist
folder.npm run build
- Compile TypeScript source code to JavaScript atdist
folder.npm run start
- Run compiled application. Need environment variables.npm run start:dev
- Build and start application. Need environment variables.npm run migration:create -- {name}
- Create database migration file with{name}
. NeedDATABASE_URL
environment variable.npm run migration:run
- Start database migrations. NeedDATABASE_URL
environment variable.npm run migration:down
- Revert last database migration. NeedDATABASE_URL
environment variable.
Environment Variable | Description | Example |
---|---|---|
REDIS_URL |
URL for connecting to Redis | redis://localhost:6379/ |
DATABASE_URL |
URL for connecting to PostgeSQL | postgresql://user:password@localhost:5432/db |
CURRENCIES_FROM |
List of currencies to convert from | BTC,ETH,MNR |
CURRENCIES_TO |
List of currencies to convert to | USD,EUR,RUB |
CURRENCIES_RATE_UPDATER_CRON |
Crontab for worker, that save currencies rates to database | */1 * * * * |
CRYPTOCOMPARE_PRICEMULTI_URL |
URL to CryptoCompare API for getting currencies rates | https://min-api.cryptocompare.com/data/pricemulti |
This application use socket.io for WebSocket server. API use custom RPC inspired JSON-RPC under WebSocket.
The Request object has the following members:
method
- Name of method.args
- Object for passing arguments.
The Response object has the following members:
status
- Result status of method execution.Ok
orError
.data
- Object for result data.message
- Error message.
Returns string Hello, world!
Args: undefined
Data: string
Example Request:
{
"method": "HelloWorld"
}
Example Response:
{
"status": "Ok",
"data": "Hello, world!"
}
Returns number 1
Args: undefined
Data: number
Example Request:
{
"method": "GetOne"
}
Example Response:
{
"status": "Ok",
"data": 1
}
Returns currencies rates
Args:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"from": {
"type": "array",
"items": {
"type": "string"
}
},
"to": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"from",
"to"
]
}
Data:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"from": {
"type": "string"
},
"to": {
"type": "string"
},
"price": {
"type": "number"
},
"date": {
"type": "string"
}
},
"required": [
"from",
"to",
"price",
"date"
]
}
}
Additional Info:
Cache | 1 minute |
---|
Example Request:
{
"method": "GetCurrenciesRates",
"args": {
"from": ["BTC", "ETH"],
"to": ["USD"]
}
}
Example Response:
{
"status": "Ok",
"data": [
{
"from": "BTC",
"to": "USD",
"price": 43958.55,
"date": "2022-01-13T00:11:45.065Z"
},
{
"from": "ETH",
"to": "USD",
"price": 3376.76,
"date": "2022-01-13T00:11:45.065Z"
}
]
}
You can change replicas count of application in docker/application.yml
.
By default, there are 4 replicas for the application.
More options here.
You can change some options for PostgeSQL in docker/postgresql/postgresql.conf
.
By default, it listens from all hosts and loads TimescaleDB plugin.
More information about PostgreSQL here.
More information about TimescaleDB here.
You can change some options for NGINX in docker/nginx/nginx.conf
.
By default, NGINX listens 3000 port and proxy pass it with upstream to application on 3000 port.
More information about NGINX here.