Repository navigation
v0.1.1 - Smart Sync Mode
🎉 New Features
Smart Sync Mode
Intelligently switch between local calculations and API queries using the sync_threshold parameter, providing the best balance of performance and accuracy.
Usage:
# Enable smart sync with 30-second threshold
sync = PositionSync(api, sync_threshold=30)
# How it works:
# - Within 30s after deal: Use local calculations (fast, responsive)
# - After 30s: Switch to API query and verify in background
# - Automatically detect and correct any inconsistenciesBenefits:
- 🚀 Fast Response: Local calculations during active trading
- ✅ Auto-Verification: Periodic API checks ensure accuracy
- 🔄 Auto-Correction: Detect and fix position inconsistencies
- 📊 Best of Both Worlds: Combines speed of local tracking with reliability of API
🔧 Improvements
- Model Separation: Public API uses
StockPosition, internal calculations useStockPositionInner - Type Safety: Use
TypedDictinstead ofDict[str, Any]for better type checking - Enhanced Error Handling: All API calls have error handling and fallback strategies
- Background Sync: Use
ThreadPoolExecutorfor non-blocking background position verification
🧪 Test Coverage
- Test Count: Increased from 50 to 58 tests (+8 tests)
- Coverage: Improved from 82.70% to 88.93% (+6.23%)
- New Tests:
- Smart sync scenario tests (7 tests)
- Error handling and edge case tests (8 tests)
📚 Documentation
- ✅ Updated README.md with smart sync features
- ✅ Added README.zh-TW.md Traditional Chinese documentation
- ✅ Updated example_usage.py with smart sync examples
📦 Installation
pip install sj-sync==0.1.1Or with uv:
uv add sj-sync==0.1.1🔗 Links
🎉 新增功能
智能同步模式
透過 sync_threshold 參數智能切換本地計算與 API 查詢,提供最佳的效能與準確性平衡。
使用方式:
# 啟用智能同步,設定 30 秒門檻值
sync = PositionSync(api, sync_threshold=30)
# 運作方式:
# - 成交後 30 秒內:使用本地計算(快速、即時)
# - 30 秒後:切換到 API 查詢並在背景驗證
# - 自動偵測並修正任何不一致優勢:
- 🚀 快速回應:活躍交易期間使用本地計算
- ✅ 自動驗證:定期 API 檢查確保準確性
- 🔄 自動修正:偵測並修復部位不一致
- 📊 兩全其美:結合本地追蹤的速度與 API 的可靠性
🔧 改進
- 模型分離:公開 API 使用
StockPosition,內部計算使用StockPositionInner - 型別安全:使用
TypedDict替代Dict[str, Any],提升型別檢查 - 錯誤處理增強:所有 API 呼叫都有錯誤處理和降級策略
- 背景同步:使用
ThreadPoolExecutor進行非阻塞的背景部位驗證
🧪 測試覆蓋率
- 測試數量:從 50 個增加到 58 個(+8 個測試)
- 覆蓋率:從 82.70% 提升到 88.93%(+6.23%)
- 新增測試:
- 智能同步各種場景測試(7 個)
- 錯誤處理和邊界情況測試(8 個)
📚 文件
- ✅ 更新 README.md 包含智能同步功能說明
- ✅ 新增 README.zh-TW.md 繁體中文文件
- ✅ 更新 example_usage.py 包含智能同步範例
📦 安裝
pip install sj-sync==0.1.1或使用 uv:
uv add sj-sync==0.1.1🔗 相關連結
Full Changelog: v0.1.0...v0.1.1