A High-Performance C++ Trading Framework for Cryptocurrency Markets
CipherTrader is a sophisticated, high-performance trading framework built in modern C++ that provides institutional-grade tools for cryptocurrency trading. Designed for speed, reliability, and scalability, it offers comprehensive state management, real-time data processing, and advanced trading capabilities.
- 🚀 High-Performance Engine: Built with modern C++17 for maximum speed and efficiency
- 📊 Comprehensive State Management: Advanced state tracking for orders, positions, trades, and orderbooks
- 🗄️ Robust Database Layer: PostgreSQL integration with SQLPP11 for type-safe database operations
- 💾 Intelligent Caching: Multi-level caching system with Cereal serialization for optimal performance
- 🔐 Secure Authentication: Built-in authentication system with token-based security
- 📈 Real-Time Data Processing: WebSocket support for live market data streaming
- 🔄 Arbitrage Capabilities: Triangular arbitrage detection and execution
- 🧪 Sandbox Environment: Complete testing and simulation environment
- 📋 Advanced Order Management: Support for market, limit, and stop orders with partial fills
- ⚡ Multi-Exchange Support: Unified interface for multiple cryptocurrency exchanges
⚠️ Development Status: This project is currently under active development and is NOT STABLE for production use. APIs may change without notice, and features may be incomplete or experimental. Use at your own risk.
CipherTrader/
├── �� State Management
│ ├── OrdersState # Order lifecycle management
│ ├── PositionsState # Position tracking and calculations
│ ├── TradesState # Trade aggregation and analysis
│ ├── OrderbooksState # Real-time orderbook processing
│ └── ClosedTradesState # Historical trade analysis
├── 🗄️ Database Layer
│ ├── PostgreSQL Integration
│ ├── Type-safe SQLPP11 queries
│ └── Advanced filtering and caching
├── �� Trading Engine
│ ├── Broker implementation
│ ├── Exchange adapters
│ └── Arbitrage detection
└── 🛠️ Infrastructure
├── Authentication system
├── Configuration management
└── Logging and monitoring
- C++17 compatible compiler (Clang recommended)
- CMake 3.20+
- PostgreSQL 12+
- Boost Libraries
- Blaze Math Library
git clone https://github.com/your-username/cipherTrader.git
cd cipherTrader
Ubuntu/Debian:
sudo apt update
sudo apt install build-essential cmake libboost-all-dev \
libpq-dev libssl-dev libz-dev libgtest-dev \
libspdlog-dev libyaml-cpp-dev libhiredis-dev \
libblaze-dev nlohmann-json3-dev
macOS:
brew install cmake boost postgresql openssl zlib \
googletest spdlog yaml-cpp hiredis nlohmann-json
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
make test
#include "CipherTrader.hpp"
class MyStrategy : public ct::helper::Strategy {
public:
void execute() override {
// Get current market data
auto orderbook = ct::orderbook::OrderbooksState::getInstance()
.getOrderbook(ct::enums::ExchangeName::BINANCE_SPOT, "BTC/USDT");
// Place a limit order
auto order = std::make_shared<ct::db::Order>();
order->setSymbol("BTC/USDT");
order->setOrderSide(ct::enums::OrderSide::BUY);
order->setOrderType(ct::enums::OrderType::LIMIT);
order->setQty(0.001);
order->setPrice(50000.0);
// Submit order
ct::order::OrdersState::getInstance().addOrder(order);
}
};
#include "ArbitrageBot.hpp"
// Configure arbitrage bot
BotConfig config;
config.useTestNet = true;
config.accessToken = "your_token";
config.symbolB = "USDT";
config.symbolC = "ETH";
config.tradeAmountA = 0.001;
// Create and run bot
ArbitrageBot bot(config);
bot.start();
// Monitor for arbitrage opportunities
while (bot.isRunning()) {
auto profit = bot.calculateArbitrageProfit();
if (profit > 0.001) { // 0.1% minimum profit
bot.executeArbitrage();
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
#include "DB.hpp"
// Create a new order
auto order = std::make_shared<ct::db::Order>();
order->setSymbol("BTC/USDT");
order->setExchangeName(ct::enums::ExchangeName::BINANCE_SPOT);
order->setOrderSide(ct::enums::OrderSide::BUY);
order->setQty(0.001);
order->setPrice(50000.0);
// Save to database
order->save();
// Query orders with filters
auto filter = ct::db::Order::Filter()
.withSymbol("BTC/USDT")
.withExchangeName(ct::enums::ExchangeName::BINANCE_SPOT);
auto orders = ct::db::Order::findByFilter(nullptr, filter);
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=ciphertrader
DB_USER=trader
DB_PASSWORD=secure_password
# Exchange API Keys
BINANCE_API_KEY=your_binance_key
BINANCE_SECRET_KEY=your_binance_secret
# Trading Configuration
TRADING_MODE=live # or 'sandbox'
MAX_LEVERAGE=10
RISK_PERCENTAGE=2.0
# config.yaml
app:
trading_symbols: ["BTC/USDT", "ETH/USDT"]
trading_timeframes: ["1m", "5m", "1h"]
env:
exchanges:
binance:
fee: 0.001
type: "spot"
balance: 10000.0
data:
warmup_candles_num: 240
generate_candles_from_1m: false
persistency: true
cd build
make test
# Database tests
./tests/DB_Test
# Trading engine tests
./tests/Trading_Test
# Performance tests
./tests/Performance_Test
# Start sandbox mode
./cipherTrader --mode=sandbox --config=config.yaml
# Run with specific strategy
./cipherTrader --strategy=MyStrategy --backtest --start-date=2024-01-01
- Order Processing: 10,000+ orders/second
- Market Data: 100,000+ ticks/second
- Database Operations: 50,000+ queries/second
- Memory Usage: < 100MB for typical trading operations
- Precompiled Headers: Faster compilation times
- Link-Time Optimization: Smaller, faster binaries
- SIMD Operations: Vectorized mathematical operations
- Lock-Free Data Structures: Minimal contention in high-frequency scenarios
- Token-based authentication system
- Secure API key management
- Encrypted configuration storage
- Position size limits
- Maximum drawdown protection
- Real-time risk monitoring
- Automatic stop-loss mechanisms
We welcome contributions! Please see our Contributing Guidelines for details.
# Install development dependencies
sudo apt install clang-format clang-tidy cppcheck
# Format code
make format
# Run static analysis
make analyze
# Run all checks
make check
This project is licensed under the MIT License - see the LICENSE file for details.
Trading cryptocurrencies involves substantial risk of loss and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade cryptocurrencies, you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose.
- Documentation: docs.ciphertrader.com
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: [email protected]
Built with ❤️ by the CipherTrader Team
Empowering traders with institutional-grade tools for the digital asset revolution.