AlgoTradeKit 1.2.0__tar.gz → 1.3.0__tar.gz

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 (140) hide show
  1. {algotradekit-1.2.0 → algotradekit-1.3.0}/CHANGELOG.md +86 -0
  2. {algotradekit-1.2.0 → algotradekit-1.3.0}/PKG-INFO +201 -26
  3. {algotradekit-1.2.0 → algotradekit-1.3.0}/README.md +200 -25
  4. algotradekit-1.3.0/examples/02_chart_timeframes_replay.py +153 -0
  5. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/03_multi_chart_page.py +21 -4
  6. algotradekit-1.3.0/examples/10_chart_edits.py +191 -0
  7. {algotradekit-1.2.0 → algotradekit-1.3.0}/pyproject.toml +1 -1
  8. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/__init__.py +1 -1
  9. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/metatrader/_client.py +107 -4
  10. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_live.py +23 -0
  11. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/strategy/_base.py +159 -18
  12. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/strategy/_types.py +3 -1
  13. algotradekit-1.3.0/src/AlgoTradeKit/trader/_chart_edits.py +246 -0
  14. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_config.py +63 -0
  15. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_display.py +33 -1
  16. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_notify.py +5 -1
  17. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_run_live.py +113 -1
  18. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_trader.py +72 -14
  19. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/__init__.py +19 -0
  20. algotradekit-1.3.0/src/AlgoTradeKit/visual/_edits.py +143 -0
  21. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/_page.py +34 -1
  22. algotradekit-1.3.0/src/AlgoTradeKit/visual/_style.py +56 -0
  23. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/chart.py +691 -34
  24. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/indicator_renderer.py +33 -0
  25. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/models.py +117 -3
  26. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/server.py +79 -5
  27. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/static/index.html +1627 -155
  28. algotradekit-1.3.0/src/AlgoTradeKit/visual/static/page.html +824 -0
  29. algotradekit-1.3.0/tests/test_broker_mt5_clock.py +247 -0
  30. algotradekit-1.3.0/tests/test_chart_clock.py +178 -0
  31. algotradekit-1.3.0/tests/test_chart_edits.py +609 -0
  32. algotradekit-1.3.0/tests/test_chart_page_tools.py +290 -0
  33. algotradekit-1.3.0/tests/test_frontend_js.py +3336 -0
  34. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify_pictures.py +53 -0
  35. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_simulate.py +31 -0
  36. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_snapshot.py +49 -0
  37. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_trader.py +53 -0
  38. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_visual.py +501 -0
  39. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_visual_page.py +89 -0
  40. algotradekit-1.2.0/examples/02_chart_timeframes_replay.py +0 -61
  41. algotradekit-1.2.0/src/AlgoTradeKit/visual/static/page.html +0 -392
  42. algotradekit-1.2.0/tests/test_frontend_js.py +0 -1529
  43. {algotradekit-1.2.0 → algotradekit-1.3.0}/.gitignore +0 -0
  44. {algotradekit-1.2.0 → algotradekit-1.3.0}/LICENSE +0 -0
  45. {algotradekit-1.2.0 → algotradekit-1.3.0}/MT5_WINE_SETUP.md +0 -0
  46. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/01_backtest_report.py +0 -0
  47. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/04_telegram_messages.py +0 -0
  48. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/05_telegram_paper_alerts.py +0 -0
  49. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/06_telegram_chart_picture.py +0 -0
  50. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/07_price_alerts.py +0 -0
  51. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/08_telegram_commands.py +0 -0
  52. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/09_other_backends.py +0 -0
  53. {algotradekit-1.2.0 → algotradekit-1.3.0}/examples/_sample_data.py +0 -0
  54. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/__init__.py +0 -0
  55. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/_errors.py +0 -0
  56. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/_stream.py +0 -0
  57. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/_timeutil.py +0 -0
  58. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/_types.py +0 -0
  59. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/base.py +0 -0
  60. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/exchange/__init__.py +0 -0
  61. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/exchange/binance/__init__.py +0 -0
  62. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/exchange/binance/_client.py +0 -0
  63. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/exchange/binance/_endpoints.py +0 -0
  64. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/exchange/binance/_rest.py +0 -0
  65. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/exchange/binance/_ws.py +0 -0
  66. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/metatrader/__init__.py +0 -0
  67. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/metatrader/_bridge_client.py +0 -0
  68. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/metatrader/_native.py +0 -0
  69. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/metatrader/_ops.py +0 -0
  70. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/broker/metatrader/bridge_server.py +0 -0
  71. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/__init__.py +0 -0
  72. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/_utils.py +0 -0
  73. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/collector.py +0 -0
  74. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/converter.py +0 -0
  75. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/normalizer.py +0 -0
  76. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/sources/__init__.py +0 -0
  77. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/sources/base.py +0 -0
  78. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/sources/binance.py +0 -0
  79. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/storage/__init__.py +0 -0
  80. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/data/storage/csv_handler.py +0 -0
  81. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/indicator/__init__.py +0 -0
  82. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/indicator/_base.py +0 -0
  83. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/indicator/atr.py +0 -0
  84. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/indicator/ichimoku.py +0 -0
  85. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/indicator/ma.py +0 -0
  86. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/indicator/macd.py +0 -0
  87. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/indicator/rsi.py +0 -0
  88. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/__init__.py +0 -0
  89. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_alerts.py +0 -0
  90. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_commands.py +0 -0
  91. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_core.py +0 -0
  92. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_discord.py +0 -0
  93. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_email.py +0 -0
  94. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_pictures.py +0 -0
  95. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_telegram.py +0 -0
  96. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_template.py +0 -0
  97. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/notify/_webhook.py +0 -0
  98. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/report/__init__.py +0 -0
  99. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/report/_builder.py +0 -0
  100. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/report/_display.py +0 -0
  101. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/report/_server.py +0 -0
  102. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/report/static/report.html +0 -0
  103. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/__init__.py +0 -0
  104. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_config.py +0 -0
  105. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_engine.py +0 -0
  106. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_lot.py +0 -0
  107. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_position.py +0 -0
  108. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_position_math.py +0 -0
  109. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_report.py +0 -0
  110. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_runner.py +0 -0
  111. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/simulate/_session.py +0 -0
  112. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/strategy/__init__.py +0 -0
  113. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/strategy/_incremental.py +0 -0
  114. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/strategy/builtin/__init__.py +0 -0
  115. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/strategy/builtin/macd.py +0 -0
  116. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/__init__.py +0 -0
  117. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_events.py +0 -0
  118. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_execution.py +0 -0
  119. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_scheduler.py +0 -0
  120. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/trader/_state.py +0 -0
  121. {algotradekit-1.2.0 → algotradekit-1.3.0}/src/AlgoTradeKit/visual/_snapshot.py +0 -0
  122. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_broker.py +0 -0
  123. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_broker_mt5.py +0 -0
  124. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_data.py +0 -0
  125. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_data_converter.py +0 -0
  126. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_data_normalizer.py +0 -0
  127. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_docs.py +0 -0
  128. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_indicator.py +0 -0
  129. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify.py +0 -0
  130. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify_alerts.py +0 -0
  131. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify_commands.py +0 -0
  132. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify_discord.py +0 -0
  133. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify_email.py +0 -0
  134. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify_events.py +0 -0
  135. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_notify_webhook.py +0 -0
  136. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_report.py +0 -0
  137. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_strategy.py +0 -0
  138. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_visual__0_4_1.py +0 -0
  139. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_visual_replay.py +0 -0
  140. {algotradekit-1.2.0 → algotradekit-1.3.0}/tests/test_visual_timeframe.py +0 -0
