This is a TypeScript
project for synchronizing currencies prices using the Binance API
.
It is built with the Nest.js
framework and includes GraphQL
functionality for retrieving and managing price data.
You choose currencies via adding to CURRENCIES
variable in .env
.
Cron job retrieves data from API and saves in database once per minute.
While server runs you can check GraphQL sandbox: http://localhost:3000/graphql
or simple web-client: http://localhost:3000
To run this project locally, you will need Node.js and npm installed on your machine.
-
Clone this repository:
git clone https://github.com/maks-der/btcusdt-price-synchronizer.git
-
Navigate to the project directory:
cd btcusdt-price-synchronizer
-
Create a
.env
file in the project root or copy it fromexample.env
:PORT=3000 APP_ENV=dev CURRENCIES=BTCUSDT;DOGEUSDT;APEUSDT JWT_SECRET=jwt-secret-string DATABASE_URL=postgresql://root:secret@localhost:5432/price-synchronizer
-
Install dependencies:
npm install
To start the database using Docker Compose (ensure Docker is installed):
npm run start:db
To start the development server with watch mode:
npm run start:dev
To build and start the production server:
npm run build
npm run start:prod
To run tests:
npm test
-
login
(Query):- Input Parameters:
email
(String): The email address of the user attempting to log in.password
(String): The password associated with the user's account.
- Description: This query is used for user authentication. If the provided credentials are valid, it returns an
accessToken
.
Example:
query { login(email: "test@example.com", password: "secret") { accessToken } }
- Input Parameters:
-
register
(Mutation):- Input Parameters:
fullName
(String): The full name of the user to be registered.email
(String): The email address the user wishes to use for registration.password
(String): The desired password for the new account.
- Description: This mutation is used to create a new user account. If the registration is successful, it returns an
accessToken
Example:
mutation { register(fullName: "Test", email: "test@example.com", password: "secret") { accessToken } }
- Input Parameters:
-
current
Query:- Input Parameters:
currency
(String): The currency pair for which the current price is being requested. In this case, it is set to "BTCUSDT."
- Description: This query is used to fetch the current price information for the specified currency pair.
id
(String): A unique identifier for the price record.price
(Float): The current price of the currency pair.currency
(String): The currency pair being queried.createdAt
(DateTime): The timestamp when the price record was created.updatedAt
(DateTime): The timestamp when the price record was last updated.
Example:
query { current(currency: "BTCUSDT") { id price currency createdAt updatedAt } }
- Input Parameters:
-
history
Query:- Input Parameters:
currency
(String): The currency pair for which historical price data is being requested.
- Description: This query is used to retrieve historical price information for the specified currency pair
Example:
query { history(currency: "ETHUSDT") { id price currency createdAt updatedAt } }
- Input Parameters: