Contents
Overview
This Project contains two main components: Trading System and WebSocket Server, both designed to interact with the Deribit API for trading and real-time market updates. These systems are optimized for ultra-low latency and high-frequency trading applications.
Trading System
The Trading System is a C++ application designed to interface with the Deribit API. It provides functionalities for authentication, order placement, order management, and market data retrieval. The system ensures low latency, making it ideal for high-frequency trading.
Key Features
- Authentication: Authenticate users with the Deribit API and retrieve access tokens.
- Order Management: Place, modify, and cancel orders for various instruments (futures, perpetual contracts, options).
- Market Data Retrieval: Fetch order book data and trading positions.
- Instrument Support:
- Futures: Example:
BTC-25MAR23
- Perpetual Contracts: Example:
BTC-PERPETUAL
- Options: Example:
BTC-25MAR23-420-C
- Futures: Example:
Project Structure
- main.cpp: Contains the main logic for interacting with the trading API.
- helper.h: Declares utility functions used in the project.
Dependencies
- CURL: A fast and lightweight library used for making HTTP requests to the trading API. It supports various protocols and allows easy integration of network capabilities.
- JsonCpp and nlohmann/json: Libraries for parsing and manipulating JSON data, making it easier to handle responses from the API.
- Regex: Used for validating instrument names to ensure they conform to expected formats.
Running the Trading System
- Add your Deribit API key and secret to the
main.cpp
file. - Install the required dependencies.
- Compile the project using a C++ compiler.
- Run the executable file.
WebSocket Server
The WebSocket Server provides real-time updates to clients subscribed to different trading symbols. It broadcasts changes in order book data using WebSocket technology, ensuring faster data delivery and responsiveness to market changes.
Key Features
- Subscription Management: Efficiently manage client subscriptions for different trading symbols.
- Dynamic Order Book Updates: Listen to the Deribit WebSocket API and update order books in real time.
- Targeted Broadcasts: Push updates to clients subscribed to specific symbols.
- High-Frequency Updates: Designed to handle multiple client connections and high-frequency data updates.
Main Functions
- broadcastOrderBookUpdate: Sends the latest order book data to all clients subscribed to a specific symbol.
- on_deribit_message: Handles incoming messages from Deribit’s WebSocket feed and updates order books.
- on_message: Manages client subscriptions to trading symbols.
- on_open and on_close: Handle new connections and clean up closed connections.
Dependencies
- CURL: For making HTTP requests to the trading API.
- WebSocket++: For WebSocket communication.
- JsonCpp and nlohmann/json: For JSON parsing and manipulation.
Running the WebSocket Server
- Install the required dependencies.
- Compile the project using a C++ compiler.
- Run the executable file.
Folder Structure
- Trading System: Contains the C++ application for trading functionalities.
- WebSocket Server: Includes the server for real-time market updates.
- Server: WebSocket server implementation.
- Client: Sample client for testing WebSocket server functionality.