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,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
|
pynecore/lib/polyline.py
ADDED
|
@@ -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)
|
pynecore/lib/position.py
ADDED
|
@@ -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')
|
pynecore/lib/request.py
ADDED
|
@@ -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
|
pynecore/lib/runtime.py
ADDED