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,8 @@
1
+ from ..types.pivotpointtype import PivotPointType
2
+
3
+ traditional = PivotPointType("Traditional")
4
+ fibonacci = PivotPointType("Fibonacci")
5
+ woodie = PivotPointType("Woodie")
6
+ classic = PivotPointType("Classic")
7
+ dm = PivotPointType("DM")
8
+ camarilla = PivotPointType("Camarilla")
pynecore/lib/plot.py ADDED
@@ -0,0 +1,95 @@
1
+ from typing import Any
2
+ import sys
3
+
4
+ from ..types.plot import PlotEnum, Plot
5
+ from ..types.plot_meta import PlotMeta
6
+
7
+
8
+ #
9
+ # Constants
10
+ #
11
+
12
+ style_area = PlotEnum()
13
+ style_areabr = PlotEnum()
14
+ style_circles = PlotEnum()
15
+ style_columns = PlotEnum()
16
+ style_cross = PlotEnum()
17
+ style_histogram = PlotEnum()
18
+ style_line = PlotEnum()
19
+ style_linebr = PlotEnum()
20
+ style_stepline = PlotEnum()
21
+ style_steplinebr = PlotEnum()
22
+ style_stepline_diamond = PlotEnum()
23
+
24
+ linestyle_solid = PlotEnum()
25
+ linestyle_dashed = PlotEnum()
26
+ linestyle_dotted = PlotEnum()
27
+
28
+
29
+ #
30
+ # Module function
31
+ #
32
+
33
+ # noinspection PyProtectedMember,PyShadowingBuiltins
34
+ def plot(series: Any, title: str | None = None, color: Any = None, linewidth: int = 1,
35
+ style: Any = None, trackprice: bool = False, histbase: float = 0.0, offset: int = 0,
36
+ join: bool = False, editable: bool = True, show_last: int | None = None,
37
+ display: Any = None, format: str | None = None, precision: int | None = None,
38
+ force_overlay: bool = False, *_, **__):
39
+ """
40
+ Plot a series on the chart.
41
+
42
+ :param series: The value to plot on every bar
43
+ :param title: The title of the plot; if several plots share a title a number is appended
44
+ :param color: Plot color; when it varies per bar it is recorded as a dynamic channel
45
+ :param linewidth: Width of the plotted line in pixels
46
+ :param style: Plot style (``plot.style_*``); ``None`` means Pine's ``style_line``
47
+ :param trackprice: If true, a horizontal price line is shown at the last value
48
+ :param histbase: Reference value for ``style_histogram``, ``style_columns`` and ``style_area``
49
+ :param offset: Horizontal shift of the plot, in bars
50
+ :param join: If true, ``style_circles`` / ``style_cross`` points are joined with lines
51
+ :param editable: If true, the plot style is editable in the Format dialog
52
+ :param show_last: If set, only the last ``show_last`` bars are plotted
53
+ :param display: Controls where the plot is displayed
54
+ :param format: Formatting of the plotted values (``format.price``, ``format.volume`` etc.)
55
+ :param precision: Number of decimal places for the plotted values
56
+ :param force_overlay: If true, the plot displays on the main chart pane
57
+ :return: A Plot object, used to reference the plot in other functions
58
+ """
59
+ from .. import lib
60
+ if lib._lib_semaphore:
61
+ return Plot('')
62
+
63
+ if lib.bar_index == 0: # Only check if it is the first bar for performance reasons
64
+ # Check if it is called from the main function
65
+ if sys._getframe(1).f_code.co_name != 'main': # noqa
66
+ raise RuntimeError("The plot function can only be called from the main function!")
67
+
68
+ # Ensure unique title
69
+ title: str = 'Plot' if title is None else title
70
+ # Handle duplicate titles
71
+ c = 0
72
+ t: str = title
73
+ while t in lib._plot_data:
74
+ t = title + ' ' + str(c)
75
+ c += 1
76
+
77
+ lib._plot_data[t] = series
78
+ meta = lib._plot_meta.get(t)
79
+ if meta is None:
80
+ meta = PlotMeta(id=t, kind='plot', title=t, color=color, linewidth=linewidth, style=style,
81
+ trackprice=trackprice, histbase=histbase, offset=offset, join=join,
82
+ editable=editable, show_last=show_last, display=display, format=format,
83
+ precision=precision, force_overlay=force_overlay)
84
+ lib._plot_meta[t] = meta
85
+ lib._plot_meta_new.append(meta)
86
+ if meta.dynamic:
87
+ # Once dynamic, record every bar so a return to the static color is emitted
88
+ lib._viz_dyn[t] = color
89
+ elif color is not None and color is not meta.color:
90
+ lib._viz_dyn[t] = color
91
+ meta.dynamic = True
92
+ # The static meta record is already out — re-queue an updated one.
93
+ lib._plot_meta_new.append(meta)
94
+
95
+ return Plot(t)
pynecore/lib/plot.pyi ADDED
@@ -0,0 +1,33 @@
1
+ from typing import Any
2
+
3
+ from ..types.plot import Plot
4
+ from ..types.plot import PlotEnum
5
+
6
+
7
+ # IDE-facing view of the function-and-namespace module: user code reads the
8
+ # constants and calls the bare name; the AST transformer resolves both at runtime.
9
+ class PlotModule:
10
+ style_area: PlotEnum
11
+ style_areabr: PlotEnum
12
+ style_circles: PlotEnum
13
+ style_columns: PlotEnum
14
+ style_cross: PlotEnum
15
+ style_histogram: PlotEnum
16
+ style_line: PlotEnum
17
+ style_linebr: PlotEnum
18
+ style_stepline: PlotEnum
19
+ style_steplinebr: PlotEnum
20
+ style_stepline_diamond: PlotEnum
21
+ linestyle_solid: PlotEnum
22
+ linestyle_dashed: PlotEnum
23
+ linestyle_dotted: PlotEnum
24
+
25
+ def __call__(self, series: Any, title: str | None = None, color: Any = None,
26
+ linewidth: int = 1, style: PlotEnum | None = None, trackprice: bool = False,
27
+ histbase: float = 0.0, offset: int = 0, join: bool = False, editable: bool = True,
28
+ show_last: int | None = None, display: Any = None, format: str | None = None,
29
+ precision: int | None = None, force_overlay: bool = False,
30
+ *args, **kwargs) -> Plot: ...
31
+
32
+
33
+ plot: PlotModule
@@ -0,0 +1,91 @@
1
+ from ..core.module_property import module_property
2
+ from ..types.base import next_vid
3
+ from ..types.chart import ChartPoint
4
+ from ..types.polyline import Polyline
5
+ from ..types.na import NA
6
+ from ..lib import xloc as _xloc, color as _color
7
+ from ..types.line import LineEnum
8
+ from .. import lib
9
+
10
+ _registry: dict[Polyline, None] = {}
11
+
12
+ # Line style constants (same as in line.py)
13
+ style_arrow_both = LineEnum()
14
+ style_arrow_left = LineEnum()
15
+ style_arrow_right = LineEnum()
16
+ style_dashed = LineEnum()
17
+ style_dotted = LineEnum()
18
+ style_solid = LineEnum()
19
+
20
+
21
+ # noinspection PyProtectedMember
22
+ def new(points: list[ChartPoint], curved: bool = False, closed: bool = False,
23
+ xloc: _xloc.XLoc = _xloc.bar_index, line_color: _color.Color = _color.blue,
24
+ fill_color: _color.Color | None = None, line_style: LineEnum = style_solid,
25
+ line_width: int = 1, force_overlay: bool = False) -> Polyline | NA[Polyline]:
26
+ """
27
+ Creates a new polyline instance and displays it on the chart, sequentially connecting all of the
28
+ points in the points array with line segments.
29
+
30
+ :param points: An array of chart.point objects for the drawing to sequentially connect
31
+ :param curved: If true, the drawing will connect all points using curved line segments
32
+ :param closed: If true, the drawing will connect the first point to the last point, resulting in a closed polyline
33
+ :param xloc: Determines the field of the chart.point objects that the polyline will use for its x-coordinates
34
+ :param line_color: The color of the line segments
35
+ :param fill_color: The fill color of the polyline
36
+ :param line_style: The style of the polyline
37
+ :param line_width: The width of the line segments, expressed in pixels
38
+ :param force_overlay: If true, the drawing will display on the main chart pane
39
+ :return: The ID of a new polyline object
40
+ """
41
+ if not points or len(points) == 0:
42
+ return NA(Polyline)
43
+
44
+ # Check if any points are NA
45
+ for point in points:
46
+ if isinstance(point, NA):
47
+ return NA(Polyline)
48
+
49
+ polyline_obj = Polyline(
50
+ points=points,
51
+ curved=curved,
52
+ closed=closed,
53
+ xloc=xloc,
54
+ line_color=line_color,
55
+ fill_color=fill_color,
56
+ line_style=line_style,
57
+ line_width=line_width,
58
+ force_overlay=force_overlay
59
+ )
60
+ polyline_obj.vid = next_vid()
61
+ _registry[polyline_obj] = None
62
+ # Enforce Pine's max_polylines_count cap: drop the oldest polyline (FIFO) past the limit.
63
+ # A security child never sets ``lib._script``; fall back to TV's hard maximum
64
+ # (500) there, otherwise the registry grows without bound (the child re-runs
65
+ # main() for every bar of its own series, accumulating every drawing ever made).
66
+ if len(_registry) > (lib._script.max_polylines_count if lib._script is not None else 500):
67
+ del _registry[next(iter(_registry))]
68
+ return polyline_obj
69
+
70
+
71
+ # noinspection PyShadowingBuiltins
72
+ def delete(id: Polyline) -> None:
73
+ """
74
+ Deletes the specified polyline object. It has no effect if the id doesn't exist.
75
+
76
+ :param id: The polyline ID to delete
77
+ """
78
+ if isinstance(id, NA):
79
+ return
80
+ _registry.pop(id, None)
81
+
82
+
83
+ # noinspection PyShadowingBuiltins
84
+ @module_property
85
+ def all() -> list[Polyline]:
86
+ """
87
+ Returns an array containing all current polyline instances drawn by the script.
88
+
89
+ :return: Array of all polyline objects
90
+ """
91
+ return list(_registry)
@@ -0,0 +1,15 @@
1
+ from ..types.position import Position
2
+
3
+ #
4
+ # Constants
5
+ #
6
+
7
+ bottom_center = Position('bottom_center')
8
+ bottom_left = Position('bottom_left')
9
+ bottom_right = Position('bottom_right')
10
+ middle_center = Position('middle_center')
11
+ middle_left = Position('middle_left')
12
+ middle_right = Position('middle_right')
13
+ top_center = Position('top_center')
14
+ top_left = Position('top_left')
15
+ top_right = Position('top_right')
@@ -0,0 +1,281 @@
1
+ from __future__ import annotations
2
+
3
+ from math import nan
4
+ from typing import TYPE_CHECKING, Any, TypeVar, overload
5
+
6
+ from ..types.footprint import Footprint
7
+ from ..types.na import NA
8
+
9
+ if TYPE_CHECKING:
10
+ from ..core.currency import CurrencyRateProvider
11
+
12
+ _currency_provider: CurrencyRateProvider | None = None
13
+
14
+ T = TypeVar('T')
15
+
16
+
17
+ # noinspection PyUnusedLocal
18
+ def security(symbol, timeframe, expression: T, *args, **kwargs) -> T:
19
+ """
20
+ Request data from another symbol/timeframe.
21
+
22
+ Pine v6 positional signature:
23
+ ``security(symbol, timeframe, expression, gaps, lookahead,
24
+ ignore_invalid_symbol, currency, ...)``.
25
+
26
+ Supported ``lookahead`` modes:
27
+
28
+ - ``barmerge.lookahead_off`` (default): closed-only — the security
29
+ context shows the most recently CLOSED security bar in both
30
+ historical and live mode. Repaint-free.
31
+ - ``barmerge.lookahead_last_closed``: PyneSys-native synonym for
32
+ "last closed" in any mode. Functionally identical to
33
+ ``lookahead_off`` in PyneCore; prefer it when "last closed" is the
34
+ explicit intent (no reliance on the TV ``close[1]`` idiom).
35
+ - ``barmerge.lookahead_on``: TV-compatible. Same-symbol HTF: the
36
+ security context steps into the containing HTF bar. In live mode the
37
+ developing bar runs with ``barstate.isconfirmed=False`` and OHLCV
38
+ aggregated from the chart timeframe; in historical/backtest mode the
39
+ containing bar is already complete in the data file, so a bare
40
+ ``close`` reads its final value (TV's classical future-leak) while an
41
+ inner ``close[1]`` reads the just-closed prior period — the daily-pivot
42
+ idiom ``security(sym, "D", close[1], lookahead_on)``. Cross-symbol HTF:
43
+ the developing bar cannot be aggregated (wrong instrument), so the
44
+ chart bar inside an open HTF period reads as ``na``; ``close[1]`` at
45
+ the period boundary still delivers the just-closed cross-symbol HTF
46
+ close, so the idiom continues to work.
47
+
48
+ This function exists for IDE support only. In compiled scripts, the
49
+ SecurityTransformer rewrites all calls into the signal/write/read
50
+ protocol at AST level — this function is never called at runtime.
51
+ """
52
+ raise RuntimeError(
53
+ "request.security() should not be called directly. "
54
+ "It is rewritten by SecurityTransformer during compilation."
55
+ )
56
+
57
+
58
+ # noinspection PyUnusedLocal
59
+ @overload
60
+ def security_lower_tf(
61
+ symbol, timeframe, expression: tuple,
62
+ ignore_invalid_symbol=False, currency=None,
63
+ ignore_invalid_timeframe=False, calc_bars_count=None,
64
+ ) -> tuple[list, ...]: ...
65
+
66
+
67
+ # noinspection PyUnusedLocal
68
+ @overload
69
+ def security_lower_tf(
70
+ symbol, timeframe, expression: T,
71
+ ignore_invalid_symbol=False, currency=None,
72
+ ignore_invalid_timeframe=False, calc_bars_count=None,
73
+ ) -> list[T]: ...
74
+
75
+
76
+ # noinspection PyUnusedLocal
77
+ def security_lower_tf(
78
+ symbol, timeframe, expression,
79
+ ignore_invalid_symbol=False, currency=None,
80
+ ignore_invalid_timeframe=False, calc_bars_count=None,
81
+ ) -> Any:
82
+ """
83
+ Request intrabar data from a lower timeframe.
84
+
85
+ Returns an array of values, one per intrabar within each chart bar; a tuple
86
+ expression yields a tuple of such arrays, one per tuple element.
87
+ This function exists for IDE support only. In compiled scripts, the
88
+ SecurityTransformer rewrites all calls into the LTF signal/write/read
89
+ protocol at AST level — this function is never called at runtime.
90
+
91
+ :param symbol: Symbol to request data from
92
+ :param timeframe: Lower timeframe string (must be <= chart timeframe)
93
+ :param expression: Expression to evaluate in the lower timeframe context
94
+ :param ignore_invalid_symbol: If True, return empty array for invalid symbols
95
+ :param currency: Currency for conversion (not yet supported)
96
+ :param ignore_invalid_timeframe: If True, ignore invalid timeframe
97
+ :param calc_bars_count: Number of bars to calculate (not yet supported)
98
+ :return: array of expression values per intrabar
99
+ """
100
+ raise RuntimeError(
101
+ "request.security_lower_tf() should not be called directly. "
102
+ "It is rewritten by SecurityTransformer during compilation."
103
+ )
104
+
105
+
106
+ def currency_rate(from_currency: str, to_currency: str) -> float:
107
+ """
108
+ Get the currency conversion rate between two currencies.
109
+
110
+ Returns the exchange rate to convert from ``from_currency`` to ``to_currency``
111
+ at the current bar's timestamp. The rate is looked up from OHLCV data files
112
+ whose TOML metadata matches the requested currency pair.
113
+
114
+ :param from_currency: Source currency code (e.g. ``"EUR"``, ``currency.EUR``)
115
+ :param to_currency: Target currency code (e.g. ``"USD"``, ``currency.USD``)
116
+ :return: Exchange rate as float, or ``na`` if no data is available
117
+ """
118
+ if _currency_provider is None:
119
+ return nan
120
+ from .. import lib
121
+ # noinspection PyProtectedMember
122
+ timestamp = int(lib._datetime.timestamp())
123
+ return _currency_provider.get_rate(str(from_currency), str(to_currency), timestamp)
124
+
125
+
126
+ # noinspection PyUnusedLocal
127
+ def dividends(
128
+ ticker=None, field=None, gaps=None, lookahead=None,
129
+ ignore_invalid_symbol=False,
130
+ ) -> float:
131
+ """
132
+ Request dividend data for a symbol.
133
+
134
+ :param ticker: Symbol ticker
135
+ :param field: Dividend field (dividends.gross, dividends.net)
136
+ :param gaps: Gap handling mode (barmerge.gaps_on/off)
137
+ :param lookahead: Lookahead mode (barmerge.lookahead_on/off)
138
+ :param ignore_invalid_symbol: If True, return na instead of raising
139
+ :return: Dividend value or na
140
+ :raises NotImplementedError: When ignore_invalid_symbol is False
141
+ """
142
+ if ignore_invalid_symbol:
143
+ return nan
144
+ raise NotImplementedError("request.dividends() is not yet implemented in PyneCore")
145
+
146
+
147
+ # noinspection PyUnusedLocal
148
+ def splits(
149
+ ticker=None, field=None, gaps=None, lookahead=None,
150
+ ignore_invalid_symbol=False,
151
+ ) -> float:
152
+ """
153
+ Request stock split data for a symbol.
154
+
155
+ :param ticker: Symbol ticker
156
+ :param field: Split field (splits.numerator, splits.denominator)
157
+ :param gaps: Gap handling mode (barmerge.gaps_on/off)
158
+ :param lookahead: Lookahead mode (barmerge.lookahead_on/off)
159
+ :param ignore_invalid_symbol: If True, return na instead of raising
160
+ :return: Split value or na
161
+ :raises NotImplementedError: When ignore_invalid_symbol is False
162
+ """
163
+ if ignore_invalid_symbol:
164
+ return nan
165
+ raise NotImplementedError("request.splits() is not yet implemented in PyneCore")
166
+
167
+
168
+ # noinspection PyUnusedLocal
169
+ def earnings(
170
+ ticker=None, field=None, gaps=None, lookahead=None,
171
+ ignore_invalid_symbol=False,
172
+ ) -> float:
173
+ """
174
+ Request earnings data for a symbol.
175
+
176
+ :param ticker: Symbol ticker
177
+ :param field: Earnings field (earnings.actual, earnings.estimate, earnings.standardized)
178
+ :param gaps: Gap handling mode (barmerge.gaps_on/off)
179
+ :param lookahead: Lookahead mode (barmerge.lookahead_on/off)
180
+ :param ignore_invalid_symbol: If True, return na instead of raising
181
+ :return: Earnings value or na
182
+ :raises NotImplementedError: When ignore_invalid_symbol is False
183
+ """
184
+ if ignore_invalid_symbol:
185
+ return nan
186
+ raise NotImplementedError("request.earnings() is not yet implemented in PyneCore")
187
+
188
+
189
+ # noinspection PyUnusedLocal
190
+ def financial(
191
+ symbol=None, financial_id=None, period=None, gaps=None,
192
+ ignore_invalid_symbol=False, currency=None,
193
+ ) -> float:
194
+ """
195
+ Request financial data from FactSet.
196
+
197
+ :param symbol: Symbol ticker
198
+ :param financial_id: Financial metric id (e.g. "MARKET_CAP_BASIC")
199
+ :param period: Reporting period ("FQ", "FH", "FY", "TTM", "D")
200
+ :param gaps: Gap handling mode (barmerge.gaps_on/off)
201
+ :param ignore_invalid_symbol: If True, return na instead of raising
202
+ :param currency: Currency for conversion
203
+ :return: Financial value or na
204
+ :raises NotImplementedError: When ignore_invalid_symbol is False
205
+ """
206
+ if ignore_invalid_symbol:
207
+ return nan
208
+ raise NotImplementedError("request.financial() is not yet implemented in PyneCore")
209
+
210
+
211
+ # noinspection PyUnusedLocal
212
+ def economic(*args, **kwargs) -> float:
213
+ """
214
+ Request economic data.
215
+
216
+ :raises NotImplementedError: Not yet implemented in PyneCore
217
+ """
218
+ raise NotImplementedError("request.economic() is not yet implemented in PyneCore")
219
+
220
+
221
+ # noinspection PyUnusedLocal
222
+ def quandl(*args, **kwargs) -> float:
223
+ """
224
+ Request data from Quandl/Nasdaq.
225
+
226
+ :raises NotImplementedError: Not yet implemented in PyneCore
227
+ """
228
+ raise NotImplementedError("request.quandl() is not yet implemented in PyneCore")
229
+
230
+
231
+ # noinspection PyUnusedLocal
232
+ def seed(source=None, symbol=None, expression=None,
233
+ ignore_invalid_symbol=False, calc_bars_count=None):
234
+ """
235
+ Request data from user-maintained GitHub repositories.
236
+
237
+ Seed data lives in TradingView-hosted community repositories that PyneCore
238
+ has no access to — like :func:`footprint`, the data is fundamentally
239
+ unavailable, so the call returns ``na`` instead of aborting the script;
240
+ well-written scripts guard their seed series with ``na()`` checks.
241
+
242
+ :param source: Seed repository name (e.g. "seed_crypto_santiment")
243
+ :param symbol: Data series name within the repository
244
+ :param expression: Expression to evaluate in the seed context
245
+ :param ignore_invalid_symbol: If True, return na for invalid symbols
246
+ :param calc_bars_count: Number of bars to calculate (unused)
247
+ :return: na — seed data is not available in PyneCore. When ``expression`` is a
248
+ tuple of series (e.g. ``request.seed(id, sym, [close, ta.sma(close, 10)])``),
249
+ Pine returns a tuple, so return a tuple of ``na`` of the same arity to keep
250
+ the tuple destructuring valid; ``na()``-guarding scripts then see na as usual.
251
+ """
252
+ if isinstance(expression, (list, tuple)):
253
+ return tuple(NA(None) for _ in expression)
254
+ return NA(None)
255
+
256
+
257
+ # noinspection PyUnusedLocal
258
+ def footprint(ticks_per_row: int, va_percent: int = 70,
259
+ imbalance_percent: int = 300) -> Footprint | NA[Footprint]:
260
+ """
261
+ Request volume footprint data for the current bar.
262
+
263
+ Footprint order flow (per-tick buy/sell aggressor split, POC, VAH, VAL) is
264
+ sourced by TradingView from tick-level bid/ask data that PyneCore does not
265
+ have — only OHLCV bars are available. Rather than aborting the whole script,
266
+ the footprint is reported as ``na`` so that scripts guarding their footprint
267
+ reads with ``na()`` (the required Pine pattern, since TV itself returns na
268
+ when footprint data is unavailable) fall back to their price-action paths.
269
+
270
+ :param ticks_per_row: Number of ticks per footprint row
271
+ :param va_percent: Value Area percentage
272
+ :param imbalance_percent: Buy/sell imbalance threshold percentage
273
+ :return: ``na`` footprint (order-flow data unavailable in PyneCore)
274
+ """
275
+ return NA(Footprint)
276
+
277
+
278
+ def _reset_request_state() -> None:
279
+ """Reset request module state between script runs."""
280
+ global _currency_provider
281
+ _currency_provider = None
@@ -0,0 +1,5 @@
1
+ def error(message: str):
2
+ """
3
+ Stop running script with an error message
4
+ """
5
+ raise RuntimeError(message)
pynecore/lib/scale.py ADDED
@@ -0,0 +1,9 @@
1
+ from ..types.scale import Scale
2
+
3
+ #
4
+ # Constants
5
+ #
6
+
7
+ left = Scale()
8
+ none = Scale()
9
+ right = Scale()