market-feed 0.8.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 +135 -0
- package/dist/alerts.d.cts +3 -41
- package/dist/alerts.d.ts +3 -41
- package/dist/react.cjs +735 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +103 -0
- package/dist/react.d.ts +103 -0
- package/dist/react.js +731 -0
- package/dist/react.js.map +1 -0
- package/dist/screener.cjs +76 -0
- package/dist/screener.cjs.map +1 -0
- package/dist/screener.d.cts +108 -0
- package/dist/screener.d.ts +108 -0
- package/dist/screener.js +74 -0
- package/dist/screener.js.map +1 -0
- package/dist/stream.d.cts +7 -84
- package/dist/stream.d.ts +7 -84
- package/dist/types-B5oHwrPy.d.ts +85 -0
- package/dist/types-C8OPQ-Yj.d.cts +85 -0
- package/dist/types-D90J5xwU.d.ts +43 -0
- package/dist/types-hzOO9Cst.d.cts +43 -0
- package/package.json +25 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,140 @@
|
|
|
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
|
+
|
|
77
|
+
## 0.9.0 — 2026-03-12
|
|
78
|
+
|
|
79
|
+
### New module
|
|
80
|
+
|
|
81
|
+
**`market-feed/screener`** — Filter a list of symbols against a set of criteria using live quote data.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { screen } from "market-feed/screener";
|
|
85
|
+
import { MarketFeed } from "market-feed";
|
|
86
|
+
|
|
87
|
+
const feed = new MarketFeed();
|
|
88
|
+
|
|
89
|
+
const results = await screen(feed, ["AAPL", "MSFT", "GOOGL", "TSLA", "NVDA"], {
|
|
90
|
+
criteria: [
|
|
91
|
+
{ type: "price_above", value: 100 },
|
|
92
|
+
{ type: "change_pct_above", value: 1.5 },
|
|
93
|
+
{ type: "volume_above", value: 10_000_000 },
|
|
94
|
+
{ type: "market_cap_above", value: 100_000_000_000 },
|
|
95
|
+
],
|
|
96
|
+
limit: 10,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
console.log(results.map((r) => `${r.symbol} @ ${r.quote.price}`));
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Criterion types
|
|
103
|
+
|
|
104
|
+
| Type | Description |
|
|
105
|
+
|------|-------------|
|
|
106
|
+
| `price_above` / `price_below` | Filter by current price |
|
|
107
|
+
| `change_pct_above` / `change_pct_below` | Filter by daily % change |
|
|
108
|
+
| `volume_above` / `volume_below` | Filter by trading volume |
|
|
109
|
+
| `market_cap_above` / `market_cap_below` | Filter by market cap |
|
|
110
|
+
| `52w_high_pct_below` | Price is within N% of the 52-week high |
|
|
111
|
+
| `52w_low_pct_above` | Price is at least N% above the 52-week low |
|
|
112
|
+
| `custom` | Arbitrary predicate: `{ type: "custom", fn: (quote) => boolean }` |
|
|
113
|
+
|
|
114
|
+
All criteria are evaluated with **AND logic** — a symbol must pass every criterion to be included.
|
|
115
|
+
|
|
116
|
+
#### Options
|
|
117
|
+
|
|
118
|
+
| Option | Description |
|
|
119
|
+
|--------|-------------|
|
|
120
|
+
| `criteria` | Array of `ScreenerCriterion` (required) |
|
|
121
|
+
| `batchSize` | Max symbols per quote fetch call (default: all at once) |
|
|
122
|
+
| `limit` | Max number of results to return |
|
|
123
|
+
|
|
124
|
+
#### Result shape
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
interface ScreenerResult {
|
|
128
|
+
symbol: string;
|
|
129
|
+
quote: Quote;
|
|
130
|
+
matchedCriteria: number; // always === criteria.length
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`screen()` accepts any object with a `quote(symbols[]) → Quote[]` method — works with `MarketFeed`, individual providers, or your own mock.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
3
138
|
## 0.8.0 — 2026-03-12
|
|
4
139
|
|
|
5
140
|
### 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
|
-
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
32
|
+
export { AlertConfig, AlertEvent, AlertsOptions, watchAlerts };
|