openalgo-charts 1.0.3 → 1.0.5

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Library version string. Matches package.json (published npm release). */
2
- declare const VERSION = "1.0.3";
2
+ declare const VERSION = "1.0.5";
3
3
  /** Returns the current library version. */
4
4
  declare function version(): string;
5
5
 
@@ -492,6 +492,10 @@ interface PrimitiveRenderContext {
492
492
  priceAxisWidth: number;
493
493
  dpr: number;
494
494
  theme: ChartTheme;
495
+ /** externalId of the primitive hit under the pointer (hover state), if any. */
496
+ hoverId?: string | null;
497
+ /** externalId of the line being dragged (active state), if any. */
498
+ dragId?: string | null;
495
499
  }
496
500
  interface PrimitiveHit {
497
501
  externalId: string;
@@ -634,6 +638,10 @@ interface PaneRenderContext {
634
638
  showHorzGrid: boolean;
635
639
  /** Optional custom time label formatter (UTC seconds -> string). Defaults to IST. */
636
640
  timeFormatter?: (utcSeconds: number, tickMark?: TickMarkType) => string;
641
+ /** externalId of the primitive under the pointer (hover visual state). */
642
+ hoverId?: string | null;
643
+ /** externalId of the line currently being dragged (active visual state). */
644
+ dragId?: string | null;
637
645
  }
638
646
  declare class Pane {
639
647
  readonly element: HTMLElement;
@@ -946,8 +954,8 @@ declare class TradingController {
946
954
  private _renderTrades;
947
955
  private _sync;
948
956
  private _sig;
957
+ /** Info segment for a position: live P&L text (side/size live in badge/qty). */
949
958
  private _positionPill;
950
- private _orderPill;
951
959
  private _positionOpts;
952
960
  private _orderOpts;
953
961
  private _onClick;
@@ -958,7 +966,11 @@ declare class TradingController {
958
966
  /**
959
967
  * Horizontal price line primitive (ARCHITECTURE.md §8). The reusable base for
960
968
  * order/SL/TP/alert/indicator-level lines: a line across the plot plus a fixed
961
- * right-axis price tag. Drag handling is added by the trade layer in Phase 9.
969
+ * right-axis price tag and an optional broker-style segmented pill group on the
970
+ * line — [badge][qty][label][✕] — with hover / dragging states (the chart
971
+ * passes `hoverId`/`dragId` on the render context) and a drag ghost at the
972
+ * pre-drag price via `setDragGhost`. Interaction semantics are unchanged from
973
+ * the classic tag: the ✕ hit-tests as `${id}::close`, everything else drags.
962
974
  */
963
975
 
964
976
  interface PriceLineOptions {
@@ -968,7 +980,11 @@ interface PriceLineOptions {
968
980
  dashed: boolean;
969
981
  /** Right-axis tag text. Defaults to the formatted price. */
970
982
  label?: string;
971
- /** Optional tag drawn at the LEFT end of the line (broker-style order tag). */
983
+ /** Solid colored badge segment at the start of the pill group (e.g. 'BUY', 'TP', 'SL'). */
984
+ badge?: string;
985
+ /** Quantity segment rendered as a neutral box after the badge. */
986
+ qty?: string | number;
987
+ /** Info text segment (order type, price, P&L ...) — the classic left tag text. */
972
988
  leftLabel?: string;
973
989
  /**
974
990
  * Fraction of the plot width the line spans, measured from the right (price)
@@ -976,7 +992,7 @@ interface PriceLineOptions {
976
992
  * partial-width order line. The right-axis tag is always drawn.
977
993
  */
978
994
  extentFromRight?: number;
979
- /** Draw a small cancel (cross) box at the right end; hit-tests as `${id}::close`. */
995
+ /** Draw a cancel (✕) segment at the end of the pill group; hit-tests as `${id}::close`. */
980
996
  closeButton?: boolean;
981
997
  /** Stable id returned by hit-test (for click/drag routing). */
982
998
  id: string;
@@ -986,14 +1002,22 @@ interface PriceLineOptions {
986
1002
  declare class PriceLine implements IPrimitive {
987
1003
  private _opts;
988
1004
  private _host;
1005
+ private _ghostPrice;
1006
+ /** Pill-group geometry from the last draw (media px) for hit-testing. */
1007
+ private _group;
989
1008
  constructor(opts: PriceLineOptions);
990
1009
  attached(host: PrimitiveHost): void;
991
1010
  detached(): void;
992
1011
  get price(): number;
993
1012
  /** Move the line; schedules a repaint via the host. */
994
1013
  setPrice(price: number): void;
995
- /** Update the left-end tag text (e.g. live position P&L); repaints. */
1014
+ /** Update the info segment text (e.g. live position P&L); repaints. */
996
1015
  setLeftLabel(text: string): void;
1016
+ /**
1017
+ * Show a dimmed reference line at the pre-drag price while the user drags
1018
+ * (pass the original price on drag start, null on drag end to clear).
1019
+ */
1020
+ setDragGhost(price: number | null): void;
997
1021
  options(): Readonly<PriceLineOptions>;
998
1022
  zOrder(): ZOrder;
999
1023
  autoscaleInfo(): {
@@ -1194,6 +1218,8 @@ declare class Chart {
1194
1218
  private _downX;
1195
1219
  private _downLocalY;
1196
1220
  private _dragId;
1221
+ private _hoverId;
1222
+ private _overlayFrozen;
1197
1223
  private _dragCb;
1198
1224
  private _dragEndCb;
1199
1225
  private _axisDrag;
@@ -1340,6 +1366,21 @@ declare class Chart {
1340
1366
  private _onFrame;
1341
1367
  private _attachInput;
1342
1368
  private readonly _onPointerEnter;
1369
+ /**
1370
+ * The chart renders as stacked canvases, so the browser's right-click
1371
+ * "Save image as…" would capture only the topmost (transparent overlay)
1372
+ * layer — a blank image. Just before the native menu opens, composite the
1373
+ * clicked pane's base layer *beneath* its overlay bitmap so the saved image
1374
+ * is the visible chart, and freeze overlay repaints (live ticks repaint every
1375
+ * few hundred ms and would wipe the snapshot while the menu is open). The
1376
+ * freeze lifts on the next pointer/wheel/key input after the menu closes.
1377
+ * Apps that present their own menu (preventDefault on contextmenu) are
1378
+ * unaffected. Multi-pane note: the native save captures the clicked pane
1379
+ * only — use `downloadScreenshot()` for the full multi-pane composite.
1380
+ */
1381
+ private readonly _onContextMenu;
1382
+ /** Resume overlay repaints after the native context menu closes. */
1383
+ private _unfreezeOverlay;
1343
1384
  private _localPoint;
1344
1385
  private readonly _onPointerDown;
1345
1386
  private readonly _onPointerMove;
@@ -1360,9 +1401,21 @@ declare class Chart {
1360
1401
  private _shortcutsActive;
1361
1402
  /** Execute a built-in command; returns false for unknown (custom) commands. */
1362
1403
  private _runShortcut;
1363
- private _downloadScreenshot;
1404
+ /**
1405
+ * Composite the full chart (all panes + overlays) and trigger a PNG download.
1406
+ * This is what the screenshot keyboard shortcut runs; call it from a toolbar
1407
+ * button for a reliable "save image" — the browser's native right-click
1408
+ * "Save image as…" captures only the topmost (transparent overlay) canvas.
1409
+ */
1410
+ downloadScreenshot(filename?: string): void;
1364
1411
  /** Refresh the polite live-region summary screen readers announce. */
1365
1412
  private _updateAccessibleSummary;
1413
+ /**
1414
+ * Track the primitive under the pointer: apply its cursor hint to the
1415
+ * container and repaint on hover enter/leave so lines/pills can render
1416
+ * hover states (they read `hoverId` off the render context).
1417
+ */
1418
+ private _setHover;
1366
1419
  private _updateCursor;
1367
1420
  private _maybeLoadHistory;
1368
1421
  private _startKinetic;
@@ -1799,6 +1852,32 @@ interface LtpEvent {
1799
1852
  volume?: number;
1800
1853
  timeSec: number;
1801
1854
  }
1855
+ /**
1856
+ * Real-time order lifecycle event from the `subscribe_orders` stream — fills,
1857
+ * partial fills, rejections, cancellations, pushed by the broker (or by the
1858
+ * sandbox engine in analyze mode).
1859
+ */
1860
+ interface OrderUpdateEvent {
1861
+ orderId: string;
1862
+ symbol: string;
1863
+ exchange: string;
1864
+ action: 'BUY' | 'SELL';
1865
+ quantity: number;
1866
+ price: number;
1867
+ /** Undefined when the broker reports 0 (plain LIMIT/MARKET). */
1868
+ triggerPrice?: number;
1869
+ pricetype: string;
1870
+ product: string;
1871
+ /** Lowercase OpenAlgo status: open | trigger pending | complete | rejected | cancelled | ... */
1872
+ status: string;
1873
+ filledQuantity: number;
1874
+ pendingQuantity: number;
1875
+ averagePrice: number;
1876
+ /** Broker RMS/OMS text when rejected. */
1877
+ rejectionReason: string;
1878
+ /** 'live' for broker events, 'analyze' for sandbox events. */
1879
+ mode: string;
1880
+ }
1802
1881
  /**
1803
1882
  * Pure: build a subscribe message — `{ action, symbol, exchange, mode }`, where
1804
1883
  * `mode` is the numeric OpenAlgo data mode. Depth subscriptions may request a
@@ -1830,6 +1909,8 @@ declare class OpenAlgoWsFeed {
1830
1909
  private readonly _depthCbs;
1831
1910
  private readonly _stateCbs;
1832
1911
  private readonly _controlCbs;
1912
+ private readonly _orderCbs;
1913
+ private _ordersSubscribed;
1833
1914
  private readonly _subs;
1834
1915
  private _userClosed;
1835
1916
  private _attempts;
@@ -1855,6 +1936,10 @@ declare class OpenAlgoWsFeed {
1855
1936
  onDepth(cb: (symbol: string, exchange: string, depth: MarketDepth) => void): () => void;
1856
1937
  subscribe(mode: WsMode, symbol: string, exchange: string, depthLevel?: number): void;
1857
1938
  unsubscribe(mode: WsMode, symbol: string, exchange: string): void;
1939
+ /** Subscribe to real-time order updates (fills / cancels / rejections). Account-level; replayed on reconnect. */
1940
+ onOrderUpdate(cb: (e: OrderUpdateEvent) => void): () => void;
1941
+ subscribeOrders(): void;
1942
+ unsubscribeOrders(): void;
1858
1943
  close(): void;
1859
1944
  private _dispatch;
1860
1945
  }