This project provides a server for an order book application. It uses Node.js, Express, and Socket.io to connect to Binance WebSocket streams and broadcast order book and ticker updates to connected clients.
- Clone the repository:
git clone https://github.com/yourusername/order-book-server.git
- Change to the project directory:
cd order-book-server
- Install dependencies:
npm install
-
Start the server:
npm start
-
The server will be running on port 4000. You can change the port by setting the
PORT
environment variable.
Create a .env
file in the root directory of your project and add any necessary configuration variables. For example:
ALLOWED_ORIGINS=http://localhost:3000/
-
POST /api/setcoin
- Description: Switch the current coin being tracked.
- Request Body:
{ "coinID": "btcusdt" }
- Response:
200 OK
with a message indicating the switched coin.
-
GET /
- Description: Returns a motivational quote.
- changeCoin
- Description: Change the coin for which updates are being received.
- Data:
string
- Coin ID (e.g., "btcusdt").
-
orderBookUpdate
- Description: Order book updates from Binance.
- Data:
Object
- Order book data.
-
tickerUpdate
- Description: Ticker updates from Binance.
- Data:
Object
- Ticker data.
├── config
│ ├── config.js # Configuration settings
├── helper
│ ├── disconnect.js # Handles disconnection logic
│ ├── heartBeatServices.js # Manages WebSocket heartbeat
│ ├── orderBookHelper.js # Helper functions for managing order book data
├── node_modules
├── services
│ ├── webSocket.js # Handles order book WebSocket connections
│ ├── switchCoin.js # Switches the coin and manages connections
│ ├── urlBuilder.js # Builds URLs for WebSocket connections
├── .env # Environment variables
├── .gitignore # Files and directories to ignore in git
├── index.js # Main entry point of the application
├── package-lock.json # Lockfile for npm dependencies
├── package.json # Project dependencies and scripts
├── vercel.json # Vercel configuration
└── README.md # Project documentation
Thank you for using the Order Book Server! We hope it helps you build something great. If you have any feedback or suggestions, feel free to reach out.