tradepose-client 0.1.0__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.

@@ -0,0 +1,186 @@
1
+ import polars as pl
2
+
3
+ # Enhanced OHLCV Schema
4
+ enhanced_ohlcv_schema = {
5
+ "idx": pl.Int64,
6
+ "ts": pl.Datetime("ms"),
7
+ "open": pl.Float64,
8
+ "high": pl.Float64,
9
+ "low": pl.Float64,
10
+ "close": pl.Float64,
11
+ "volume": pl.Float64,
12
+ "gap_type": pl.Int64,
13
+ "gap_points": pl.Float64,
14
+ "gap_range_min": pl.Float64,
15
+ "gap_range_max": pl.Float64,
16
+ "entry_signal": pl.Boolean,
17
+ "exit_signal": pl.Boolean,
18
+ "cleaned_entry_signal": pl.Boolean,
19
+ "cleaned_exit_signal": pl.Boolean,
20
+ "base_entry_price": pl.Float64,
21
+ "base_entry_strategy": pl.Int64,
22
+ "base_exit_price": pl.Float64,
23
+ "base_exit_strategy": pl.Int64,
24
+ "base_position_id": pl.Int64,
25
+ # 巢狀結構統一使用 Struct
26
+ "base_trading_context": pl.Struct(
27
+ [
28
+ pl.Field("bars_in_position", pl.Int64),
29
+ pl.Field("highest_since_entry", pl.Float64),
30
+ pl.Field("lowest_since_entry", pl.Float64),
31
+ pl.Field("position_entry_price", pl.Float64),
32
+ ]
33
+ ),
34
+ # 來自 trigger 自動產生
35
+ # "base_entry": pl.Struct(
36
+ # [
37
+ # pl.Field("cond", pl.Boolean),
38
+ # pl.Field("price", pl.Float64),
39
+ # pl.Field("strategy", pl.Int64),
40
+ # pl.Field("priority", pl.Int64),
41
+ # ]
42
+ # ),
43
+ "advanced_favorable_entry_hypo_price": pl.Float64,
44
+ "advanced_adverse_entry_hypo_price": pl.Float64,
45
+ "advanced_neutral_entry_hypo_price": pl.Float64,
46
+ "advanced_favorable_entry_strategy": pl.Int64,
47
+ "advanced_adverse_entry_strategy": pl.Int64,
48
+ "advanced_neutral_entry_strategy": pl.Int64,
49
+ "advanced_entry_price": pl.Float64,
50
+ "advanced_entry_strategy": pl.Int64,
51
+ "is_entry_gap_filled": pl.Boolean,
52
+ "advanced_cleaned_entry_signal": pl.Boolean,
53
+ "advanced_entry_position_id": pl.Int64,
54
+ "advanced_entry_trading_context": pl.Struct(
55
+ [
56
+ pl.Field("bars_since_advanced_entry", pl.Int64),
57
+ pl.Field("highest_since_advanced_entry", pl.Float64),
58
+ pl.Field("lowest_since_advanced_entry", pl.Float64),
59
+ pl.Field("position_entry_price", pl.Float64),
60
+ ]
61
+ ),
62
+ # 來自 trigger 自動產生
63
+ # "base_exit": pl.Struct(
64
+ # [
65
+ # pl.Field("cond", pl.Boolean),
66
+ # pl.Field("price", pl.Float64),
67
+ # pl.Field("strategy", pl.Int64),
68
+ # pl.Field("priority", pl.Int64),
69
+ # ]
70
+ # ),
71
+ "advanced_favorable_exit_hypo_price": pl.Float64,
72
+ "advanced_adverse_exit_hypo_price": pl.Float64,
73
+ "advanced_neutral_exit_hypo_price": pl.Float64,
74
+ "advanced_favorable_exit_strategy": pl.Int64,
75
+ "advanced_adverse_exit_strategy": pl.Int64,
76
+ "advanced_neutral_exit_strategy": pl.Int64,
77
+ "advanced_exit_price": pl.Float64,
78
+ "advanced_exit_strategy": pl.Int64,
79
+ "is_exit_gap_filled": pl.Boolean,
80
+ "advanced_cleaned_exit_signal": pl.Boolean,
81
+ "advanced_exit_position_id": pl.Int64,
82
+ "advanced_exit_trading_context": pl.Struct(
83
+ [
84
+ pl.Field("bars_since_advanced_entry", pl.Int64),
85
+ pl.Field("highest_since_advanced_entry", pl.Float64),
86
+ pl.Field("lowest_since_advanced_entry", pl.Float64),
87
+ pl.Field("position_entry_price", pl.Float64),
88
+ ]
89
+ ),
90
+ "is_entry_valid": pl.Boolean,
91
+ "entry_rejection_reason": pl.Utf8,
92
+ "validated_entry_signal": pl.Boolean,
93
+ "validated_exit_signal": pl.Boolean,
94
+ "final_position_id": pl.Int64,
95
+ "final_trading_context": pl.Struct(
96
+ [
97
+ pl.Field("bars_in_position", pl.Int64),
98
+ pl.Field("highest_since_entry", pl.Float64),
99
+ pl.Field("lowest_since_entry", pl.Float64),
100
+ pl.Field("position_entry_price", pl.Float64),
101
+ ]
102
+ ),
103
+ "strategy_name": pl.Utf8,
104
+ "blueprint_name": pl.Utf8,
105
+ }
106
+
107
+ # Trades Schema (from backtest-results or latest-trades export)
108
+ # Complete schema matching API response with MAE/MFE fields
109
+ trades_schema = {
110
+ # Position identifiers
111
+ "final_position_id": pl.UInt32,
112
+ "position_id": pl.UInt32,
113
+ "direction": pl.Int32, # -1 for Short, 1 for Long
114
+ "status": pl.Boolean, # false = closed, true = open
115
+
116
+ # Entry details
117
+ "entry_idx": pl.UInt32,
118
+ "entry_time": pl.Datetime("ms"),
119
+ "entry_price": pl.Float64,
120
+ "entry_reason": pl.UInt32,
121
+ "favorable_entry_hypo_price": pl.Float64,
122
+ "adverse_entry_hypo_price": pl.Float64,
123
+ "favorable_entry_strategy": pl.UInt32,
124
+ "adverse_entry_strategy": pl.UInt32,
125
+
126
+ # Exit details
127
+ "exit_idx": pl.UInt32,
128
+ "exit_time": pl.Datetime("ms"),
129
+ "exit_price": pl.Float64,
130
+ "exit_reason": pl.UInt32,
131
+ "favorable_exit_hypo_price": pl.Float64,
132
+ "adverse_exit_hypo_price": pl.Float64,
133
+ "favorable_exit_strategy": pl.UInt32,
134
+ "adverse_exit_strategy": pl.UInt32,
135
+
136
+ # Holding period
137
+ "holding_seconds": pl.Int64,
138
+ "holding_bars": pl.UInt32,
139
+
140
+ # MAE/MFE metrics (Maximum Adverse/Favorable Excursion)
141
+ "g_mfe": pl.Float64, # Global Maximum Favorable Excursion
142
+ "mae": pl.Float64, # Maximum Adverse Excursion
143
+ "mfe": pl.Float64, # Maximum Favorable Excursion
144
+ "mae_lv1": pl.Float64, # MAE Level 1
145
+ "mhl": pl.Float64, # Maximum High/Low
146
+
147
+ # MAE/MFE indices (bar index where each occurred)
148
+ "g_mfe_idx": pl.UInt32,
149
+ "mae_idx": pl.UInt32,
150
+ "mfe_idx": pl.UInt32,
151
+ "mae_lv1_idx": pl.UInt32,
152
+ "mhl_idx": pl.UInt32,
153
+
154
+ # Volatility at each key point (typically ATR)
155
+ "entry_volatility": pl.Float64,
156
+ "exit_volatility": pl.Float64,
157
+ "g_mfe_volatility": pl.Float64,
158
+ "mae_volatility": pl.Float64,
159
+ "mfe_volatility": pl.Float64,
160
+ "mae_lv1_volatility": pl.Float64,
161
+ "mhl_volatility": pl.Float64,
162
+
163
+ # P&L metrics
164
+ "pnl": pl.Float64, # Absolute profit/loss
165
+ "pnl_pct": pl.Float64, # Percentage profit/loss
166
+
167
+ # Metadata
168
+ "strategy_name": pl.Utf8,
169
+ "blueprint_name": pl.Utf8,
170
+ }
171
+
172
+ # Performance Schema (from backtest-results export)
173
+ performance_schema = {
174
+ "strategy_name": pl.Utf8,
175
+ "total_trades": pl.Int64,
176
+ "win_trades": pl.Int64,
177
+ "loss_trades": pl.Int64,
178
+ "win_rate": pl.Float64,
179
+ "total_pnl": pl.Float64,
180
+ "avg_pnl": pl.Float64,
181
+ "max_drawdown": pl.Float64,
182
+ "sharpe_ratio": pl.Float64,
183
+ "sortino_ratio": pl.Float64,
184
+ "max_consecutive_wins": pl.Int64,
185
+ "max_consecutive_losses": pl.Int64,
186
+ }