@dsh-ft/dsh-fft-paper-trading 0.6.0 → 0.6.2
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.
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/agent/format.d.ts.map +1 -1
- package/lib/agent/format.js +4 -0
- package/lib/agent/format.js.map +1 -1
- package/lib/agent/tools.d.ts.map +1 -1
- package/lib/agent/tools.js +5 -3
- package/lib/agent/tools.js.map +1 -1
- package/lib/client.js +76 -13
- package/lib/contract.d.ts.map +1 -1
- package/lib/contract.js +3 -1
- package/lib/contract.js.map +1 -1
- package/lib/core/risk.d.ts.map +1 -1
- package/lib/core/risk.js +10 -2
- package/lib/core/risk.js.map +1 -1
- package/lib/core/views.js +2 -2
- package/lib/core/views.js.map +1 -1
- package/lib/data/ftshare-trading-calendar.d.ts +47 -12
- package/lib/data/ftshare-trading-calendar.d.ts.map +1 -1
- package/lib/data/ftshare-trading-calendar.js +156 -44
- package/lib/data/ftshare-trading-calendar.js.map +1 -1
- package/lib/service/paper-service.d.ts +1 -1
- package/lib/service/paper-service.d.ts.map +1 -1
- package/lib/service/paper-service.js +24 -12
- package/lib/service/paper-service.js.map +1 -1
- package/lib/service/rpc.d.ts.map +1 -1
- package/lib/service/rpc.js +12 -1
- package/lib/service/rpc.js.map +1 -1
- package/node_modules/@ftshare-lab/dsh-kline/CHANGELOG.md +98 -0
- package/node_modules/@ftshare-lab/dsh-kline/README.en.md +116 -26
- package/node_modules/@ftshare-lab/dsh-kline/README.md +125 -25
- package/node_modules/@ftshare-lab/dsh-kline/chart_service.py +38 -0
- package/node_modules/@ftshare-lab/dsh-kline/cordis.patch.yml +3 -9
- package/node_modules/@ftshare-lab/dsh-kline/core/calc.py +63 -269
- package/node_modules/@ftshare-lab/dsh-kline/core/rows.py +15 -3
- package/node_modules/@ftshare-lab/dsh-kline/core/ta_engine.py +99 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/candle-sequence.js +15 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-annotations.js +33 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-applications.js +1 -1
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-context.js +12 -3
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-observation.js +91 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/chart-sources.js +64 -13
- package/node_modules/@ftshare-lab/dsh-kline/lib/client.js +3356 -787
- package/node_modules/@ftshare-lab/dsh-kline/lib/drawing-feedback.js +96 -19
- package/node_modules/@ftshare-lab/dsh-kline/lib/fibonacci.js +18 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/index.js +19 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/labeled-polyline.js +17 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/price-bands.js +55 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/price-series.js +47 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/price-sticks.js +32 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/candle-sequence.d.ts +2 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-annotations.d.ts +4 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-context.d.ts +1 -1
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/chart-observation.d.ts +2 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/BetterSidebarTab.d.ts +3 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/ClassicShell.d.ts +1 -1
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/chart-context.d.ts +1 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/client-context.d.ts +14 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/conversation.d.ts +11 -3
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/embed.d.ts +2 -2
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/generated-view.d.ts +1 -1
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/host-services.d.ts +0 -36
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/index.d.ts +2 -1
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-contract.d.ts +35 -4
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-register.d.ts +46 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar-services.d.ts +45 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/client/native-sidebar.d.ts +21 -36
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/fibonacci.d.ts +5 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/labeled-polyline.d.ts +11 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-bands.d.ts +3 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-series.d.ts +5 -0
- package/node_modules/@ftshare-lab/dsh-kline/lib/types/price-sticks.d.ts +3 -0
- package/node_modules/@ftshare-lab/dsh-kline/package.json +27 -5
- package/node_modules/@ftshare-lab/dsh-kline/requirements.txt +2 -0
- package/node_modules/@ftshare-lab/dsh-kline/scripts/dsh-mcp-plugin.mjs +27 -0
- package/node_modules/@ftshare-lab/dsh-kline/scripts/run-dsh-kline.mjs +180 -49
- package/node_modules/@ftshare-lab/dsh-kline/server.py +300 -34
- package/node_modules/@ftshare-lab/dsh-kline/tools/annotations.py +119 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/baostock_source.py +176 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/channel_candidates.py +260 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_applications.py +1 -1
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_context.py +22 -3
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_edits.py +141 -16
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_functions.py +466 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/chart_indicators.py +63 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/draw.py +3 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_feedback.py +13 -7
- package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_interaction.py +117 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/drawing_verification.py +58 -3
- package/node_modules/@ftshare-lab/dsh-kline/tools/fetch.py +164 -40
- package/node_modules/@ftshare-lab/dsh-kline/tools/fibonacci.py +83 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/free_sources.py +78 -21
- package/node_modules/@ftshare-lab/dsh-kline/tools/pivots.py +60 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/polylines.py +125 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/price_bands.py +165 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/price_series.py +162 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/price_sticks.py +114 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/range_candidates.py +170 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/regression_channels.py +87 -0
- package/node_modules/@ftshare-lab/dsh-kline/tools/ta_functions.py +228 -0
- package/package.json +3 -3
- package/src/agent/format.ts +3 -0
- package/src/agent/tools.ts +5 -3
- package/src/client/index.js +75 -12
- package/src/contract.ts +3 -1
- package/src/core/risk.ts +10 -2
- package/src/core/views.ts +2 -2
- package/src/data/ftshare-trading-calendar.ts +184 -45
- package/src/service/paper-service.ts +22 -19
- package/src/service/rpc.ts +12 -1
|
@@ -5,7 +5,7 @@ from copy import deepcopy
|
|
|
5
5
|
import hashlib
|
|
6
6
|
import json
|
|
7
7
|
import os
|
|
8
|
-
from typing import Any, Literal
|
|
8
|
+
from typing import Annotated, Any, Literal
|
|
9
9
|
|
|
10
10
|
from pydantic import BaseModel, ConfigDict, Field
|
|
11
11
|
|
|
@@ -16,14 +16,22 @@ from tools.lines import ColorInput, LINE_COMMAND, LineError, edit_horizontal_lin
|
|
|
16
16
|
from tools.trend_lines import TREND_COMMAND, edit_trend_line
|
|
17
17
|
from tools.channels import CHANNEL_COMMAND, edit_channel
|
|
18
18
|
from tools.rectangles import RECTANGLE_COMMAND, edit_rectangle
|
|
19
|
+
from tools.fibonacci import FIBONACCI_COMMAND, edit_fibonacci
|
|
20
|
+
from tools.polylines import LabeledPoint, POLYLINE_COMMAND, edit_polyline, normalize_point_label
|
|
21
|
+
from tools.annotations import ANNOTATION_COMMAND, ANNOTATION_KINDS, edit_annotation
|
|
22
|
+
from tools.price_series import SERIES_COMMAND, edit_price_series
|
|
23
|
+
from tools.price_bands import BAND_COMMAND, edit_price_band
|
|
24
|
+
from tools.price_sticks import STICKS_COMMAND, edit_price_sticks
|
|
19
25
|
|
|
20
26
|
KINDS = {LINE_COMMAND: "horizontal_line", TREND_COMMAND: "trend_line",
|
|
21
|
-
CHANNEL_COMMAND: "channel", RECTANGLE_COMMAND: "rectangle"
|
|
27
|
+
CHANNEL_COMMAND: "channel", RECTANGLE_COMMAND: "rectangle", FIBONACCI_COMMAND: "fibonacci_retracement",
|
|
28
|
+
POLYLINE_COMMAND: "labeled_polyline", ANNOTATION_COMMAND: "annotation", SERIES_COMMAND: "series_line",
|
|
29
|
+
BAND_COMMAND: "price_band", STICKS_COMMAND: "price_sticks"}
|
|
22
30
|
|
|
23
31
|
|
|
24
32
|
class ChartEdit(BaseModel):
|
|
25
33
|
model_config = ConfigDict(extra="forbid")
|
|
26
|
-
kind: Literal["horizontal_line", "trend_line", "channel", "rectangle"]
|
|
34
|
+
kind: Literal["horizontal_line", "trend_line", "channel", "rectangle", "fibonacci_retracement", "labeled_polyline", "text_annotation", "number_annotation", "icon_annotation", "series_line", "price_band", "price_sticks", "all_drawings"]
|
|
27
35
|
action: Literal["create", "update", "delete"]
|
|
28
36
|
object_id: str | None = Field(default=None, min_length=1, max_length=128,
|
|
29
37
|
description="修改/删除使用当前观察中的 AI 稳定 ID;创建不填")
|
|
@@ -40,24 +48,69 @@ class ChartEdit(BaseModel):
|
|
|
40
48
|
upper_price: float | None = Field(default=None, gt=0, allow_inf_nan=False, strict=True)
|
|
41
49
|
show_midline: bool | None = Field(default=None, strict=True)
|
|
42
50
|
show_fill: bool | None = Field(default=None, strict=True)
|
|
51
|
+
points: list[LabeledPoint] | None = Field(default=None, min_length=2, max_length=8, description="仅用于创建标注折线,续改用单点字段")
|
|
52
|
+
point_label: str | None = Field(default=None, min_length=1, max_length=16, description="更新该对象内的唯一点名,不按索引猜点")
|
|
53
|
+
point_time: str | None = None
|
|
54
|
+
point_price: float | None = Field(default=None, gt=0, allow_inf_nan=False, strict=True)
|
|
55
|
+
anchor_time: str | None = Field(default=None, description="标注锚定的已加载K线日期/时间")
|
|
56
|
+
anchor_price: float | None = Field(default=None, gt=0, allow_inf_nan=False, strict=True)
|
|
57
|
+
annotation_text: str | None = Field(default=None, max_length=120, description="文字标注内容")
|
|
58
|
+
annotation_value: float | None = Field(default=None, allow_inf_nan=False, strict=True, description="数值标注内容,可为负数或零")
|
|
59
|
+
annotation_icon: Literal["arrow_up", "arrow_down", "diamond"] | None = Field(default=None, description="图标标注:向上箭头、向下箭头或菱形")
|
|
60
|
+
ratios: list[Annotated[float, Field(strict=True, ge=0, le=1, allow_inf_nan=False)]] | None = Field(default=None, min_length=1, max_length=16)
|
|
61
|
+
result_ref: str | None = Field(default=None, pattern=r"^[a-f0-9]{64}$",
|
|
62
|
+
description="run_chart_function 返回的结果引用;不能同时指定锚点、边界或比例。名称、颜色可另填。")
|
|
63
|
+
ta_result_ref: str | None = Field(default=None, pattern=r"^[a-f0-9]{64}$",
|
|
64
|
+
description="明确选择同一当前图的 SMA/EMA(close) 到 series_line,或 BBANDS(close) 三线到 price_band;不自动绘图。")
|
|
65
|
+
candidate_result_ref: str | None = Field(default=None, pattern=r"^[a-f0-9]{64}$",
|
|
66
|
+
description="通道/平台候选函数返回的只读引用;只有用户明确选定候选后才能用来创建图形")
|
|
67
|
+
candidate_number: int | None = Field(default=None, strict=True, ge=1, le=5,
|
|
68
|
+
description="用户选择的候选序号,从1开始;必须与 candidate_result_ref 同时提供")
|
|
69
|
+
user_confirmed_candidate: bool | None = Field(default=None, strict=True,
|
|
70
|
+
description="仅当用户明确确认该候选才填 true;候选函数不会自动绘图")
|
|
43
71
|
|
|
44
72
|
|
|
45
73
|
def edit_parameters(edit: ChartEdit) -> dict[str, Any]:
|
|
46
74
|
fields = edit.model_dump(exclude_none=True)
|
|
47
75
|
for key in ("kind", "action", "object_id"): fields.pop(key, None)
|
|
48
|
-
supported = {"name", "color"} | {
|
|
76
|
+
supported = {"name", "color", "result_ref", "ta_result_ref", "candidate_result_ref", "candidate_number", "user_confirmed_candidate"} | {
|
|
49
77
|
"horizontal_line": {"price"},
|
|
50
78
|
"trend_line": {"start_time", "end_time", "start_price", "end_price"},
|
|
51
79
|
"channel": {"start_time", "end_time", "start_price", "end_price", "parallel_time", "parallel_price", "show_midline"},
|
|
52
80
|
"rectangle": {"start_time", "end_time", "lower_price", "upper_price", "show_fill"},
|
|
81
|
+
"fibonacci_retracement": {"start_time", "end_time", "start_price", "end_price", "ratios"},
|
|
82
|
+
"labeled_polyline": {"points", "point_label", "point_time", "point_price"},
|
|
83
|
+
"text_annotation": {"anchor_time", "anchor_price", "annotation_text"},
|
|
84
|
+
"number_annotation": {"anchor_time", "anchor_price", "annotation_value"},
|
|
85
|
+
"icon_annotation": {"anchor_time", "anchor_price", "annotation_icon"},
|
|
86
|
+
"series_line": set(),
|
|
87
|
+
"price_band": set(),
|
|
88
|
+
"price_sticks": set(),
|
|
89
|
+
"all_drawings": set(),
|
|
53
90
|
}[edit.kind]
|
|
54
91
|
if fields.keys() - supported or edit.action == "delete" and fields:
|
|
55
|
-
raise LineError("invalid_edit_fields", "参数不适用于该图形;删除只填类型、action
|
|
56
|
-
if edit.
|
|
92
|
+
raise LineError("invalid_edit_fields", "参数不适用于该图形;删除只填类型、action,单对象删除另填 object_id。")
|
|
93
|
+
if edit.kind == "labeled_polyline" and edit.action != "create" and (edit.result_ref is not None or edit.points is not None):
|
|
94
|
+
raise LineError("polyline_replacement_not_supported", "标注折线续改使用 point_label 和 point_time / point_price;名称 / 颜色可另填,不重写整组。")
|
|
95
|
+
if edit.result_ref is not None and (edit.kind not in {"fibonacci_retracement", "channel", "rectangle", "labeled_polyline", "series_line", "price_band", "price_sticks", *ANNOTATION_KINDS}
|
|
96
|
+
or fields.keys() - {"result_ref", "name", "color", "show_midline", "show_fill"}):
|
|
97
|
+
raise LineError("conflicting_function_parameters", "结果引用与直接锚点、边界或比例互斥;请修改参数后重新运行函数。")
|
|
98
|
+
if edit.ta_result_ref is not None and (edit.kind not in {"series_line", "price_band"} or edit.action not in {"create", "update"}
|
|
99
|
+
or fields.keys() - {"ta_result_ref", "name", "color"}):
|
|
100
|
+
raise LineError("ta_result_not_drawable", "仅允许把明确选定的 SMA/EMA 单线或 BBANDS 三线结果创建或更新为对应图形。")
|
|
101
|
+
candidate_fields = {"candidate_result_ref", "candidate_number", "user_confirmed_candidate"}
|
|
102
|
+
if fields.keys() & candidate_fields and (edit.action != "create" or edit.kind not in {"channel", "rectangle"}
|
|
103
|
+
or not candidate_fields <= fields.keys() or edit.user_confirmed_candidate is not True
|
|
104
|
+
or fields.keys() - candidate_fields - {"name", "color", "show_midline", "show_fill"}):
|
|
105
|
+
raise LineError("candidate_confirmation_required", "只有用户明确选定通道/平台候选及序号后才能创建;不能混用直接锚点或其他结果引用。")
|
|
106
|
+
if edit.kind == "all_drawings" and (edit.action != "delete" or edit.object_id is not None):
|
|
107
|
+
raise LineError("invalid_object_identity", "清空当前图只使用 all_drawings/delete,不指定单个对象 ID。")
|
|
108
|
+
if edit.kind != "all_drawings" and (edit.action == "create" and edit.object_id is not None or edit.action != "create" and edit.object_id is None):
|
|
57
109
|
raise LineError("invalid_object_identity", "创建不指定 object_id;修改/删除必须使用当前观察中的完整 AI ID。")
|
|
58
110
|
_, name, color = validate_line_fields(name=edit.name, color=edit.color)
|
|
59
111
|
if "name" in fields: fields["name"] = name
|
|
60
112
|
if "color" in fields: fields["color"] = color
|
|
113
|
+
if "point_label" in fields: fields["point_label"] = normalize_point_label(fields["point_label"])
|
|
61
114
|
return fields
|
|
62
115
|
|
|
63
116
|
|
|
@@ -65,16 +118,27 @@ def snapshot_inventory(payload: dict) -> list[dict]:
|
|
|
65
118
|
"""Same canonical AI fields exposed by the browser collector; no manual objects."""
|
|
66
119
|
inventory = []
|
|
67
120
|
for cmd in payload.get("chartCommands", []):
|
|
68
|
-
kind = KINDS.get(cmd.get("type"))
|
|
121
|
+
kind = cmd.get("kind") if cmd.get("type") == ANNOTATION_COMMAND and cmd.get("kind") in ANNOTATION_KINDS else KINDS.get(cmd.get("type"))
|
|
69
122
|
if not kind: continue
|
|
70
123
|
item = {"id": cmd.get("id"), "kind": kind, "origin": "ai", "name": cmd.get("label", ""),
|
|
71
124
|
"color": cmd.get("color", "info"), "interval": cmd.get("interval", payload.get("interval"))}
|
|
72
125
|
if kind == "horizontal_line": item["price"] = cmd["price"]
|
|
73
126
|
elif kind == "rectangle":
|
|
74
127
|
item.update({k: cmd[k] for k in ("start_time", "end_time", "lower_price", "upper_price", "show_fill")})
|
|
128
|
+
elif kind == "labeled_polyline": item["points"] = deepcopy(cmd["points"])
|
|
129
|
+
elif kind == "series_line": item.update(series_hash=cmd["series_hash"], bar_count=cmd["bar_count"])
|
|
130
|
+
elif kind == "price_band": item.update(band_hash=cmd["band_hash"], bar_count=cmd["bar_count"])
|
|
131
|
+
elif kind == "price_sticks": item.update(sticks_hash=cmd["sticks_hash"], bar_count=cmd["bar_count"])
|
|
132
|
+
elif kind in ANNOTATION_KINDS:
|
|
133
|
+
item.update(time=cmd["time"], price=cmd["price"])
|
|
134
|
+
if kind == "text_annotation": item["text"] = cmd["text"]
|
|
135
|
+
elif kind == "number_annotation": item["value"] = cmd["value"]
|
|
136
|
+
else: item["icon"] = cmd["icon"]
|
|
75
137
|
else:
|
|
76
138
|
item["points"] = [cmd["from"], cmd["to"]] + ([cmd["parallel"]] if kind == "channel" else [])
|
|
77
139
|
if kind == "channel": item["show_midline"] = cmd["show_midline"]
|
|
140
|
+
if kind == "fibonacci_retracement":
|
|
141
|
+
item.update(ratios=deepcopy(cmd["ratios"]), levels=deepcopy(cmd["levels"]))
|
|
78
142
|
inventory.append(item)
|
|
79
143
|
return inventory
|
|
80
144
|
|
|
@@ -115,6 +179,24 @@ def _hash(value: Any) -> str:
|
|
|
115
179
|
return hashlib.sha256(json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":"), allow_nan=False).encode()).hexdigest()
|
|
116
180
|
|
|
117
181
|
|
|
182
|
+
def _public_edit_object(kind: str, obj: dict) -> dict:
|
|
183
|
+
if kind not in {"series_line", "price_band", "price_sticks"}:
|
|
184
|
+
return obj
|
|
185
|
+
# Sequence values stay in the candidate snapshot. The host only needs a
|
|
186
|
+
# stable identity, provenance and a checkable count/hash.
|
|
187
|
+
fields = {
|
|
188
|
+
"series_line": ("series_hash", "values"),
|
|
189
|
+
"price_band": ("band_hash", "upper_values"),
|
|
190
|
+
"price_sticks": ("sticks_hash", "start_values"),
|
|
191
|
+
}
|
|
192
|
+
digest_field, count_field = fields[kind]
|
|
193
|
+
visible = ("type", "id", "interval", "bar_count", "row_hash", digest_field,
|
|
194
|
+
"source", "upper_source", "lower_source", "start_source", "end_source",
|
|
195
|
+
"condition", "label", "color")
|
|
196
|
+
return {key: deepcopy(obj[key]) for key in visible if key in obj} | {
|
|
197
|
+
"valid_bars": sum(value is not None for value in obj[count_field])}
|
|
198
|
+
|
|
199
|
+
|
|
118
200
|
def prepare_chart_edit(context_ref: str, expected_revision: int, chart_session: str, symbol: str,
|
|
119
201
|
request_id: str, edit: ChartEdit, *, publish=None) -> dict:
|
|
120
202
|
"""Prepare at most one candidate per observed revision; durable fail-closed retry journal.
|
|
@@ -130,8 +212,23 @@ def prepare_chart_edit(context_ref: str, expected_revision: int, chart_session:
|
|
|
130
212
|
context = read_chart_context(context_ref, candle_scope="loaded", limit=4000)
|
|
131
213
|
if context["revision"] != expected_revision:
|
|
132
214
|
raise LineError("chart_context_revision_conflict", "当前图观察版本已变化,请重新读取并核对用户意图;未准备修改。")
|
|
215
|
+
if edit.result_ref is not None:
|
|
216
|
+
from tools.chart_functions import resolve_result
|
|
217
|
+
params.update(resolve_result(edit.result_ref, context, edit.kind))
|
|
218
|
+
if edit.ta_result_ref is not None:
|
|
219
|
+
from tools.ta_functions import resolve_ta_drawing
|
|
220
|
+
params.update(resolve_ta_drawing(edit.ta_result_ref, context, edit.kind))
|
|
221
|
+
if edit.candidate_result_ref is not None:
|
|
222
|
+
from tools.chart_functions import resolve_selected_candidate
|
|
223
|
+
params.update(resolve_selected_candidate(edit.candidate_result_ref, context, edit.kind, edit.candidate_number))
|
|
224
|
+
# A sequence's full values belong only in the candidate snapshot. The
|
|
225
|
+
# journal/guard bind them by digest so preparation does not echo thousands
|
|
226
|
+
# of prices back into the host conversation.
|
|
227
|
+
guarded_params = {"digest_sha256": _hash(params)} if edit.kind in {
|
|
228
|
+
"series_line", "price_band", "price_sticks"} else params
|
|
133
229
|
identity = {"context_ref": context_ref, "expected_revision": expected_revision, "chart_session": chart_session,
|
|
134
|
-
"symbol": symbol.strip().casefold(), "kind": edit.kind, "action": edit.action,
|
|
230
|
+
"symbol": symbol.strip().casefold(), "kind": edit.kind, "action": edit.action,
|
|
231
|
+
"object_id": edit.object_id, "parameters": guarded_params}
|
|
135
232
|
fingerprint = _hash(identity)
|
|
136
233
|
directory = chart_service.RUNTIME_DIR / "edits" / str(chart_service.HOST_PROCESS_ID) / context_ref
|
|
137
234
|
directory.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
@@ -175,16 +272,43 @@ def prepare_chart_edit(context_ref: str, expected_revision: int, chart_session:
|
|
|
175
272
|
if edit.object_id is not None and not any(obj.get("origin") == "ai" and obj["kind"] == edit.kind
|
|
176
273
|
and obj["id"] == edit.object_id for obj in context["drawings"]):
|
|
177
274
|
raise LineError("drawing_not_editable", "目标不是当前观察中的该类型 AI 图形,手动/自动对象不允许修改。")
|
|
178
|
-
if edit.object_id is not None and edit.kind in {"channel", "rectangle"}:
|
|
275
|
+
if edit.object_id is not None and edit.kind in {"channel", "rectangle", "fibonacci_retracement", "labeled_polyline", "series_line", "price_band", "price_sticks", *ANNOTATION_KINDS}:
|
|
179
276
|
target = next(obj for obj in context["drawings"] if obj.get("origin") == "ai" and obj["id"] == edit.object_id)
|
|
180
277
|
if target.get("interval") != context["interval"]:
|
|
181
278
|
raise LineError("drawing_interval_mismatch", "目标属于其他周期,当前周期不能改写或删除该对象;请明确切回其适用周期,不自动搬锚点。")
|
|
182
|
-
|
|
183
|
-
"channel": (edit_channel, "channel_id"), "rectangle": (edit_rectangle, "rectangle_id")
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
279
|
+
editors = {"horizontal_line": (edit_horizontal_line, "line_id"), "trend_line": (edit_trend_line, "line_id"),
|
|
280
|
+
"channel": (edit_channel, "channel_id"), "rectangle": (edit_rectangle, "rectangle_id"),
|
|
281
|
+
"fibonacci_retracement": (edit_fibonacci, "fibonacci_id"),
|
|
282
|
+
"labeled_polyline": (edit_polyline, "polyline_id"),
|
|
283
|
+
"series_line": (edit_price_series, "series_id"),
|
|
284
|
+
"price_band": (edit_price_band, "band_id"),
|
|
285
|
+
"price_sticks": (edit_price_sticks, "sticks_id"),
|
|
286
|
+
"text_annotation": (edit_annotation, "annotation_id"),
|
|
287
|
+
"number_annotation": (edit_annotation, "annotation_id"),
|
|
288
|
+
"icon_annotation": (edit_annotation, "annotation_id")}
|
|
289
|
+
if edit.kind == "all_drawings":
|
|
290
|
+
targets = {item["id"] for item in context["drawings"] if item.get("origin") == "ai"
|
|
291
|
+
and item.get("interval") == context["interval"]}
|
|
292
|
+
if not targets:
|
|
293
|
+
raise LineError("drawing_not_found", "当前周期没有可清空的 AI 图形。")
|
|
294
|
+
edited = deepcopy(payload)
|
|
295
|
+
edited["chartCommands"] = [command for command in payload["chartCommands"]
|
|
296
|
+
if not (command.get("type") in KINDS and command.get("id") in targets)]
|
|
297
|
+
obj = {"kind": "all_drawings", "deleted_count": len(targets)}
|
|
298
|
+
else:
|
|
299
|
+
editor, id_key = editors[edit.kind]
|
|
300
|
+
arguments = dict(params)
|
|
301
|
+
if edit.kind in ANNOTATION_KINDS:
|
|
302
|
+
arguments["kind"] = edit.kind
|
|
303
|
+
arguments = {({"annotation_text": "text", "annotation_value": "value", "annotation_icon": "icon"}.get(k, k)): v
|
|
304
|
+
for k, v in arguments.items()}
|
|
305
|
+
arguments.pop("result_ref", None)
|
|
306
|
+
arguments.pop("ta_result_ref", None)
|
|
307
|
+
for key in ("candidate_result_ref", "candidate_number", "user_confirmed_candidate"):
|
|
308
|
+
arguments.pop(key, None)
|
|
309
|
+
if edit.action == "create": arguments["request_id"] = context_ref + ":" + hashlib.sha256(request_id.encode()).hexdigest()
|
|
310
|
+
else: arguments[id_key] = edit.object_id
|
|
311
|
+
edited, obj = editor(payload, edit.action, **arguments)
|
|
188
312
|
# The new drawing candidate has its own guarded application proof.
|
|
189
313
|
# Do not misidentify it as the unchanged root browser-source token.
|
|
190
314
|
edited.pop("view_source_guard", None)
|
|
@@ -207,7 +331,8 @@ def prepare_chart_edit(context_ref: str, expected_revision: int, chart_session:
|
|
|
207
331
|
"conversation_id": context["conversation_id"], "view_id": context["view_id"],
|
|
208
332
|
"chart_session": token, "parent_chart_session": chart_session, "symbol": payload["symbol"],
|
|
209
333
|
"interval": payload["interval"], "request_id": request_id, "edit": {"kind": edit.kind, "action": edit.action},
|
|
210
|
-
"object": obj, "drawing_guard": guard,
|
|
334
|
+
"object": _public_edit_object(edit.kind, obj), "drawing_guard": guard,
|
|
335
|
+
"source_snapshot_alignment": "verified_for_preparation"}
|
|
211
336
|
entry.update(status="prepared", result=result)
|
|
212
337
|
chart_service._atomic_runtime_json(journal, {"entries": entries})
|
|
213
338
|
except Exception:
|