Cross-exchange quantitative trading toolkit with unified API for 1024ex, Binance, IBKR and more
Project description
quant1024
A cross-exchange quantitative trading toolkit for structured data retrieval and real-time trading
跨券商跨交易所的开源量化交易工具包,支持结构化数据获取、快速连接多个交易所、实时 WebSocket/Webhook 数据推送。
Documentation: English | 中文 | 中文文档
Features
-
🌐 Multi-Exchange Support: Unified interface for multiple exchanges
- ✅ 1024 Exchange (Decentralized Perpetuals)
- 🔄 Binance (Crypto Exchange)
- 🔄 IBKR (Interactive Brokers - Traditional Finance)
- 🔄 More exchanges coming...
-
📊 Structured Data Retrieval: Multi-source aggregation and standardized format
- Multi-source aggregation: Combine data from multiple exchanges/brokers
- Historical time series: Get historical data for any trading pair
- Klines (1m, 5m, 1h, 1d, etc.)
- Trade history
- Order history
- Funding rate history
- Multiple trading pairs: Perpetuals, Spot, Futures, Options
- Cross-exchange data: Compare and arbitrage across exchanges
- Standardized format: Same data structure across all sources
-
🔌 Real-time Data Push: Live data via WebSocket and Webhook
- WebSocket for price updates
- Webhook callbacks for order events
- Continuous live trading data
-
🚀 Quick Connection: One-line code to connect any exchange
- Auto-handled authentication
- Unified API interface
- Easy to switch between exchanges
Installation
Method 1: Install from PyPI (after package is published)
pip install quant1024
Method 2: Install from Git Repository
pip install git+https://github.com/yourusername/quant1024.git
Method 3: Install from Local Source
# After cloning or downloading the repository
cd quant1024
# Development mode installation (recommended for development)
pip install -e .
# Or normal installation
pip install .
Install Development Dependencies
pip install -e ".[dev]"
Quick Start
1. Create a Custom Strategy
from quant1024 import QuantStrategy
class MyStrategy(QuantStrategy):
"""Custom trading strategy"""
def generate_signals(self, data):
"""Generate trading signals"""
signals = []
for i, price in enumerate(data):
if i == 0:
signals.append(0)
elif price > data[i-1]:
signals.append(1) # Buy
else:
signals.append(-1) # Sell
return signals
def calculate_position(self, signal, current_position):
"""Calculate position size"""
if signal == 1:
return 1.0 # Full position
elif signal == -1:
return 0.0 # No position
else:
return current_position
2. Run Backtest
# Create strategy instance
strategy = MyStrategy(
name="MyFirstStrategy",
params={"param1": "value1"}
)
# Prepare price data
prices = [100, 102, 101, 105, 103, 108, 110]
# Run backtest
result = strategy.backtest(prices)
print(result)
# Output:
# {
# 'strategy_name': 'MyFirstStrategy',
# 'total_signals': 7,
# 'buy_signals': 4,
# 'sell_signals': 2,
# 'sharpe_ratio': 0.1234
# }
3. Use Utility Functions
from quant1024 import calculate_returns, calculate_sharpe_ratio
# Calculate returns
prices = [100, 110, 105, 115]
returns = calculate_returns(prices)
print(returns) # [0.1, -0.0454..., 0.0952...]
# Calculate Sharpe ratio
sharpe = calculate_sharpe_ratio(returns)
print(sharpe) # 1.2345
API Documentation
QuantStrategy Abstract Base Class
All strategies must inherit from this base class and implement the following methods:
Methods
-
__init__(name: str, params: Optional[Dict[str, Any]] = None)- Initialize the strategy
name: Strategy nameparams: Strategy parameters dictionary (optional)
-
initialize() -> None- Initialize the strategy (called automatically before backtesting)
-
generate_signals(data: List[float]) -> List[int][Abstract Method]- Generate trading signals
data: List of price data- Returns: List of signals (1=buy, -1=sell, 0=hold)
-
calculate_position(signal: int, current_position: float) -> float[Abstract Method]- Calculate position size based on signal
signal: Trading signalcurrent_position: Current position size- Returns: New position size
-
backtest(data: List[float]) -> Dict[str, Any]- Run backtest
data: Historical price data- Returns: Backtest results dictionary
Utility Functions
-
calculate_returns(prices: List[float]) -> List[float]- Calculate returns series
prices: Price series- Returns: Returns series
-
calculate_sharpe_ratio(returns: List[float], risk_free_rate: float = 0.0) -> float- Calculate Sharpe ratio
returns: Returns seriesrisk_free_rate: Risk-free rate (default 0)- Returns: Sharpe ratio value
Documentation
For detailed guides and tutorials, please visit:
- 📖 Quick Start Guide - Get started in 5 minutes
- 📦 Installation Guide - Detailed installation instructions
- 💡 Usage Guide - Comprehensive usage examples
- 🚀 Publishing Guide - How to publish to PyPI
中文用户请访问 中文指南
Examples
See examples/usage_example.py for more detailed examples, including:
- Mean reversion strategy
- Momentum strategy
- Utility function usage
- Direct strategy method calls
Run the example:
cd examples
python usage_example.py
Development
Install Development Dependencies
uv pip install -e ".[dev]"
Run Tests
pytest tests/ -v
Test Coverage
pytest tests/ --cov=quant1024 --cov-report=html
Project Structure
quant1024/
├── src/quant1024/ # Source code
│ ├── __init__.py # Package initialization
│ └── core.py # Core functionality
├── tests/ # Test code
│ ├── __init__.py
│ └── test_core.py # Core functionality tests
├── examples/ # Example code
│ └── usage_example.py # Usage examples
├── guide/ # Documentation guides
│ ├── en/ # English guides
│ └── zh-hans/ # Chinese guides
├── pyproject.toml # Project configuration
├── README.md # Project documentation (English)
├── README_zh.md # Project documentation (Chinese)
└── LICENSE # License
Testing
This project includes comprehensive test cases to ensure external software can properly call the API:
- ✅ Import Tests: Verify all public APIs can be correctly imported
- ✅ Inheritance Tests: Verify external code can inherit from the abstract base class
- ✅ Functionality Tests: Verify all methods work correctly
- ✅ Integration Tests: Verify typical use cases
- ✅ Edge Case Tests: Verify exception handling
Run tests to ensure everything works:
pytest tests/ -v
License
See the LICENSE file for license information.
Contributing
Issues and Pull Requests are welcome!
Contact
For questions or suggestions, please submit an Issue.
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 quant1024-0.2.0.tar.gz.
File metadata
- Download URL: quant1024-0.2.0.tar.gz
- Upload date:
- Size: 42.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e8cf9af2c6339c887a88331e03702831bdfed9249a49bd11ff46d05a3fdbcac
|
|
| MD5 |
bd827cdbabed741c7ed3bd1f7dee7b6c
|
|
| BLAKE2b-256 |
1dea1fb5a7658dd3e7c91343584aa0d90596ede5159e6179acffad88797c0f28
|
Provenance
The following attestation bundles were made for quant1024-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on chuci-qin/quant1024
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quant1024-0.2.0.tar.gz -
Subject digest:
6e8cf9af2c6339c887a88331e03702831bdfed9249a49bd11ff46d05a3fdbcac - Sigstore transparency entry: 684814365
- Sigstore integration time:
-
Permalink:
chuci-qin/quant1024@582824e50ea99a519f0c7905b6bb9a6faecdaa5d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/chuci-qin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@582824e50ea99a519f0c7905b6bb9a6faecdaa5d -
Trigger Event:
release
-
Statement type:
File details
Details for the file quant1024-0.2.0-py3-none-any.whl.
File metadata
- Download URL: quant1024-0.2.0-py3-none-any.whl
- Upload date:
- Size: 26.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53f4a5d3c0a293fc232c3c048d187c369e9c5b9aa0669095fd76a6f5a221c1e0
|
|
| MD5 |
fcc2676da758e600f0dfdb65a97220a0
|
|
| BLAKE2b-256 |
3a2f816d99abf16b32b1a5dd6df38d1f6c48cf933dbd78ddcf3d8503d75495ed
|
Provenance
The following attestation bundles were made for quant1024-0.2.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on chuci-qin/quant1024
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quant1024-0.2.0-py3-none-any.whl -
Subject digest:
53f4a5d3c0a293fc232c3c048d187c369e9c5b9aa0669095fd76a6f5a221c1e0 - Sigstore transparency entry: 684814369
- Sigstore integration time:
-
Permalink:
chuci-qin/quant1024@582824e50ea99a519f0c7905b6bb9a6faecdaa5d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/chuci-qin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@582824e50ea99a519f0c7905b6bb9a6faecdaa5d -
Trigger Event:
release
-
Statement type: