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.
- opencode_pyneruntime-6.6.4.dist-info/METADATA +281 -0
- opencode_pyneruntime-6.6.4.dist-info/RECORD +261 -0
- opencode_pyneruntime-6.6.4.dist-info/WHEEL +5 -0
- opencode_pyneruntime-6.6.4.dist-info/entry_points.txt +6 -0
- opencode_pyneruntime-6.6.4.dist-info/licenses/LICENSE +201 -0
- opencode_pyneruntime-6.6.4.dist-info/licenses/NOTICE +21 -0
- opencode_pyneruntime-6.6.4.dist-info/top_level.txt +1 -0
- pynecore/__init__.py +6 -0
- pynecore/cli/__init__.py +2 -0
- pynecore/cli/app.py +238 -0
- pynecore/cli/commands/__init__.py +343 -0
- pynecore/cli/commands/benchmark.py +186 -0
- pynecore/cli/commands/compile.py +198 -0
- pynecore/cli/commands/data.py +857 -0
- pynecore/cli/commands/debug.py +63 -0
- pynecore/cli/commands/optimize.py +956 -0
- pynecore/cli/commands/plugin.py +242 -0
- pynecore/cli/commands/run.py +2006 -0
- pynecore/cli/pluggable.py +132 -0
- pynecore/cli/utils/__init__.py +0 -0
- pynecore/cli/utils/api_error_handler.py +168 -0
- pynecore/cli/utils/broker_picker.py +330 -0
- pynecore/cli/utils/error_hook.py +28 -0
- pynecore/cli/utils/keyreader.py +178 -0
- pynecore/cli/utils/provider_picker.py +19 -0
- pynecore/cli/utils/symbol_browser.py +1149 -0
- pynecore/core/__init__.py +0 -0
- pynecore/core/aggregator.py +257 -0
- pynecore/core/bar_magnifier.py +168 -0
- pynecore/core/broker/__init__.py +64 -0
- pynecore/core/broker/defaults.py +113 -0
- pynecore/core/broker/disappearance.py +927 -0
- pynecore/core/broker/emulator.py +345 -0
- pynecore/core/broker/exceptions.py +346 -0
- pynecore/core/broker/idempotency.py +401 -0
- pynecore/core/broker/intent_builder.py +334 -0
- pynecore/core/broker/journal.py +1785 -0
- pynecore/core/broker/models.py +1600 -0
- pynecore/core/broker/native_failsafe_manager.py +1436 -0
- pynecore/core/broker/one_way_emulator.py +1128 -0
- pynecore/core/broker/position.py +787 -0
- pynecore/core/broker/run_identity.py +126 -0
- pynecore/core/broker/software_entry_stop_engine.py +351 -0
- pynecore/core/broker/software_partial_bracket_engine.py +1379 -0
- pynecore/core/broker/spot_inventory.py +1327 -0
- pynecore/core/broker/storage.py +2655 -0
- pynecore/core/broker/store_helpers.py +2161 -0
- pynecore/core/broker/sync_engine.py +16070 -0
- pynecore/core/broker/validation.py +382 -0
- pynecore/core/class_property.py +7 -0
- pynecore/core/config.py +392 -0
- pynecore/core/csv_file.py +547 -0
- pynecore/core/currency.py +262 -0
- pynecore/core/data_converter.py +1002 -0
- pynecore/core/datetime.py +296 -0
- pynecore/core/download_info.py +71 -0
- pynecore/core/download_runner.py +274 -0
- pynecore/core/htf_aggregator.py +181 -0
- pynecore/core/import_hook.py +358 -0
- pynecore/core/instance_state.py +494 -0
- pynecore/core/live_ltf_collector.py +442 -0
- pynecore/core/live_ltf_window.py +189 -0
- pynecore/core/live_runner.py +1347 -0
- pynecore/core/module_property.py +26 -0
- pynecore/core/ohlcv_file.py +1888 -0
- pynecore/core/overload.py +371 -0
- pynecore/core/pine_cast.py +113 -0
- pynecore/core/pine_export.py +95 -0
- pynecore/core/pine_method.py +244 -0
- pynecore/core/pine_range.py +86 -0
- pynecore/core/pine_udt.py +69 -0
- pynecore/core/plugin/__init__.py +394 -0
- pynecore/core/plugin/broker.py +781 -0
- pynecore/core/plugin/cli.py +96 -0
- pynecore/core/plugin/live_provider.py +208 -0
- pynecore/core/plugin/provider.py +331 -0
- pynecore/core/provider_string.py +148 -0
- pynecore/core/random.py +40 -0
- pynecore/core/resampler.py +686 -0
- pynecore/core/safe_convert.py +64 -0
- pynecore/core/script.py +1011 -0
- pynecore/core/script_runner.py +3202 -0
- pynecore/core/security.py +1749 -0
- pynecore/core/security_process.py +1253 -0
- pynecore/core/security_shm.py +456 -0
- pynecore/core/series.py +417 -0
- pynecore/core/strategy_stats.py +669 -0
- pynecore/core/symbol_map.py +134 -0
- pynecore/core/syminfo.py +505 -0
- pynecore/core/viz.py +591 -0
- pynecore/lib/__init__.py +1771 -0
- pynecore/lib/_fixnan.py +32 -0
- pynecore/lib/_math_stateful.py +202 -0
- pynecore/lib/_timeframe_change.py +101 -0
- pynecore/lib/adjustment.py +6 -0
- pynecore/lib/alert.py +39 -0
- pynecore/lib/alert.pyi +14 -0
- pynecore/lib/array.py +1051 -0
- pynecore/lib/barmerge.py +60 -0
- pynecore/lib/barstate.py +30 -0
- pynecore/lib/box.py +415 -0
- pynecore/lib/chart.py +128 -0
- pynecore/lib/color.py +152 -0
- pynecore/lib/color.pyi +50 -0
- pynecore/lib/currency.py +62 -0
- pynecore/lib/dayofweek.py +36 -0
- pynecore/lib/dayofweek.pyi +18 -0
- pynecore/lib/display.py +8 -0
- pynecore/lib/dividends.py +9 -0
- pynecore/lib/earnings.py +11 -0
- pynecore/lib/extend.py +6 -0
- pynecore/lib/font.py +5 -0
- pynecore/lib/footprint.py +79 -0
- pynecore/lib/format.py +11 -0
- pynecore/lib/hline.py +67 -0
- pynecore/lib/hline.pyi +24 -0
- pynecore/lib/label.py +409 -0
- pynecore/lib/line.py +433 -0
- pynecore/lib/linefill.py +93 -0
- pynecore/lib/location.py +11 -0
- pynecore/lib/log.py +362 -0
- pynecore/lib/map.py +150 -0
- pynecore/lib/math.py +385 -0
- pynecore/lib/matrix.py +708 -0
- pynecore/lib/order.py +8 -0
- pynecore/lib/pivotpointtype.py +8 -0
- pynecore/lib/plot.py +95 -0
- pynecore/lib/plot.pyi +33 -0
- pynecore/lib/polyline.py +91 -0
- pynecore/lib/position.py +15 -0
- pynecore/lib/request.py +281 -0
- pynecore/lib/runtime.py +5 -0
- pynecore/lib/scale.py +9 -0
- pynecore/lib/session.py +267 -0
- pynecore/lib/session.pyi +12 -0
- pynecore/lib/shape.py +18 -0
- pynecore/lib/size.py +12 -0
- pynecore/lib/splits.py +4 -0
- pynecore/lib/strategy/__init__.py +4778 -0
- pynecore/lib/strategy/closedtrades.py +347 -0
- pynecore/lib/strategy/closedtrades.pyi +53 -0
- pynecore/lib/strategy/commission.py +9 -0
- pynecore/lib/strategy/direction.py +9 -0
- pynecore/lib/strategy/oca.py +13 -0
- pynecore/lib/strategy/opentrades.py +281 -0
- pynecore/lib/strategy/opentrades.pyi +49 -0
- pynecore/lib/strategy/risk.py +109 -0
- pynecore/lib/string.py +649 -0
- pynecore/lib/syminfo.py +84 -0
- pynecore/lib/ta.py +2230 -0
- pynecore/lib/table.py +290 -0
- pynecore/lib/text.py +17 -0
- pynecore/lib/ticker.py +207 -0
- pynecore/lib/timeframe.py +293 -0
- pynecore/lib/volume_row.py +67 -0
- pynecore/lib/xloc.py +4 -0
- pynecore/lib/yloc.py +5 -0
- pynecore/providers/__init__.py +0 -0
- pynecore/providers/ccxt.py +664 -0
- pynecore/providers/replay.py +187 -0
- pynecore/pynesys/__init__.py +0 -0
- pynecore/pynesys/api.py +498 -0
- pynecore/pynesys/compiler.py +112 -0
- pynecore/standalone.py +99 -0
- pynecore/testing/__init__.py +1 -0
- pynecore/testing/broker_lab/__init__.py +41 -0
- pynecore/testing/broker_lab/__main__.py +5 -0
- pynecore/testing/broker_lab/cli.py +87 -0
- pynecore/testing/broker_lab/generate.py +47 -0
- pynecore/testing/broker_lab/model.py +84 -0
- pynecore/testing/broker_lab/reference.py +645 -0
- pynecore/testing/broker_lab/runner.py +372 -0
- pynecore/testing/broker_lab/scheduler.py +50 -0
- pynecore/testing/broker_lab/subprocess.py +73 -0
- pynecore/transformers/__init__.py +0 -0
- pynecore/transformers/builtin_shadow.py +136 -0
- pynecore/transformers/closure_arguments_transformer.py +428 -0
- pynecore/transformers/display_rewrite.py +140 -0
- pynecore/transformers/dynamic_default.py +147 -0
- pynecore/transformers/function_isolation.py +757 -0
- pynecore/transformers/import_lifter.py +61 -0
- pynecore/transformers/import_normalizer.py +328 -0
- pynecore/transformers/inline_series_hoist.py +178 -0
- pynecore/transformers/input_transformer.py +175 -0
- pynecore/transformers/lib_series.py +201 -0
- pynecore/transformers/locations.py +70 -0
- pynecore/transformers/module_properties.json +3387 -0
- pynecore/transformers/module_property.py +221 -0
- pynecore/transformers/ne_guard.py +70 -0
- pynecore/transformers/persistent.py +320 -0
- pynecore/transformers/persistent_series.py +76 -0
- pynecore/transformers/safe_convert_transformer.py +97 -0
- pynecore/transformers/safe_division_transformer.py +95 -0
- pynecore/transformers/script_requirements.py +308 -0
- pynecore/transformers/security.py +752 -0
- pynecore/transformers/security_instantiation.py +274 -0
- pynecore/transformers/series.py +275 -0
- pynecore/transformers/slot_layout.py +381 -0
- pynecore/transformers/type_checking_stripper.py +25 -0
- pynecore/transformers/unused_series_detector.py +267 -0
- pynecore/types/__init__.py +21 -0
- pynecore/types/alert.py +5 -0
- pynecore/types/barmerge.py +5 -0
- pynecore/types/base.py +39 -0
- pynecore/types/box.py +37 -0
- pynecore/types/chart.py +17 -0
- pynecore/types/color.py +107 -0
- pynecore/types/currency.py +5 -0
- pynecore/types/datetime.py +6 -0
- pynecore/types/display.py +5 -0
- pynecore/types/dividends.py +5 -0
- pynecore/types/earnings.py +5 -0
- pynecore/types/extend.py +5 -0
- pynecore/types/font.py +5 -0
- pynecore/types/footprint.py +41 -0
- pynecore/types/format.py +5 -0
- pynecore/types/hline.py +24 -0
- pynecore/types/ib_persistent.py +8 -0
- pynecore/types/ib_persistent.pyi +10 -0
- pynecore/types/label.py +35 -0
- pynecore/types/line.py +32 -0
- pynecore/types/linefill.py +13 -0
- pynecore/types/location.py +5 -0
- pynecore/types/matrix.py +999 -0
- pynecore/types/na.py +237 -0
- pynecore/types/na.pyi +83 -0
- pynecore/types/ohlcv.py +12 -0
- pynecore/types/order.py +5 -0
- pynecore/types/persistent.py +8 -0
- pynecore/types/persistent.pyi +13 -0
- pynecore/types/pine_types.py +11 -0
- pynecore/types/pine_types.pyi +15 -0
- pynecore/types/pivotpointtype.py +5 -0
- pynecore/types/plot.py +12 -0
- pynecore/types/plot_meta.py +60 -0
- pynecore/types/polyline.py +40 -0
- pynecore/types/position.py +5 -0
- pynecore/types/scale.py +5 -0
- pynecore/types/script_type.py +15 -0
- pynecore/types/series.py +23 -0
- pynecore/types/series.pyi +19 -0
- pynecore/types/session.py +35 -0
- pynecore/types/shape.py +5 -0
- pynecore/types/size.py +5 -0
- pynecore/types/source.py +33 -0
- pynecore/types/splits.py +5 -0
- pynecore/types/strategy.py +45 -0
- pynecore/types/table.py +87 -0
- pynecore/types/text.py +13 -0
- pynecore/types/type_checker.py +7 -0
- pynecore/types/type_checker.pyi +48 -0
- pynecore/types/volume_row.py +36 -0
- pynecore/types/weekdays.py +11 -0
- pynecore/types/xloc.py +5 -0
- pynecore/types/yloc.py +5 -0
- pynecore/utils/__init__.py +0 -0
- pynecore/utils/file_utils.py +50 -0
- pynecore/utils/rich/__init__.py +0 -0
- pynecore/utils/rich/date_column.py +25 -0
- pynecore/utils/sequence_view.py +92 -0
- pynecore/utils/stdlib_checker.py +17 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
from ...types.na import NA, na_float
|
|
2
|
+
from ...types import PyneFloat, PyneInt, PyneStr
|
|
3
|
+
from ... import lib
|
|
4
|
+
|
|
5
|
+
from ...core.module_property import module_property
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# Functions
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
# noinspection PyProtectedMember
|
|
13
|
+
def commission(trade_num: int) -> PyneFloat:
|
|
14
|
+
"""
|
|
15
|
+
Returns the sum of entry and exit fees paid in the closed trade, expressed in strategy.account_currency
|
|
16
|
+
|
|
17
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
18
|
+
:return: The sum of entry and exit fees paid in the closed trade, expressed in strategy.account_currency
|
|
19
|
+
"""
|
|
20
|
+
if trade_num < 0:
|
|
21
|
+
return na_float
|
|
22
|
+
try:
|
|
23
|
+
assert lib._script is not None
|
|
24
|
+
assert lib._script.position is not None
|
|
25
|
+
return lib._script.position.closed_trades[trade_num].commission
|
|
26
|
+
except (IndexError, AssertionError):
|
|
27
|
+
return 0.0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# noinspection PyProtectedMember
|
|
31
|
+
def entry_bar_index(trade_num: int) -> PyneInt:
|
|
32
|
+
"""
|
|
33
|
+
Returns the bar_index of the closed trade's entry
|
|
34
|
+
|
|
35
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
36
|
+
:return: The bar_index of the closed trade's entry
|
|
37
|
+
"""
|
|
38
|
+
if trade_num < 0:
|
|
39
|
+
return NA(int)
|
|
40
|
+
try:
|
|
41
|
+
assert lib._script is not None
|
|
42
|
+
assert lib._script.position is not None
|
|
43
|
+
return lib._script.position.closed_trades[trade_num].entry_bar_index
|
|
44
|
+
except (IndexError, AssertionError):
|
|
45
|
+
return NA(int)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# noinspection PyProtectedMember
|
|
49
|
+
def entry_comment(trade_num: int) -> PyneStr:
|
|
50
|
+
"""
|
|
51
|
+
Returns the comment message of the closed trade's entry
|
|
52
|
+
|
|
53
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
54
|
+
:return: The comment message of the closed trade's entry
|
|
55
|
+
"""
|
|
56
|
+
if trade_num < 0:
|
|
57
|
+
return NA(str)
|
|
58
|
+
try:
|
|
59
|
+
assert lib._script is not None
|
|
60
|
+
assert lib._script.position is not None
|
|
61
|
+
comment = lib._script.position.closed_trades[trade_num].entry_comment
|
|
62
|
+
return comment if comment is not None else NA(str)
|
|
63
|
+
except (IndexError, AssertionError):
|
|
64
|
+
return NA(str)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# noinspection PyProtectedMember
|
|
68
|
+
def entry_id(trade_num: int) -> PyneStr:
|
|
69
|
+
"""
|
|
70
|
+
Returns the id of the closed trade's entry
|
|
71
|
+
|
|
72
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
73
|
+
:return: The id of the closed trade's entry
|
|
74
|
+
"""
|
|
75
|
+
if trade_num < 0:
|
|
76
|
+
return NA(str)
|
|
77
|
+
try:
|
|
78
|
+
assert lib._script is not None
|
|
79
|
+
assert lib._script.position is not None
|
|
80
|
+
entry_id_ = lib._script.position.closed_trades[trade_num].entry_id
|
|
81
|
+
return entry_id_ if entry_id_ is not None else NA(str)
|
|
82
|
+
except (IndexError, AssertionError):
|
|
83
|
+
return NA(str)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# noinspection PyProtectedMember
|
|
87
|
+
def entry_price(trade_num: int) -> PyneFloat:
|
|
88
|
+
"""
|
|
89
|
+
Returns the price of the closed trade's entry
|
|
90
|
+
|
|
91
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
92
|
+
:return: The price of the closed trade's entry
|
|
93
|
+
"""
|
|
94
|
+
if trade_num < 0:
|
|
95
|
+
return na_float
|
|
96
|
+
try:
|
|
97
|
+
assert lib._script is not None
|
|
98
|
+
assert lib._script.position is not None
|
|
99
|
+
return lib._script.position.closed_trades[trade_num].entry_price
|
|
100
|
+
except (IndexError, AssertionError):
|
|
101
|
+
return na_float
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# noinspection PyProtectedMember
|
|
105
|
+
def entry_time(trade_num: int) -> PyneInt:
|
|
106
|
+
"""
|
|
107
|
+
Returns the time of the closed trade's entry (UNIX)
|
|
108
|
+
|
|
109
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
110
|
+
:return: The time of the closed trade's entry
|
|
111
|
+
"""
|
|
112
|
+
if trade_num < 0:
|
|
113
|
+
return NA(int)
|
|
114
|
+
try:
|
|
115
|
+
assert lib._script is not None
|
|
116
|
+
assert lib._script.position is not None
|
|
117
|
+
return lib._script.position.closed_trades[trade_num].entry_time
|
|
118
|
+
except (IndexError, AssertionError):
|
|
119
|
+
return NA(int)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# noinspection PyProtectedMember
|
|
123
|
+
def exit_bar_index(trade_num: int) -> PyneInt:
|
|
124
|
+
"""
|
|
125
|
+
Returns the bar_index of the closed trade's exit
|
|
126
|
+
|
|
127
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
128
|
+
:return: The bar_index of the closed trade's exit
|
|
129
|
+
"""
|
|
130
|
+
if trade_num < 0:
|
|
131
|
+
return NA(int)
|
|
132
|
+
try:
|
|
133
|
+
assert lib._script is not None
|
|
134
|
+
assert lib._script.position is not None
|
|
135
|
+
return lib._script.position.closed_trades[trade_num].exit_bar_index
|
|
136
|
+
except (IndexError, AssertionError):
|
|
137
|
+
return NA(int)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# noinspection PyProtectedMember
|
|
141
|
+
def exit_comment(trade_num: int) -> PyneStr:
|
|
142
|
+
"""
|
|
143
|
+
Returns the comment message of the closed trade's exit
|
|
144
|
+
|
|
145
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
146
|
+
:return: The comment message of the closed trade's exit
|
|
147
|
+
"""
|
|
148
|
+
if trade_num < 0:
|
|
149
|
+
return NA(str)
|
|
150
|
+
try:
|
|
151
|
+
assert lib._script is not None
|
|
152
|
+
assert lib._script.position is not None
|
|
153
|
+
return lib._script.position.closed_trades[trade_num].exit_comment
|
|
154
|
+
except (IndexError, AssertionError):
|
|
155
|
+
return NA(str)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# noinspection PyProtectedMember
|
|
159
|
+
def exit_id(trade_num: int) -> PyneStr:
|
|
160
|
+
"""
|
|
161
|
+
Returns the id of the closed trade's exit
|
|
162
|
+
|
|
163
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
164
|
+
:return: The id of the closed trade's exit
|
|
165
|
+
"""
|
|
166
|
+
if trade_num < 0:
|
|
167
|
+
return NA(str)
|
|
168
|
+
try:
|
|
169
|
+
assert lib._script is not None
|
|
170
|
+
assert lib._script.position is not None
|
|
171
|
+
exit_id_ = lib._script.position.closed_trades[trade_num].exit_id
|
|
172
|
+
return exit_id_ if exit_id_ is not None else NA(str)
|
|
173
|
+
except (IndexError, AssertionError):
|
|
174
|
+
return NA(str)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# noinspection PyProtectedMember
|
|
178
|
+
def exit_price(trade_num: int) -> PyneFloat:
|
|
179
|
+
"""
|
|
180
|
+
Returns the price of the closed trade's exit
|
|
181
|
+
|
|
182
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
183
|
+
:return: The price of the closed trade's exit
|
|
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.closed_trades[trade_num].exit_price
|
|
191
|
+
except (IndexError, AssertionError):
|
|
192
|
+
return na_float
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# noinspection PyProtectedMember
|
|
196
|
+
def exit_time(trade_num: int) -> PyneInt:
|
|
197
|
+
"""
|
|
198
|
+
Returns the time of the closed trade's exit (UNIX)
|
|
199
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
200
|
+
:return: The time of the closed trade's exit
|
|
201
|
+
"""
|
|
202
|
+
if trade_num < 0:
|
|
203
|
+
return NA(int)
|
|
204
|
+
try:
|
|
205
|
+
assert lib._script is not None
|
|
206
|
+
assert lib._script.position is not None
|
|
207
|
+
return lib._script.position.closed_trades[trade_num].exit_time
|
|
208
|
+
except (IndexError, AssertionError):
|
|
209
|
+
return NA(int)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# noinspection PyProtectedMember
|
|
213
|
+
def max_drawdown(trade_num: int) -> PyneFloat:
|
|
214
|
+
"""
|
|
215
|
+
Returns the maximum drawdown of the closed trade
|
|
216
|
+
|
|
217
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
218
|
+
:return: The maximum drawdown of the closed trade
|
|
219
|
+
"""
|
|
220
|
+
if trade_num < 0:
|
|
221
|
+
return na_float
|
|
222
|
+
try:
|
|
223
|
+
assert lib._script is not None
|
|
224
|
+
assert lib._script.position is not None
|
|
225
|
+
return lib._script.position.closed_trades[trade_num].max_drawdown
|
|
226
|
+
except (IndexError, AssertionError):
|
|
227
|
+
return 0.0
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
# noinspection PyProtectedMember
|
|
231
|
+
def max_drawdown_percent(trade_num: int) -> PyneFloat:
|
|
232
|
+
"""
|
|
233
|
+
Returns the maximum drawdown percent of the closed trade
|
|
234
|
+
|
|
235
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
236
|
+
:return: The maximum drawdown percent of the closed trade
|
|
237
|
+
"""
|
|
238
|
+
if trade_num < 0:
|
|
239
|
+
return na_float
|
|
240
|
+
try:
|
|
241
|
+
assert lib._script is not None
|
|
242
|
+
assert lib._script.position is not None
|
|
243
|
+
return lib._script.position.closed_trades[trade_num].max_drawdown_percent
|
|
244
|
+
except (IndexError, AssertionError):
|
|
245
|
+
return 0.0
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# noinspection PyProtectedMember
|
|
249
|
+
def max_runup(trade_num: int) -> PyneFloat:
|
|
250
|
+
"""
|
|
251
|
+
Returns the maximum runup of the closed trade
|
|
252
|
+
|
|
253
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
254
|
+
:return: The maximum runup of the closed trade
|
|
255
|
+
"""
|
|
256
|
+
if trade_num < 0:
|
|
257
|
+
return na_float
|
|
258
|
+
try:
|
|
259
|
+
assert lib._script is not None
|
|
260
|
+
assert lib._script.position is not None
|
|
261
|
+
return lib._script.position.closed_trades[trade_num].max_runup
|
|
262
|
+
except (IndexError, AssertionError):
|
|
263
|
+
return 0.0
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
# noinspection PyProtectedMember
|
|
267
|
+
def max_runup_percent(trade_num: int) -> PyneFloat:
|
|
268
|
+
"""
|
|
269
|
+
Returns the maximum runup percent of the closed trade
|
|
270
|
+
|
|
271
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
272
|
+
:return: The maximum runup percent of the closed trade
|
|
273
|
+
"""
|
|
274
|
+
if trade_num < 0:
|
|
275
|
+
return na_float
|
|
276
|
+
try:
|
|
277
|
+
assert lib._script is not None
|
|
278
|
+
assert lib._script.position is not None
|
|
279
|
+
return lib._script.position.closed_trades[trade_num].max_runup_percent
|
|
280
|
+
except (IndexError, AssertionError):
|
|
281
|
+
return 0.0
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
# noinspection PyProtectedMember
|
|
285
|
+
def profit(trade_num: int) -> PyneFloat:
|
|
286
|
+
"""
|
|
287
|
+
Returns the profit of the closed trade
|
|
288
|
+
|
|
289
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
290
|
+
:return: The profit of the closed trade
|
|
291
|
+
"""
|
|
292
|
+
if trade_num < 0:
|
|
293
|
+
return na_float
|
|
294
|
+
try:
|
|
295
|
+
assert lib._script is not None
|
|
296
|
+
assert lib._script.position is not None
|
|
297
|
+
return lib._script.position.closed_trades[trade_num].profit
|
|
298
|
+
except (IndexError, AssertionError):
|
|
299
|
+
return 0.0
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
# noinspection PyProtectedMember
|
|
303
|
+
def profit_percent(trade_num: int) -> PyneFloat:
|
|
304
|
+
"""
|
|
305
|
+
Returns the profit percent of the closed trade
|
|
306
|
+
|
|
307
|
+
:param trade_num: The trade number of the closed trade. The number of the first trade is zero
|
|
308
|
+
:return: The profit percent of the closed trade
|
|
309
|
+
"""
|
|
310
|
+
if trade_num < 0:
|
|
311
|
+
return na_float
|
|
312
|
+
try:
|
|
313
|
+
assert lib._script is not None
|
|
314
|
+
assert lib._script.position is not None
|
|
315
|
+
return lib._script.position.closed_trades[trade_num].profit_percent
|
|
316
|
+
except (IndexError, AssertionError):
|
|
317
|
+
return 0.0
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
# noinspection PyProtectedMember
|
|
321
|
+
def size(trade_num: int) -> PyneFloat:
|
|
322
|
+
if trade_num < 0:
|
|
323
|
+
return 0.0
|
|
324
|
+
try:
|
|
325
|
+
assert lib._script is not None
|
|
326
|
+
assert lib._script.position is not None
|
|
327
|
+
return lib._script.position.closed_trades[trade_num].size
|
|
328
|
+
except (IndexError, AssertionError):
|
|
329
|
+
return 0.0
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
#
|
|
333
|
+
# Module property
|
|
334
|
+
#
|
|
335
|
+
|
|
336
|
+
# noinspection PyProtectedMember
|
|
337
|
+
@module_property
|
|
338
|
+
def closedtrades() -> int:
|
|
339
|
+
"""
|
|
340
|
+
Number of trades, which were closed for the whole trading range.
|
|
341
|
+
|
|
342
|
+
:return: The number of closed trades
|
|
343
|
+
"""
|
|
344
|
+
if lib._script is None or lib._script.position is None:
|
|
345
|
+
return 0
|
|
346
|
+
position = lib._script.position
|
|
347
|
+
return len(position.closed_trades)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from ...types import PyneFloat, PyneInt, PyneStr
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# IDE-facing view of the function-and-namespace module: bare ``strategy.closedtrades``
|
|
5
|
+
# is an int value, ``strategy.closedtrades.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 ClosedTradesModule(int):
|
|
9
|
+
|
|
10
|
+
def __call__(self) -> int: ...
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
# Functions
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
def commission(self, trade_num: int) -> PyneFloat: ...
|
|
17
|
+
|
|
18
|
+
def entry_bar_index(self, trade_num: int) -> PyneInt: ...
|
|
19
|
+
|
|
20
|
+
def entry_comment(self, trade_num: int) -> PyneStr: ...
|
|
21
|
+
|
|
22
|
+
def entry_id(self, trade_num: int) -> PyneStr: ...
|
|
23
|
+
|
|
24
|
+
def entry_price(self, trade_num: int) -> PyneFloat: ...
|
|
25
|
+
|
|
26
|
+
def entry_time(self, trade_num: int) -> PyneInt: ...
|
|
27
|
+
|
|
28
|
+
def exit_bar_index(self, trade_num: int) -> PyneInt: ...
|
|
29
|
+
|
|
30
|
+
def exit_comment(self, trade_num: int) -> PyneStr: ...
|
|
31
|
+
|
|
32
|
+
def exit_id(self, trade_num: int) -> PyneStr: ...
|
|
33
|
+
|
|
34
|
+
def exit_price(self, trade_num: int) -> PyneFloat: ...
|
|
35
|
+
|
|
36
|
+
def exit_time(self, trade_num: int) -> PyneInt: ...
|
|
37
|
+
|
|
38
|
+
def max_drawdown(self, trade_num: int) -> PyneFloat: ...
|
|
39
|
+
|
|
40
|
+
def max_drawdown_percent(self, trade_num: int) -> PyneFloat: ...
|
|
41
|
+
|
|
42
|
+
def max_runup(self, trade_num: int) -> PyneFloat: ...
|
|
43
|
+
|
|
44
|
+
def max_runup_percent(self, trade_num: int) -> PyneFloat: ...
|
|
45
|
+
|
|
46
|
+
def profit(self, trade_num: int) -> PyneFloat: ...
|
|
47
|
+
|
|
48
|
+
def profit_percent(self, trade_num: int) -> PyneFloat: ...
|
|
49
|
+
|
|
50
|
+
def size(self, trade_num: int) -> PyneFloat: ...
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
closedtrades: ClosedTradesModule
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from ...types.strategy import Oca
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Constants
|
|
5
|
+
#
|
|
6
|
+
# The string values here are the Pine-side literals; the broker layer treats
|
|
7
|
+
# them as the authoritative enum members of
|
|
8
|
+
# :class:`pynecore.core.broker.models.OcaType`. A new OCA semantic must be
|
|
9
|
+
# added in both places or the sync engine will reject the intent.
|
|
10
|
+
|
|
11
|
+
cancel = Oca("cancel")
|
|
12
|
+
reduce = Oca("reduce")
|
|
13
|
+
none = Oca("none")
|