A cross-exchange quantitative trading toolkit for structured data retrieval and real-time trading
่ทจๅธๅ่ทจไบคๆๆ็ๅผๆบ้ๅไบคๆๅทฅๅ ทๅ ๏ผๆฏๆ็ปๆๅๆฐๆฎ่ทๅใๅฟซ้่ฟๆฅๅคไธชไบคๆๆใๅฎๆถ WebSocket/Webhook ๆฐๆฎๆจ้ใ
Documentation: English | ไธญๆ | ไธญๆๆๆกฃ
-
๐ 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
pip install quant1024pip install git+https://github.com/yourusername/quant1024.git# After cloning or downloading the repository
cd quant1024
# Development mode installation (recommended for development)
pip install -e .
# Or normal installation
pip install .pip install -e ".[dev]"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# 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
# }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.2345All strategies must inherit from this base class and implement the following 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
-
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
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
ไธญๆ็จๆท่ฏท่ฎฟ้ฎ ไธญๆๆๅ
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.pyuv pip install -e ".[dev]"pytest tests/ -vpytest tests/ --cov=quant1024 --cov-report=htmlquant1024/
โโโ 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
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/ -vSee the LICENSE file for license information.
Issues and Pull Requests are welcome!
For questions or suggestions, please submit an Issue.