opencode-pyneruntime 6.6.4__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 (261) hide show
  1. opencode_pyneruntime-6.6.4.dist-info/METADATA +281 -0
  2. opencode_pyneruntime-6.6.4.dist-info/RECORD +261 -0
  3. opencode_pyneruntime-6.6.4.dist-info/WHEEL +5 -0
  4. opencode_pyneruntime-6.6.4.dist-info/entry_points.txt +6 -0
  5. opencode_pyneruntime-6.6.4.dist-info/licenses/LICENSE +201 -0
  6. opencode_pyneruntime-6.6.4.dist-info/licenses/NOTICE +21 -0
  7. opencode_pyneruntime-6.6.4.dist-info/top_level.txt +1 -0
  8. pynecore/__init__.py +6 -0
  9. pynecore/cli/__init__.py +2 -0
  10. pynecore/cli/app.py +238 -0
  11. pynecore/cli/commands/__init__.py +343 -0
  12. pynecore/cli/commands/benchmark.py +186 -0
  13. pynecore/cli/commands/compile.py +198 -0
  14. pynecore/cli/commands/data.py +857 -0
  15. pynecore/cli/commands/debug.py +63 -0
  16. pynecore/cli/commands/optimize.py +956 -0
  17. pynecore/cli/commands/plugin.py +242 -0
  18. pynecore/cli/commands/run.py +2006 -0
  19. pynecore/cli/pluggable.py +132 -0
  20. pynecore/cli/utils/__init__.py +0 -0
  21. pynecore/cli/utils/api_error_handler.py +168 -0
  22. pynecore/cli/utils/broker_picker.py +330 -0
  23. pynecore/cli/utils/error_hook.py +28 -0
  24. pynecore/cli/utils/keyreader.py +178 -0
  25. pynecore/cli/utils/provider_picker.py +19 -0
  26. pynecore/cli/utils/symbol_browser.py +1149 -0
  27. pynecore/core/__init__.py +0 -0
  28. pynecore/core/aggregator.py +257 -0
  29. pynecore/core/bar_magnifier.py +168 -0
  30. pynecore/core/broker/__init__.py +64 -0
  31. pynecore/core/broker/defaults.py +113 -0
  32. pynecore/core/broker/disappearance.py +927 -0
  33. pynecore/core/broker/emulator.py +345 -0
  34. pynecore/core/broker/exceptions.py +346 -0
  35. pynecore/core/broker/idempotency.py +401 -0
  36. pynecore/core/broker/intent_builder.py +334 -0
  37. pynecore/core/broker/journal.py +1785 -0
  38. pynecore/core/broker/models.py +1600 -0
  39. pynecore/core/broker/native_failsafe_manager.py +1436 -0
  40. pynecore/core/broker/one_way_emulator.py +1128 -0
  41. pynecore/core/broker/position.py +787 -0
  42. pynecore/core/broker/run_identity.py +126 -0
  43. pynecore/core/broker/software_entry_stop_engine.py +351 -0
  44. pynecore/core/broker/software_partial_bracket_engine.py +1379 -0
  45. pynecore/core/broker/spot_inventory.py +1327 -0
  46. pynecore/core/broker/storage.py +2655 -0
  47. pynecore/core/broker/store_helpers.py +2161 -0
  48. pynecore/core/broker/sync_engine.py +16070 -0
  49. pynecore/core/broker/validation.py +382 -0
  50. pynecore/core/class_property.py +7 -0
  51. pynecore/core/config.py +392 -0
  52. pynecore/core/csv_file.py +547 -0
  53. pynecore/core/currency.py +262 -0
  54. pynecore/core/data_converter.py +1002 -0
  55. pynecore/core/datetime.py +296 -0
  56. pynecore/core/download_info.py +71 -0
  57. pynecore/core/download_runner.py +274 -0
  58. pynecore/core/htf_aggregator.py +181 -0
  59. pynecore/core/import_hook.py +358 -0
  60. pynecore/core/instance_state.py +494 -0
  61. pynecore/core/live_ltf_collector.py +442 -0
  62. pynecore/core/live_ltf_window.py +189 -0
  63. pynecore/core/live_runner.py +1347 -0
  64. pynecore/core/module_property.py +26 -0
  65. pynecore/core/ohlcv_file.py +1888 -0
  66. pynecore/core/overload.py +371 -0
  67. pynecore/core/pine_cast.py +113 -0
  68. pynecore/core/pine_export.py +95 -0
  69. pynecore/core/pine_method.py +244 -0
  70. pynecore/core/pine_range.py +86 -0
  71. pynecore/core/pine_udt.py +69 -0
  72. pynecore/core/plugin/__init__.py +394 -0
  73. pynecore/core/plugin/broker.py +781 -0
  74. pynecore/core/plugin/cli.py +96 -0
  75. pynecore/core/plugin/live_provider.py +208 -0
  76. pynecore/core/plugin/provider.py +331 -0
  77. pynecore/core/provider_string.py +148 -0
  78. pynecore/core/random.py +40 -0
  79. pynecore/core/resampler.py +686 -0
  80. pynecore/core/safe_convert.py +64 -0
  81. pynecore/core/script.py +1011 -0
  82. pynecore/core/script_runner.py +3202 -0
  83. pynecore/core/security.py +1749 -0
  84. pynecore/core/security_process.py +1253 -0
  85. pynecore/core/security_shm.py +456 -0
  86. pynecore/core/series.py +417 -0
  87. pynecore/core/strategy_stats.py +669 -0
  88. pynecore/core/symbol_map.py +134 -0
  89. pynecore/core/syminfo.py +505 -0
  90. pynecore/core/viz.py +591 -0
  91. pynecore/lib/__init__.py +1771 -0
  92. pynecore/lib/_fixnan.py +32 -0
  93. pynecore/lib/_math_stateful.py +202 -0
  94. pynecore/lib/_timeframe_change.py +101 -0
  95. pynecore/lib/adjustment.py +6 -0
  96. pynecore/lib/alert.py +39 -0
  97. pynecore/lib/alert.pyi +14 -0
  98. pynecore/lib/array.py +1051 -0
  99. pynecore/lib/barmerge.py +60 -0
  100. pynecore/lib/barstate.py +30 -0
  101. pynecore/lib/box.py +415 -0
  102. pynecore/lib/chart.py +128 -0
  103. pynecore/lib/color.py +152 -0
  104. pynecore/lib/color.pyi +50 -0
  105. pynecore/lib/currency.py +62 -0
  106. pynecore/lib/dayofweek.py +36 -0
  107. pynecore/lib/dayofweek.pyi +18 -0
  108. pynecore/lib/display.py +8 -0
  109. pynecore/lib/dividends.py +9 -0
  110. pynecore/lib/earnings.py +11 -0
  111. pynecore/lib/extend.py +6 -0
  112. pynecore/lib/font.py +5 -0
  113. pynecore/lib/footprint.py +79 -0
  114. pynecore/lib/format.py +11 -0
  115. pynecore/lib/hline.py +67 -0
  116. pynecore/lib/hline.pyi +24 -0
  117. pynecore/lib/label.py +409 -0
  118. pynecore/lib/line.py +433 -0
  119. pynecore/lib/linefill.py +93 -0
  120. pynecore/lib/location.py +11 -0
  121. pynecore/lib/log.py +362 -0
  122. pynecore/lib/map.py +150 -0
  123. pynecore/lib/math.py +385 -0
  124. pynecore/lib/matrix.py +708 -0
  125. pynecore/lib/order.py +8 -0
  126. pynecore/lib/pivotpointtype.py +8 -0
  127. pynecore/lib/plot.py +95 -0
  128. pynecore/lib/plot.pyi +33 -0
  129. pynecore/lib/polyline.py +91 -0
  130. pynecore/lib/position.py +15 -0
  131. pynecore/lib/request.py +281 -0
  132. pynecore/lib/runtime.py +5 -0
  133. pynecore/lib/scale.py +9 -0
  134. pynecore/lib/session.py +267 -0
  135. pynecore/lib/session.pyi +12 -0
  136. pynecore/lib/shape.py +18 -0
  137. pynecore/lib/size.py +12 -0
  138. pynecore/lib/splits.py +4 -0
  139. pynecore/lib/strategy/__init__.py +4778 -0
  140. pynecore/lib/strategy/closedtrades.py +347 -0
  141. pynecore/lib/strategy/closedtrades.pyi +53 -0
  142. pynecore/lib/strategy/commission.py +9 -0
  143. pynecore/lib/strategy/direction.py +9 -0
  144. pynecore/lib/strategy/oca.py +13 -0
  145. pynecore/lib/strategy/opentrades.py +281 -0
  146. pynecore/lib/strategy/opentrades.pyi +49 -0
  147. pynecore/lib/strategy/risk.py +109 -0
  148. pynecore/lib/string.py +649 -0
  149. pynecore/lib/syminfo.py +84 -0
  150. pynecore/lib/ta.py +2230 -0
  151. pynecore/lib/table.py +290 -0
  152. pynecore/lib/text.py +17 -0
  153. pynecore/lib/ticker.py +207 -0
  154. pynecore/lib/timeframe.py +293 -0
  155. pynecore/lib/volume_row.py +67 -0
  156. pynecore/lib/xloc.py +4 -0
  157. pynecore/lib/yloc.py +5 -0
  158. pynecore/providers/__init__.py +0 -0
  159. pynecore/providers/ccxt.py +664 -0
  160. pynecore/providers/replay.py +187 -0
  161. pynecore/pynesys/__init__.py +0 -0
  162. pynecore/pynesys/api.py +498 -0
  163. pynecore/pynesys/compiler.py +112 -0
  164. pynecore/standalone.py +99 -0
  165. pynecore/testing/__init__.py +1 -0
  166. pynecore/testing/broker_lab/__init__.py +41 -0
  167. pynecore/testing/broker_lab/__main__.py +5 -0
  168. pynecore/testing/broker_lab/cli.py +87 -0
  169. pynecore/testing/broker_lab/generate.py +47 -0
  170. pynecore/testing/broker_lab/model.py +84 -0
  171. pynecore/testing/broker_lab/reference.py +645 -0
  172. pynecore/testing/broker_lab/runner.py +372 -0
  173. pynecore/testing/broker_lab/scheduler.py +50 -0
  174. pynecore/testing/broker_lab/subprocess.py +73 -0
  175. pynecore/transformers/__init__.py +0 -0
  176. pynecore/transformers/builtin_shadow.py +136 -0
  177. pynecore/transformers/closure_arguments_transformer.py +428 -0
  178. pynecore/transformers/display_rewrite.py +140 -0
  179. pynecore/transformers/dynamic_default.py +147 -0
  180. pynecore/transformers/function_isolation.py +757 -0
  181. pynecore/transformers/import_lifter.py +61 -0
  182. pynecore/transformers/import_normalizer.py +328 -0
  183. pynecore/transformers/inline_series_hoist.py +178 -0
  184. pynecore/transformers/input_transformer.py +175 -0
  185. pynecore/transformers/lib_series.py +201 -0
  186. pynecore/transformers/locations.py +70 -0
  187. pynecore/transformers/module_properties.json +3387 -0
  188. pynecore/transformers/module_property.py +221 -0
  189. pynecore/transformers/ne_guard.py +70 -0
  190. pynecore/transformers/persistent.py +320 -0
  191. pynecore/transformers/persistent_series.py +76 -0
  192. pynecore/transformers/safe_convert_transformer.py +97 -0
  193. pynecore/transformers/safe_division_transformer.py +95 -0
  194. pynecore/transformers/script_requirements.py +308 -0
  195. pynecore/transformers/security.py +752 -0
  196. pynecore/transformers/security_instantiation.py +274 -0
  197. pynecore/transformers/series.py +275 -0
  198. pynecore/transformers/slot_layout.py +381 -0
  199. pynecore/transformers/type_checking_stripper.py +25 -0
  200. pynecore/transformers/unused_series_detector.py +267 -0
  201. pynecore/types/__init__.py +21 -0
  202. pynecore/types/alert.py +5 -0
  203. pynecore/types/barmerge.py +5 -0
  204. pynecore/types/base.py +39 -0
  205. pynecore/types/box.py +37 -0
  206. pynecore/types/chart.py +17 -0
  207. pynecore/types/color.py +107 -0
  208. pynecore/types/currency.py +5 -0
  209. pynecore/types/datetime.py +6 -0
  210. pynecore/types/display.py +5 -0
  211. pynecore/types/dividends.py +5 -0
  212. pynecore/types/earnings.py +5 -0
  213. pynecore/types/extend.py +5 -0
  214. pynecore/types/font.py +5 -0
  215. pynecore/types/footprint.py +41 -0
  216. pynecore/types/format.py +5 -0
  217. pynecore/types/hline.py +24 -0
  218. pynecore/types/ib_persistent.py +8 -0
  219. pynecore/types/ib_persistent.pyi +10 -0
  220. pynecore/types/label.py +35 -0
  221. pynecore/types/line.py +32 -0
  222. pynecore/types/linefill.py +13 -0
  223. pynecore/types/location.py +5 -0
  224. pynecore/types/matrix.py +999 -0
  225. pynecore/types/na.py +237 -0
  226. pynecore/types/na.pyi +83 -0
  227. pynecore/types/ohlcv.py +12 -0
  228. pynecore/types/order.py +5 -0
  229. pynecore/types/persistent.py +8 -0
  230. pynecore/types/persistent.pyi +13 -0
  231. pynecore/types/pine_types.py +11 -0
  232. pynecore/types/pine_types.pyi +15 -0
  233. pynecore/types/pivotpointtype.py +5 -0
  234. pynecore/types/plot.py +12 -0
  235. pynecore/types/plot_meta.py +60 -0
  236. pynecore/types/polyline.py +40 -0
  237. pynecore/types/position.py +5 -0
  238. pynecore/types/scale.py +5 -0
  239. pynecore/types/script_type.py +15 -0
  240. pynecore/types/series.py +23 -0
  241. pynecore/types/series.pyi +19 -0
  242. pynecore/types/session.py +35 -0
  243. pynecore/types/shape.py +5 -0
  244. pynecore/types/size.py +5 -0
  245. pynecore/types/source.py +33 -0
  246. pynecore/types/splits.py +5 -0
  247. pynecore/types/strategy.py +45 -0
  248. pynecore/types/table.py +87 -0
  249. pynecore/types/text.py +13 -0
  250. pynecore/types/type_checker.py +7 -0
  251. pynecore/types/type_checker.pyi +48 -0
  252. pynecore/types/volume_row.py +36 -0
  253. pynecore/types/weekdays.py +11 -0
  254. pynecore/types/xloc.py +5 -0
  255. pynecore/types/yloc.py +5 -0
  256. pynecore/utils/__init__.py +0 -0
  257. pynecore/utils/file_utils.py +50 -0
  258. pynecore/utils/rich/__init__.py +0 -0
  259. pynecore/utils/rich/date_column.py +25 -0
  260. pynecore/utils/sequence_view.py +92 -0
  261. pynecore/utils/stdlib_checker.py +17 -0
@@ -0,0 +1,281 @@
1
+ from ...types.na import NA, na_float
2
+ from ...types import PyneFloat, PyneInt, PyneStr
3
+ from ... import lib
4
+ from .. import syminfo
5
+
6
+ from ...core.module_property import module_property
7
+
8
+
9
+ #
10
+ # Functions
11
+ #
12
+
13
+ # noinspection PyProtectedMember
14
+ def commission(trade_num: int) -> PyneFloat:
15
+ """
16
+ Returns the sum of entry and exit fees paid in the open trade, expressed in strategy.account_currency
17
+
18
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
19
+ :return: The sum of entry and exit fees paid in the open trade, expressed in strategy.account_currency
20
+ """
21
+ if trade_num < 0:
22
+ return na_float
23
+ try:
24
+ assert lib._script is not None
25
+ assert lib._script.position is not None
26
+ return lib._script.position.open_trades[trade_num].commission
27
+ except (IndexError, AssertionError):
28
+ return 0.0
29
+
30
+
31
+ # noinspection PyProtectedMember
32
+ def entry_bar_index(trade_num: int) -> PyneInt:
33
+ """
34
+ Returns the bar_index of the open trade's entry
35
+
36
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
37
+ :return: The bar_index of the open trade's entry
38
+ """
39
+ if trade_num < 0:
40
+ return NA(int)
41
+ try:
42
+ assert lib._script is not None
43
+ assert lib._script.position is not None
44
+ return lib._script.position.open_trades[trade_num].entry_bar_index
45
+ except (IndexError, AssertionError):
46
+ return NA(int)
47
+
48
+
49
+ # noinspection PyProtectedMember
50
+ def entry_comment(trade_num: int) -> PyneStr:
51
+ """
52
+ Returns the comment message of the open trade's entry
53
+
54
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
55
+ :return: The comment message of the open trade's entry
56
+ """
57
+ if trade_num < 0:
58
+ return NA(str)
59
+ try:
60
+ assert lib._script is not None
61
+ assert lib._script.position is not None
62
+ comment = lib._script.position.open_trades[trade_num].entry_comment
63
+ return comment if comment is not None else NA(str)
64
+ except (IndexError, AssertionError):
65
+ return NA(str)
66
+
67
+
68
+ # noinspection PyProtectedMember
69
+ def entry_id(trade_num: int) -> PyneStr:
70
+ """
71
+ Returns the id of the open trade's entry
72
+
73
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
74
+ :return: The id of the open trade's entry
75
+ """
76
+ if trade_num < 0:
77
+ return NA(str)
78
+ try:
79
+ assert lib._script is not None
80
+ assert lib._script.position is not None
81
+ entry_id_ = lib._script.position.open_trades[trade_num].entry_id
82
+ return entry_id_ if entry_id_ is not None else NA(str)
83
+ except (IndexError, AssertionError):
84
+ return NA(str)
85
+
86
+
87
+ # noinspection PyProtectedMember
88
+ def entry_price(trade_num: int) -> PyneFloat:
89
+ """
90
+ Returns the price of the open trade's entry
91
+
92
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
93
+ :return: The price of the open trade's entry
94
+ """
95
+ if trade_num < 0:
96
+ return na_float
97
+ try:
98
+ assert lib._script is not None
99
+ assert lib._script.position is not None
100
+ return lib._script.position.open_trades[trade_num].entry_price
101
+ except (IndexError, AssertionError):
102
+ return na_float
103
+
104
+
105
+ # noinspection PyProtectedMember
106
+ def entry_time(trade_num: int) -> PyneInt:
107
+ """
108
+ Returns the time of the open trade's entry (UNIX)
109
+
110
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
111
+ :return: The time of the open trade's entry (UNIX)
112
+ """
113
+ if trade_num < 0:
114
+ return NA(int)
115
+ try:
116
+ assert lib._script is not None
117
+ assert lib._script.position is not None
118
+ return lib._script.position.open_trades[trade_num].entry_time
119
+ except (IndexError, AssertionError):
120
+ return NA(int)
121
+
122
+
123
+ # noinspection PyProtectedMember
124
+ def max_drawdown(trade_num: int) -> PyneFloat:
125
+ """
126
+ Returns the maximum drawdown of the open trade
127
+
128
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
129
+ :return: The maximum drawdown of the open trade
130
+ """
131
+ if trade_num < 0:
132
+ return na_float
133
+ try:
134
+ assert lib._script is not None
135
+ assert lib._script.position is not None
136
+ return lib._script.position.open_trades[trade_num].max_drawdown
137
+ except (IndexError, AssertionError):
138
+ return 0.0
139
+
140
+
141
+ # noinspection PyProtectedMember
142
+ def max_drawdown_percent(trade_num: int) -> PyneFloat:
143
+ """
144
+ Returns the maximum drawdown percentage of the open trade
145
+
146
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
147
+ :return: The maximum drawdown percentage of the open trade
148
+ """
149
+ if trade_num < 0:
150
+ return na_float
151
+ try:
152
+ assert lib._script is not None
153
+ assert lib._script.position is not None
154
+ return lib._script.position.open_trades[trade_num].max_drawdown_percent
155
+ except (IndexError, AssertionError):
156
+ return 0.0
157
+
158
+
159
+ # noinspection PyProtectedMember
160
+ def max_runup(trade_num: int) -> PyneFloat:
161
+ """
162
+ Returns the maximum runup of the open trade
163
+
164
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
165
+ :return: The maximum runup of the open trade
166
+ """
167
+ if trade_num < 0:
168
+ return na_float
169
+ try:
170
+ assert lib._script is not None
171
+ assert lib._script.position is not None
172
+ return lib._script.position.open_trades[trade_num].max_runup
173
+ except (IndexError, AssertionError):
174
+ return 0.0
175
+
176
+
177
+ # noinspection PyProtectedMember
178
+ def max_runup_percent(trade_num: int) -> PyneFloat:
179
+ """
180
+ Returns the maximum runup percentage of the open trade
181
+
182
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
183
+ :return: The maximum runup percentage of the open trade
184
+ """
185
+ if trade_num < 0:
186
+ return na_float
187
+ try:
188
+ assert lib._script is not None
189
+ assert lib._script.position is not None
190
+ return lib._script.position.open_trades[trade_num].max_runup_percent
191
+ except (IndexError, AssertionError):
192
+ return 0.0
193
+
194
+
195
+ # noinspection PyProtectedMember
196
+ def profit(trade_num: int) -> PyneFloat:
197
+ """
198
+ Returns the profit of the open trade expressed in strategy.account_currency
199
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
200
+ :return: The profit of the open trade expressed in strategy.account_currency
201
+ """
202
+ if trade_num < 0:
203
+ return na_float
204
+ try:
205
+ assert lib._script is not None
206
+ assert lib._script.position is not None
207
+ return lib._script.position.open_trades[trade_num].profit
208
+ except IndexError:
209
+ return 0.0
210
+
211
+
212
+ # noinspection PyProtectedMember
213
+ def profit_percent(trade_num: int) -> PyneFloat:
214
+ """
215
+ Returns the profit percentage of the open trade
216
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
217
+ :return: The profit percentage of the open trade
218
+ """
219
+ if trade_num < 0:
220
+ return na_float
221
+ try:
222
+ assert lib._script is not None
223
+ assert lib._script.position is not None
224
+ return lib._script.position.open_trades[trade_num].profit_percent
225
+ except (IndexError, AssertionError):
226
+ return 0.0
227
+
228
+
229
+ # noinspection PyProtectedMember
230
+ def size(trade_num: int) -> PyneFloat:
231
+ """
232
+ Returns the size and direction (<0 short >0 long) of the open trade
233
+
234
+ :param trade_num: The trade number of the open trade. The number of the first trade is zero
235
+ :return: The size and direction (<0 short >0 long) of the open trade
236
+ """
237
+ if trade_num < 0:
238
+ return 0.0
239
+ try:
240
+ assert lib._script is not None
241
+ assert lib._script.position is not None
242
+ return lib._script.position.open_trades[trade_num].size
243
+ except (IndexError, AssertionError):
244
+ return 0.0
245
+
246
+
247
+ #
248
+ # Module properties
249
+ #
250
+
251
+ # noinspection PyProtectedMember
252
+ @module_property
253
+ def capital_held() -> PyneFloat:
254
+ """
255
+ Returns the amount of capital held in open positions, expressed in
256
+ strategy.account_currency.
257
+
258
+ :return: The capital tied up by the currently open trades
259
+ """
260
+ if lib._script is None or lib._script.position is None:
261
+ return 0.0
262
+ position = lib._script.position
263
+ # pointvalue converts contracts -> account currency (1 for spot/stocks,
264
+ # but e.g. 100000 for VN30 futures); omitting it understates the held
265
+ # capital by that factor on non-unit-pointvalue instruments.
266
+ return sum(abs(trade.size) * trade.entry_price * syminfo.pointvalue
267
+ for trade in position.open_trades)
268
+
269
+
270
+ # noinspection PyProtectedMember
271
+ @module_property
272
+ def opentrades() -> int:
273
+ """
274
+ Number of market position entries, which were not closed and remain opened.
275
+
276
+ :return: The number of open trades
277
+ """
278
+ if lib._script is None or lib._script.position is None:
279
+ return 0
280
+ position = lib._script.position
281
+ return len(position.open_trades)
@@ -0,0 +1,49 @@
1
+ from ...types import PyneFloat, PyneInt, PyneStr
2
+
3
+
4
+ # IDE-facing view of the function-and-namespace module: bare ``strategy.opentrades``
5
+ # is an int value, ``strategy.opentrades.commission(...)`` a namespaced function;
6
+ # the AST transformer resolves both at runtime. The ``int`` base keeps arithmetic
7
+ # on the bare name type-checking.
8
+ class OpenTradesModule(int):
9
+ def __call__(self) -> int: ...
10
+
11
+ #
12
+ # Functions
13
+ #
14
+
15
+ def commission(self, trade_num: int) -> PyneFloat: ...
16
+
17
+ def entry_bar_index(self, trade_num: int) -> PyneInt: ...
18
+
19
+ def entry_comment(self, trade_num: int) -> PyneStr: ...
20
+
21
+ def entry_id(self, trade_num: int) -> PyneStr: ...
22
+
23
+ def entry_price(self, trade_num: int) -> PyneFloat: ...
24
+
25
+ def entry_time(self, trade_num: int) -> PyneInt: ...
26
+
27
+ def max_drawdown(self, trade_num: int) -> PyneFloat: ...
28
+
29
+ def max_drawdown_percent(self, trade_num: int) -> PyneFloat: ...
30
+
31
+ def max_runup(self, trade_num: int) -> PyneFloat: ...
32
+
33
+ def max_runup_percent(self, trade_num: int) -> PyneFloat: ...
34
+
35
+ def profit(self, trade_num: int) -> PyneFloat: ...
36
+
37
+ def profit_percent(self, trade_num: int) -> PyneFloat: ...
38
+
39
+ def size(self, trade_num: int) -> PyneFloat: ...
40
+
41
+ #
42
+ # Properties
43
+ #
44
+
45
+ @property
46
+ def capital_held(self) -> PyneFloat: ...
47
+
48
+
49
+ opentrades: OpenTradesModule
@@ -0,0 +1,109 @@
1
+ from ...types.na import NA
2
+ from ...types import PyneStr
3
+ from .. import strategy
4
+
5
+ from ... import lib
6
+
7
+
8
+ # noinspection PyShadowingBuiltins,PyProtectedMember
9
+ def max_drawdown(
10
+ value: float | int,
11
+ type: strategy.QtyType = strategy.percent_of_equity,
12
+ alert_message: PyneStr = NA(str)
13
+ ) -> None:
14
+ """
15
+ The purpose of this rule is to determine maximum drawdown. The rule affects the whole strategy.
16
+ Once the maximum drawdown value is reached, all pending orders are cancelled, all open positions
17
+ are closed and no new orders can be placed.
18
+
19
+ :param value: The maximum drawdown value
20
+ :param type: The type of the value
21
+ :param alert_message: The alert message
22
+ """
23
+ if lib._script is None or lib._script.position is None:
24
+ return
25
+
26
+ lib._script.position.risk_max_drawdown_value = value
27
+ lib._script.position.risk_max_drawdown_type = type
28
+ lib._script.position.risk_max_drawdown_alert = None if isinstance(alert_message, NA) else str(alert_message)
29
+
30
+
31
+ # noinspection PyProtectedMember
32
+ def allow_entry_in(value: strategy.direction.Direction) -> None:
33
+ """
34
+ This function can be used to specify in which market direction the strategy.entry function is
35
+ allowed to open positions.
36
+
37
+ :param value: The allowed direction
38
+ """
39
+ if lib._script is None or lib._script.position is None:
40
+ return
41
+
42
+ lib._script.position.risk_allowed_direction = value
43
+
44
+
45
+ # noinspection PyProtectedMember
46
+ def max_cons_loss_days(count: int, alert_message: PyneStr = NA(str)) -> None:
47
+ """
48
+ The purpose of this rule is to determine the maximum number of consecutive losing days.
49
+ Once the maximum number of consecutive losing days is reached, all pending orders are cancelled,
50
+ all open positions are closed and no new orders can be placed
51
+
52
+ :param count: The maximum number of consecutive losing days
53
+ :param alert_message: The alert message
54
+ """
55
+ if lib._script is None or lib._script.position is None:
56
+ return
57
+
58
+ lib._script.position.risk_max_cons_loss_days = count
59
+ lib._script.position.risk_max_cons_loss_days_alert = None if isinstance(alert_message, NA) else str(alert_message)
60
+
61
+
62
+ # noinspection PyProtectedMember
63
+ def max_intraday_filled_orders(count: int, alert_message: PyneStr = NA(str)) -> None:
64
+ """
65
+ The purpose of this rule is to determine the maximum number of intraday filled orders
66
+
67
+ :param count: The maximum number of intraday filled orders
68
+ :param alert_message: The alert message
69
+ """
70
+ if lib._script is None or lib._script.position is None:
71
+ return
72
+
73
+ lib._script.position.risk_max_intraday_filled_orders = count
74
+ lib._script.position.risk_max_intraday_filled_orders_alert = (
75
+ None if isinstance(alert_message, NA) else str(alert_message)
76
+ )
77
+
78
+
79
+ # noinspection PyShadowingBuiltins,PyProtectedMember
80
+ def max_intraday_loss(value: float | int, type: strategy.QtyType = strategy.percent_of_equity,
81
+ alert_message: PyneStr = NA(str)) -> None:
82
+ """
83
+ The purpose of this rule is to determine the maximum intraday loss. The rule affects the whole strategy.
84
+ Once the maximum intraday loss value is reached, all pending orders are cancelled, all open positions
85
+ are closed and no new orders can be placed
86
+
87
+ :param value: The maximum intraday loss value
88
+ :param type: The type of the value
89
+ :param alert_message: The alert message
90
+ """
91
+ if lib._script is None or lib._script.position is None:
92
+ return
93
+
94
+ lib._script.position.risk_max_intraday_loss_value = value
95
+ lib._script.position.risk_max_intraday_loss_type = type
96
+ lib._script.position.risk_max_intraday_loss_alert = None if isinstance(alert_message, NA) else str(alert_message)
97
+
98
+
99
+ # noinspection PyProtectedMember
100
+ def max_position_size(contracts: int | float):
101
+ """
102
+ The purpose of this rule is to determine maximum size of a market position
103
+
104
+ :param contracts: The maximum size of a market position
105
+ """
106
+ if lib._script is None or lib._script.position is None:
107
+ return
108
+
109
+ lib._script.position.risk_max_position_size = abs(contracts)