@@ -7,6 +7,92 @@ Versioning: [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
7
7
 
8
8
  ---
9
9
 
10
+ ## [1.3.0] — 2026-11-12
11
+
12
+ Edits on the chart. A chart page takes the viewer's changes — a zone moved,
13
+ deleted or made — and a live session hands them to the strategy between two
14
+ candles. The page grows with it: colours, time zones, a countdown, copy and
15
+ paste, and a layout for phones. Nothing changes for code that asks for none,
16
+ except pictures, which now leave room after their last candle.
17
+
18
+ ### Added
19
+
20
+ - **Keyed drawings report their edits** — `key=`, `editable=` (`True`,
21
+ `False`, or a tuple of `"price"`, `"time"` and `"move"`), `deletable=` and
22
+ `title=` on every drawing. `Chart.on_drawing_edit(fn)` and
23
+ `Chart.on_drawing_delete(fn)` call `fn` with a `DrawingEdit` (`chart`,
24
+ `drawing_id`, `key`, `before`, `after`) on the chart's own thread. A callback
25
+ that raises `EditRefused` puts the drawing back on every open page, whose
26
+ status bar says «Refused: …».
27
+ - **Menus and buttons** — `Chart.add_action(label, fn)` in the candle menu (a
28
+ right-click on the chart) and `Chart.add_drawing_action(label, fn)` on a
29
+ drawing the viewer drew, both with a `ChartAction` (`chart`, `label`, `time`,
30
+ `price`, `drawing`); `Chart.add_button(label, fn, confirm=)` in the toolbar;
31
+ `Chart.add_vline(time, …)`, a vertical line across the price pane.
32
+ - **The edit key** — `Chart(edit_key=…)` and `TraderConfig(chart_edit_key=…)`:
33
+ only a page opened with `?key=…` may change the chart. Any other page looks,
34
+ scrolls, replays and draws its own lines, and changes nothing another viewer
35
+ sees.
36
+ - **Edits reach the strategy** — `BaseStrategy.on_chart_edit(edit)` (return
37
+ `False` to refuse), `on_chart_action(action)`, `chart_actions`,
38
+ `chart_drawing_actions`, `watch_chart(chart, actions=, drawing_actions=)`, and
39
+ `draw(dict)` / `erase(key)` for the strategy's own drawings on a live
40
+ session's chart. `run_live` and `Trader` call the hooks between candles, under
41
+ the session's step lock; a backtest never does.
42
+ - **Saved edits and «Re-run with edits»** — `TraderConfig(chart_edits_path=…)`
43
+ keeps every edit, delete and action the strategy accepts and hands them back
44
+ as `chart_edits` before `setup()`. With a fixed `chart_port`, `run_live`'s
45
+ chart offers «Re-run with edits»: the program starts again — the same
46
+ address, the same key — and walks the history with them.
47
+ - **Colours** — `Chart(style={…})` with `background`, `up_color`, `down_color`
48
+ and `grid`; `Chart.set_style(…)`; `TraderConfig(chart_style=…)`; and Settings
49
+ → Colours, each browser's own, for each theme apart.
50
+ - **Time zones** — `Chart(timezone=, source_timezone=)` and
51
+ `TraderConfig(chart_timezone=, chart_source_timezone=)`: the zone the candles
52
+ are stamped in, and the one the axis, the crosshair, GO TO and pictures read
53
+ in. Settings → Time zone lists them offset first («+03:30 Tehran»), sorted by
54
+ the offset.
55
+ - **On the page** — GO TO (Alt+G); a countdown to the candle's close on the
56
+ feed's own clock; room after the last candle; the brand links to the
57
+ repository. A drawing with `time2=None` (a position box with
58
+ `close_time=None`) runs to the live edge, five candles past the last. A Fib
59
+ resizes from all four corners and takes its own levels. The replay keeps the
60
+ viewer's drawings and shows an open trade's planned RR.
61
+ - **Copy and paste** — Ctrl+C / Ctrl+V, «📋 Copy» and «📋 Paste here»: a
62
+ drawing goes to another chart of the page, or another page, as the viewer's
63
+ own.
64
+ - **`ChartPage` on a phone** — on a screen taller than wide, a row's charts
65
+ stack (`ChartPage(stack_upright=False)` keeps them side by side). ⊞ LAYOUT
66
+ lets each viewer arrange the charts as they like, kept in their browser for
67
+ wide and upright screens apart. The dividers drag with a finger.
68
+ - **Pictures leave room** — 10 empty candles after the last one:
69
+ `Chart.picture_room`, on one chart or on the class for every picture, and
70
+ `Chart.screenshot(right_room=)`.
71
+ - **Runnable example 10** — edits on the chart reach a paper strategy.
72
+
73
+ ### Changed
74
+
75
+ - **MetaTrader's clock** — `clock_offset_ms()` reads the trade server's clock
76
+ from its newest tick, rounded to a quarter hour, and `server_time()` is on
77
+ that clock. Candle closes fire when they happen on the server, and the live
78
+ seeds keep the last closed candle; a broker two hours ahead of UTC used to
79
+ fire them two hours late.
80
+ - A picture reads its times in the chart's own `timezone` unless told
81
+ otherwise.
82
+ - An action that raises `EditRefused` says why on every open page.
83
+
84
+ ### Fixed
85
+
86
+ - A page reload showed a stale chart; a chart added after `ChartPage.show()`
87
+ never got its candles; a picture of a `ChartPage`'s chart always failed.
88
+ - Browser edits of a strategy's drawings were not kept.
89
+ - A box that reached past the last candle could not be resized, and one 18–22
90
+ px tall could not be clicked in its middle.
91
+ - A view's address without its view (`/view?key=…`) opened a blank chart; it
92
+ opens the page now.
93
+
94
+ ---
95
+
10
96
  ## [1.2.0] — 2026-10-23
11
97
 
12
98
  Notifications. A trading session's events, chart pictures, price alerts and a
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: AlgoTradeKit
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: Algorithmic Trading Toolkit — data collection, indicators, strategy, simulation, and live trading
5
5
  Project-URL: Homepage, https://github.com/AmirMohammadBazdar/AlgoTradeKit
6
6
  Project-URL: Repository, https://github.com/AmirMohammadBazdar/AlgoTradeKit
@@ -90,36 +90,43 @@ python examples/06_telegram_chart_picture.py # a chart picture to Telegram (sa
90
90
  python examples/07_price_alerts.py # price alerts to Telegram (same)
91
91
  python examples/08_telegram_commands.py # /status, /positions, /stop from Telegram (same)
92
92
  python examples/09_other_backends.py # Discord, e-mail, a webhook (their own variables)
93
+ python examples/10_chart_edits.py # edits on the chart reach a paper strategy
93
94
  ```
94
95
 
95
- > ### 🔔 New in v1.2.0 — notifications
96
+ > ### ✏️ New in v1.3.0 — the chart talks back
96
97
  >
97
- > Your strategy's trades, a picture of the chart with each, price alerts and a
98
- > backtest's report, sent to Telegram, and commands back from your phone:
98
+ > Move, resize or delete a strategy's zone on its live chart, and the strategy
99
+ > hears it between two candles:
99
100
  >
100
101
  > ```python
101
- > from AlgoTradeKit import run_live
102
- > from AlgoTradeKit.broker import Broker
103
- > from AlgoTradeKit.notify import TelegramNotifier
104
- > from AlgoTradeKit.trader import TraderConfig
102
+ > class Zones(BaseStrategy):
103
+ > def on_chart_edit(self, edit): # edit.key, edit.before, edit.after
104
+ > if edit.after is None: # deleted on the chart
105
+ > self.zones.pop(edit.key, None)
106
+ > elif too_tall(edit.after):
107
+ > return False # refused: it goes back, the page says why
108
+ > else:
109
+ > self.zones[edit.key] = edit.after
105
110
  >
106
- > bot = TelegramNotifier(token, {"me": 123456789}, # your private chat with the bot
107
- > images={"open", "close"}, # chart pictures: the [notify] extra
108
- > commanders=[123456789]) # /status, /chart, /stop from your phone
109
- > config = TraderConfig(symbol="BTCUSDT", min_candles=200, notifiers=[bot])
110
- > run_live(strategy=MyStrategy(), broker=Broker("binance-spot"), config=config)
111
+ > config = TraderConfig(symbol="BTCUSDT", min_candles=200, chart_port=8710,
112
+ > chart_edit_key="a-long-secret", # only ?key=… may change it
113
+ > chart_edits_path="chart_edits.json") # kept, and «Re-run with edits»
111
114
  > ```
112
115
  >
113
- > * **Trading events** — signals, opens, closes, the start, the stop and the day,
114
- > from `run_live` and `Trader` alike. A trade's messages reply to its first one,
115
- > and trading never waits for a message.
116
- > * **Chart pictures** on trade messages, or on demand with `send_chart` and
117
- > `send_report`.
118
- > * **Price alerts** with no strategy: `bot.watch(broker, "BTCUSDT", above=65_000)`.
119
- > * **Commands**: `/status`, `/positions`, `/chart`, `/stop` and `/help`.
120
- > * **Discord, e-mail and webhooks** get the same messages.
116
+ > * **Edits, menus and buttons** — keyed drawings report every change; candle and
117
+ > drawing menus, toolbar buttons and the edit key.
118
+ > * **The chart page** — colours, time zones, GO TO, a countdown, Fib levels, and
119
+ > copy and paste.
120
+ > * **On a phone** — charts stack when the screen is upright, and ⊞ LAYOUT
121
+ > arranges them your way.
122
+ > * **Pictures** leave room after the last candle, and MetaTrader's clock is read
123
+ > from its ticks.
121
124
  >
122
- > See [`notify`](#notify--notifications-v120).
125
+ > See [`strategy`](#edits-from-the-chart-v130) and [`visual`](#visual--interactive-chart).
126
+ >
127
+ > **v1.2.0** brought notifications: trades, chart pictures, price alerts and
128
+ > commands on Telegram, Discord, e-mail and webhooks. See
129
+ > [`notify`](#notify--notifications-v120).
123
130
  >
124
131
  > **v1.1.0** grew the chart: timeframe switching, several synced charts on one
125
132
  > page, and bar replay. See [`visual`](#visual--interactive-chart).
@@ -162,13 +169,15 @@ AlgoTradeKit/
162
169
  └── report/ Interactive simulation report web page ← v0.7.0
163
170
  ```
164
171
 
165
- Data flows in one direction:
172
+ Data flows in one direction, and a viewer's edits come back to the strategy
173
+ by callbacks *(v1.3.0)*:
166
174
 
167
175
  ```
168
176
  broker ──► data ──► indicator ──► strategy ──► simulate ──► report
169
- │ └──────► visual
170
- └──────► trader ◄────┘
171
- └──────► notify
177
+ ▲ │ └──────► visual ┄┄┐
178
+ ┆ └──────► trader ◄────┘ ┆
179
+ ┆ └──────► notify ┆
180
+ └┄┄┄┄┄┄ edits and actions ┄┄┄┄┄┄┘
172
181
  ```
173
182
 
174
183
  `trader` is a leaf: it consumes `broker`, `strategy` and `simulate`, and nothing
@@ -177,6 +186,11 @@ concerns while both share the same position maths. `trader` hands its events to
177
186
  `notify`, which imports no other module when it is imported: a broker reaches it
178
187
  as an object, and the chart and the report load only to make a picture.
179
188
 
189
+ *(v1.3.0)* One arrow runs back, from the chart page to the strategy: what a
190
+ viewer changes on a live session's chart reaches the strategy's `on_chart_edit`
191
+ and `on_chart_action`. It is made of callbacks the live session installs, never
192
+ of imports — `visual` imports no strategy, and `strategy` no chart.
193
+
180
194
  ---
181
195
 
182
196
  ## broker — Exchanges & MetaTrader *(v0.9.0)*
@@ -238,6 +252,12 @@ Binance reports your account's real taker fee and a live book spread;
238
252
  MetaTrader reports spread and contract size from `symbol_info`. The live trader
239
253
  uses both to size positions correctly and to fire exactly on candle close.
240
254
 
255
+ *(v1.3.0)* On MetaTrader the clock is the **trade server's**, read from the
256
+ newest tick and rounded to a quarter hour: a broker two hours ahead of UTC reads
257
+ +2:00, and `b.server_time()` is on that clock. MetaTrader stamps its candles in
258
+ that time, so candle closes fire when they happen there, not hours late, and the
259
+ live seeds keep the last closed candle.
260
+
241
261
  **MetaTrader (forex) — Windows and Linux** *(v1.0.0)*
242
262
 
243
263
  MetaTrader has no public API: the terminal speaks a proprietary protocol to your
@@ -492,6 +512,53 @@ columns back — accurate for windowed indicators, and never revising a value it
492
512
  already wrote. Implement the hook if your strategy repaints or builds Python
493
513
  objects (order blocks, zones, SMC structures) during `prepare_indicators`.
494
514
 
515
+ ### Edits from the Chart *(v1.3.0)*
516
+
517
+ A live session's chart talks back. The strategy draws its own objects with a
518
+ `key` — the object's own name — and the viewer may move, resize or delete them
519
+ on the page. The strategy hears it between two candles, under the session's
520
+ step lock, so it never sees half a candle:
521
+
522
+ ```python
523
+ class Zones(BaseStrategy):
524
+ chart_actions = ("Add zone here",) # a right-click on the chart
525
+ chart_drawing_actions = ("Make it a zone",) # a right-click on a box the viewer drew
526
+
527
+ def generate_signals(self, i, data):
528
+ ...
529
+ self.draw({"type": "box", "key": f"zone:{made}", "title": "High zone",
530
+ "time1": made // 1000, "price1": top, "time2": None, "price2": bottom,
531
+ "editable": ("price",)}) # time2 None: it runs to the live edge
532
+ ...
533
+
534
+ def on_chart_edit(self, edit): # edit.key, edit.before, edit.after
535
+ if edit.after is None: # deleted
536
+ self.zones.pop(edit.key, None)
537
+ return None
538
+ if too_tall(edit.after):
539
+ return False # refused: it goes back, the page says so
540
+ self.zones[edit.key].update(top=..., bottom=...)
541
+
542
+ def on_chart_action(self, action): # action.label, .time (UTC ms), .price, .drawing
543
+ ...
544
+ ```
545
+
546
+ * `draw(dict)` and `erase(key)` put the strategy's drawings on the session's
547
+ chart; in a backtest `run()` returns them in `StrategyResult.drawings`. Drawing
548
+ again with a key replaces that drawing.
549
+ * `watch_chart(chart, actions=, drawing_actions=)` brings a chart the strategy
550
+ builds itself to the same hooks.
551
+ * `TraderConfig(chart_edits_path="chart_edits.json")` saves every edit, delete
552
+ and action the strategy accepts and hands them back as `self.chart_edits`
553
+ before `setup()` at the next start, so a zone made again takes its edit. With
554
+ a fixed `chart_port` the chart's toolbar offers **Re-run with edits**: the
555
+ session starts again — the same address, the same key — and walks the history
556
+ with them.
557
+ * `TraderConfig(chart_edit_key="…")` keeps all this to the address with
558
+ `?key=…`; any other page only looks.
559
+
560
+ `examples/10_chart_edits.py` runs it on Binance's public candles.
561
+
495
562
  ### Built-in Strategies
496
563
 
497
564
  | Strategy | Import |
@@ -785,6 +852,19 @@ TraderConfig(
785
852
  `"sim"` shows theoretical strategy performance, `"real"` shows your actual
786
853
  fills, `"both"` overlays them.
787
854
 
855
+ *(v1.3.0)* The session's chart takes the chart's new settings too:
856
+
857
+ ```python
858
+ TraderConfig(
859
+ ...,
860
+ chart_style={"background": "#101820", "grid": False}, # its colours
861
+ chart_timezone="Asia/Tehran", # the times it shows
862
+ chart_source_timezone="Europe/Athens", # what the venue stamps in (MetaTrader: the broker's)
863
+ chart_edit_key="a-long-secret", # only the address with ?key=… may change it
864
+ chart_edits_path="chart_edits.json", # the strategy's accepted edits, and «Re-run with edits»
865
+ )
866
+ ```
867
+
788
868
  ---
789
869
 
790
870
  ## notify — Notifications *(v1.2.0)*
@@ -900,6 +980,12 @@ characters goes on in a reply. Pictures need the `[notify]` extra and its Chromi
900
980
  headless Chromium photographs the library's own chart page, on the notifier's thread, and
901
981
  stays open while the notifier lives: about 450 MB idle.
902
982
 
983
+ *(v1.3.0)* A picture leaves **10 empty candles** after its last one.
984
+ `Chart.picture_room = 4` changes that for every picture, the notifiers' included;
985
+ `chart.picture_room = 4` for one chart; `chart.screenshot(right_room=0)` for one
986
+ picture (0: the last candle at the edge). A picture reads its times in the
987
+ chart's own `timezone`.
988
+
903
989
  ### Price alerts
904
990
 
905
991
  ```python
@@ -1053,6 +1139,86 @@ chart.add_box(time1=1700000000, price1=41_000,
1053
1139
  chart.add_signal(time=1700000000, side="buy")
1054
1140
  ```
1055
1141
 
1142
+ ### Colours *(v1.3.0)*
1143
+
1144
+ ```python
1145
+ chart = Chart(style={"background": "#101820", "up_color": "#26a69a",
1146
+ "down_color": "#ef5350", "grid": False})
1147
+ chart.set_style(background=None) # the theme's background again
1148
+ ```
1149
+
1150
+ Each viewer may pick their own in the chart's **Settings → Colours**: their
1151
+ browser keeps it, for each theme apart, on top of the program's, and every chart
1152
+ of a page follows a colour picked on one of them.
1153
+
1154
+ ### Edits, Menus and the Edit Key *(v1.3.0)*
1155
+
1156
+ Give a drawing a `key` — the program's own name for it — and the viewer may
1157
+ change it on the page; the program hears every change:
1158
+
1159
+ ```python
1160
+ from AlgoTradeKit.visual import Chart, EditRefused
1161
+
1162
+ chart = Chart(title="BTCUSDT", edit_key="a-long-secret") # only ?key=… may change it
1163
+ chart.add_box(t1, 64_200, None, 64_000, key="zone:1", editable=("price",),
1164
+ title="Buy zone") # time2 None: it runs to the live edge
1165
+
1166
+ @chart.on_drawing_edit
1167
+ def edited(edit): # edit.key, edit.before, edit.after
1168
+ if abs(edit.after["price1"] - edit.after["price2"]) > 500:
1169
+ raise EditRefused("a zone is at most 500 tall") # it goes back; the page says why
1170
+
1171
+ @chart.on_drawing_delete
1172
+ def deleted(edit): # edit.after is None
1173
+ ...
1174
+
1175
+ chart.add_action("Mark here", lambda a: print(a.time, a.price)) # the candle menu
1176
+ chart.add_drawing_action("Measure", lambda a: print(a.drawing)) # on a drawing the viewer drew
1177
+ chart.add_button("Flatten", flatten, confirm="Close everything?") # a toolbar button
1178
+ chart.add_vline(t2, label="restart", key="restart:1") # a vertical line
1179
+ ```
1180
+
1181
+ * `editable=` is `True` (every handle), `False`, or a tuple of `"price"`,
1182
+ `"time"` and `"move"`; `deletable=False` keeps it on the chart; `title` heads
1183
+ its right-click menu.
1184
+ * Callbacks run on the chart's own thread, in order. One that raises
1185
+ `EditRefused` puts the drawing back on every open page, whose status bar says
1186
+ «Refused: …» — for an action too.
1187
+ * Without `edit_key` every page may change the chart, as before. With it, any
1188
+ other page only looks: it scrolls, replays and draws its own lines, and changes
1189
+ nothing another viewer sees.
1190
+
1191
+ ### Time Zones *(v1.3.0)*
1192
+
1193
+ ```python
1194
+ Chart(timezone="Asia/Tehran") # the times the chart shows
1195
+ Chart(source_timezone="Europe/Athens") # the zone the candles are stamped in
1196
+ ```
1197
+
1198
+ A candle's time is what the venue stamps: UTC on Binance, the broker's own clock
1199
+ on MetaTrader. The chart cannot tell which, so the program says it with
1200
+ `source_timezone`; the axis, the crosshair, GO TO and the pictures read in
1201
+ `timezone`. A viewer may pick both in **Settings → Time zone** («+03:30 Tehran»,
1202
+ sorted by the offset), and their browser keeps the choice.
1203
+
1204
+ ### On the Page *(v1.3.0)*
1205
+
1206
+ * **GO TO** (or `Alt+G`) takes the chart to a date and time, as its axis shows it.
1207
+ * **The countdown** under the last price: the time left until the candle closes,
1208
+ on the feed's own clock (Settings turns it off).
1209
+ * **Running drawings**: a box, a line or a Fib with `time2=None` — a position
1210
+ box with `close_time=None` — runs to the live edge, five candles past the last
1211
+ candle, and moves with it.
1212
+ * **Room after the last candle**, so the newest one is not on the edge.
1213
+ * **Fib**: any of its four corners resizes it; right-click → **Levels…** sets
1214
+ its own levels, Settings → «Fib levels» the ones a new Fib starts with.
1215
+ * **Copy and paste**: click a drawing and press `Ctrl+C` (`⌘C`), or right-click →
1216
+ **📋 Copy**. `Ctrl+V` pastes it where it was — on another chart of the page, or
1217
+ another page, too — and a right-click on the chart → **📋 Paste here** puts it
1218
+ at the click. A copy is the viewer's own.
1219
+ * **The replay** keeps the viewer's drawings, and a trade still open at the
1220
+ cursor shows the RR it was planned with.
1221
+
1056
1222
  ### Position Boxes (v0.7.0)
1057
1223
 
1058
1224
  TradingView-style position boxes showing SL/TP zones with R:R labels:
@@ -1223,6 +1389,15 @@ Attaching a chart changes nothing about how you drive it: indicators, drawings,
1223
1389
  live positions, streaming and `set_timeframe` all work exactly as they do on a
1224
1390
  chart of its own. Charts can also be added after `show()`.
1225
1391
 
1392
+ *(v1.3.0)* **On a phone held upright** — a screen taller than wide — the charts
1393
+ of a row stack, one under the other, each the full width; turned sideways, they
1394
+ are side by side again, and nothing reloads. `ChartPage(stack_upright=False)`
1395
+ keeps rows side by side. **⊞ LAYOUT** in the page header lets each viewer
1396
+ arrange the charts as they like: drag a chart onto another's side to put it
1397
+ beside, above or below it, or onto its middle to swap the two. Their browser
1398
+ keeps it, for wide and for upright screens apart; **RESET** brings the program's
1399
+ layout back. The dividers drag with a finger too.
1400
+
1226
1401
  ### Bar Replay *(v1.1.0)*
1227
1402
 
1228
1403
  Press **⏵⏵ REPLAY**, click a candle, and the chart forgets everything after it.