Multi-source quantitative trading toolkit for structured data retrieval and real-time trading - supports exchanges, financial data providers, and blockchain sources
Project description
quant1024
A cross-exchange quantitative trading toolkit for structured data retrieval, real-time trading, and cloud backtesting
跨券商跨交易所的开源量化交易工具包,支持结构化数据获取、快速连接多个交易所、实时交易和 QuantConnect 云端回测。
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
-
🧪 QuantConnect Cloud Backtesting: Full QuantConnect REST API integration
- Cloud-based strategy backtesting
- Complete result processing and export
- Support for stocks, crypto, futures, and options
Installation
Method 1: Install from PyPI
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]"
Public API
quant1024 exposes two main public APIs:
Exchange1024ex- 1024 Exchange connector for live tradingqc- QuantConnect API infrastructure for cloud backtesting
Quick Start
1. Connect to 1024 Exchange
from quant1024 import Exchange1024ex
# Create exchange instance
exchange = Exchange1024ex(
api_key="your_api_key",
api_secret="your_api_secret"
)
# Get market data
markets = exchange.perp.get_markets()
print(markets)
# Get account info
account = exchange.account.get_account_info()
print(account)
# Place an order
order = exchange.perp.place_order(
market="ETH-PERP",
side="buy",
size=0.1,
price=3000.0
)
print(order)
2. QuantConnect Cloud Backtesting
from quant1024 import qc
# Quick backtest run
qc.run_backtest(
user_id="your_user_id",
api_token="your_api_token",
strategy_file="my_strategy.py",
export_json=True, # Export full results
)
3. Advanced QuantConnect API Usage
from quant1024 import qc
# Create credentials and API client
credentials = qc.QCCredentials(
user_id="your_user_id",
api_token="your_api_token"
)
api = qc.QuantConnectAPI(credentials)
# Authenticate
api.authenticate()
# Create project
project_id = api.create_project("MyStrategy")
# Upload strategy code
with open("my_strategy.py") as f:
api.create_file(project_id, "main.py", f.read())
# Compile
compile_id = api.compile(project_id)
api.wait_for_compile(project_id, compile_id)
# Run backtest
backtest_id = api.create_backtest(project_id, compile_id, "test_run")
result = api.wait_for_backtest(project_id, backtest_id)
# Get result summary
summary = qc.BacktestResultProcessor.get_summary(result)
print(summary)
# Output:
# {
# '总收益率': '15.5%',
# '年化收益率': '31.2%',
# '夏普比率': '1.85',
# '最大回撤': '-8.2%',
# ...
# }
API Documentation
Exchange1024ex
The main exchange connector for 1024 Exchange:
from quant1024 import Exchange1024ex
exchange = Exchange1024ex(api_key="xxx", api_secret="xxx")
# Modules available:
exchange.perp # Perpetual futures trading
exchange.spot # Spot trading
exchange.account # Account management
exchange.prediction # Prediction markets
exchange.championship # Championship trading
qc Module
QuantConnect API infrastructure for cloud backtesting:
qc.run_backtest()
Quick function to run a complete backtest:
qc.run_backtest(
user_id: str, # QuantConnect User ID
api_token: str, # QuantConnect API Token
strategy_file: str, # Path to strategy file
project_name: str = None, # Optional project name
export_json: bool = False # Export results to JSON
) -> Dict
qc.QCCredentials
Data class for API credentials:
credentials = qc.QCCredentials(
user_id="your_user_id",
api_token="your_api_token"
)
qc.QuantConnectAPI
Full API client with methods:
authenticate()- Verify authenticationcreate_project(name)- Create a new projectcreate_file(project_id, name, content)- Upload file to projectcompile(project_id)- Compile projectwait_for_compile(project_id, compile_id)- Wait for compilationcreate_backtest(project_id, compile_id, name)- Start backtestwait_for_backtest(project_id, backtest_id)- Wait for backtest completionget_backtest_orders(project_id, backtest_id)- Get order recordsget_full_backtest_with_charts(project_id, backtest_id)- Get full results with charts
qc.BacktestResultProcessor
Result processing utilities:
get_summary(backtest)- Extract key metricsget_full_data(backtest)- Get complete data for custom dashboardsexport_chart_data(backtest)- Export chart data for frontendparse_equity_curve(charts_data)- Parse equity curve dataparse_drawdown_curve(charts_data)- Parse drawdown dataexport_to_json(...)- Export full data to JSON file
Examples
Example Directory Structure
examples/
├── lean-engine/ # QuantConnect strategy examples
│ ├── main.py # Mag 7 Alpha + Beta strategy
│ ├── btc_futures_arbitrage.py # BTC futures arbitrage
│ ├── backtest.py # Backtest runner
│ └── README.md # Detailed usage guide
├── sdk-examples/ # SDK usage examples
│ ├── sdk_usage_example.py # Basic SDK usage
│ ├── dual_ma_backtest.py # Dual MA strategy backtest
│ └── price_trigger_buy.py # Price trigger trading
├── live_trading_example.py # Live trading example
├── example_1024ex.py # 1024 Exchange example
└── usage_example.py # General usage examples
Run Lean Engine Examples
cd examples/lean-engine
# Set credentials (or modify backtest.py)
export QC_USER_ID="your_user_id"
export QC_API_TOKEN="your_api_token"
# Run backtest
python backtest.py
Strategy Examples
Mag 7 Alpha + Beta Market Neutral Strategy
Long Mag 7 tech stocks + Short QQQ for market hedging:
# See examples/lean-engine/main.py
from AlgorithmImports import *
class Mag7AlphaBetaStrategy(QCAlgorithm):
def initialize(self):
self.set_start_date(2025, 7, 1)
self.set_end_date(2026, 1, 1)
self.set_cash(1000000)
# Long Mag 7
self.mag7_tickers = ["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA", "META", "TSLA"]
for ticker in self.mag7_tickers:
self.add_equity(ticker, Resolution.DAILY)
# Short QQQ for hedge
self.add_equity("QQQ", Resolution.DAILY)
BTC Futures Spot Arbitrage Strategy
Cash-and-carry arbitrage using Coinbase spot + CME futures:
# See examples/lean-engine/btc_futures_arbitrage.py
from AlgorithmImports import *
class BTCFuturesArbitrageStrategy(QCAlgorithm):
def initialize(self):
self.set_start_date(2024, 1, 1)
self.set_end_date(2025, 1, 1)
self.set_cash(1000000)
# Coinbase BTC spot
self.btc_spot = self.add_crypto("BTCUSD", Resolution.HOUR, Market.COINBASE)
# CME BTC futures
self.btc_future = self.add_future(Futures.Currencies.BTC, Resolution.HOUR)
Project Structure
quant1024/
├── src/quant1024/ # Source code
│ ├── __init__.py # Package initialization (public API)
│ ├── exchanges/ # Exchange connectors
│ │ ├── exchange_1024ex.py # 1024 Exchange
│ │ └── modules/ # Trading modules
│ ├── qc/ # QuantConnect API
│ │ ├── client.py # REST API client
│ │ ├── models.py # Data models
│ │ ├── runner.py # Backtest runner
│ │ └── result_processor.py # Result processing
│ ├── interfaces/ # Trading interfaces
│ ├── models/ # Data models
│ └── utils/ # Utilities
├── tests/ # Test code
├── examples/ # Example code
│ └── lean-engine/ # QuantConnect strategy examples
├── guide/ # Documentation
│ ├── en/ # English guides
│ └── zh-hans/ # Chinese guides
├── pyproject.toml # Project configuration
├── README.md # This file
├── README_zh.md # Chinese documentation
└── LICENSE # License
Development
Install Development Dependencies
uv pip install -e ".[dev]"
Run Tests
pytest tests/ -v
Test Coverage
pytest tests/ --cov=quant1024 --cov-report=html
Testing
This project includes comprehensive test cases:
- ✅ Import Tests: Verify public APIs can be correctly imported
- ✅ Exchange Tests: Verify exchange connector functionality
- ✅ QC API Tests: Verify QuantConnect API integration
- ✅ Integration Tests: Verify typical use cases
- ✅ Edge Case Tests: Verify exception handling
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.5.5.tar.gz.
File metadata
- Download URL: quant1024-0.5.5.tar.gz
- Upload date:
- Size: 528.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9c7a914daf132ffb65f2885561a487305a8541e52a1fccb3cee6e25cf1c14a1
|
|
| MD5 |
18561c176b2680a8f000df6137b7aafe
|
|
| BLAKE2b-256 |
72cdfacccb36419f18a7df4d2c32059efce3360dda39537809e1aded541b4a8f
|
Provenance
The following attestation bundles were made for quant1024-0.5.5.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.5.5.tar.gz -
Subject digest:
f9c7a914daf132ffb65f2885561a487305a8541e52a1fccb3cee6e25cf1c14a1 - Sigstore transparency entry: 868640022
- Sigstore integration time:
-
Permalink:
chuci-qin/quant1024@288fe4d9a62a212100b5e1b3bb90fa26de91ae02 -
Branch / Tag:
refs/heads/main - 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@288fe4d9a62a212100b5e1b3bb90fa26de91ae02 -
Trigger Event:
push
-
Statement type:
File details
Details for the file quant1024-0.5.5-py3-none-any.whl.
File metadata
- Download URL: quant1024-0.5.5-py3-none-any.whl
- Upload date:
- Size: 86.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 |
b7d4d6c3903953549fd39d8bdeadea15e72fb38eac9fbb0e2ff6e4529da56cf0
|
|
| MD5 |
a333f3e549f35b0243ee96c8c3f75ad5
|
|
| BLAKE2b-256 |
d611a4175df811ec2e2d3cd805cf768d8e192b2390e3f2bf5a4b5d61884b5bb0
|
Provenance
The following attestation bundles were made for quant1024-0.5.5-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.5.5-py3-none-any.whl -
Subject digest:
b7d4d6c3903953549fd39d8bdeadea15e72fb38eac9fbb0e2ff6e4529da56cf0 - Sigstore transparency entry: 868640025
- Sigstore integration time:
-
Permalink:
chuci-qin/quant1024@288fe4d9a62a212100b5e1b3bb90fa26de91ae02 -
Branch / Tag:
refs/heads/main - 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@288fe4d9a62a212100b5e1b3bb90fa26de91ae02 -
Trigger Event:
push
-
Statement type: