Thank you for your interest in contributing to the Hyperliquid Backtester! This document provides guidelines and information for contributors.
- Rust: 1.70 or later
- Git: For version control
- Internet: For API testing and dependency downloads
-
Fork and Clone
git clone https://github.com/xsa-dev/hyperliquid-backtest.git cd hyperliquid-backtest -
Build the Project
cargo build
-
Run Tests
cargo test -
Check Code Quality
cargo fmt --check cargo clippy -- -D warnings
We follow standard Rust conventions with some additional guidelines:
- Formatting: Use
rustfmtwith default settings - Linting: All
clippywarnings must be addressed - Documentation: All public APIs must have comprehensive documentation
- Testing: New features require corresponding tests
# Format code
cargo fmt
# Check linting
cargo clippy -- -D warnings
# Generate documentation
cargo doc --no-deps --openUse conventional commit format:
type(scope): description
[optional body]
[optional footer]
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasks
Examples:
feat(data): add support for 30s intervals
fix(backtest): correct funding payment calculation
docs(readme): update installation instructions
test(strategies): add funding arbitrage test cases
Use descriptive branch names:
feature/add-new-strategyfix/funding-calculation-bugdocs/update-examplesrefactor/improve-error-handling
- Unit Tests: Test individual functions and methods
- Integration Tests: Test component interactions
- Performance Tests: Benchmark critical operations
- API Tests: Test external API integrations (with mocks)
# Run all tests
cargo test
# Run specific test module
cargo test --test integration_tests
# Run with logging
RUST_LOG=debug cargo test
# Run benchmarks
cargo bench
# Test with all features
cargo test --all-features- Place unit tests in the same file as the code being tested
- Place integration tests in the
tests/directory - Use descriptive test names that explain what is being tested
- Include both positive and negative test cases
- Mock external dependencies (Hyperliquid API calls)
Example test structure:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_funding_calculation_positive_rate() {
// Test positive funding rate scenario
}
#[test]
fn test_funding_calculation_negative_rate() {
// Test negative funding rate scenario
}
#[tokio::test]
async fn test_data_fetching_success() {
// Test successful data fetching
}
#[tokio::test]
async fn test_data_fetching_api_error() {
// Test API error handling
}
}- Public APIs: Must have comprehensive rustdoc comments
- Examples: Include practical usage examples
- Error Cases: Document when functions can fail
- Safety: Document any unsafe code (should be rare)
/// Brief description of the function.
///
/// Longer description explaining the purpose, behavior, and any important
/// details about the function.
///
/// # Arguments
///
/// * `param1` - Description of the first parameter
/// * `param2` - Description of the second parameter
///
/// # Returns
///
/// Description of what the function returns.
///
/// # Errors
///
/// This function will return an error if:
/// - Condition 1 occurs
/// - Condition 2 occurs
///
/// # Examples
///
/// ```rust
/// use hyperliquid_backtest::prelude::*;
///
/// let result = function_name(param1, param2)?;
/// assert_eq!(result.value, expected_value);
/// ```
///
/// # Panics
///
/// This function panics if... (only if applicable)
pub fn function_name(param1: Type1, param2: Type2) -> Result<ReturnType, Error> {
// Implementation
}When adding new features, include examples in:
- Rustdoc comments: Simple usage examples
- Examples directory: Complete, runnable examples
- README: Key usage patterns
- Integration tests: Real-world usage scenarios
- Search existing issues to avoid duplicates
- Update to latest version to see if the bug is already fixed
- Create minimal reproduction to isolate the issue
## Bug Description
Brief description of the bug.
## Steps to Reproduce
1. Step 1
2. Step 2
3. Step 3
## Expected Behavior
What you expected to happen.
## Actual Behavior
What actually happened.
## Environment
- Rust version: `rustc --version`
- Crate version: `0.1.0`
- Operating system: `uname -a`
## Additional Context
Any additional information, logs, or screenshots.
## Minimal Reproduction
```rust
// Minimal code that reproduces the issue## Feature Description
Brief description of the proposed feature.
## Use Case
Describe the problem this feature would solve.
## Proposed Solution
Describe your proposed solution.
## Alternatives Considered
Describe alternative solutions you've considered.
## Additional Context
Any additional information or context.- Create an issue to discuss the change (for significant features)
- Fork the repository and create a feature branch
- Write tests for your changes
- Update documentation as needed
- Run the full test suite
- Check code formatting and linting
- Tests: All tests pass (
cargo test) - Formatting: Code is formatted (
cargo fmt) - Linting: No clippy warnings (
cargo clippy -- -D warnings) - Documentation: Public APIs are documented
- Examples: New features include examples
- Changelog: Update CHANGELOG.md if needed
- Breaking Changes: Clearly marked and documented
## Description
Brief description of the changes.
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] All tests pass locally
## Documentation
- [ ] Code is documented
- [ ] README updated (if needed)
- [ ] Examples added/updated (if needed)
## Checklist
- [ ] Code follows project style guidelines
- [ ] Self-review completed
- [ ] No unnecessary debug prints or commented code
- [ ] Breaking changes are documentedsrc/
βββ lib.rs # Public API and re-exports
βββ data.rs # Data structures and fetching
βββ backtest.rs # Backtesting engine
βββ strategies.rs # Trading strategies
βββ indicators.rs # Technical indicators
βββ errors.rs # Error types
βββ funding_report.rs # Funding-specific reporting
βββ csv_export.rs # Data export functionality
βββ migration.rs # Migration utilities
βββ api_docs.rs # API documentation
βββ tests/ # Integration tests
- Async First: Use async/await for I/O operations
- Error Handling: Comprehensive error types with context
- Type Safety: Leverage Rust's type system for correctness
- Performance: Optimize for large datasets
- Compatibility: Maintain compatibility with rs-backtester
- Extensibility: Design for easy extension and customization
- Consistent Naming: Use clear, consistent naming conventions
- Builder Pattern: For complex configuration objects
- Result Types: All fallible operations return
Result<T, E> - Prelude Module: Export commonly used types
- Semantic Versioning: Follow SemVer for API changes
- Patch (0.1.0 β 0.1.1): Bug fixes, documentation updates
- Minor (0.1.0 β 0.2.0): New features, backward compatible
- Major (0.1.0 β 1.0.0): Breaking changes
- Update version in
Cargo.toml - Update
CHANGELOG.md - Run full test suite
- Update documentation
- Create git tag
- Publish to crates.io
- Create GitHub release
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: docs.rs
By contributing to this project, you agree that your contributions will be licensed under the same license as the project (MIT OR Apache-2.0).
Contributors will be recognized in:
- README.md: Contributors section
- CHANGELOG.md: Release notes
- GitHub: Contributor graphs and statistics
Thank you for contributing to Hyperliquid Backtester! π