market-feed 0.9.0 → 1.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,79 @@
1
1
  # market-feed Changelog
2
2
 
3
+ ## 1.0.0 — 2026-03-12
4
+
5
+ ### New module
6
+
7
+ **`market-feed/react`** — React hooks for live market data. Requires React ≥ 18.
8
+
9
+ ```tsx
10
+ import { useQuote, useStream, useAlerts } from "market-feed/react";
11
+ import { MarketFeed } from "market-feed";
12
+
13
+ const feed = new MarketFeed();
14
+
15
+ // Poll a single quote
16
+ function StockPrice({ symbol }: { symbol: string }) {
17
+ const { data, loading, error } = useQuote(feed, symbol);
18
+ if (loading) return <span>…</span>;
19
+ if (error) return <span>Error: {error.message}</span>;
20
+ return <span>{symbol}: ${data?.price.toFixed(2)}</span>;
21
+ }
22
+
23
+ // Subscribe to a live stream
24
+ function LiveFeed() {
25
+ const { event } = useStream(feed, ["AAPL", "MSFT", "GOOGL"]);
26
+ if (!event || event.type !== "quote") return null;
27
+ return <p>{event.symbol}: ${event.quote.price}</p>;
28
+ }
29
+
30
+ // Collect price alerts
31
+ function AlertLog() {
32
+ const { events, clearEvents } = useAlerts(feed, [
33
+ { symbol: "AAPL", condition: { type: "price_above", threshold: 200 }, once: false },
34
+ ]);
35
+ return (
36
+ <ul>
37
+ {events.map((e, i) => <li key={i}>{e.alert.symbol} triggered @ ${e.quote.price}</li>)}
38
+ <button onClick={clearEvents}>Clear</button>
39
+ </ul>
40
+ );
41
+ }
42
+ ```
43
+
44
+ #### Hook reference
45
+
46
+ **`useQuote(source, symbol, options?)`**
47
+
48
+ | Option | Default | Description |
49
+ |--------|---------|-------------|
50
+ | `intervalMs` | `5000` | Poll interval in milliseconds |
51
+ | `enabled` | `true` | Set to `false` to suspend polling |
52
+
53
+ Returns `{ data: Quote \| null, loading: boolean, error: Error \| null, refetch() }`.
54
+
55
+ **`useStream(feed, symbols, options?)`**
56
+
57
+ Drives a `watch()` async generator. Restarts automatically when `symbols` changes. Stops on unmount via an internal `AbortSignal`.
58
+
59
+ Returns `{ event: StreamEvent \| null, error: Error \| null }`.
60
+
61
+ **`useAlerts(feed, alerts, options?)`**
62
+
63
+ Drives a `watchAlerts()` async generator. Restarts when alert definitions (symbol + condition type + threshold) change.
64
+
65
+ Returns `{ events: AlertEvent[], error: Error \| null, clearEvents() }`.
66
+
67
+ #### Note on peer dependency
68
+
69
+ `react` is a peer dependency — install it separately in your project:
70
+
71
+ ```
72
+ npm install react
73
+ ```
74
+
75
+ ---
76
+
3
77
  ## 0.9.0 — 2026-03-12
4
78
 
5
79
  ### New module
package/dist/alerts.d.cts CHANGED
@@ -1,44 +1,6 @@
1
1
  import { a as Quote } from './quote-Cfh_7Cgg.cjs';
2
-
3
- type AlertCondition = {
4
- type: "price_above";
5
- threshold: number;
6
- } | {
7
- type: "price_below";
8
- threshold: number;
9
- } | {
10
- type: "change_pct_above";
11
- threshold: number;
12
- } | {
13
- type: "change_pct_below";
14
- threshold: number;
15
- } | {
16
- type: "volume_above";
17
- threshold: number;
18
- };
19
- interface AlertConfig {
20
- symbol: string;
21
- condition: AlertCondition;
22
- /** Emit this alert at most once, then stop watching it. Defaults to false. */
23
- once?: boolean;
24
- /**
25
- * Suppress re-fires within this many milliseconds after the last trigger.
26
- * Defaults to 0 (no debounce).
27
- */
28
- debounceMs?: number;
29
- }
30
- interface AlertEvent {
31
- type: "triggered";
32
- alert: AlertConfig;
33
- quote: Quote;
34
- triggeredAt: Date;
35
- }
36
- interface AlertsOptions {
37
- /** Poll interval in milliseconds. Defaults to 5 000. */
38
- intervalMs?: number;
39
- /** AbortSignal to stop the generator. */
40
- signal?: AbortSignal;
41
- }
2
+ import { A as AlertConfig, a as AlertsOptions, b as AlertEvent } from './types-hzOO9Cst.cjs';
3
+ export { c as AlertCondition } from './types-hzOO9Cst.cjs';
42
4
 
43
5
  interface QuoteFetcher {
44
6
  quote(symbols: string[]): Promise<Quote[]>;
@@ -67,4 +29,4 @@ interface QuoteFetcher {
67
29
  */
68
30
  declare function watchAlerts(feed: QuoteFetcher, alerts: AlertConfig[], options?: AlertsOptions): AsyncGenerator<AlertEvent>;
69
31
 
70
- export { type AlertCondition, type AlertConfig, type AlertEvent, type AlertsOptions, watchAlerts };
32
+ export { AlertConfig, AlertEvent, AlertsOptions, watchAlerts };
package/dist/alerts.d.ts CHANGED
@@ -1,44 +1,6 @@
1
1
  import { a as Quote } from './quote-Cfh_7Cgg.js';
2
-
3
- type AlertCondition = {
4
- type: "price_above";
5
- threshold: number;
6
- } | {
7
- type: "price_below";
8
- threshold: number;
9
- } | {
10
- type: "change_pct_above";
11
- threshold: number;
12
- } | {
13
- type: "change_pct_below";
14
- threshold: number;
15
- } | {
16
- type: "volume_above";
17
- threshold: number;
18
- };
19
- interface AlertConfig {
20
- symbol: string;
21
- condition: AlertCondition;
22
- /** Emit this alert at most once, then stop watching it. Defaults to false. */
23
- once?: boolean;
24
- /**
25
- * Suppress re-fires within this many milliseconds after the last trigger.
26
- * Defaults to 0 (no debounce).
27
- */
28
- debounceMs?: number;
29
- }
30
- interface AlertEvent {
31
- type: "triggered";
32
- alert: AlertConfig;
33
- quote: Quote;
34
- triggeredAt: Date;
35
- }
36
- interface AlertsOptions {
37
- /** Poll interval in milliseconds. Defaults to 5 000. */
38
- intervalMs?: number;
39
- /** AbortSignal to stop the generator. */
40
- signal?: AbortSignal;
41
- }
2
+ import { A as AlertConfig, a as AlertsOptions, b as AlertEvent } from './types-D90J5xwU.js';
3
+ export { c as AlertCondition } from './types-D90J5xwU.js';
42
4
 
43
5
  interface QuoteFetcher {
44
6
  quote(symbols: string[]): Promise<Quote[]>;
@@ -67,4 +29,4 @@ interface QuoteFetcher {
67
29
  */
68
30
  declare function watchAlerts(feed: QuoteFetcher, alerts: AlertConfig[], options?: AlertsOptions): AsyncGenerator<AlertEvent>;
69
31
 
70
- export { type AlertCondition, type AlertConfig, type AlertEvent, type AlertsOptions, watchAlerts };
32
+ export { AlertConfig, AlertEvent, AlertsOptions, watchAlerts };