This project is a high-performance order execution and management system built to trade on the Deribit Testnet API. It includes a robust WebSocket server for real-time market data streaming, enabling seamless interaction between trading clients and the system.
- Place Orders: Submit buy or sell orders with configurable parameters like instrument, price, and amount.
- Cancel Orders: Efficiently cancel specific orders by their unique ID.
- Modify Orders: Dynamically update existing orders for price and quantity adjustments.
- Retrieve Open Orders: Fetch details of all active orders.
- Order Book Retrieval: Access real-time order book data for any trading instrument.
- View Positions: Display detailed information on current positions, including size, average price, and mark price.
- Client Connectivity: Supports multiple client connections via Boost.Asio and Boost.Beast.
- Dynamic Subscriptions: Allows clients to subscribe to specific symbols for real-time order book updates.
- Real-Time Broadcasting: Continuously streams live updates for subscribed symbols to all connected clients.
- C++: Core implementation language.
- Boost.Asio and Boost.Beast: For WebSocket server functionality.
- cURL: For making HTTP requests to the Deribit API.
- nlohmann/json: For JSON parsing and manipulation.
project_root/
├── main.cpp # Entry point for the application.
├── websocket/ # Contains WebSocket server logic.
│ ├── server.h # Header file for WebSocket server class.
│ └── server.cpp # Implementation of WebSocket server functions.
- Compiler: A C++17 compatible compiler (e.g., GCC, Clang, MSVC).
- Libraries:
- Boost (Asio and Beast)
- cURL
- nlohmann/json
- API Credentials: Generate
client_idandclient_secretfrom the Deribit Testnet.
- Clone the repository:
git clone https://github.com/Shubhammore71/deribit-trader-cpp cd deribit-trader-cpp - Compile the code:
g++ -std=c++17 main.cpp websocket/server.cpp -o trading_system -lboost_system -lssl -lcrypto -lcurl
- Execute the compiled binary:
./trading_system
- The WebSocket server will run on the specified port, and trading operations will execute based on the implemented logic in
main.cpp.
- Authenticate with the Deribit Testnet API to retrieve an access token.
- Use the access token to send authenticated requests for order execution, cancellation, and data retrieval.
- Listens for incoming connections and manages multiple clients.
- Handles subscriptions to specific trading symbols for order book updates.
- Broadcasts real-time market data updates to all connected clients based on their subscriptions.
placeOrder("buy", "100", accessToken, "1", "BTC-PERPETUAL");cancelOrder("30454002197", accessToken);getOrderBook("ETH-PERPETUAL", accessToken);- Send:
subscribe:BTC-PERPETUAL - Server Response:
Acknowledged: subscribe:BTC-PERPETUAL
- Enhance error handling and implement retry mechanisms for network failures.
- Extend WebSocket functionality to include additional data types like trades and positions.
- Optimize performance using multi-threading for handling high client traffic and lower latency.
This project showcases advanced C++ programming skills, expertise in WebSocket development, and proficiency in API integration. It is designed with modularity and scalability, making it a robust solution for real-time trading systems.