Cryptocurrency Price API
Getting started
Service for track the latest price of cryptocurrency asset
Prerequisities
How To Run
-
Create .env
file
NAME="Cryptocurrency Price API"
PORT=PORT
DB_PATH=DB_PATH
DB_MAX_IDLE_CONNECTION=DB_MAX_IDLE_CONNECTION
DB_MAX_OPEN_CONNECTION=DB_MAX_OPEN_CONNECTION
DB_CONNECTION_MAX_LIFE_TIME=DB_CONNECTION_MAX_LIFE_TIME
DB_LOG_MODE=DB_LOG_MODE
DB_LOG_SLOW_THRESHOLD=DB_LOG_SLOW_THRESHOLD
DB_RETRY=DB_RETRY
DB_WAIT_SLEEP=DB_WAIT_SLEEP
LOG_MODE=LOG_MODE
BCRYPT_COST=BCRYPT_COST
JWT_PUBLIC_KEY=JWT_PUBLIC_KEY
JWT_ALG=JWT_ALG
JWT_EXPIRES=JWT_EXPIRES
COINCAP_BASE_PATH=COINCAP_BASE_PATH
COINCAP_PRICE_SYNC_MODE=COINCAP_PRICE_SYNC_MODE
-
Migrate the database by
make db DOCKER= SQLPATH= DBPATH= DBFILENAME= ENVFILENAME=
Note:
The command make db
automatically create the docker image (make db_init
) and run the migration (make db_migrate
) if the DOCKER
parameter is true
-
Run the service by
make app DOCKER= PORT= DBPATH= DBFILENAME= ENVFILENAME=
Note:
The command make app
automatically create the docker image (make app_init
) and run the migration (make app_run
) if the DOCKER
parameter is true
Testing
If you want to test the code, run
go test ./... -count=1 -failfast
Make Command
Initialize migration
The command create the docker image of migration naufalfmm/cryptocurrency-price-api-migration
make db_init DOCKER=
Create SQL file
The command create the sql file
make db_create DOCKER= SQLPATH= DBPATH= DBFILENAME= ENVFILENAME=
Migrate SQL files
The command migrates all sql files in ./migrates/sql
or ./sql
make db_migrate DOCKER= SQLPATH= DBPATH= DBFILENAME= ENVFILENAME=
Rollback SQL files
The command rollbacks all sql files in ./migrates/sql
or ./sql
make db_migrate DOCKER= SQLPATH= DBPATH= DBFILENAME= ENVFILENAME= VERSION=
API Docs
If the JWT inputted in Authorization
header is not valid, the endpoint return
{
"ok": false,
"message": "invalid token",
"data": {
"error": "invalid token"
}
}
Sign Up (POST /v1/auth/signup)
Description
Endpoint to sign up new user
Request
Body
{
"email": "",
"password": "",
"password_confirmation": ""
}
Response (200)
{
"ok": true,
"message": "Success",
"data": {
"id": 0,
"email": ""
}
}
Response (403)
Email Has Been Used
{
"ok": false,
"message": "email has been used",
"data": {
"error": "email has been used"
}
}
Response (500)
{
"ok": false,
"message": "internal server error",
"data": {
"error": "internal server error"
}
}
Sign In (POST /v1/auth/signin)
Description
Endpoint to sign in
Request
Body
{
"email": "",
"password": "",
}
Response (200)
{
"ok": true,
"message": "Success",
"data": {
"jwt": "xxxxx.yyyyy.zzzzz",
"user": {
"id": 0,
"email": ""
}
}
}
Response (403)
Wrong Password
{
"ok": false,
"message": "wrong password",
"data": {
"error": "wrong password"
}
}
Email Missing
{
"ok": false,
"message": "email missing",
"data": {
"error": "email missing"
}
}
Response (500)
{
"ok": false,
"message": "internal server error",
"data": {
"error": "internal server error"
}
}
Track Coin Asset (POST /user-coins/track)
Description
Endpoint for add the coin to the user's tracker. Coin cannot be added to the tracker more than once.
Request
- Authorization:
Bearer <JWT>
Body
{
"coin_symbol": "ETH"
}
Response (200)
{
"ok": true,
"message": "Success",
"data": {
"track_id": 0,
"code": "ETH",
"name": "Ethereum",
"latest_price": 2919.4101049055726,
"latest_price_currency": "USD",
"added_at": "2024-05-12T10:14:26.5455845+07:00",
"added_by": ""
}
}
Response (400)
Coin Has Been Added for The User
{
"ok": false,
"message": "coin has been added for the user",
"data": {
"error": "coin has been added for the user"
}
}
Response (500)
{
"ok": false,
"message": "internal server error",
"data": {
"error": "internal server error"
}
}
Untrack Coin Asset (POST /user-coins/untrack)
Description
Endpoint for remove the coin to the user's tracker
Request
- Authorization:
Bearer <JWT>
Body
{
"coin_symbol": "ETH"
}
Response (200)
{
"ok": true,
"message": "Success"
}
Response (400)
Coin Missing
{
"ok": false,
"message": "coin is missing",
"data": {
"error": "coin is missing"
}
}
Tracking Coin is Missing (If we untrack unadded coin)
{
"ok": false,
"message": "tracking coin is missing",
"data": {
"error": "tracking coin is missing"
}
}
Response (500)
{
"ok": false,
"message": "internal server error",
"data": {
"error": "internal server error"
}
}
Get All Tracking Coins (GET /user-coins)
Request
- Authorization:
Bearer <JWT>
- X-Currency: // Example: IDR, USD, CLP
Response (200)
{
"ok": true,
"message": "Success",
"data": {
"items": [
{
"track_id": 12,
"code": "ETH",
"name": "Ethereum",
"latest_price": 2931.13,
"latest_price_currency": "USD",
"added_at": "2024-05-12T10:14:26.5455845+07:00",
"added_by": ""
}
]
}
}
Response (500)
{
"ok": false,
"message": "internal server error",
"data": {
"error": "internal server error"
}
}