@adrienhobbs/candlekit 0.1.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/LICENSE +21 -0
- package/README.md +129 -0
- package/dist/index.d.ts +425 -0
- package/dist/index.js +3903 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 adrienhobbs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Trading Chart Component
|
|
2
|
+
|
|
3
|
+
A powerful, provider-agnostic trading chart built on TradingView's Lightweight Charts library.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Chart Visualization
|
|
8
|
+
- Real-time candlestick charts with volume
|
|
9
|
+
- Technical indicators (SMA, EMA, RSI, Bollinger Bands, VWAP)
|
|
10
|
+
- Interactive price lines for entry/exit levels
|
|
11
|
+
- Bar selection and inspection
|
|
12
|
+
- Infinite scroll for historical data
|
|
13
|
+
- Context menu for quick actions
|
|
14
|
+
|
|
15
|
+
### Data Management
|
|
16
|
+
- Provider-agnostic architecture (works with any data source)
|
|
17
|
+
- Built-in Alpaca Markets integration
|
|
18
|
+
- Real-time WebSocket support
|
|
19
|
+
- Historical data fetching with pagination
|
|
20
|
+
- Data validation and normalization utilities
|
|
21
|
+
- Error handling and retry logic
|
|
22
|
+
- Easy to create custom adapters for other providers
|
|
23
|
+
|
|
24
|
+
## Install (as a package)
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @adrienhobbs/candlekit lightweight-charts react react-dom
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`react`, `react-dom`, and `lightweight-charts` are peer dependencies — install them
|
|
31
|
+
alongside the package.
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { ChartComponent } from '@adrienhobbs/candlekit';
|
|
35
|
+
import '@adrienhobbs/candlekit/styles.css';
|
|
36
|
+
|
|
37
|
+
<ChartComponent bars={bars} />
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Indicator overlays persist via localStorage by default
|
|
41
|
+
(`createPersistenceAdapter('localStorage')`), or pass `'noop'` to disable.
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
> The sections below describe the **dev harness** (`npm run dev`) bundled in this repo,
|
|
46
|
+
> not the published package.
|
|
47
|
+
|
|
48
|
+
### Option 1: With Mock Data (No Setup Required)
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install
|
|
52
|
+
npm run dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The app will run with realistic mock data - perfect for testing and development.
|
|
56
|
+
|
|
57
|
+
### Option 2: With Real Alpaca Market Data
|
|
58
|
+
|
|
59
|
+
1. Install dependencies:
|
|
60
|
+
```bash
|
|
61
|
+
npm install
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
2. Get free Alpaca API credentials (see below)
|
|
65
|
+
|
|
66
|
+
3. Copy `.env.example` to `.env` and add your credentials:
|
|
67
|
+
```bash
|
|
68
|
+
cp .env.example .env
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Edit `.env`:
|
|
72
|
+
```
|
|
73
|
+
VITE_ALPACA_API_KEY=your-api-key
|
|
74
|
+
VITE_ALPACA_SECRET_KEY=your-secret-key
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
4. Run the development server:
|
|
78
|
+
```bash
|
|
79
|
+
npm run dev
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The app will automatically detect your API keys and switch to real market data!
|
|
83
|
+
|
|
84
|
+
## Getting Alpaca API Credentials
|
|
85
|
+
|
|
86
|
+
1. Sign up for a free account at [Alpaca Markets](https://alpaca.markets/)
|
|
87
|
+
2. Navigate to the [Paper Trading Dashboard](https://app.alpaca.markets/paper/dashboard/overview)
|
|
88
|
+
3. Go to "Your API Keys" section
|
|
89
|
+
4. Generate new API keys
|
|
90
|
+
5. Copy the API Key ID and Secret Key to your `.env` file
|
|
91
|
+
|
|
92
|
+
## Documentation
|
|
93
|
+
|
|
94
|
+
See the [docs](./docs) folder for comprehensive documentation:
|
|
95
|
+
|
|
96
|
+
- [Data Management Guide](./docs/data-management.md) - Complete guide to fetching and managing market data
|
|
97
|
+
- [ChartComponent Usage](./docs/chart-component.md) - Complete guide to using the chart
|
|
98
|
+
- [Creating Indicators](./docs/creating-indicators.md) - Build custom indicators
|
|
99
|
+
- [Architecture](./docs/architecture.md) - System design and architecture
|
|
100
|
+
- [API Reference](./docs/api-reference.md) - Complete API documentation
|
|
101
|
+
- [Examples](./docs/examples.md) - Code examples and recipes
|
|
102
|
+
|
|
103
|
+
## Project Structure
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
src/
|
|
107
|
+
├── components/ # React components
|
|
108
|
+
│ ├── ChartComponent.tsx
|
|
109
|
+
│ ├── IndicatorBrowser.tsx
|
|
110
|
+
│ └── SettingsDialog.tsx
|
|
111
|
+
├── hooks/ # Custom React hooks
|
|
112
|
+
│ ├── useBarsData.ts # Data management hook
|
|
113
|
+
│ ├── useChartAPI.ts # Chart API hook
|
|
114
|
+
│ └── useRealtimeUpdates.ts (deprecated)
|
|
115
|
+
├── adapters/ # Data provider adapters
|
|
116
|
+
│ ├── types.ts
|
|
117
|
+
│ └── alpaca.ts
|
|
118
|
+
├── indicators/ # Technical indicators
|
|
119
|
+
│ ├── core/
|
|
120
|
+
│ ├── primitives/
|
|
121
|
+
│ ├── registry/
|
|
122
|
+
│ └── utils/
|
|
123
|
+
├── types/ # TypeScript type definitions
|
|
124
|
+
└── utils/ # Utility functions
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
interface OHLCVBar {
|
|
5
|
+
timestamp: number;
|
|
6
|
+
open: number;
|
|
7
|
+
high: number;
|
|
8
|
+
low: number;
|
|
9
|
+
close: number;
|
|
10
|
+
volume: number;
|
|
11
|
+
trade_count?: number;
|
|
12
|
+
vwap?: number;
|
|
13
|
+
}
|
|
14
|
+
interface ChartLine {
|
|
15
|
+
id: string;
|
|
16
|
+
price: number;
|
|
17
|
+
color: string;
|
|
18
|
+
lineWidth?: number;
|
|
19
|
+
lineStyle?: 'solid' | 'dashed' | 'dotted';
|
|
20
|
+
title?: string;
|
|
21
|
+
type?: 'entry' | 'stopLoss' | 'takeProfit';
|
|
22
|
+
}
|
|
23
|
+
interface IndicatorSettings$1 {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
interface IndicatorPanel {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
type: 'line' | 'histogram' | 'area';
|
|
30
|
+
settings: IndicatorSettings$1;
|
|
31
|
+
data: any[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare enum IndicatorCategory {
|
|
35
|
+
TREND = "Trend",
|
|
36
|
+
MOMENTUM = "Momentum",
|
|
37
|
+
VOLATILITY = "Volatility",
|
|
38
|
+
VOLUME = "Volume",
|
|
39
|
+
OSCILLATORS = "Oscillators"
|
|
40
|
+
}
|
|
41
|
+
declare enum ChartSeriesType {
|
|
42
|
+
LINE = "line",
|
|
43
|
+
HISTOGRAM = "histogram",
|
|
44
|
+
AREA = "area"
|
|
45
|
+
}
|
|
46
|
+
declare const SettingFieldTypeSchema: z.ZodEnum<{
|
|
47
|
+
number: "number";
|
|
48
|
+
boolean: "boolean";
|
|
49
|
+
color: "color";
|
|
50
|
+
select: "select";
|
|
51
|
+
lineStyle: "lineStyle";
|
|
52
|
+
}>;
|
|
53
|
+
declare const LineStyleSchema: z.ZodEnum<{
|
|
54
|
+
solid: "solid";
|
|
55
|
+
dashed: "dashed";
|
|
56
|
+
dotted: "dotted";
|
|
57
|
+
}>;
|
|
58
|
+
declare const SettingFieldSchema: z.ZodObject<{
|
|
59
|
+
type: z.ZodEnum<{
|
|
60
|
+
number: "number";
|
|
61
|
+
boolean: "boolean";
|
|
62
|
+
color: "color";
|
|
63
|
+
select: "select";
|
|
64
|
+
lineStyle: "lineStyle";
|
|
65
|
+
}>;
|
|
66
|
+
label: z.ZodString;
|
|
67
|
+
defaultValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
68
|
+
description: z.ZodOptional<z.ZodString>;
|
|
69
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
step: z.ZodOptional<z.ZodNumber>;
|
|
72
|
+
options: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
73
|
+
label: z.ZodString;
|
|
74
|
+
value: z.ZodString;
|
|
75
|
+
}, z.core.$strip>>>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
declare const IndicatorSettingsSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
78
|
+
type: z.ZodEnum<{
|
|
79
|
+
number: "number";
|
|
80
|
+
boolean: "boolean";
|
|
81
|
+
color: "color";
|
|
82
|
+
select: "select";
|
|
83
|
+
lineStyle: "lineStyle";
|
|
84
|
+
}>;
|
|
85
|
+
label: z.ZodString;
|
|
86
|
+
defaultValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
87
|
+
description: z.ZodOptional<z.ZodString>;
|
|
88
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
89
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
step: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
options: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
92
|
+
label: z.ZodString;
|
|
93
|
+
value: z.ZodString;
|
|
94
|
+
}, z.core.$strip>>>;
|
|
95
|
+
}, z.core.$strip>>;
|
|
96
|
+
declare const IndicatorMetadataSchema: z.ZodObject<{
|
|
97
|
+
id: z.ZodString;
|
|
98
|
+
name: z.ZodString;
|
|
99
|
+
description: z.ZodString;
|
|
100
|
+
category: z.ZodEnum<typeof IndicatorCategory>;
|
|
101
|
+
version: z.ZodDefault<z.ZodString>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
declare const RenderConfigSchema: z.ZodObject<{
|
|
104
|
+
seriesType: z.ZodEnum<typeof ChartSeriesType>;
|
|
105
|
+
outputCount: z.ZodDefault<z.ZodNumber>;
|
|
106
|
+
overlay: z.ZodDefault<z.ZodBoolean>;
|
|
107
|
+
hasBandFill: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
fillBands: z.ZodOptional<z.ZodObject<{
|
|
109
|
+
upper: z.ZodString;
|
|
110
|
+
lower: z.ZodString;
|
|
111
|
+
}, z.core.$strip>>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
type SettingFieldType = z.infer<typeof SettingFieldTypeSchema>;
|
|
114
|
+
type LineStyle = z.infer<typeof LineStyleSchema>;
|
|
115
|
+
type SettingField = z.infer<typeof SettingFieldSchema>;
|
|
116
|
+
type IndicatorSettings = z.infer<typeof IndicatorSettingsSchema>;
|
|
117
|
+
type IndicatorMetadata = z.infer<typeof IndicatorMetadataSchema>;
|
|
118
|
+
type RenderConfig = z.infer<typeof RenderConfigSchema>;
|
|
119
|
+
interface IndicatorOutput {
|
|
120
|
+
time: number;
|
|
121
|
+
value: number;
|
|
122
|
+
[key: string]: number;
|
|
123
|
+
}
|
|
124
|
+
type IndicatorCalculation = (bars: OHLCVBar[], settings: Record<string, any>) => IndicatorOutput[];
|
|
125
|
+
interface IndicatorDefinition {
|
|
126
|
+
metadata: IndicatorMetadata;
|
|
127
|
+
settings: IndicatorSettings;
|
|
128
|
+
renderConfig: RenderConfig;
|
|
129
|
+
calculate: IndicatorCalculation;
|
|
130
|
+
}
|
|
131
|
+
interface IndicatorInstance {
|
|
132
|
+
id: string;
|
|
133
|
+
definitionId: string;
|
|
134
|
+
name: string;
|
|
135
|
+
settings: Record<string, any>;
|
|
136
|
+
data?: IndicatorOutput[];
|
|
137
|
+
}
|
|
138
|
+
declare const IndicatorInstanceSchema: z.ZodObject<{
|
|
139
|
+
id: z.ZodString;
|
|
140
|
+
definitionId: z.ZodString;
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
settings: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
143
|
+
}, z.core.$strip>;
|
|
144
|
+
|
|
145
|
+
interface ChartComponentProps {
|
|
146
|
+
bars: OHLCVBar[];
|
|
147
|
+
onLoadMoreData?: (oldestTimestamp: number) => void;
|
|
148
|
+
indicators?: IndicatorInstance[];
|
|
149
|
+
lines?: ChartLine[];
|
|
150
|
+
onBarUpdate?: (updatedBar: OHLCVBar) => void;
|
|
151
|
+
onNewBar?: (newBar: OHLCVBar) => void;
|
|
152
|
+
onDeleteLine?: (lineId: string) => void;
|
|
153
|
+
onAddLine?: (type: 'entry' | 'stopLoss' | 'takeProfit' | 'support' | 'resistance', price: number) => void;
|
|
154
|
+
onClearAllLines?: () => void;
|
|
155
|
+
enableBarSelection?: boolean;
|
|
156
|
+
onBarClick?: (bar: OHLCVBar | null) => void;
|
|
157
|
+
}
|
|
158
|
+
declare function ChartComponent({ bars, onLoadMoreData, indicators, lines, onBarUpdate, onNewBar, onDeleteLine, onAddLine, onClearAllLines, enableBarSelection, onBarClick, }: ChartComponentProps): react_jsx_runtime.JSX.Element;
|
|
159
|
+
|
|
160
|
+
interface IndicatorBrowserProps {
|
|
161
|
+
isOpen: boolean;
|
|
162
|
+
onClose: () => void;
|
|
163
|
+
onAddIndicator: (definitionId: string) => void;
|
|
164
|
+
}
|
|
165
|
+
declare function IndicatorBrowser({ isOpen, onClose, onAddIndicator, }: IndicatorBrowserProps): react_jsx_runtime.JSX.Element | null;
|
|
166
|
+
|
|
167
|
+
interface IndicatorSettingsFormProps {
|
|
168
|
+
settings: IndicatorSettings;
|
|
169
|
+
currentValues: Record<string, any>;
|
|
170
|
+
onChange: (key: string, value: any) => void;
|
|
171
|
+
}
|
|
172
|
+
declare function IndicatorSettingsForm({ settings, currentValues, onChange, }: IndicatorSettingsFormProps): react_jsx_runtime.JSX.Element;
|
|
173
|
+
|
|
174
|
+
interface SettingsDialogProps {
|
|
175
|
+
isOpen: boolean;
|
|
176
|
+
onClose: () => void;
|
|
177
|
+
indicator: IndicatorInstance | null;
|
|
178
|
+
onSave: (indicatorId: string, settings: Record<string, any>) => void;
|
|
179
|
+
}
|
|
180
|
+
declare function SettingsDialog({ isOpen, onClose, indicator, onSave, }: SettingsDialogProps): react_jsx_runtime.JSX.Element | null;
|
|
181
|
+
|
|
182
|
+
interface PersistenceAdapter {
|
|
183
|
+
saveIndicators(indicators: IndicatorInstance[]): Promise<void>;
|
|
184
|
+
loadIndicators(): Promise<IndicatorInstance[]>;
|
|
185
|
+
deleteIndicator(id: string): Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
declare class LocalStoragePersistenceAdapter implements PersistenceAdapter {
|
|
188
|
+
private storageKey;
|
|
189
|
+
saveIndicators(indicators: IndicatorInstance[]): Promise<void>;
|
|
190
|
+
loadIndicators(): Promise<IndicatorInstance[]>;
|
|
191
|
+
deleteIndicator(id: string): Promise<void>;
|
|
192
|
+
}
|
|
193
|
+
declare class NoOpPersistenceAdapter implements PersistenceAdapter {
|
|
194
|
+
saveIndicators(indicators: IndicatorInstance[]): Promise<void>;
|
|
195
|
+
loadIndicators(): Promise<IndicatorInstance[]>;
|
|
196
|
+
deleteIndicator(id: string): Promise<void>;
|
|
197
|
+
}
|
|
198
|
+
declare function createPersistenceAdapter(kind: 'noop' | 'localStorage'): PersistenceAdapter;
|
|
199
|
+
|
|
200
|
+
interface UseChartAPIOptions {
|
|
201
|
+
persistenceAdapter?: PersistenceAdapter;
|
|
202
|
+
}
|
|
203
|
+
declare function useChartAPI(options?: UseChartAPIOptions): {
|
|
204
|
+
lines: ChartLine[];
|
|
205
|
+
indicators: IndicatorInstance[];
|
|
206
|
+
isLoadingIndicators: boolean;
|
|
207
|
+
addLine: (id: string, price: number, options?: {
|
|
208
|
+
color?: string;
|
|
209
|
+
lineWidth?: number;
|
|
210
|
+
lineStyle?: "solid" | "dashed" | "dotted";
|
|
211
|
+
title?: string;
|
|
212
|
+
}) => void;
|
|
213
|
+
removeLine: (id: string) => void;
|
|
214
|
+
updateLine: (id: string, price: number) => void;
|
|
215
|
+
addEntryLine: (price: number) => void;
|
|
216
|
+
addStopLoss: (price: number) => void;
|
|
217
|
+
addTakeProfit: (price: number) => void;
|
|
218
|
+
addSupportLine: (price: number) => void;
|
|
219
|
+
addResistanceLine: (price: number) => void;
|
|
220
|
+
clearAllLines: () => void;
|
|
221
|
+
addLineByType: (type: "entry" | "stopLoss" | "takeProfit" | "support" | "resistance", price: number) => void;
|
|
222
|
+
addIndicator: (definitionId: string, customSettings?: Record<string, any>) => IndicatorInstance;
|
|
223
|
+
removeIndicator: (id: string) => void;
|
|
224
|
+
updateIndicatorSettings: (id: string, settings: Record<string, any>) => void;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
interface HistoricalDataParams {
|
|
228
|
+
symbol: string;
|
|
229
|
+
timeframe: string;
|
|
230
|
+
before?: number;
|
|
231
|
+
after?: number;
|
|
232
|
+
limit?: number;
|
|
233
|
+
}
|
|
234
|
+
interface RealtimeSubscription {
|
|
235
|
+
unsubscribe: () => void;
|
|
236
|
+
}
|
|
237
|
+
interface RealtimeHandlers {
|
|
238
|
+
onBar?: (bar: OHLCVBar) => void;
|
|
239
|
+
onTrade?: (price: number, volume: number) => void;
|
|
240
|
+
onError?: (error: Error) => void;
|
|
241
|
+
onConnect?: () => void;
|
|
242
|
+
onDisconnect?: () => void;
|
|
243
|
+
}
|
|
244
|
+
interface BarDataAdapter {
|
|
245
|
+
fetchHistoricalBars(params: HistoricalDataParams): Promise<OHLCVBar[]>;
|
|
246
|
+
subscribeRealtime?(symbol: string, handlers: RealtimeHandlers): RealtimeSubscription;
|
|
247
|
+
unsubscribeAll?(): void;
|
|
248
|
+
}
|
|
249
|
+
interface BarDataAdapterOptions {
|
|
250
|
+
apiKey?: string;
|
|
251
|
+
secretKey?: string;
|
|
252
|
+
baseUrl?: string;
|
|
253
|
+
[key: string]: any;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
interface UseBarsDataOptions {
|
|
257
|
+
adapter?: BarDataAdapter;
|
|
258
|
+
symbol?: string;
|
|
259
|
+
timeframe?: string;
|
|
260
|
+
autoFetch?: boolean;
|
|
261
|
+
autoSubscribe?: boolean;
|
|
262
|
+
limit?: number;
|
|
263
|
+
}
|
|
264
|
+
interface UseBarsDataReturn {
|
|
265
|
+
bars: OHLCVBar[];
|
|
266
|
+
loading: boolean;
|
|
267
|
+
error: Error | null;
|
|
268
|
+
connected: boolean;
|
|
269
|
+
setBars: (bars: OHLCVBar[]) => void;
|
|
270
|
+
appendBar: (bar: OHLCVBar) => void;
|
|
271
|
+
updateLastBar: (bar: OHLCVBar) => void;
|
|
272
|
+
updateCurrentBar: (tradePrice: number, tradeVolume: number) => void;
|
|
273
|
+
prependBars: (bars: OHLCVBar[]) => void;
|
|
274
|
+
clearBars: () => void;
|
|
275
|
+
fetchHistorical: (params?: Partial<HistoricalDataParams>) => Promise<void>;
|
|
276
|
+
subscribe: () => void;
|
|
277
|
+
unsubscribe: () => void;
|
|
278
|
+
refetch: () => Promise<void>;
|
|
279
|
+
}
|
|
280
|
+
declare function useBarsData(options?: UseBarsDataOptions): UseBarsDataReturn;
|
|
281
|
+
|
|
282
|
+
interface RealtimeUpdateConfig {
|
|
283
|
+
enabled: boolean;
|
|
284
|
+
updateIntervalMs: number;
|
|
285
|
+
newBarIntervalMs: number;
|
|
286
|
+
}
|
|
287
|
+
declare function useRealtimeUpdates(initialBars: OHLCVBar[], config: RealtimeUpdateConfig): {
|
|
288
|
+
bars: OHLCVBar[];
|
|
289
|
+
updateCurrentBar: (tradePrice: number, tradeVolume: number) => void;
|
|
290
|
+
addNewBar: (newBar: OHLCVBar) => void;
|
|
291
|
+
prependBars: (newBars: OHLCVBar[]) => void;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
declare class IndicatorRegistry {
|
|
295
|
+
private indicators;
|
|
296
|
+
private instanceCounters;
|
|
297
|
+
register(definition: IndicatorDefinition): void;
|
|
298
|
+
unregister(id: string): boolean;
|
|
299
|
+
get(id: string): IndicatorDefinition | undefined;
|
|
300
|
+
getAll(): IndicatorDefinition[];
|
|
301
|
+
getByCategory(category: IndicatorCategory): IndicatorDefinition[];
|
|
302
|
+
search(query: string): IndicatorDefinition[];
|
|
303
|
+
createInstance(definitionId: string, customSettings?: Record<string, any>): IndicatorInstance;
|
|
304
|
+
validateSettings(definitionId: string, settings: Record<string, any>): boolean;
|
|
305
|
+
getMetadataList(): IndicatorMetadata[];
|
|
306
|
+
clear(): void;
|
|
307
|
+
}
|
|
308
|
+
declare const indicatorRegistry: IndicatorRegistry;
|
|
309
|
+
|
|
310
|
+
declare class IndicatorCalculator {
|
|
311
|
+
private cache;
|
|
312
|
+
private hashSettings;
|
|
313
|
+
calculate(instance: IndicatorInstance, bars: OHLCVBar[]): IndicatorOutput[];
|
|
314
|
+
invalidateCache(instanceId?: string): void;
|
|
315
|
+
getCacheSize(): number;
|
|
316
|
+
}
|
|
317
|
+
declare const indicatorCalculator: IndicatorCalculator;
|
|
318
|
+
|
|
319
|
+
declare const SMAIndicator: IndicatorDefinition;
|
|
320
|
+
|
|
321
|
+
declare const EMAIndicator: IndicatorDefinition;
|
|
322
|
+
|
|
323
|
+
declare const RSIIndicator: IndicatorDefinition;
|
|
324
|
+
|
|
325
|
+
declare const BollingerBandsIndicator: IndicatorDefinition;
|
|
326
|
+
|
|
327
|
+
declare const VWAPIndicator: IndicatorDefinition;
|
|
328
|
+
|
|
329
|
+
declare const StochasticIndicator: IndicatorDefinition;
|
|
330
|
+
|
|
331
|
+
declare const OBVIndicator: IndicatorDefinition;
|
|
332
|
+
|
|
333
|
+
declare const MFIIndicator: IndicatorDefinition;
|
|
334
|
+
|
|
335
|
+
declare const ForceIndexIndicator: IndicatorDefinition;
|
|
336
|
+
|
|
337
|
+
declare const ATRIndicator: IndicatorDefinition;
|
|
338
|
+
|
|
339
|
+
declare const ADXIndicator: IndicatorDefinition;
|
|
340
|
+
|
|
341
|
+
declare const MACDIndicator: IndicatorDefinition;
|
|
342
|
+
|
|
343
|
+
declare const PSARIndicator: IndicatorDefinition;
|
|
344
|
+
|
|
345
|
+
declare const CCIIndicator: IndicatorDefinition;
|
|
346
|
+
|
|
347
|
+
declare const WilliamsRIndicator: IndicatorDefinition;
|
|
348
|
+
|
|
349
|
+
declare const KeltnerChannelsIndicator: IndicatorDefinition;
|
|
350
|
+
|
|
351
|
+
declare const SuperTrendIndicator: IndicatorDefinition;
|
|
352
|
+
|
|
353
|
+
declare const IchimokuIndicator: IndicatorDefinition;
|
|
354
|
+
|
|
355
|
+
declare const DonchianChannelsIndicator: IndicatorDefinition;
|
|
356
|
+
|
|
357
|
+
declare const ROCIndicator: IndicatorDefinition;
|
|
358
|
+
|
|
359
|
+
declare const StochRSIIndicator: IndicatorDefinition;
|
|
360
|
+
|
|
361
|
+
declare const WMAIndicator: IndicatorDefinition;
|
|
362
|
+
|
|
363
|
+
declare function registerBuiltInIndicators(): void;
|
|
364
|
+
|
|
365
|
+
declare function padIndicatorArray(result: number[], barsLength: number): number[];
|
|
366
|
+
declare function displaceArray(arr: number[], offset: number): number[];
|
|
367
|
+
declare function calculateSMA(bars: OHLCVBar[], period: number): number[];
|
|
368
|
+
declare function calculateEMA(bars: OHLCVBar[], period: number): number[];
|
|
369
|
+
declare function calculateRSI(bars: OHLCVBar[], period: number): number[];
|
|
370
|
+
declare function calculateStandardDeviation(values: number[], period: number): number[];
|
|
371
|
+
declare function calculateBollingerBands(bars: OHLCVBar[], period: number, stdDev: number): {
|
|
372
|
+
upper: number[];
|
|
373
|
+
middle: number[];
|
|
374
|
+
lower: number[];
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
declare class AlpacaBarAdapter implements BarDataAdapter {
|
|
378
|
+
private apiKey;
|
|
379
|
+
private secretKey;
|
|
380
|
+
private baseUrl;
|
|
381
|
+
private wsUrl;
|
|
382
|
+
private ws;
|
|
383
|
+
private reconnectAttempts;
|
|
384
|
+
private maxReconnectAttempts;
|
|
385
|
+
private reconnectDelay;
|
|
386
|
+
private currentHandlers;
|
|
387
|
+
private currentSymbol;
|
|
388
|
+
private authenticated;
|
|
389
|
+
constructor(options: BarDataAdapterOptions);
|
|
390
|
+
fetchHistoricalBars(params: HistoricalDataParams): Promise<OHLCVBar[]>;
|
|
391
|
+
subscribeRealtime(symbol: string, handlers: RealtimeHandlers): RealtimeSubscription;
|
|
392
|
+
unsubscribeAll(): void;
|
|
393
|
+
private connectWebSocket;
|
|
394
|
+
private authenticate;
|
|
395
|
+
private subscribe;
|
|
396
|
+
private handleMessage;
|
|
397
|
+
private handleTrade;
|
|
398
|
+
private handleBar;
|
|
399
|
+
private attemptReconnect;
|
|
400
|
+
private disconnect;
|
|
401
|
+
private convertAlpacaBars;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
declare class MockAdapter implements BarDataAdapter {
|
|
405
|
+
private intervalId;
|
|
406
|
+
fetchHistoricalBars(params: HistoricalDataParams): Promise<OHLCVBar[]>;
|
|
407
|
+
subscribeRealtime(symbol: string, handlers: RealtimeHandlers): RealtimeSubscription;
|
|
408
|
+
unsubscribeAll(): void;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
declare function validateBar(bar: any): bar is OHLCVBar;
|
|
412
|
+
declare function isValidBar(bar: any): bar is OHLCVBar;
|
|
413
|
+
declare function normalizeTimestamp(timestamp: number): number;
|
|
414
|
+
declare function sortBars(bars: OHLCVBar[]): OHLCVBar[];
|
|
415
|
+
declare function deduplicateBars(bars: OHLCVBar[]): OHLCVBar[];
|
|
416
|
+
declare function mergeBars(existingBars: OHLCVBar[], newBars: OHLCVBar[]): OHLCVBar[];
|
|
417
|
+
declare function validateAndNormalizeBars(bars: any[]): OHLCVBar[];
|
|
418
|
+
declare function updateBarInArray(bars: OHLCVBar[], updatedBar: OHLCVBar): OHLCVBar[];
|
|
419
|
+
declare function appendBar(bars: OHLCVBar[], newBar: OHLCVBar): OHLCVBar[];
|
|
420
|
+
declare function prependBars(bars: OHLCVBar[], newBars: OHLCVBar[]): OHLCVBar[];
|
|
421
|
+
declare function getOldestBar(bars: OHLCVBar[]): OHLCVBar | null;
|
|
422
|
+
declare function getNewestBar(bars: OHLCVBar[]): OHLCVBar | null;
|
|
423
|
+
declare function updateCurrentBar(bars: OHLCVBar[], tradePrice: number, tradeVolume: number): OHLCVBar[];
|
|
424
|
+
|
|
425
|
+
export { ADXIndicator, ATRIndicator, AlpacaBarAdapter, type BarDataAdapter, type BarDataAdapterOptions, BollingerBandsIndicator, CCIIndicator, ChartComponent, type ChartLine, ChartSeriesType, DonchianChannelsIndicator, EMAIndicator, ForceIndexIndicator, type HistoricalDataParams, IchimokuIndicator, IndicatorBrowser, type IndicatorCalculation, IndicatorCategory, type IndicatorDefinition, type IndicatorInstance, IndicatorInstanceSchema, type IndicatorMetadata, IndicatorMetadataSchema, type IndicatorOutput, type IndicatorPanel, type IndicatorSettings$1 as IndicatorSettings, IndicatorSettingsForm, IndicatorSettingsSchema, KeltnerChannelsIndicator, type LineStyle, LineStyleSchema, LocalStoragePersistenceAdapter, MACDIndicator, MFIIndicator, MockAdapter, NoOpPersistenceAdapter, OBVIndicator, type OHLCVBar, PSARIndicator, type PersistenceAdapter, ROCIndicator, RSIIndicator, type RealtimeHandlers, type RealtimeSubscription, type RenderConfig, RenderConfigSchema, SMAIndicator, type SettingField, SettingFieldSchema, type SettingFieldType, SettingFieldTypeSchema, SettingsDialog, StochRSIIndicator, StochasticIndicator, SuperTrendIndicator, VWAPIndicator, WMAIndicator, WilliamsRIndicator, appendBar, calculateBollingerBands, calculateEMA, calculateRSI, calculateSMA, calculateStandardDeviation, createPersistenceAdapter, deduplicateBars, displaceArray, getNewestBar, getOldestBar, indicatorCalculator, indicatorRegistry, isValidBar, mergeBars, normalizeTimestamp, padIndicatorArray, prependBars, registerBuiltInIndicators, sortBars, updateBarInArray, updateCurrentBar, useBarsData, useChartAPI, useRealtimeUpdates, validateAndNormalizeBars, validateBar };
|