cyqnt-trd 0.1.2__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. cyqnt_trd/CHANGELOG_0.1.7.md +111 -0
  2. cyqnt_trd/__init__.py +1 -1
  3. cyqnt_trd/backtesting/factor_test.py +3 -2
  4. cyqnt_trd/get_data/__init__.py +16 -1
  5. cyqnt_trd/get_data/get_futures_data.py +3 -3
  6. cyqnt_trd/get_data/get_kline_with_factor.py +808 -0
  7. cyqnt_trd/get_data/get_web3_trending_data.py +389 -0
  8. cyqnt_trd/online_trading/__init__.py +1 -0
  9. cyqnt_trd/online_trading/realtime_price_tracker.py +142 -2
  10. cyqnt_trd/trading_signal/example_usage.py +123 -7
  11. cyqnt_trd/trading_signal/factor/__init__.py +23 -0
  12. cyqnt_trd/trading_signal/factor/adx_factor.py +116 -0
  13. cyqnt_trd/trading_signal/factor/ao_factor.py +66 -0
  14. cyqnt_trd/trading_signal/factor/bbp_factor.py +68 -0
  15. cyqnt_trd/trading_signal/factor/cci_factor.py +65 -0
  16. cyqnt_trd/trading_signal/factor/ema_factor.py +102 -0
  17. cyqnt_trd/trading_signal/factor/macd_factor.py +97 -0
  18. cyqnt_trd/trading_signal/factor/momentum_factor.py +44 -0
  19. cyqnt_trd/trading_signal/factor/stochastic_factor.py +76 -0
  20. cyqnt_trd/trading_signal/factor/stochastic_tsi_factor.py +129 -0
  21. cyqnt_trd/trading_signal/factor/uo_factor.py +92 -0
  22. cyqnt_trd/trading_signal/factor/williams_r_factor.py +60 -0
  23. cyqnt_trd/trading_signal/factor_details.json +107 -0
  24. cyqnt_trd/trading_signal/selected_alpha/alpha1.py +4 -2
  25. cyqnt_trd/trading_signal/selected_alpha/alpha15.py +4 -2
  26. cyqnt_trd/trading_signal/selected_alpha/generate_alphas.py +1 -0
  27. {cyqnt_trd-0.1.2.dist-info → cyqnt_trd-0.1.7.dist-info}/METADATA +16 -12
  28. {cyqnt_trd-0.1.2.dist-info → cyqnt_trd-0.1.7.dist-info}/RECORD +34 -23
  29. {cyqnt_trd-0.1.2.dist-info → cyqnt_trd-0.1.7.dist-info}/WHEEL +1 -1
  30. test/real_time_trade.py +467 -10
  31. test/test_now_factor.py +1082 -0
  32. test/track_k_line_continue.py +372 -0
  33. cyqnt_trd/test_script/get_symbols_by_volume.py +0 -227
  34. cyqnt_trd/test_script/test_alpha.py +0 -261
  35. cyqnt_trd/test_script/test_kline_data.py +0 -479
  36. test/test_example_usage.py +0 -381
  37. test/test_get_data.py +0 -310
  38. test/test_realtime_price_tracker.py +0 -546
  39. {cyqnt_trd-0.1.2.dist-info → cyqnt_trd-0.1.7.dist-info}/licenses/LICENSE +0 -0
  40. {cyqnt_trd-0.1.2.dist-info → cyqnt_trd-0.1.7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,111 @@
1
+ # cyqnt_trd 0.1.7 新版本特性
2
+
3
+ **cyqnt-trd** 0.1.7 是加密货币交易工具包当前版本,主要包含数据获取、交易信号与回测能力,并与 Binance SDK、链上数据接口集成。
4
+
5
+ ---
6
+
7
+ ## 一、数据获取 (get_data)
8
+
9
+ ### 1. 期货与现货 K 线
10
+
11
+ - **`get_and_save_futures_klines`**:从 Binance 获取 USDT 永续期货 K 线并保存。
12
+ - **`get_and_save_klines`** / **`get_and_save_klines_direct`**:现货 K 线获取与直接拉取。
13
+
14
+ ### 2. Web3 / 链上 K 线(0.1.7 增强)
15
+
16
+ - **`get_and_save_web3_klines`**:通过 **dquery.sintral.io** 的 u-kline API 获取链上 K 线。
17
+ - 支持 BSC 等链、按 **USD 计价**、多周期(如 1min, 5min, 15min, 1h, 4h, 1d)。
18
+ - 支持时间范围、合约地址等参数。
19
+
20
+ ### 3. 带因子的 K 线接口(0.1.7 核心特性)
21
+
22
+ 在原始 K 线基础上,直接产出「K 线 + 归一化因子」结果,便于与排序/信号模型对接:
23
+
24
+ | 接口 | 说明 |
25
+ |------|------|
26
+ | **`get_klines_with_factors`** | 输入原始 `klines_data`,输出整段带因子的 K 线列表(批量)。 |
27
+ | **`get_klines_with_factors_at_time`** | 指定某一时间点,返回该时刻的**单条**带因子数据。 |
28
+ | **`get_klines_with_factors_n_points`** | 以某时间为 end,向前取 **n 根** K 线的带因子数据。 |
29
+ | **`get_kline_with_factor_at_time`** | 单因子版本的「某时刻单点」数据。 |
30
+ | **`get_kline_with_factor_n_points`** | 单因子版本的「向前 n 点」数据。 |
31
+
32
+ - 因子计算支持 **lookback 窗口**、**最小样本要求**、**因子缓存**,与 `model-training/trading_report_signal_ranking_v1` 中逻辑对齐。
33
+ - 支持多种时间输入格式(datetime / 字符串 / 时间戳秒或毫秒)及 K 线周期(1m, 5m, 1h, 1d 等)。
34
+
35
+ ---
36
+
37
+ ## 二、交易信号 (trading_signal)
38
+
39
+ ### 1. 技术因子 (factor)
40
+
41
+ 统一约定:因子函数接收 `(data, index)`,输出数值;**正数看多、负数看空、0 中性**。
42
+
43
+ - **均线类**:`ma_factor`, `ma_cross_factor`, `ema_factor`, `ema_cross_factor`
44
+ - **动量/摆动**:`rsi_factor`, `momentum_factor`, `stochastic_k_factor`, `stochastic_tsi_fast_factor`, `williams_r_factor`, `uo_factor`, `cci_factor`
45
+ - **趋势/强度**:`adx_factor`, `ao_factor`, `macd_level_factor`
46
+ - **波动/通道**:`bbp_factor`
47
+
48
+ ### 2. 信号策略 (signal)
49
+
50
+ - **`ma_signal`** / **`ma_cross_signal`**:均线及均线交叉信号。
51
+ - **`factor_based_signal`**:基于单因子的买卖/持有信号。
52
+ - **`multi_factor_signal`** / **`normalized_factor_signal`**:多因子组合与归一化因子信号。
53
+
54
+ ### 3. Alpha 因子库 (selected_alpha)
55
+
56
+ - 提供 **alpha1 ~ alpha98** 等大量 Alpha 因子,便于选因子、组合与回测。
57
+ - 配套 `alpha_utils`、`test_alpha`、`example_usage` 等示例与测试。
58
+
59
+ ---
60
+
61
+ ## 三、回测 (backtesting)
62
+
63
+ - **`BacktestFramework`**:统一回测入口,可从本地数据路径加载 K 线并运行因子/策略测试。
64
+ - **`FactorTester`**:单因子胜率与表现测试。
65
+ - **`StrategyBacktester`**:完整策略回测(开平仓、收益统计等)。
66
+
67
+ ---
68
+
69
+ ## 四、其他模块
70
+
71
+ - **online_trading**:`realtime_price_tracker` 等实时价格跟踪。
72
+ - **utils**:如 `set_user` 等配置/工具。
73
+ - **test_script**:网络信息、订单、实时价格等测试脚本。
74
+
75
+ ---
76
+
77
+ ## 五、依赖与版本
78
+
79
+ - **Python**:>=3.8, <3.11
80
+ - **主要依赖**:pandas, numpy, matplotlib, scipy, requests
81
+ - **Binance 生态**:binance-sdk-spot, binance-sdk-derivatives-trading-usds-futures, binance-sdk-algo, binance-common
82
+
83
+ ---
84
+
85
+ ## 六、使用示例(0.1.7)
86
+
87
+ ```python
88
+ # 数据获取:期货 K 线
89
+ from cyqnt_trd.get_data import get_and_save_futures_klines
90
+ get_and_save_futures_klines("BTCUSDT", interval="1h", limit=100)
91
+
92
+ # 带因子的 K 线(单点 / n 点)
93
+ from cyqnt_trd.get_data import get_klines_with_factors_at_time, get_klines_with_factors_n_points
94
+ # 按需传入 klines_data、时间、因子列表等
95
+
96
+ # 链上 K 线
97
+ from cyqnt_trd.get_data import get_and_save_web3_klines
98
+ # 指定合约、链、周期等
99
+
100
+ # 信号与回测
101
+ from cyqnt_trd.trading_signal.factor import ma_factor, rsi_factor
102
+ from cyqnt_trd.trading_signal.signal import ma_signal, factor_based_signal
103
+ from cyqnt_trd.backtesting import BacktestFramework, FactorTester, StrategyBacktester
104
+
105
+ framework = BacktestFramework(data_path="data/BTCUSDT_1h.json")
106
+ result = framework.test_factor(ma_factor, short_window=5, long_window=20)
107
+ ```
108
+
109
+ ---
110
+
111
+ *文档根据当前代码库整理,适用于 **cyqnt-trd 0.1.7**。*
cyqnt_trd/__init__.py CHANGED
@@ -9,7 +9,7 @@ Cyqnt Trading Package
9
9
  - backtesting: 回测框架,支持因子测试和策略回测
10
10
  """
11
11
 
12
- __version__ = "0.1.0"
12
+ __version__ = "0.1.7"
13
13
 
14
14
  # 导入主要模块
15
15
  from . import get_data
@@ -103,8 +103,9 @@ class FactorTester:
103
103
  try:
104
104
  # 计算因子值:传递数据切片而不是整个data和index
105
105
  # 需要确定因子函数需要多少历史数据
106
- # 为了兼容性,传递足够的数据切片(假设最多需要50个周期)
107
- max_period = 50
106
+ # 为了兼容性,传递足够的数据切片
107
+ # 使用min_periods + 一些缓冲,或者至少50个周期
108
+ max_period = max(min_periods + 10, 50)
108
109
  start_idx = max(0, i - max_period)
109
110
  data_slice = self.data.iloc[start_idx:i+1].copy()
110
111
  factor_value = factor_func(data_slice)
@@ -1,15 +1,30 @@
1
1
  """
2
2
  数据获取模块
3
3
 
4
- 提供从 Binance 获取期货和现货K线数据的功能
4
+ 提供从 Binance 获取期货和现货K线数据的功能,以及 Web3/链上 u-kline K 线数据,
5
+ 以及带因子的 K 线获取(公用 get_klines_with_factors、单点 at_time、向前 n 点)。
5
6
  """
6
7
 
7
8
  from .get_futures_data import get_and_save_futures_klines
8
9
  from .get_trending_data import get_and_save_klines, get_and_save_klines_direct
10
+ from .get_web3_trending_data import get_and_save_web3_klines
11
+ from .get_kline_with_factor import (
12
+ get_klines_with_factors,
13
+ get_klines_with_factors_at_time,
14
+ get_klines_with_factors_n_points,
15
+ get_kline_with_factor_at_time,
16
+ get_kline_with_factor_n_points,
17
+ )
9
18
 
10
19
  __all__ = [
11
20
  'get_and_save_futures_klines',
12
21
  'get_and_save_klines',
13
22
  'get_and_save_klines_direct',
23
+ 'get_and_save_web3_klines',
24
+ 'get_klines_with_factors',
25
+ 'get_klines_with_factors_at_time',
26
+ 'get_klines_with_factors_n_points',
27
+ 'get_kline_with_factor_at_time',
28
+ 'get_kline_with_factor_n_points',
14
29
  ]
15
30
 
@@ -421,9 +421,9 @@ if __name__ == "__main__":
421
421
  for symbol in symbol_list:
422
422
  get_and_save_futures_klines(
423
423
  symbol=symbol,
424
- interval="1d",
425
- start_time="2024-01-01 00:00:00",
426
- end_time="2025-11-30 23:59:59",
424
+ interval="30m",
425
+ start_time="2025-11-30 00:00:00",
426
+ end_time="2026-01-05 23:59:59",
427
427
  limit=1000, # 每次请求的 limit,实际会分页获取所有数据
428
428
  output_dir=f"/Users/user/Desktop/repo/cyqnt_trd/tmp/data/{symbol}_futures"
429
429
  )