Skip to content

This is my solution to the challenge of Rather labs for SR backend develepor. The focus is to create a Market status api.

License

Notifications You must be signed in to change notification settings

damiancipolat/RatherLabsChallege

Repository files navigation

RatherLabs challenge - Membrane

In this challenge I solve the statement proposed in the following pdf, which consists of creating a market status api. https://github.com/damiancipolat/RatherLabsChallege/blob/main/doc/challenge.pdf

Readme sections

Exchange provider:

For this challenge, I decided to use the bitfinex api through communication via websocket after analyzing both providers, bitfinex presents a better developer experience and better documentation.

Stack:

  • Node.js v16
  • Docker
  • Test: jest
  • config: dotenv
  • express.js
  • pino: For logging.

Configuration:

The project uses .env files to handle the configuration, the format is as follows.

#Provider websocker url.
BITFINEX_HOST="wss://api-pub.bitfinex.com/ws/2"

#Limit of pair name point length on memory.
TIPS_LIMIT=50

#Server port
SERVER_PORT=8000

Money pair-names: You can configure the pair names in the file: '/src/config/index.ts'.

  moneys: [
    'tBTCUSD',
    'tETHUSD',
  ],

Note: Trading pairs are prepended by a “t” before the pair (e.g. tBTCUSD, tETHUSD, ...), the project only works with bitfinex supported trading pairs. https://docs.bitfinex.com/docs/ws-general

Commands:

These are several useful commands to run the project.

  • Run unit test:
damian@challenge:~$ npm test
  • Run coverage report.
damian@challenge:~$ npm run coverage
  • Run app in development mode:
damian@challenge:~$ npm run dev
  • Run app:
damian@challenge:~$ npm start
  • Create and run docker container:
damian@challenge:~$ npm run build

Architecture:

The project is divided into several layers, each with different responsibilities. Three stand out consumer / memory / api server.

  • Comsumer: Get data from the socket and keep the book updated in memory, separated by buy and sell.
  • Api: HTTP interface to obtain the different features proposed.
  • Memory (Store): In this layer we store the data obtained from the bitfinex provider through the websocket.
  • Configuration: Here I centralize the configuration from which the api or the consumer obtained information
  • Utilis: Cross functionality, only the logger is found.

Layer diagrams:

Here we see the main layers of the project.

Component diagrams:

Here we see the component of every layers of the project.

Endpoints:

Here are examples of how to use the requested endpoints.

  • 1) BID ASK:

Receive a parir name and retrieve bid-ask prices, format: 'http://127.0.0.1:8000/orders/:pair-name/prices'

curl 'http://127.0.0.1:8000/orders/tBTCUSD/prices'
  • 2) Simulate order execution:

Receive a pair name a operation and ammount and return the price if the order is executed, format: 'http://127.0.0.1:8000/market/execute/:pair-name/[BUY/SELL]/:ammount'

curl 'http://127.0.0.1:8000/market/execute/tBTCUSD/BUY/0.5'
curl 'http://127.0.0.1:8000/market/execute/tBTCUSD/SELL/0.5'
  • 3) Simulate order execution with limit BONUS:

Receive a pair name a operation, ammount, limit and return the price if the order is executed, format: 'http://127.0.0.1:8000/market/execute/:pair-name/[BUY/SELL]/:ammount/limit/:limit-ammount'

curl 'http://127.0.0.1:8000/market/execute/tBTCUSD/BUY/0.5/limit/100'
curl 'http://127.0.0.1:8000/market/execute/tBTCUSD/SELL/0.5/limit/100'

About

This is my solution to the challenge of Rather labs for SR backend develepor. The focus is to create a Market status api.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published