tradepose-client 0.1.0__py3-none-any.whl → 0.1.2__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.
Potentially problematic release.
This version of tradepose-client might be problematic. Click here for more details.
- tradepose_client/__init__.py +24 -4
- tradepose_client/builder/__init__.py +22 -0
- tradepose_client/builder/blueprint_builder.py +276 -0
- tradepose_client/builder/indicator_wrapper.py +126 -0
- tradepose_client/builder/strategy_builder.py +312 -0
- tradepose_client/builder/trading_context.py +140 -0
- tradepose_client/enums.py +176 -0
- tradepose_client/indicator_models.py +300 -0
- tradepose_client/models.py +266 -261
- {tradepose_client-0.1.0.dist-info → tradepose_client-0.1.2.dist-info}/METADATA +1 -1
- tradepose_client-0.1.2.dist-info/RECORD +22 -0
- tradepose_client-0.1.0.dist-info/RECORD +0 -15
- {tradepose_client-0.1.0.dist-info → tradepose_client-0.1.2.dist-info}/WHEEL +0 -0
- {tradepose_client-0.1.0.dist-info → tradepose_client-0.1.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Indicator Pydantic Models for Strong Typing
|
|
3
|
+
|
|
4
|
+
为每个指标类型创建强类型的 Pydantic 模型,提供:
|
|
5
|
+
- 编译时类型检查
|
|
6
|
+
- IDE 自动补全
|
|
7
|
+
- 参数验证
|
|
8
|
+
- 与 Rust backend 对齐的序列化
|
|
9
|
+
|
|
10
|
+
All models are aligned with Rust Indicator enum variants.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import Any, Dict, List, Literal, Optional
|
|
14
|
+
from pydantic import BaseModel, Field
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# ============================================================================
|
|
18
|
+
# 移动平均类指标(Moving Average Indicators)
|
|
19
|
+
# ============================================================================
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SMAIndicator(BaseModel):
|
|
23
|
+
"""Simple Moving Average (SMA) 指标
|
|
24
|
+
|
|
25
|
+
对应 Rust: Indicator::SMA { period, column }
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
period: 计算周期(必须 > 0)
|
|
29
|
+
column: 计算列名(默认 "close")
|
|
30
|
+
|
|
31
|
+
Example:
|
|
32
|
+
>>> sma = SMAIndicator(period=20)
|
|
33
|
+
>>> sma = SMAIndicator(period=50, column="high")
|
|
34
|
+
"""
|
|
35
|
+
type: Literal["SMA"] = "SMA"
|
|
36
|
+
period: int = Field(gt=0, le=500, description="Period must be > 0 and <= 500")
|
|
37
|
+
column: str = Field(
|
|
38
|
+
default="close",
|
|
39
|
+
pattern="^(open|high|low|close|volume)$",
|
|
40
|
+
description="OHLCV column name"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class EMAIndicator(BaseModel):
|
|
45
|
+
"""Exponential Moving Average (EMA) 指标
|
|
46
|
+
|
|
47
|
+
对应 Rust: Indicator::EMA { period, column }
|
|
48
|
+
"""
|
|
49
|
+
type: Literal["EMA"] = "EMA"
|
|
50
|
+
period: int = Field(gt=0, le=500)
|
|
51
|
+
column: str = Field(default="close", pattern="^(open|high|low|close|volume)$")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class SMMAIndicator(BaseModel):
|
|
55
|
+
"""Smoothed Moving Average (SMMA) 指标
|
|
56
|
+
|
|
57
|
+
对应 Rust: Indicator::SMMA { period, column }
|
|
58
|
+
"""
|
|
59
|
+
type: Literal["SMMA"] = "SMMA"
|
|
60
|
+
period: int = Field(gt=0, le=500)
|
|
61
|
+
column: str = Field(default="close", pattern="^(open|high|low|close|volume)$")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class WMAIndicator(BaseModel):
|
|
65
|
+
"""Weighted Moving Average (WMA) 指标
|
|
66
|
+
|
|
67
|
+
对应 Rust: Indicator::WMA { period, column }
|
|
68
|
+
"""
|
|
69
|
+
type: Literal["WMA"] = "WMA"
|
|
70
|
+
period: int = Field(gt=0, le=500)
|
|
71
|
+
column: str = Field(default="close", pattern="^(open|high|low|close|volume)$")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# ============================================================================
|
|
75
|
+
# 波动率类指标(Volatility Indicators)
|
|
76
|
+
# ============================================================================
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class ATRIndicator(BaseModel):
|
|
80
|
+
"""Average True Range (ATR) 指标
|
|
81
|
+
|
|
82
|
+
对应 Rust: Indicator::ATR { period }
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
单一数值字段(不是 struct)
|
|
86
|
+
|
|
87
|
+
Example:
|
|
88
|
+
>>> atr = ATRIndicator(period=14)
|
|
89
|
+
>>> atr = ATRIndicator(period=21)
|
|
90
|
+
"""
|
|
91
|
+
type: Literal["ATR"] = "ATR"
|
|
92
|
+
period: int = Field(gt=0, le=200, description="Period must be > 0 and <= 200")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class ATRQuantileIndicator(BaseModel):
|
|
96
|
+
"""ATR Rolling Quantile 指标
|
|
97
|
+
|
|
98
|
+
对应 Rust: Indicator::AtrQuantile { atr_column, window, quantile }
|
|
99
|
+
|
|
100
|
+
计算 ATR 的滚动分位数,用于动态止损等场景。
|
|
101
|
+
|
|
102
|
+
注意:这是依赖指标,必须先定义 ATR 指标。
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
atr_column: 引用的 ATR 列名(如 "ATR|14")
|
|
106
|
+
window: 滚动窗口大小
|
|
107
|
+
quantile: 分位数值 (0, 1),0.5 表示中位数
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
单一数值字段(不是 struct)
|
|
111
|
+
|
|
112
|
+
Example:
|
|
113
|
+
>>> atr_q = ATRQuantileIndicator(
|
|
114
|
+
... atr_column="ATR|21",
|
|
115
|
+
... window=40,
|
|
116
|
+
... quantile=0.75 # 75th percentile
|
|
117
|
+
... )
|
|
118
|
+
"""
|
|
119
|
+
type: Literal["AtrQuantile"] = "AtrQuantile"
|
|
120
|
+
atr_column: str = Field(min_length=1, description="Reference to existing ATR column")
|
|
121
|
+
window: int = Field(gt=0, le=500, description="Rolling window size")
|
|
122
|
+
quantile: float = Field(gt=0, lt=1, description="Quantile value in (0, 1)")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# ============================================================================
|
|
126
|
+
# 趋势类指标(Trend Indicators)
|
|
127
|
+
# ============================================================================
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class SuperTrendIndicator(BaseModel):
|
|
131
|
+
"""SuperTrend 指标
|
|
132
|
+
|
|
133
|
+
对应 Rust: Indicator::SuperTrend { multiplier, volatility_column, high, low, close }
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
multiplier: ATR 倍数(通常 2.0-3.0)
|
|
137
|
+
volatility_column: 引用的波动率列名(如 "ATR|14",注意是列名不是 struct 字段)
|
|
138
|
+
high: 高价列名(默认 "high")
|
|
139
|
+
low: 低价列名(默认 "low")
|
|
140
|
+
close: 收盘价列名(默认 "close")
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
Struct { direction: i32, value: f64, trend: f64, ...}
|
|
144
|
+
|
|
145
|
+
Example:
|
|
146
|
+
>>> st = SuperTrendIndicator(
|
|
147
|
+
... multiplier=3.0,
|
|
148
|
+
... volatility_column="ATR|21"
|
|
149
|
+
... )
|
|
150
|
+
"""
|
|
151
|
+
type: Literal["SuperTrend"] = "SuperTrend"
|
|
152
|
+
multiplier: float = Field(gt=0, le=10, description="ATR multiplier (typically 2.0-3.0)")
|
|
153
|
+
volatility_column: str = Field(
|
|
154
|
+
min_length=1,
|
|
155
|
+
description="Reference to volatility column (e.g., 'ATR|14')"
|
|
156
|
+
)
|
|
157
|
+
high: str = Field(default="high", pattern="^(high|open|low|close)$")
|
|
158
|
+
low: str = Field(default="low", pattern="^(high|open|low|close)$")
|
|
159
|
+
close: str = Field(default="close", pattern="^(high|open|low|close)$")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class MACDIndicator(BaseModel):
|
|
163
|
+
"""Moving Average Convergence Divergence (MACD) 指标
|
|
164
|
+
|
|
165
|
+
对应 Rust: Indicator::MACD { fast_period, slow_period, signal_period, column, fields }
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
Struct { macd: f64, signal: f64, histogram: f64 }
|
|
169
|
+
"""
|
|
170
|
+
type: Literal["MACD"] = "MACD"
|
|
171
|
+
fast_period: int = Field(default=12, gt=0, le=100)
|
|
172
|
+
slow_period: int = Field(default=26, gt=0, le=200)
|
|
173
|
+
signal_period: int = Field(default=9, gt=0, le=50)
|
|
174
|
+
column: str = Field(default="close", pattern="^(open|high|low|close|volume)$")
|
|
175
|
+
fields: Optional[List[str]] = Field(
|
|
176
|
+
default=None,
|
|
177
|
+
description="Select specific fields: ['macd', 'signal', 'histogram']"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class ADXIndicator(BaseModel):
|
|
182
|
+
"""Average Directional Index (ADX) 指标
|
|
183
|
+
|
|
184
|
+
对应 Rust: Indicator::ADX { period, fields }
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
Struct { adx: f64, plus_di: f64, minus_di: f64 }
|
|
188
|
+
"""
|
|
189
|
+
type: Literal["ADX"] = "ADX"
|
|
190
|
+
period: int = Field(default=14, gt=0, le=100)
|
|
191
|
+
fields: Optional[List[str]] = Field(
|
|
192
|
+
default=None,
|
|
193
|
+
description="Select specific fields: ['adx', 'plus_di', 'minus_di']"
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
# ============================================================================
|
|
198
|
+
# 动量类指标(Momentum Indicators)
|
|
199
|
+
# ============================================================================
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
class RSIIndicator(BaseModel):
|
|
203
|
+
"""Relative Strength Index (RSI) 指标
|
|
204
|
+
|
|
205
|
+
对应 Rust: Indicator::RSI { period, column }
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
单一数值字段(0-100 范围)
|
|
209
|
+
"""
|
|
210
|
+
type: Literal["RSI"] = "RSI"
|
|
211
|
+
period: int = Field(default=14, gt=0, le=100)
|
|
212
|
+
column: str = Field(default="close", pattern="^(open|high|low|close|volume)$")
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class CCIIndicator(BaseModel):
|
|
216
|
+
"""Commodity Channel Index (CCI) 指标
|
|
217
|
+
|
|
218
|
+
对应 Rust: Indicator::CCI { period }
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
单一数值字段
|
|
222
|
+
"""
|
|
223
|
+
type: Literal["CCI"] = "CCI"
|
|
224
|
+
period: int = Field(default=20, gt=0, le=100)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
class StochasticIndicator(BaseModel):
|
|
228
|
+
"""Stochastic Oscillator 指标
|
|
229
|
+
|
|
230
|
+
对应 Rust: Indicator::Stochastic { k_period, d_period, fields }
|
|
231
|
+
|
|
232
|
+
Returns:
|
|
233
|
+
Struct { k: f64, d: f64 }
|
|
234
|
+
"""
|
|
235
|
+
type: Literal["Stochastic"] = "Stochastic"
|
|
236
|
+
k_period: int = Field(default=14, gt=0, le=100, description="%K period")
|
|
237
|
+
d_period: int = Field(default=3, gt=0, le=50, description="%D period (smoothing)")
|
|
238
|
+
fields: Optional[List[str]] = Field(
|
|
239
|
+
default=None,
|
|
240
|
+
description="Select specific fields: ['k', 'd']"
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
# ============================================================================
|
|
245
|
+
# 其他指标(Other Indicators)
|
|
246
|
+
# ============================================================================
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
class BollingerBandsIndicator(BaseModel):
|
|
250
|
+
"""Bollinger Bands 指标
|
|
251
|
+
|
|
252
|
+
对应 Rust: Indicator::BollingerBands { period, num_std, column, fields }
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
Struct { upper: f64, middle: f64, lower: f64, bandwidth: f64 }
|
|
256
|
+
"""
|
|
257
|
+
type: Literal["BollingerBands"] = "BollingerBands"
|
|
258
|
+
period: int = Field(default=20, gt=0, le=200)
|
|
259
|
+
num_std: float = Field(default=2.0, gt=0, le=5.0, description="Standard deviation multiplier")
|
|
260
|
+
column: str = Field(default="close", pattern="^(open|high|low|close|volume)$")
|
|
261
|
+
fields: Optional[List[str]] = Field(
|
|
262
|
+
default=None,
|
|
263
|
+
description="Select specific fields: ['upper', 'middle', 'lower', 'bandwidth']"
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class MarketProfileIndicator(BaseModel):
|
|
268
|
+
"""Market Profile 指标
|
|
269
|
+
|
|
270
|
+
对应 Rust: Indicator::MarketProfile { anchor_config, tick_size, value_area_pct, fields }
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
Struct { poc: f64, vah: f64, val: f64, value_area: List[f64], total_tpo: i32, ...}
|
|
274
|
+
"""
|
|
275
|
+
type: Literal["MarketProfile"] = "MarketProfile"
|
|
276
|
+
anchor_config: Dict[str, Any] = Field(
|
|
277
|
+
...,
|
|
278
|
+
description="Anchor configuration (use create_daily_anchor or create_weekly_anchor)"
|
|
279
|
+
)
|
|
280
|
+
tick_size: float = Field(gt=0, description="Tick size for price levels")
|
|
281
|
+
value_area_pct: float = Field(default=0.7, gt=0, lt=1, description="Value area percentage")
|
|
282
|
+
fields: Optional[List[str]] = Field(
|
|
283
|
+
default=None,
|
|
284
|
+
description="Select specific fields: ['poc', 'vah', 'val', 'value_area', 'total_tpo']"
|
|
285
|
+
)
|
|
286
|
+
shape_config: Optional[Dict[str, Any]] = Field(
|
|
287
|
+
default=None,
|
|
288
|
+
description="Profile shape recognition config (advanced feature)"
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class RawOhlcvIndicator(BaseModel):
|
|
293
|
+
"""Raw OHLCV Column 指标
|
|
294
|
+
|
|
295
|
+
对应 Rust: Indicator::RawOhlcv { column }
|
|
296
|
+
|
|
297
|
+
直接引用 OHLCV 列,用于需要原始数据的场景。
|
|
298
|
+
"""
|
|
299
|
+
type: Literal["RawOhlcv"] = "RawOhlcv"
|
|
300
|
+
column: str = Field(pattern="^(open|high|low|close|volume)$")
|