trading_client
Code
about
a high-performance order execution and management system for trading on the Deribit Testnet using C++. This project enables users to place, modify, and cancel orders, as well as subscribe to real-time market data through WebSocket.
core features
- order management:
• Place orders
• Modify orders
• Cancel orders
• View current positions
• Access orderbook data
- real-time market data:
• Streaming of market data via WebSocket
• Subscription to specific channels
• Orderbook updates for subscribed symbols
- instruments supported:
• Spot, Futures, and Options trading instruments
technical requirements
• C++ Implementation
• Focus on low-latency performance
• Proper error handling and logging
• WebSocket Server for real-time market data distribution
environment variables
required variables
- CLIENT_ID: Your Deribit API Client-id
- CLIENT_SECRET: Your Deribit API Client-secret
optional custom configuration variables
- SITE_URL: Custom URL for Deribit Test API (default: https://test.deribit.com)
- ENDPOINT_AUTH: Custom endpoint for authentication (default: /public/auth)
- ENDPOINT_BUY: Custom endpoint for placing buy orders (default: /private/buy)
- ENDPOINT_SELL: Custom endpoint for placing sell orders (default: /private/sell)
- ENDPOINT_EDIT: Custom endpoint for editing orders (default: /private/edit)
- ENDPOINT_CANCEL: Custom endpoint for canceling orders (default: /private/cancel)
- ENDPOINT_POSITION: Custom endpoint for retrieving positions (default: /private/get_positions)
- ENDPOINT_BOOK: Custom endpoint for accessing orderbook data (default: /public/get_order_book)
setting environment variables
On Linux/macOS you can set these environment variables temporarily or permanently.
- temporarily (for the current session):
export CLIENT_ID="your_client_id"
export CLIENT_SECRET="your_client_secret"
- permanently (add to
.bashrc
or.zshrc
file):
echo 'export DEFAULT_CLIENT_ID="your_client_id"' >> ~/.bashrc
echo 'export DEFAULT_CLIENT_SECRET="your_client_secret"' >> ~/.bashrc
source ~/.bashrc
installation
Linux:
sudo apt update
sudo apt install g++ libcurl4-openssl-dev libboost-all-dev libssl-dev pkg-config
macOS:
brew install gcc curl boost openssl pkg-config
building the project
make
to clean up build files:
make clean
to perform a full clean:
make fclean
to rebuild from scratch:
make re
usage
./trade
once authenticated you can interact with using the following commands:
code .Command | parameters
-----------------------------------------------------------------------
1 .Place an Order | action,instrument,type,amount,price
2 .Cancel an Order | order_id
3 .Modify an Order | order_id,new_amount,new_price
4 .Request Orderbook | instrument
5 .Request your Positions | currency,kind
6 .Subscribe/remove channels | action,channel
7 .Start streaming market data | output_file_name
8 .Stops streaming market data | -
9 .Show this Menu | -
0 .Exit program | -
example channels to subscribe to
ticker.BTC-PERPETUAL.100ms
ticker.ETH-PERPETUAL.100ms