Professional market making toolkit for Bitfinex cryptocurrency exchange
Project description
Bitfinex Maker-Kit
Modular Market Making Platform for Bitfinex
A professional, production-ready command-line interface for automated trading and market making on the Bitfinex cryptocurrency exchange. Built with modern software architecture principles including dependency injection, domain-driven design, and comprehensive testing frameworks.
๐ฏ Key Features
๐ก๏ธ Safety-First Architecture
- POST_ONLY Enforcement: Architecturally impossible to place market orders
- Dry-Run Mode: Test strategies without real trading
- Multi-Layer Validation: Domain objects, service layer, and API boundary validation
- Risk Management: Built-in safeguards and confirmation prompts
โก Modern Architecture
- Dependency Injection: Clean separation of concerns with container pattern
- Domain-Driven Design: Type-safe domain objects (OrderId, Price, Amount, Symbol)
- Service-Oriented: Modular services (trading, cache, market data, performance monitoring)
- Event-Driven: WebSocket integration with async event handling
๐งช Comprehensive Testing
- Property-Based Testing: 1000+ generated test cases using Hypothesis
- Realistic Load Testing: Integration tests against Bitfinex Paper Trading API
- Performance Benchmarking: Automated regression detection with real network conditions
- Security Scanning: Continuous vulnerability assessment
๐ Production Ready
- Modular Commands: Extensible command system with core abstractions
- Performance Monitoring: Real-time metrics and profiling tools
- Configuration Management: Environment-aware configuration system
- Quality Tooling: Streamlined workflow with Ruff, MyPy, Bandit, and pytest
๐๏ธ Architecture Overview
Modern Software Design
- Safety First: Architecturally enforced POST_ONLY orders with multiple validation layers
- Modular Design: Extensible architecture supporting multiple strategies and update methods
- Domain-Driven: Rich domain objects with business logic encapsulation
- Service-Oriented: Clean dependency injection with focused service responsibilities
Core Architecture Components
๐ฏ Command Layer (commands/)
- Individual Commands:
test,wallet,list,cancel,put,market-make,fill-spread,update - Core Abstractions:
core/with base commands, executors, and result handling - Extensible Design: Plugin-style command architecture
๐๏ธ Service Layer (services/)
- Container: Dependency injection system managing service lifecycle
- Trading Services: Sync/async trading facades with monitoring
- Cache Service: Intelligent caching with namespace isolation
- Performance Monitor: Real-time metrics collection and analysis
- Market Data Service: Real-time price feeds and historical data
๐จ Domain Layer (domain/)
- Value Objects:
OrderId,Price,Amount,Symbolwith validation - Business Logic: Type-safe operations and domain rules
- Immutable Design: Functional programming principles
โ๏ธ Core Layer (core/)
- API Client: Clean Bitfinex API wrapper with POST_ONLY enforcement
- Trading Facade: Unified interface coordinating focused components
- Order Management: Sophisticated order lifecycle management
- Validation: Multi-layer validation system
๐ ๏ธ Installation
Production Installation
# Install with pipx (recommended)
pipx install bitfinex-maker-kit
# Configure API credentials
echo 'BITFINEX_API_KEY=your_api_key_here' > .env
echo 'BITFINEX_API_SECRET=your_api_secret_here' >> .env
Development Installation
Recommended: One-Command Setup (solves externally-managed-environment errors)
# Clone repository
git clone https://github.com/0xferit/bitfinex-maker-kit.git
cd bitfinex-maker-kit
# One-command setup (creates venv + installs everything)
make setup
# Activate virtual environment (if not already active)
source venv/bin/activate # On Windows: venv\Scripts\activate
# Verify installation
make quality # Run all quality checks
pytest # Run tests
Alternative: Using pipx (for tool installation)
# Install as isolated application
pipx install git+https://github.com/0xferit/bitfinex-maker-kit.git
# For development
git clone https://github.com/0xferit/bitfinex-maker-kit.git
cd bitfinex-maker-kit
pipx install -e .
Manual Installation (if virtual environment setup fails)
# Option 1: Force install (not recommended)
pip install -e ".[dev]" --break-system-packages
# Option 2: User install
pip install -e ".[dev]" --user
# Option 3: Traditional virtual environment
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pre-commit install
๐ก Troubleshooting "externally-managed-environment" Error:
- Modern Python/macOS: Use virtual environment (recommended above)
- System Python: Use
pipxfor isolated installation - Docker: Use the provided Dockerfile for containerized development
๐ Quick Start
Basic Usage
# Test API connection
bitfinex-maker-kit test
# View wallet balances
bitfinex-maker-kit wallet
# List active orders
bitfinex-maker-kit list
# Get help
bitfinex-maker-kit --help
Market Making
# Create symmetric market making orders
bitfinex-maker-kit market-make --symbol tBTCUSD --levels 5 --spread 1.0 --size 0.1
# Start automated market making
bitfinex-maker-kit market-make --symbol tBTCUSD --levels 5
# Fill spread gaps
bitfinex-maker-kit fill-spread --symbol tETHUSD --levels 10
Advanced Features
# Dry-run mode (recommended for testing)
bitfinex-maker-kit market-make --symbol tBTCUSD --levels 3 --dry-run
# Custom order placement
bitfinex-maker-kit put --symbol tBTCUSD --amount 0.01 --price 50000.0 --side buy
# Batch order cancellation
bitfinex-maker-kit cancel --symbol tBTCUSD --side buy
# Cancel all orders for a symbol
bitfinex-maker-kit cancel --all --symbol tBTCUSD
๐งฉ Strategies Layer (strategies/, update_strategies/)
- Order Generation: Flexible order generation strategies
- Update Strategies: Multiple approaches (WebSocket, cancel-recreate, batch)
- Strategy Factory: Dynamic strategy selection based on market conditions
๐ WebSocket Layer (websocket/)
- Connection Manager: Robust WebSocket connection handling
- Event Handler: Real-time order updates and market data
- Async Event Loop: Non-blocking event processing
๐ฅ๏ธ UI Layer (ui/)
- Market Maker Console: Interactive trading interface
- Performance Dashboard: Real-time metrics visualization
- Profiler Integration: Memory and performance monitoring
โ๏ธ Configuration Layer (config/)
- Environment Management: Development, staging, production configs
- Trading Configuration: Dynamic configuration with validation
- Feature Flags: Environment-specific feature control
๐ Available Commands
| Command | Description | Architecture Features |
|---|---|---|
test |
Test API connection | Service container validation, credential testing |
wallet |
Show wallet balances | Real-time balance with caching and formatting |
list |
List active orders | Advanced filtering, display helpers, pagination |
cancel |
Cancel orders | Bulk operations, criteria matching, dry-run support, --all flag |
put |
Place single order | Domain validation, order builder pattern |
market-make |
Create staircase orders | Strategy-based generation, symmetric placement |
fill-spread |
Fill bid-ask gaps | Market data analysis, intelligent spacing |
update |
Update existing orders | Multiple update strategies, WebSocket optimization |
๐งช Testing & Quality Assurance
Comprehensive Test Architecture
Test Categories
- Unit Tests (
tests/unit/): Isolated component testing with mocks - Integration Tests (
tests/integration/): Service interaction validation - Property Tests (
tests/property/): Hypothesis-based fuzzing and edge cases - Load Tests (
tests/load/): Stress testing and traffic pattern simulation - Performance Tests (
tests/performance/): Benchmark suite with regression detection - Benchmarks (
tests/benchmarks/): Comprehensive performance analysis
Test Infrastructure
- Fixtures (
tests/fixtures/): Reusable test data (API responses, market data, trading scenarios) - Mocks (
tests/mocks/): Service mocks (API, client, trading service, WebSocket) - Utilities (
tests/utilities/): Test helpers and profiling tools
Specialized Testing
- POST_ONLY Enforcement: Architectural safety validation
- Python Version Compliance: Version requirement testing
- Wrapper Architecture: API boundary validation
Running Tests
# Run all tests with coverage
pytest --cov=bitfinex_maker_kit --cov-report=html
# Run specific test categories
pytest tests/unit/ # Unit tests
pytest tests/integration/ # Integration tests
pytest tests/property/ # Property-based tests
pytest tests/load/ # Load and stress tests
pytest tests/performance/ # Performance benchmarks
# Run with markers
pytest -m unit # Unit tests only
pytest -m integration # Integration tests
pytest -m property # Property-based tests
pytest -m load # Load tests
pytest -m benchmark # Performance benchmarks
# Run specific architectural tests
pytest tests/test_post_only_enforcement.py # Safety validation
pytest tests/test_wrapper_architecture.py # Architecture validation
pytest tests/test_python_version_requirement.py # Version compliance
Code Quality - Simple Workflow
Three commands for everything:
# Quick setup
make install # Install all dev dependencies
# Main workflow
make quality # Run all quality checks (recommended)
make test # Run tests with coverage
# Individual checks (if needed)
make format # Auto-format code
make lint # Run linter with auto-fix
make type-check # Run type checking
make security # Run security scan
Alternative: Direct commands
# All-in-one linter and formatter (replaces black, isort, flake8)
ruff check . --fix # Lint with auto-fix
ruff format . # Format code
# Type checking and security
mypy bitfinex_maker_kit/ # Type checking
bandit -r bitfinex_maker_kit/ # Security scan
Quick validation (30 seconds):
./scripts/check.sh # Fast pre-commit check
๐ Performance Monitoring & Observability
Built-in Performance Infrastructure
Performance Monitor Service (services/performance_monitor.py)
- Real-Time Metrics: P50, P95, P99 percentiles for API operations
- Cache Analytics: Hit ratios, miss patterns, namespace efficiency
- Memory Profiling: Leak detection with heap snapshots
- Error Tracking: Success/failure rates with categorization
Profiler Utilities (utilities/profiler.py)
- Execution Profiling: Function-level performance analysis
- Memory Monitoring: Detailed memory usage tracking
- Bottleneck Detection: Automated performance regression alerts
- Resource Utilization: CPU, memory, and I/O monitoring
Performance Dashboard (utilities/performance_dashboard.py)
- Real-Time Visualization: Live metrics display
- Historical Analysis: Performance trend tracking
- Alert System: Automated threshold-based notifications
- Export Capabilities: JSON, CSV data export
Market Data Caching (utilities/market_data_cache.py)
- Intelligent Caching: 90%+ API call reduction
- Cache Warming: Proactive data prefetching
- Namespace Isolation: Multi-symbol cache management
- TTL Management: Automatic cache invalidation
Using Performance Tools
# Enable performance monitoring in commands
bitfinex-maker-kit market-make --enable-monitoring
# View performance metrics (via dashboard integration)
# Dashboard accessible through market-make UI console
# Load testing and benchmarks
pytest tests/performance/ --benchmark-json=results.json
pytest tests/load/ -v # Stress testing
๐ Security Features
Built-in Security
- POST_ONLY Orders: Market orders architecturally impossible
- API Key Protection: Secure credential management
- Input Validation: Comprehensive parameter validation
- Rate Limiting: API abuse prevention
- Audit Logging: Complete operation tracking
Security Scanning
- Dependency Scanning: Automated vulnerability detection
- Code Analysis: Static security analysis with Bandit
- Secret Detection: Credential leak prevention
- License Compliance: MIT license for maximum flexibility
๐ณ Docker Deployment
Docker Usage
# Build image
docker build -t bitfinex-maker-kit .
# Run container
docker run -d \
--name bitfinex-maker-kit \
-e BITFINEX_API_KEY=your_key \
-e BITFINEX_API_SECRET=your_secret \
bitfinex-maker-kit
# View logs
docker logs bitfinex-maker-kit
Docker Compose
version: '3.8'
services:
bitfinex-maker-kit:
build: .
environment:
- BITFINEX_API_KEY=${BITFINEX_API_KEY}
- BITFINEX_API_SECRET=${BITFINEX_API_SECRET}
volumes:
- ./logs:/app/logs
restart: unless-stopped
๐ Performance Benchmarks
Typical Performance Metrics
- Order Placement: 100+ orders/second
- API Response Time: <50ms P95
- Cache Hit Ratio: >90%
- Memory Usage: <100MB steady state
- Error Rate: <0.1% under normal conditions
Load Testing Results
- Constant Load: 1000+ operations sustained
- Burst Load: 5000+ operations peak
- Stress Test: 99%+ uptime under extreme load
- Memory Efficiency: No memory leaks detected
๐ค Contributing
Development Setup
# Install development dependencies
pip install -e ".[dev,test,security]"
# Install pre-commit hooks
pre-commit install
# Run full test suite
tox
Code Standards
- Python 3.12+ required
- Type hints mandatory
- 100% test coverage for new features
- Security review for all changes
- Performance benchmarks for optimizations
Pull Request Process
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Make changes with tests and documentation
- Run quality checks:
tox - Submit pull request with detailed description
๐ Codebase Structure
Directory Organization
bitfinex_maker_kit/
โโโ __init__.py # Package entry point and exports
โโโ cli.py # Main CLI interface using focused components
โโโ bitfinex_client.py # Legacy wrapper (delegating to core/)
โโโ cli/ # CLI-specific components
โ โโโ argument_parser.py # Command-line argument parsing
โ โโโ command_router.py # Command routing logic
โโโ commands/ # Individual command implementations
โ โโโ core/ # Command abstractions and patterns
โ โ โโโ base_command.py # Base command interface
โ โ โโโ command_executor.py # Command execution framework
โ โ โโโ command_result.py # Result handling
โ โ โโโ [specialized_commands] # Command implementations
โ โโโ [individual_commands].py # Main CLI commands
โโโ core/ # Core business logic
โ โโโ api_client.py # Clean Bitfinex API wrapper
โ โโโ trading_facade.py # Unified trading interface
โ โโโ order_manager.py # Order lifecycle management
โ โโโ order_validator.py # Multi-layer validation
โโโ domain/ # Domain objects and business rules
โ โโโ order_id.py # Order identification value object
โ โโโ price.py # Price value object with validation
โ โโโ amount.py # Amount value object with validation
โ โโโ symbol.py # Trading pair symbol validation
โโโ services/ # Service layer with dependency injection
โ โโโ container.py # Dependency injection container
โ โโโ trading_service.py # Core trading operations
โ โโโ cache_service.py # Intelligent caching system
โ โโโ performance_monitor.py # Real-time metrics collection
โโโ strategies/ # Trading strategy implementations
โ โโโ order_generator.py # Flexible order generation
โโโ update_strategies/ # Order update approaches
โ โโโ base.py # Update strategy interface
โ โโโ websocket_strategy.py # Real-time WebSocket updates
โ โโโ cancel_recreate_strategy.py # Cancel-recreate fallback
โโโ websocket/ # WebSocket integration
โ โโโ connection_manager.py # Connection lifecycle
โ โโโ event_handler.py # Real-time event processing
โโโ ui/ # User interface components
โ โโโ market_maker_console.py # Interactive trading console
โโโ config/ # Configuration management
โ โโโ environment.py # Environment-aware configuration
โ โโโ trading_config.py # Trading-specific settings
โโโ utilities/ # Shared utilities and helpers
โโโ [various_utilities].py # Helper functions and utilities
โโโ performance_dashboard.py # Performance visualization
โโโ profiler.py # Performance profiling tools
Key Design Patterns
- Dependency Injection: Clean service boundaries with container pattern
- Command Pattern: Extensible command system with undo capabilities
- Strategy Pattern: Pluggable algorithms for order generation and updates
- Facade Pattern: Simplified interfaces over complex subsystems
- Domain-Driven Design: Rich domain objects with business logic
๐ค Contributing
We welcome contributions! This project uses automated semantic versioning and release management.
Development Workflow
- Fork and Clone: Fork the repository and clone locally
- Create Feature Branch: Branch from
developfor new features - Write Code: Follow existing patterns and conventions
- Test Thoroughly: Ensure all tests pass with
pytest - Submit PR: Open a pull request to
developbranch
Conventional Commits
We use Conventional Commits for automated versioning. Your commit messages determine version bumps:
| Commit Type | Example | Version Bump |
|---|---|---|
fix: |
fix: correct order cancellation logic |
Patch (0.0.X) |
feat: |
feat: add stop-loss order support |
Minor (0.X.0) |
BREAKING CHANGE: |
feat!: change API response format |
Major (X.0.0) |
chore: |
chore: update dependencies |
No release |
docs: |
docs: improve API documentation |
No release |
test: |
test: add integration tests |
No release |
refactor: |
refactor: simplify order validation |
Patch (0.0.X) |
perf: |
perf: optimize WebSocket handling |
Patch (0.0.X) |
Examples
# Bug fix (patch release)
git commit -m "fix: resolve WebSocket reconnection issue"
# New feature (minor release)
git commit -m "feat: implement adaptive spread adjustment"
# Breaking change (major release)
git commit -m "feat!: redesign order management API
BREAKING CHANGE: OrderManager.create() now requires Symbol parameter"
# No release
git commit -m "docs: add examples for market-make command"
git commit -m "chore: update ruff configuration"
Automated Release Process
When changes are merged from develop to main:
- The system analyzes commit messages since the last release
- Automatically determines the version bump type
- Updates version in
pyproject.tomland__init__.py - Creates a git tag
- Publishes to PyPI
- Creates a GitHub release
No manual version management needed!
โ ๏ธ Risk Disclaimer
IMPORTANT: Trading cryptocurrency involves substantial risk of loss and is not suitable for every investor. The volatile nature of cryptocurrency markets may result in significant financial losses. You should carefully consider whether trading is suitable for you in light of your circumstances, knowledge, and financial resources.
- Test First: Always use
--dry-runmode before live trading - Start Small: Begin with minimal position sizes
- Monitor Closely: Actively supervise automated strategies
- Risk Management: Never trade more than you can afford to lose
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Third-Party Dependencies
All dependencies use compatible permissive licenses (MIT, BSD, Apache-2.0). See THIRD_PARTY_LICENSES.md for complete license attributions.
๐ Acknowledgments
- Bitfinex API Team for comprehensive API documentation
- Open Source Community for testing frameworks and tools
- Security Researchers for vulnerability disclosure
- Trading Community for feature requests and feedback
Ready for Enterprise Trading! ๐
Start with bitfinex-maker-kit test to verify your setup, then explore the comprehensive feature set designed for professional market making.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitfinex_maker_kit-4.7.0.tar.gz.
File metadata
- Download URL: bitfinex_maker_kit-4.7.0.tar.gz
- Upload date:
- Size: 158.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7807e20c226917350c2866290425ca9a8612da4d4f66327e27f5bea20cbcf615
|
|
| MD5 |
1ba39e0d1bc2673b29053098e07f1c48
|
|
| BLAKE2b-256 |
b4910a0a3aab915f44202817a3a27d29fd396046848474cfad0cce77f45401e6
|
Provenance
The following attestation bundles were made for bitfinex_maker_kit-4.7.0.tar.gz:
Publisher:
publish.yml on 0xferit/bitfinex-maker-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bitfinex_maker_kit-4.7.0.tar.gz -
Subject digest:
7807e20c226917350c2866290425ca9a8612da4d4f66327e27f5bea20cbcf615 - Sigstore transparency entry: 427026880
- Sigstore integration time:
-
Permalink:
0xferit/bitfinex-maker-kit@5ff80eebd45c31559bc4f5edb289c14ab92c5cb2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/0xferit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5ff80eebd45c31559bc4f5edb289c14ab92c5cb2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bitfinex_maker_kit-4.7.0-py3-none-any.whl.
File metadata
- Download URL: bitfinex_maker_kit-4.7.0-py3-none-any.whl
- Upload date:
- Size: 178.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c85d08d3aa7d3d212b4237efe5ac8b0f3ae3a2d49368f68800890f6a2b732ce
|
|
| MD5 |
5175918878b3d25d32698a9472ab6d44
|
|
| BLAKE2b-256 |
7ad5c5173fc35257bbfad20872f1ca7cdb873c9e3183d0ef075905936da29b8e
|
Provenance
The following attestation bundles were made for bitfinex_maker_kit-4.7.0-py3-none-any.whl:
Publisher:
publish.yml on 0xferit/bitfinex-maker-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bitfinex_maker_kit-4.7.0-py3-none-any.whl -
Subject digest:
9c85d08d3aa7d3d212b4237efe5ac8b0f3ae3a2d49368f68800890f6a2b732ce - Sigstore transparency entry: 427026903
- Sigstore integration time:
-
Permalink:
0xferit/bitfinex-maker-kit@5ff80eebd45c31559bc4f5edb289c14ab92c5cb2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/0xferit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5ff80eebd45c31559bc4f5edb289c14ab92c5cb2 -
Trigger Event:
push
-
Statement type: