An open API service indexing awesome lists of open source software.

https://github.com/amirphl/cipher-trader

Trading bot
https://github.com/amirphl/cipher-trader

algorithmic-trading algorithmic-trading-engine crypto-bot crypto-trading cryptocurrency finance forex forex-trading trade-bot trading trading-algorithms trading-platform trading-software trading-strategies trading-strategy trading-systems tradingbot

Last synced: 29 days ago
JSON representation

Trading bot

Awesome Lists containing this project

README

          

# ๐Ÿš€ CipherTrader

**A High-Performance C++ Trading Framework for Cryptocurrency Markets**

[![C++17](https://img.shields.io/badge/C++-17-blue.svg)](https://isocpp.org/std/the-standard)
[![CMake](https://img.shields.io/badge/CMake-3.20+-green.svg)](https://cmake.org/)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Build Status](https://img.shields.io/badge/Build-Passing-brightgreen.svg)]()

---

## ๐ŸŽฏ Overview

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.

### โœจ Key Features

- **๐Ÿš€ 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.

---

## ๏ฟฝ๏ฟฝ๏ธ Architecture

### Core Components

```
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
```

---

## ๐Ÿš€ Quick Start

### Prerequisites

- **C++17** compatible compiler (Clang recommended)
- **CMake 3.20+**
- **PostgreSQL 12+**
- **Boost Libraries**
- **Blaze Math Library**

### Installation

#### 1. Clone the Repository
```bash
git clone https://github.com/your-username/cipherTrader.git
cd cipherTrader
```

#### 2. Install Dependencies

**Ubuntu/Debian:**
```bash
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:**
```bash
brew install cmake boost postgresql openssl zlib \
googletest spdlog yaml-cpp hiredis nlohmann-json
```

#### 3. Build the Project
```bash
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
```

#### 4. Run Tests
```bash
make test
```

---

## ๐Ÿ“– Usage Examples

### Basic Trading Strategy

```cpp
#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();
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);
}
};
```

### Arbitrage Detection

```cpp
#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));
}
```

### Database Operations

```cpp
#include "DB.hpp"

// Create a new order
auto order = std::make_shared();
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);
```

---

## ๏ฟฝ๏ฟฝ Configuration

### Environment Variables

```bash
# 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
```

### Configuration File

```yaml
# 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
```

---

## ๐Ÿงช Testing

### Run All Tests
```bash
cd build
make test
```

### Run Specific Test Suites
```bash
# Database tests
./tests/DB_Test

# Trading engine tests
./tests/Trading_Test

# Performance tests
./tests/Performance_Test
```

### Sandbox Environment
```bash
# Start sandbox mode
./cipherTrader --mode=sandbox --config=config.yaml

# Run with specific strategy
./cipherTrader --strategy=MyStrategy --backtest --start-date=2024-01-01
```

---

## ๐Ÿ“Š Performance

### Benchmarks

- **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

### Optimization Features

- **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

---

## ๐Ÿ”’ Security

### Authentication
- Token-based authentication system
- Secure API key management
- Encrypted configuration storage

### Risk Management
- Position size limits
- Maximum drawdown protection
- Real-time risk monitoring
- Automatic stop-loss mechanisms

---

## ๐Ÿค Contributing

We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

### Development Setup
```bash
# 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
```

---

## ๏ฟฝ๏ฟฝ Documentation

- [API Reference](docs/API.md)
- [Trading Strategies](docs/Strategies.md)
- [Database Schema](docs/Database.md)
- [Performance Guide](docs/Performance.md)
- [Deployment Guide](docs/Deployment.md)

---

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

## โš ๏ธ Disclaimer

**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.**

---

## ๐Ÿ†˜ Support

- **Documentation**: [docs.ciphertrader.com](https://docs.ciphertrader.com)
- **Issues**: [GitHub Issues](https://github.com/your-username/cipherTrader/issues)
- **Discussions**: [GitHub Discussions](https://github.com/your-username/cipherTrader/discussions)
- **Email**: support@ciphertrader.com

---

**Built with โค๏ธ by the CipherTrader Team**

*Empowering traders with institutional-grade tools for the digital asset revolution.*