A trading system that simulates the complete lifecycle of securities trading, from order submission through execution, clearing, and final settlement.
Klear is a high-performance trading infrastructure that provides:
- Order management and execution across multiple exchanges
- Real-time trade clearing and settlement processing
- Multi-lateral netting for efficient settlement
- Simulated market conditions and exchange behaviors
- Complete trade lifecycle management
-
Multi-Exchange Support: Simulates trading across 4 different exchanges with varying characteristics:
- Primary Exchange (low latency, high liquidity)
- Secondary Exchange (medium latency, medium liquidity)
- Regional Exchange (higher latency, lower liquidity)
- Dark Pool (highest latency, lowest liquidity)
-
Complete Trade Lifecycle:
- Order submission and validation
- Smart order routing
- Trade execution
- Clearing process
- T+2 Settlement (removed for testing)
-
Risk Management:
- Pre-trade validation
- Real-time position monitoring
- Dynamic margin calculations
- Exposure limits
- Go 1.21 or higher
- SQLite3
- Make
-
Clone the repository: git clone https://github.com/ksred/klear-api cd klear-api
-
Install dependencies: go mod download
-
Build the project: make build
Start the server: make run
The API will be available at http://localhost:8080
To run the trading simulation: make simulate
The simulation will:
- Generate random orders across multiple symbols
- Route orders to different exchanges
- Process executions, clearing, and settlement
- Log detailed statistics about the trading activity
- make build - Build the application
- make clean - Remove build artifacts
- make run - Run the application
- make test - Run tests
- make test-coverage - Run tests with coverage
- make lint - Run linters
- make all - Clean, lint, test, and build
- make simulate - Run the trading simulation
- make watch - Run in development mode with auto-reload (requires fswatch)
.
├── cmd/
│ ├── server/ # Main application
│ └── simulation/ # Trading simulation
├── internal/
│ ├── auth/ # Authentication
│ ├── clearing/ # Trade clearing
│ ├── database/ # Database operations
│ ├── exchange/ # Exchange simulation
│ ├── models/ # Data models
│ ├── settlement/ # Settlement processing
│ └── trading/ # Order management
├── pkg/
│ ├── common/ # Shared utilities
│ └── middleware/ # HTTP middleware
└── configs/ # Configuration files
See DOCS.md for detailed API documentation.
Run the test suite: make test
Generate test coverage report: make test-coverage
The application can be configured using environment variables:
- ENV - Environment (development/production)
- DEBUG - Enable debug logging (true/false)
- PORT - Server port (default: 8080)
- Fork the repository
- Create your feature branch (git checkout -b feature/amazing-feature)
- Commit your changes (git commit -m 'Add amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.