openalgo-charts 1.0.2 → 1.0.4

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.2";
2
+ declare const VERSION = "1.0.4";
3
3
  /** Returns the current library version. */
4
4
  declare function version(): string;
5
5
 
@@ -365,6 +365,12 @@ interface SeriesStyle {
365
365
  volumeScaled?: boolean;
366
366
  /** Whether the series is drawn and counted in autoscale. Default true. */
367
367
  visible?: boolean;
368
+ /** Optional label carried with the series (for host-drawn legends). */
369
+ title?: string;
370
+ /** Show the dashed horizontal last-price line across the plot. Default true. */
371
+ priceLineVisible?: boolean;
372
+ /** Show the last-value tag on the price axis. Default true. */
373
+ lastValueVisible?: boolean;
368
374
  color?: string;
369
375
  lineWidth?: number;
370
376
  /** Line dash style for line/step/area/HLC series. Default 'solid'. */
@@ -405,6 +411,14 @@ interface ChartTheme {
405
411
  axisFontSize?: number;
406
412
  /** Grid line dash style (default 'solid'). */
407
413
  gridStyle?: 'solid' | 'dashed' | 'dotted';
414
+ /** Crosshair line dash style (default 'dashed'). */
415
+ crosshairStyle?: 'solid' | 'dashed' | 'dotted';
416
+ /** Crosshair line width in device px (default 1 = hairline). */
417
+ crosshairWidth?: number;
418
+ /** Background of the crosshair value tags (defaults to `crosshair`). */
419
+ crosshairLabelBackground?: string;
420
+ /** Show the crosshair price/time value tags (default true). */
421
+ crosshairLabelVisible?: boolean;
408
422
  upColor: string;
409
423
  downColor: string;
410
424
  wickUpColor: string;
@@ -478,6 +492,10 @@ interface PrimitiveRenderContext {
478
492
  priceAxisWidth: number;
479
493
  dpr: number;
480
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;
481
499
  }
482
500
  interface PrimitiveHit {
483
501
  externalId: string;
@@ -578,6 +596,20 @@ interface SeriesApi {
578
596
  createMarkers(): SeriesMarkers;
579
597
  }
580
598
 
599
+ /**
600
+ * Axis label rendering (ARCHITECTURE.md §6, §5.3). Price axis (right strip) and
601
+ * time axis (bottom strip). Time labels switch from clock to date at IST day
602
+ * boundaries; gaps are already collapsed by the logical-index time scale.
603
+ */
604
+
605
+ /**
606
+ * Boundary class of a time-axis label, passed to a custom `timeFormatter` as a
607
+ * hint so a host can render adaptive labels (year at year boundaries, month at
608
+ * month boundaries, day otherwise, clock intraday) — parity with common
609
+ * `tickMarkFormatter(time, tickMarkType)` APIs.
610
+ */
611
+ type TickMarkType = 'year' | 'month' | 'day' | 'time' | 'timeWithSeconds';
612
+
581
613
  /**
582
614
  * A pane is one vertically-stacked drawing region (price pane, volume pane,
583
615
  * indicator pane). It owns a base + top canvas (ARCHITECTURE.md §3.1) and a
@@ -605,7 +637,11 @@ interface PaneRenderContext {
605
637
  /** Draw the horizontal (price) grid lines. */
606
638
  showHorzGrid: boolean;
607
639
  /** Optional custom time label formatter (UTC seconds -> string). Defaults to IST. */
608
- timeFormatter?: (utcSeconds: number) => string;
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;
609
645
  }
610
646
  declare class Pane {
611
647
  readonly element: HTMLElement;
@@ -918,8 +954,8 @@ declare class TradingController {
918
954
  private _renderTrades;
919
955
  private _sync;
920
956
  private _sig;
957
+ /** Info segment for a position: live P&L text (side/size live in badge/qty). */
921
958
  private _positionPill;
922
- private _orderPill;
923
959
  private _positionOpts;
924
960
  private _orderOpts;
925
961
  private _onClick;
@@ -930,7 +966,11 @@ declare class TradingController {
930
966
  /**
931
967
  * Horizontal price line primitive (ARCHITECTURE.md §8). The reusable base for
932
968
  * order/SL/TP/alert/indicator-level lines: a line across the plot plus a fixed
933
- * 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.
934
974
  */
935
975
 
936
976
  interface PriceLineOptions {
@@ -940,7 +980,11 @@ interface PriceLineOptions {
940
980
  dashed: boolean;
941
981
  /** Right-axis tag text. Defaults to the formatted price. */
942
982
  label?: string;
943
- /** 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. */
944
988
  leftLabel?: string;
945
989
  /**
946
990
  * Fraction of the plot width the line spans, measured from the right (price)
@@ -948,7 +992,7 @@ interface PriceLineOptions {
948
992
  * partial-width order line. The right-axis tag is always drawn.
949
993
  */
950
994
  extentFromRight?: number;
951
- /** 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`. */
952
996
  closeButton?: boolean;
953
997
  /** Stable id returned by hit-test (for click/drag routing). */
954
998
  id: string;
@@ -958,14 +1002,22 @@ interface PriceLineOptions {
958
1002
  declare class PriceLine implements IPrimitive {
959
1003
  private _opts;
960
1004
  private _host;
1005
+ private _ghostPrice;
1006
+ /** Pill-group geometry from the last draw (media px) for hit-testing. */
1007
+ private _group;
961
1008
  constructor(opts: PriceLineOptions);
962
1009
  attached(host: PrimitiveHost): void;
963
1010
  detached(): void;
964
1011
  get price(): number;
965
1012
  /** Move the line; schedules a repaint via the host. */
966
1013
  setPrice(price: number): void;
967
- /** 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. */
968
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;
969
1021
  options(): Readonly<PriceLineOptions>;
970
1022
  zOrder(): ZOrder;
971
1023
  autoscaleInfo(): {
@@ -1061,7 +1113,7 @@ interface ChartOptions {
1061
1113
  * omitted, labels use IST (Indian market default). e.g. for UTC:
1062
1114
  * `(s) => new Date(s * 1000).toISOString().slice(11, 16)`.
1063
1115
  */
1064
- timeFormatter?: (utcSeconds: number) => string;
1116
+ timeFormatter?: (utcSeconds: number, tickMark?: TickMarkType) => string;
1065
1117
  }
1066
1118
  interface AddSeriesOptions {
1067
1119
  /** Target pane index (0 = price). Higher panes are created on demand. */
@@ -1166,6 +1218,7 @@ declare class Chart {
1166
1218
  private _downX;
1167
1219
  private _downLocalY;
1168
1220
  private _dragId;
1221
+ private _hoverId;
1169
1222
  private _dragCb;
1170
1223
  private _dragEndCb;
1171
1224
  private _axisDrag;
@@ -1280,7 +1333,7 @@ declare class Chart {
1280
1333
  * Set a custom time-axis + crosshair label formatter (UTC seconds -> string)
1281
1334
  * at runtime. Pass undefined to restore the IST default.
1282
1335
  */
1283
- setTimeFormatter(fn: ((utcSeconds: number) => string) | undefined): void;
1336
+ setTimeFormatter(fn: ((utcSeconds: number, tickMark?: TickMarkType) => string) | undefined): void;
1284
1337
  /** Swap the palette at runtime (dark/light toggle) without recreating the chart. */
1285
1338
  setTheme(theme: ChartTheme): void;
1286
1339
  /**
@@ -1294,7 +1347,7 @@ declare class Chart {
1294
1347
  horzLines?: boolean;
1295
1348
  };
1296
1349
  priceFormatter?: ((price: number) => string) | null;
1297
- timeFormatter?: ((utcSeconds: number) => string) | undefined;
1350
+ timeFormatter?: ((utcSeconds: number, tickMark?: TickMarkType) => string) | undefined;
1298
1351
  crosshairMode?: CrosshairMode;
1299
1352
  }): void;
1300
1353
  panes(): readonly Pane[];
@@ -1332,9 +1385,21 @@ declare class Chart {
1332
1385
  private _shortcutsActive;
1333
1386
  /** Execute a built-in command; returns false for unknown (custom) commands. */
1334
1387
  private _runShortcut;
1335
- private _downloadScreenshot;
1388
+ /**
1389
+ * Composite the full chart (all panes + overlays) and trigger a PNG download.
1390
+ * This is what the screenshot keyboard shortcut runs; call it from a toolbar
1391
+ * button for a reliable "save image" — the browser's native right-click
1392
+ * "Save image as…" captures only the topmost (transparent overlay) canvas.
1393
+ */
1394
+ downloadScreenshot(filename?: string): void;
1336
1395
  /** Refresh the polite live-region summary screen readers announce. */
1337
1396
  private _updateAccessibleSummary;
1397
+ /**
1398
+ * Track the primitive under the pointer: apply its cursor hint to the
1399
+ * container and repaint on hover enter/leave so lines/pills can render
1400
+ * hover states (they read `hoverId` off the render context).
1401
+ */
1402
+ private _setHover;
1338
1403
  private _updateCursor;
1339
1404
  private _maybeLoadHistory;
1340
1405
  private _startKinetic;
@@ -1771,6 +1836,32 @@ interface LtpEvent {
1771
1836
  volume?: number;
1772
1837
  timeSec: number;
1773
1838
  }
1839
+ /**
1840
+ * Real-time order lifecycle event from the `subscribe_orders` stream — fills,
1841
+ * partial fills, rejections, cancellations, pushed by the broker (or by the
1842
+ * sandbox engine in analyze mode).
1843
+ */
1844
+ interface OrderUpdateEvent {
1845
+ orderId: string;
1846
+ symbol: string;
1847
+ exchange: string;
1848
+ action: 'BUY' | 'SELL';
1849
+ quantity: number;
1850
+ price: number;
1851
+ /** Undefined when the broker reports 0 (plain LIMIT/MARKET). */
1852
+ triggerPrice?: number;
1853
+ pricetype: string;
1854
+ product: string;
1855
+ /** Lowercase OpenAlgo status: open | trigger pending | complete | rejected | cancelled | ... */
1856
+ status: string;
1857
+ filledQuantity: number;
1858
+ pendingQuantity: number;
1859
+ averagePrice: number;
1860
+ /** Broker RMS/OMS text when rejected. */
1861
+ rejectionReason: string;
1862
+ /** 'live' for broker events, 'analyze' for sandbox events. */
1863
+ mode: string;
1864
+ }
1774
1865
  /**
1775
1866
  * Pure: build a subscribe message — `{ action, symbol, exchange, mode }`, where
1776
1867
  * `mode` is the numeric OpenAlgo data mode. Depth subscriptions may request a
@@ -1802,6 +1893,8 @@ declare class OpenAlgoWsFeed {
1802
1893
  private readonly _depthCbs;
1803
1894
  private readonly _stateCbs;
1804
1895
  private readonly _controlCbs;
1896
+ private readonly _orderCbs;
1897
+ private _ordersSubscribed;
1805
1898
  private readonly _subs;
1806
1899
  private _userClosed;
1807
1900
  private _attempts;
@@ -1827,6 +1920,10 @@ declare class OpenAlgoWsFeed {
1827
1920
  onDepth(cb: (symbol: string, exchange: string, depth: MarketDepth) => void): () => void;
1828
1921
  subscribe(mode: WsMode, symbol: string, exchange: string, depthLevel?: number): void;
1829
1922
  unsubscribe(mode: WsMode, symbol: string, exchange: string): void;
1923
+ /** Subscribe to real-time order updates (fills / cancels / rejections). Account-level; replayed on reconnect. */
1924
+ onOrderUpdate(cb: (e: OrderUpdateEvent) => void): () => void;
1925
+ subscribeOrders(): void;
1926
+ unsubscribeOrders(): void;
1830
1927
  close(): void;
1831
1928
  private _dispatch;
1832
1929
  }
@@ -2126,4 +2223,4 @@ declare function lerp(a: number, b: number, t: number): number;
2126
2223
  */
2127
2224
  declare function roundToTick(value: number, step: number): number;
2128
2225
 
2129
- export { ALT_PRESET, type AddSeriesOptions, type AggTick, BUILTIN_COMMANDS, type Bar, type BarUpdate, type BarsRequest, CandleBuilder, type CandleBuilderOptions, type CandleStyle, type CandleUpdate, Chart, type ChartEvent, type ChartOptions, type ChartTheme, type CrosshairMoveEvent, type CustomShortcut, DEFAULT_CANDLE_BUILDER_OPTIONS, DEFAULT_CANDLE_STYLE, DEFAULT_HISTOGRAM_STYLE, DEFAULT_KEYMAP, DEFAULT_PRICE_SCALE_OPTIONS, DEFAULT_THEME, DEFAULT_TIME_SCALE_OPTIONS, DEFAULT_TRADING_COLORS, type DataFeed, type DepthLevel, type DrawItem, EventMarkers, FakeDataFeed, type FeedScheduler, type HistogramStyle, type IPrimitive, IST_OFFSET_SECONDS, InvalidationLevel, type KeymapEntry, type LateTickPolicy, type LinePoint, type LogicalRange, LogoWatermark, type LogoWatermarkOptions, type LtpEvent, type MarkerPosition, type MarkerShape, type MarkerSize, type MarketDepth, type OpenAlgoConfig, OpenAlgoDataFeed, type OpenAlgoLiveConfig, OpenAlgoLiveDataFeed, type OpenAlgoTradeConfig, OpenAlgoTradeFeed, type OpenAlgoWsConfig, OpenAlgoWsFeed, type OrderSide$1 as OrderSide, type OrderType$1 as OrderType, type OriginalTime, Pane, type PaneInvalidation, type PlaceOrder, type PositionSide, PriceLine, type PriceLineOptions, type PriceRange, PriceScale, type PriceScaleId, type PriceScaleMode, type PriceScaleOptions, type PrimitiveHit, type PrimitiveHost, type PrimitiveRenderContext, type RendererEntry, type SeriesApi, type SeriesDataItem, type SeriesMarker, SeriesMarkers, type SeriesRenderContext, type SeriesStyle, type SeriesType, type ShortcutListItem, ShortcutManager, type ShortcutManagerOptions, type ShortcutPreset, type ShortcutScope, type ShortcutTriggerEvent, type Size, type SocketFactory, type SocketLike, type SupertrendPoint, type Tick, TickBarAggregator, type TickTimeframe, TimeScale, type TimeScaleOp, type TimeScaleOptions, type TradeFeed, type TradeMarkerVariant, TradeMarkersPrimitive, type TradingColors, TradingController, type TradingHost, type TradingLineStyle, type TradingLineVariant, type TradingOrder, type TradingOrderSide, type TradingOrderType, type TradingPosition, type TradingSettings, type TradingSyncPayload, type TradingTrade, type UTCSeconds, type UnsubscribeFn, VERSION, type VolumeMode, type WatermarkPosition, type Whitespace, type WsControlMessage, type WsMode, type WsState, type ZOrder, atr, autoscaleRange, bestHit, bitmapSize, clamp, compactVolume, conflateBars, conflateItems, conflationGroupSize, createChart, darkTheme, drawShape, effectiveMarkerPx, ema, emaSeries, epochMsToUtcSeconds, eventToCombo, formatCombo, formatIstDate, formatIstTime, formatIstTimeSeconds, formatSubscribe, formatUnsubscribe, generateBars, getChartType, intervalToSeconds, isNewIstDay, isReservedCombo, isValidCombo, isWhitespace, istStringToUtcSeconds, lerp, lightTheme, mapHistoryResponse, mapOrder, mapPosition, markerSizePx, mergeBars, niceTicks, normalizeCombo, optimalBarWidth, parseCombo, parseMessage, precisionForStep, registerChartType, registeredChartTypes, roundToTick, rowTimeToUtcSeconds, rsi, rsiSeries, snapToDevicePixel, supertrend, supertrendSeries, toBar, trueRange, utcSecondsToIstDateString, utcSecondsToIstParts, version, verticalGradient, watermarkRect };
2226
+ export { ALT_PRESET, type AddSeriesOptions, type AggTick, BUILTIN_COMMANDS, type Bar, type BarUpdate, type BarsRequest, CandleBuilder, type CandleBuilderOptions, type CandleStyle, type CandleUpdate, Chart, type ChartEvent, type ChartOptions, type ChartTheme, type CrosshairMoveEvent, type CustomShortcut, DEFAULT_CANDLE_BUILDER_OPTIONS, DEFAULT_CANDLE_STYLE, DEFAULT_HISTOGRAM_STYLE, DEFAULT_KEYMAP, DEFAULT_PRICE_SCALE_OPTIONS, DEFAULT_THEME, DEFAULT_TIME_SCALE_OPTIONS, DEFAULT_TRADING_COLORS, type DataFeed, type DepthLevel, type DrawItem, EventMarkers, FakeDataFeed, type FeedScheduler, type HistogramStyle, type IPrimitive, IST_OFFSET_SECONDS, InvalidationLevel, type KeymapEntry, type LateTickPolicy, type LinePoint, type LogicalRange, LogoWatermark, type LogoWatermarkOptions, type LtpEvent, type MarkerPosition, type MarkerShape, type MarkerSize, type MarketDepth, type OpenAlgoConfig, OpenAlgoDataFeed, type OpenAlgoLiveConfig, OpenAlgoLiveDataFeed, type OpenAlgoTradeConfig, OpenAlgoTradeFeed, type OpenAlgoWsConfig, OpenAlgoWsFeed, type OrderSide$1 as OrderSide, type OrderType$1 as OrderType, type OriginalTime, Pane, type PaneInvalidation, type PlaceOrder, type PositionSide, PriceLine, type PriceLineOptions, type PriceRange, PriceScale, type PriceScaleId, type PriceScaleMode, type PriceScaleOptions, type PrimitiveHit, type PrimitiveHost, type PrimitiveRenderContext, type RendererEntry, type SeriesApi, type SeriesDataItem, type SeriesMarker, SeriesMarkers, type SeriesRenderContext, type SeriesStyle, type SeriesType, type ShortcutListItem, ShortcutManager, type ShortcutManagerOptions, type ShortcutPreset, type ShortcutScope, type ShortcutTriggerEvent, type Size, type SocketFactory, type SocketLike, type SupertrendPoint, type Tick, TickBarAggregator, type TickMarkType, type TickTimeframe, TimeScale, type TimeScaleOp, type TimeScaleOptions, type TradeFeed, type TradeMarkerVariant, TradeMarkersPrimitive, type TradingColors, TradingController, type TradingHost, type TradingLineStyle, type TradingLineVariant, type TradingOrder, type TradingOrderSide, type TradingOrderType, type TradingPosition, type TradingSettings, type TradingSyncPayload, type TradingTrade, type UTCSeconds, type UnsubscribeFn, VERSION, type VolumeMode, type WatermarkPosition, type Whitespace, type WsControlMessage, type WsMode, type WsState, type ZOrder, atr, autoscaleRange, bestHit, bitmapSize, clamp, compactVolume, conflateBars, conflateItems, conflationGroupSize, createChart, darkTheme, drawShape, effectiveMarkerPx, ema, emaSeries, epochMsToUtcSeconds, eventToCombo, formatCombo, formatIstDate, formatIstTime, formatIstTimeSeconds, formatSubscribe, formatUnsubscribe, generateBars, getChartType, intervalToSeconds, isNewIstDay, isReservedCombo, isValidCombo, isWhitespace, istStringToUtcSeconds, lerp, lightTheme, mapHistoryResponse, mapOrder, mapPosition, markerSizePx, mergeBars, niceTicks, normalizeCombo, optimalBarWidth, parseCombo, parseMessage, precisionForStep, registerChartType, registeredChartTypes, roundToTick, rowTimeToUtcSeconds, rsi, rsiSeries, snapToDevicePixel, supertrend, supertrendSeries, toBar, trueRange, utcSecondsToIstDateString, utcSecondsToIstParts, version, verticalGradient, watermarkRect };