@funnest/charts 0.0.0-stage → 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 +202 -0
- package/NOTICE +4 -0
- package/README.md +28 -2
- package/dist/chart.d.ts +300 -0
- package/dist/datafeed/combine.d.ts +7 -0
- package/dist/datafeed/latency.d.ts +5 -0
- package/dist/datafeed/socket.d.ts +60 -0
- package/dist/events.d.ts +7 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +3749 -0
- package/dist/indicators/definitions.d.ts +74 -0
- package/dist/indicators/manager.d.ts +26 -0
- package/dist/indicators/math.d.ts +21 -0
- package/dist/interaction.d.ts +81 -0
- package/dist/model/bar-store.d.ts +36 -0
- package/dist/model/price-scale.d.ts +35 -0
- package/dist/model/time-format.d.ts +50 -0
- package/dist/model/time-scale.d.ts +42 -0
- package/dist/objects/drawings.d.ts +52 -0
- package/dist/objects/magnet.d.ts +6 -0
- package/dist/objects/trading-sync.d.ts +72 -0
- package/dist/objects/trading.d.ts +76 -0
- package/dist/objects/types.d.ts +42 -0
- package/dist/price.d.ts +17 -0
- package/dist/realtime.d.ts +39 -0
- package/dist/render/canvas-layer.d.ts +13 -0
- package/dist/render/color-resolver.d.ts +14 -0
- package/dist/render/painter.d.ts +38 -0
- package/dist/render/renderer.d.ts +100 -0
- package/dist/resolution.d.ts +8 -0
- package/dist/session.d.ts +12 -0
- package/dist/settings.d.ts +40 -0
- package/dist/theme.d.ts +24 -0
- package/dist/types.d.ts +106 -0
- package/package.json +47 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @funnest/charts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Canvas 차트 엔진 — 캔들, 지표, 실시간 연결 도구
|
|
4
|
+
|
|
5
|
+
Canvas charting engine for financial charts: candles, indicators, realtime helpers.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @funnest/charts
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
UI 없이 엔진만 쓸 때의 패키지예요. 툴바·검색·지표 UI까지 필요하면 `@funnest/charts-ui`(또는 React는 `@funnest/charts-react`)를 쓰세요.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createChart } from '@funnest/charts';
|
|
15
|
+
|
|
16
|
+
const chart = createChart(document.getElementById('chart')!, { datafeed: myDatafeed });
|
|
17
|
+
await chart.setSymbol('005930', '1D');
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- 지표: MA, EMA, 볼린저 밴드, RSI, MACD
|
|
21
|
+
- 실시간 도구: `ReconnectingWebSocket`, `TickAggregator`, `combineDatafeeds`, `monitorLatency`
|
|
22
|
+
- 한국 시장 기본값: KST, KRX 장 시간·호가 단위(`krxTickSize`), 빨강 상승/파랑 하락
|
|
23
|
+
- 거래소 연결 코드는 들어 있지 않아요. `Datafeed` 인터페이스로 직접 연결하세요.
|
|
24
|
+
|
|
25
|
+
## 링크
|
|
26
|
+
|
|
27
|
+
- 문서: https://charts.funnest.xyz/docs/
|
|
28
|
+
- GitHub: https://github.com/funnest-xyz/funnest-charts
|
|
29
|
+
- 라이선스: Apache-2.0
|
package/dist/chart.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { type Locale } from './model/time-format';
|
|
2
|
+
import { TimeScale, type IndexRange, type TimeScaleOptions } from './model/time-scale';
|
|
3
|
+
import { type IndicatorParams, type IndicatorType } from './indicators/definitions';
|
|
4
|
+
import { type IndicatorConfig, type IndicatorPatch } from './indicators/manager';
|
|
5
|
+
import { type Drawing, type DrawingType } from './objects/drawings';
|
|
6
|
+
import { type ExecutionMarker, type LineHandle, type OrderLineOptions, type PositionLineOptions } from './objects/trading';
|
|
7
|
+
import { type ChartSettings, type ChartState } from './settings';
|
|
8
|
+
import { type TradingAdapter } from './objects/trading-sync';
|
|
9
|
+
import { type ChartType, type CrosshairInfo, type PaneId } from './render/renderer';
|
|
10
|
+
import { type ThemeTokens } from './theme';
|
|
11
|
+
import type { Bar, ConnectionState, Datafeed, Quote, Resolution, SymbolInfo, TickSize } from './types';
|
|
12
|
+
export interface ChartOptions {
|
|
13
|
+
/** Merged over the light theme. Values may use CSS variables: `{ background: 'var(--bg)' }`. */
|
|
14
|
+
theme?: Partial<ThemeTokens>;
|
|
15
|
+
locale?: Locale;
|
|
16
|
+
/** IANA timezone for axis labels. Defaults to the browser's; overridden by `SymbolInfo.timezone`. */
|
|
17
|
+
timezone?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Show all times in this timezone regardless of the symbol's exchange (e.g. 'Asia/Seoul'
|
|
20
|
+
* for Korean users watching US stocks). Takes precedence over `timezone` and the symbol's.
|
|
21
|
+
*/
|
|
22
|
+
displayTimezone?: string;
|
|
23
|
+
pricePrecision?: number;
|
|
24
|
+
tickSize?: TickSize;
|
|
25
|
+
/** Show the volume pane. Default true. (Same as `settings.volume`.) */
|
|
26
|
+
volume?: boolean;
|
|
27
|
+
/** Initial chart settings (high/low markers, grid, last price line, candle colors…). */
|
|
28
|
+
settings?: Partial<ChartSettings>;
|
|
29
|
+
timeScale?: Partial<TimeScaleOptions>;
|
|
30
|
+
/** Enables `setSymbol()` with automatic history paging and realtime updates. */
|
|
31
|
+
datafeed?: Datafeed;
|
|
32
|
+
/** Bars per history request. Default 300. */
|
|
33
|
+
historyBatchSize?: number;
|
|
34
|
+
/** The user's fills, positions and orders, synced per symbol. See TradingAdapter. */
|
|
35
|
+
trading?: TradingAdapter;
|
|
36
|
+
}
|
|
37
|
+
export interface ChartEvents {
|
|
38
|
+
crosshairMove: CrosshairInfo | null;
|
|
39
|
+
visibleRangeChange: IndexRange;
|
|
40
|
+
/** Manual-data mode: the user scrolled near the oldest bar. Respond with `prependData()`. */
|
|
41
|
+
needHistory: {
|
|
42
|
+
oldestTime: number;
|
|
43
|
+
};
|
|
44
|
+
symbolChange: SymbolInfo;
|
|
45
|
+
/** Bars changed (set / realtime update / history). Fired at most once per frame. */
|
|
46
|
+
dataChange: {
|
|
47
|
+
last: Bar | undefined;
|
|
48
|
+
};
|
|
49
|
+
/** Plot area geometry changed (resize, price-axis width). */
|
|
50
|
+
layoutChange: ChartLayout;
|
|
51
|
+
/** A symbol/resolution load started (true) or finished (false). */
|
|
52
|
+
loadingChange: boolean;
|
|
53
|
+
/** Drawings were created, edited or removed (not fired during a live drag). */
|
|
54
|
+
drawingsChange: Drawing[];
|
|
55
|
+
/** The armed drawing tool changed (null = cursor). Tools disarm after one drawing. */
|
|
56
|
+
drawingToolChange: DrawingType | null;
|
|
57
|
+
selectionChange: Drawing | null;
|
|
58
|
+
magnetChange: boolean;
|
|
59
|
+
chartTypeChange: ChartType;
|
|
60
|
+
settingsChange: ChartSettings;
|
|
61
|
+
/**
|
|
62
|
+
* Something worth persisting changed (symbol, interval, chart type, settings, indicators,
|
|
63
|
+
* drawings). Batched per tick — a good hook for autosaving `save()`.
|
|
64
|
+
*/
|
|
65
|
+
stateChange: void;
|
|
66
|
+
/** Live market statistics from `Datafeed.subscribeQuotes`. */
|
|
67
|
+
quoteChange: Quote;
|
|
68
|
+
/** Realtime connection state/latency reported by the datafeed. */
|
|
69
|
+
connectionChange: ConnectionState;
|
|
70
|
+
indicatorsChange: IndicatorConfig[];
|
|
71
|
+
error: unknown;
|
|
72
|
+
}
|
|
73
|
+
export interface ChartPaneLayout {
|
|
74
|
+
id: PaneId;
|
|
75
|
+
kind: 'main' | 'volume' | 'indicator';
|
|
76
|
+
top: number;
|
|
77
|
+
height: number;
|
|
78
|
+
}
|
|
79
|
+
export interface IndicatorLegendItem {
|
|
80
|
+
id: string;
|
|
81
|
+
type: IndicatorType;
|
|
82
|
+
title: string;
|
|
83
|
+
overlay: boolean;
|
|
84
|
+
visible: boolean;
|
|
85
|
+
/** Visible series only. */
|
|
86
|
+
values: {
|
|
87
|
+
key: string;
|
|
88
|
+
label: string;
|
|
89
|
+
value: string;
|
|
90
|
+
color: string;
|
|
91
|
+
}[];
|
|
92
|
+
}
|
|
93
|
+
export interface ChartLayout {
|
|
94
|
+
width: number;
|
|
95
|
+
height: number;
|
|
96
|
+
plotWidth: number;
|
|
97
|
+
panesHeight: number;
|
|
98
|
+
timeAxisHeight: number;
|
|
99
|
+
/** Price pane, volume pane and one pane per non-overlay indicator, top to bottom. */
|
|
100
|
+
panes: ChartPaneLayout[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Keeps the requested resolution when the symbol supports it; otherwise picks the closest
|
|
104
|
+
* supported one (preferring the next shorter), e.g. 3개월 → 1개월 on an exchange without 3M bars.
|
|
105
|
+
*/
|
|
106
|
+
export declare function fallbackResolution(requested: Resolution, supported: readonly Resolution[] | undefined): Resolution;
|
|
107
|
+
export declare function createChart(container: HTMLElement, options?: ChartOptions): Chart;
|
|
108
|
+
export declare class Chart {
|
|
109
|
+
readonly timeScale: TimeScale;
|
|
110
|
+
private readonly root;
|
|
111
|
+
private readonly mainLayer;
|
|
112
|
+
private readonly overlayLayer;
|
|
113
|
+
private readonly store;
|
|
114
|
+
private readonly mainScale;
|
|
115
|
+
private readonly volumeScale;
|
|
116
|
+
private readonly indicators;
|
|
117
|
+
private readonly indicatorScales;
|
|
118
|
+
private readonly emitter;
|
|
119
|
+
private readonly colors;
|
|
120
|
+
private readonly interaction;
|
|
121
|
+
private readonly cleanups;
|
|
122
|
+
private readonly drawings;
|
|
123
|
+
private readonly trading;
|
|
124
|
+
private readonly tradingSync;
|
|
125
|
+
private tooltipKey;
|
|
126
|
+
private chartType;
|
|
127
|
+
private magnet;
|
|
128
|
+
private objectDrag;
|
|
129
|
+
private theme;
|
|
130
|
+
private locale;
|
|
131
|
+
private formatter;
|
|
132
|
+
private pricePrecision;
|
|
133
|
+
private tickSize;
|
|
134
|
+
private settingsValue;
|
|
135
|
+
/** Drawings of symbols other than the current one (the current set lives in DrawingManager). */
|
|
136
|
+
private readonly drawingsBySymbol;
|
|
137
|
+
private stateQueued;
|
|
138
|
+
private readonly datafeed;
|
|
139
|
+
private readonly historyBatchSize;
|
|
140
|
+
private size;
|
|
141
|
+
private priceAxisWidth;
|
|
142
|
+
private frame;
|
|
143
|
+
private crosshair;
|
|
144
|
+
private lastCrosshairKey;
|
|
145
|
+
private lastRangeKey;
|
|
146
|
+
private lastLayoutKey;
|
|
147
|
+
private dataVersion;
|
|
148
|
+
private emittedDataVersion;
|
|
149
|
+
private rafId;
|
|
150
|
+
private mainDirty;
|
|
151
|
+
private destroyed;
|
|
152
|
+
private symbol;
|
|
153
|
+
private resolution;
|
|
154
|
+
private loadToken;
|
|
155
|
+
private unsubscribeBars;
|
|
156
|
+
private unsubscribeQuotes;
|
|
157
|
+
private latestQuote;
|
|
158
|
+
private connectionState;
|
|
159
|
+
private readonly displayTimezone;
|
|
160
|
+
private loadingHistory;
|
|
161
|
+
private noMoreHistory;
|
|
162
|
+
private historyRequestedFor;
|
|
163
|
+
constructor(container: HTMLElement, options?: ChartOptions);
|
|
164
|
+
/** Replaces all bars and scrolls to the latest. */
|
|
165
|
+
setData(bars: readonly Bar[]): void;
|
|
166
|
+
/** Realtime tick: same time as the last bar updates it, a newer time appends a bar. */
|
|
167
|
+
update(bar: Bar): void;
|
|
168
|
+
/** Adds older bars (history paging). The view stays where it is. */
|
|
169
|
+
prependData(bars: readonly Bar[], options?: {
|
|
170
|
+
noMoreData?: boolean;
|
|
171
|
+
}): void;
|
|
172
|
+
get bars(): readonly Bar[];
|
|
173
|
+
get symbolInfo(): SymbolInfo | null;
|
|
174
|
+
/** Loads a symbol through the datafeed, then follows realtime updates. */
|
|
175
|
+
setSymbol(symbol: string, resolution: Resolution): Promise<void>;
|
|
176
|
+
/** Latest market statistics (merged across partial updates), if the datafeed provides them. */
|
|
177
|
+
get quote(): Quote | null;
|
|
178
|
+
/** Realtime connection state, if the datafeed reports it. */
|
|
179
|
+
get connection(): ConnectionState | null;
|
|
180
|
+
get currentResolution(): Resolution | null;
|
|
181
|
+
/** Reloads the current symbol at another resolution. */
|
|
182
|
+
setResolution(resolution: Resolution): Promise<void>;
|
|
183
|
+
/** Plot geometry, for positioning overlays. */
|
|
184
|
+
get layout(): ChartLayout;
|
|
185
|
+
/**
|
|
186
|
+
* Reserves `px` at the top of the price pane so overlays (like a legend) never cover
|
|
187
|
+
* the candles. Auto-scaled data is laid out below the inset.
|
|
188
|
+
*/
|
|
189
|
+
setTopInset(px: number): void;
|
|
190
|
+
/** factor > 1 zooms in. Anchored to the latest bar when it's on screen, otherwise to the center. */
|
|
191
|
+
zoom(factor: number): void;
|
|
192
|
+
/** Scrolls by a number of bars; positive moves toward newer bars. */
|
|
193
|
+
scrollBars(bars: number): void;
|
|
194
|
+
/** True when the newest bar is visible. */
|
|
195
|
+
isAtRealtime(): boolean;
|
|
196
|
+
/** Snapshot of the chart (without the crosshair) at device resolution. */
|
|
197
|
+
takeScreenshot(): HTMLCanvasElement;
|
|
198
|
+
/**
|
|
199
|
+
* Re-fetches the latest window and merges it in, keeping the view. Datafeeds trigger this
|
|
200
|
+
* via the `onResetCache` callback of subscribeBars after a WebSocket reconnect, so bars
|
|
201
|
+
* missed while disconnected are filled in.
|
|
202
|
+
*/
|
|
203
|
+
private resync;
|
|
204
|
+
get type(): ChartType;
|
|
205
|
+
setChartType(type: ChartType): void;
|
|
206
|
+
get settings(): ChartSettings;
|
|
207
|
+
setSettings(patch: Partial<ChartSettings>): void;
|
|
208
|
+
/** Serializable snapshot of the layout. Pair with `load()`; see `stateChange` for autosave. */
|
|
209
|
+
save(): ChartState;
|
|
210
|
+
/**
|
|
211
|
+
* Restores a layout from `save()` (or JSON from storage — it's validated). Loads the saved
|
|
212
|
+
* symbol/interval through the datafeed first unless `{ symbol: false }`.
|
|
213
|
+
*/
|
|
214
|
+
load(input: ChartState | unknown, options?: {
|
|
215
|
+
symbol?: boolean;
|
|
216
|
+
}): Promise<void>;
|
|
217
|
+
/** Swaps the active drawing set to `symbol`'s. */
|
|
218
|
+
private restoreDrawingsFor;
|
|
219
|
+
private stateChanged;
|
|
220
|
+
/** Arms a drawing tool (null = cursor). It disarms itself after one drawing is placed. */
|
|
221
|
+
setDrawingTool(tool: DrawingType | null): void;
|
|
222
|
+
get drawingTool(): DrawingType | null;
|
|
223
|
+
/** Magnet mode: drawing points snap to the nearest open/high/low/close of the bar. */
|
|
224
|
+
setMagnet(on: boolean): void;
|
|
225
|
+
get magnetEnabled(): boolean;
|
|
226
|
+
getDrawings(): Drawing[];
|
|
227
|
+
/** Restores drawings (e.g. from storage). */
|
|
228
|
+
setDrawings(drawings: readonly Drawing[]): void;
|
|
229
|
+
updateDrawing(id: string, patch: Partial<Omit<Drawing, 'id'>>): void;
|
|
230
|
+
removeDrawing(id: string): void;
|
|
231
|
+
clearDrawings(): void;
|
|
232
|
+
get selectedDrawing(): Drawing | null;
|
|
233
|
+
selectDrawing(id: string | null): void;
|
|
234
|
+
/** Adds an indicator (overlays draw on the candles, others get their own pane). Returns its id. */
|
|
235
|
+
addIndicator(type: IndicatorType, params?: IndicatorParams): string;
|
|
236
|
+
removeIndicator(id: string): void;
|
|
237
|
+
/** Changes params, per-series styles (color/width/visible) and/or overall visibility. */
|
|
238
|
+
updateIndicator(id: string, patch: IndicatorPatch): void;
|
|
239
|
+
setIndicatorVisible(id: string, visible: boolean): void;
|
|
240
|
+
getIndicators(): IndicatorConfig[];
|
|
241
|
+
/** Restores indicators (e.g. from storage). */
|
|
242
|
+
setIndicators(configs: readonly IndicatorConfig[]): void;
|
|
243
|
+
/** Formatted indicator values at a bar index (default: the last bar), for legends. */
|
|
244
|
+
indicatorLegend(index?: number): IndicatorLegendItem[];
|
|
245
|
+
private indicatorsChanged;
|
|
246
|
+
private indicatorScale;
|
|
247
|
+
/**
|
|
248
|
+
* Connects the user's account (fills, positions, orders). The chart loads them for the
|
|
249
|
+
* current symbol, pages older fills with history and applies live updates. Pass null to detach.
|
|
250
|
+
*/
|
|
251
|
+
setTradingAdapter(adapter: TradingAdapter | null): void;
|
|
252
|
+
/** Average-price line with live P&L against the last price. */
|
|
253
|
+
addPositionLine(options: PositionLineOptions): LineHandle<PositionLineOptions>;
|
|
254
|
+
/** Pending order line. Pass `onMove` to make it draggable and `onCancel` for an × button. */
|
|
255
|
+
addOrderLine(options: OrderLineOptions): LineHandle<OrderLineOptions>;
|
|
256
|
+
/** Fill markers (▲ buy under the bar, ▼ sell above). Replaces the previous set. */
|
|
257
|
+
setExecutions(markers: readonly ExecutionMarker[]): void;
|
|
258
|
+
setTheme(theme: Partial<ThemeTokens>): void;
|
|
259
|
+
/** Re-reads CSS variables used by the theme (call after changing them outside of class/style attributes). */
|
|
260
|
+
refreshTheme(): void;
|
|
261
|
+
setLocale(locale: Locale): void;
|
|
262
|
+
setTimezone(timeZone: string): void;
|
|
263
|
+
setPriceFormat(format: {
|
|
264
|
+
precision?: number;
|
|
265
|
+
tickSize?: TickSize;
|
|
266
|
+
}): void;
|
|
267
|
+
setVolumeVisible(visible: boolean): void;
|
|
268
|
+
fitContent(): void;
|
|
269
|
+
scrollToRealtime(): void;
|
|
270
|
+
resetView(): void;
|
|
271
|
+
on<K extends keyof ChartEvents>(event: K, listener: (payload: ChartEvents[K]) => void): () => void;
|
|
272
|
+
destroy(): void;
|
|
273
|
+
/** Coalesces any number of changes into one paint per animation frame. */
|
|
274
|
+
private invalidate;
|
|
275
|
+
private render;
|
|
276
|
+
private renderModel;
|
|
277
|
+
/** Approximate ms per bar: the resolution when known, else the smallest recent gap. */
|
|
278
|
+
private barInterval;
|
|
279
|
+
private paneCoords;
|
|
280
|
+
private computeFrame;
|
|
281
|
+
/** Auto-scales the price pane to visible candles and overlay indicators; returns the candle extremes. */
|
|
282
|
+
private autoScale;
|
|
283
|
+
private autoScaleIndicator;
|
|
284
|
+
private resolvePalette;
|
|
285
|
+
private isIntraday;
|
|
286
|
+
private afterFrame;
|
|
287
|
+
private requestHistory;
|
|
288
|
+
private resolveCrosshair;
|
|
289
|
+
private paneAt;
|
|
290
|
+
private setTooltip;
|
|
291
|
+
private executionTooltip;
|
|
292
|
+
private emitCrosshair;
|
|
293
|
+
private paneScale;
|
|
294
|
+
private createInteractionHost;
|
|
295
|
+
/** Esc cancels a drawing in progress or deselects; Delete/Backspace removes the selected drawing. */
|
|
296
|
+
private observeKeyboard;
|
|
297
|
+
private observeSize;
|
|
298
|
+
/** Theme values using `var(--x)` follow the host page's dark-mode / theme switches automatically. */
|
|
299
|
+
private observeThemeVariables;
|
|
300
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Datafeed } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Serves several datafeeds through one chart. Symbols are namespaced as `KEY:SYMBOL`
|
|
4
|
+
* (e.g. 'UPBIT:KRW-BTC', 'BINANCE:BTCUSDT'); search merges every feed's results.
|
|
5
|
+
* A symbol without a prefix goes to the first feed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function combineDatafeeds(feeds: Record<string, Datafeed>): Datafeed;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Periodically times an async probe (e.g. a tiny REST call) as a latency estimate, for venues
|
|
3
|
+
* whose WebSocket has no usable ping. Returns a stop function.
|
|
4
|
+
*/
|
|
5
|
+
export declare function monitorLatency(probe: () => Promise<unknown>, onLatency: (ms: number) => void, interval?: number): () => void;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type SocketStatus = 'connecting' | 'open' | 'reconnecting' | 'closed';
|
|
2
|
+
export interface ReconnectingWebSocketOptions {
|
|
3
|
+
/** Runs on every (re)connect — send subscription messages here. `reconnected` is false the first time. */
|
|
4
|
+
onOpen?(socket: WebSocket, reconnected: boolean): void;
|
|
5
|
+
/** Text frames as-is; binary frames decoded as UTF-8 (Upbit sends binary JSON). */
|
|
6
|
+
onMessage(data: string): void;
|
|
7
|
+
onStatus?(status: SocketStatus): void;
|
|
8
|
+
/** First retry delay. Default 500ms; doubles each attempt with jitter. */
|
|
9
|
+
minDelay?: number;
|
|
10
|
+
/** Retry delay cap. Default 15s. */
|
|
11
|
+
maxDelay?: number;
|
|
12
|
+
/** Force a reconnect when nothing arrives for this long (half-open connections). 0 = off. */
|
|
13
|
+
idleTimeout?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Application-level ping to measure round-trip latency (browsers can't send WS ping frames).
|
|
16
|
+
* Pong messages are consumed and not passed to `onMessage`.
|
|
17
|
+
*/
|
|
18
|
+
ping?: {
|
|
19
|
+
interval: number;
|
|
20
|
+
message: () => string;
|
|
21
|
+
isPong: (data: string) => boolean;
|
|
22
|
+
};
|
|
23
|
+
onLatency?(ms: number): void;
|
|
24
|
+
}
|
|
25
|
+
/** Maps socket states onto the chart's ConnectionState vocabulary. */
|
|
26
|
+
export declare const toConnectionStatus: (status: SocketStatus) => "connected" | "connecting" | "disconnected" | "reconnecting";
|
|
27
|
+
/**
|
|
28
|
+
* WebSocket that never gives up: exponential backoff with jitter, immediate retry when the
|
|
29
|
+
* browser comes back online, and an optional idle watchdog. Pair `onOpen(…, reconnected)`
|
|
30
|
+
* with the datafeed's `onResetCache` so the chart refetches bars missed while disconnected.
|
|
31
|
+
*/
|
|
32
|
+
export declare class ReconnectingWebSocket {
|
|
33
|
+
private readonly url;
|
|
34
|
+
private readonly options;
|
|
35
|
+
private ws;
|
|
36
|
+
private attempt;
|
|
37
|
+
private everOpened;
|
|
38
|
+
private closed;
|
|
39
|
+
private retryTimer;
|
|
40
|
+
private idleTimer;
|
|
41
|
+
private pingTimer;
|
|
42
|
+
private pingSentAt;
|
|
43
|
+
private readonly onOnline;
|
|
44
|
+
constructor(url: string, options: ReconnectingWebSocketOptions);
|
|
45
|
+
get status(): SocketStatus;
|
|
46
|
+
/** Drops the current connection and reconnects right away (e.g. after the tab wakes up). */
|
|
47
|
+
reconnect(): void;
|
|
48
|
+
send(data: string): void;
|
|
49
|
+
close(): void;
|
|
50
|
+
private connect;
|
|
51
|
+
/**
|
|
52
|
+
* Abandons a socket and schedules the next attempt immediately. Doesn't wait for the
|
|
53
|
+
* close handshake: on a dead network the server never answers, and `close()` alone would
|
|
54
|
+
* leave us hanging with no `onclose` for a long time.
|
|
55
|
+
*/
|
|
56
|
+
private drop;
|
|
57
|
+
private startPing;
|
|
58
|
+
private scheduleReconnect;
|
|
59
|
+
private armIdle;
|
|
60
|
+
}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Listener<T> = (payload: T) => void;
|
|
2
|
+
export declare class Emitter<Events extends object> {
|
|
3
|
+
private readonly listeners;
|
|
4
|
+
on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): () => void;
|
|
5
|
+
emit<K extends keyof Events>(event: K, payload: Events[K]): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { Chart, createChart, fallbackResolution } from './chart';
|
|
2
|
+
export { DEFAULT_CHART_SETTINGS, parseChartState } from './settings';
|
|
3
|
+
export type { ChartSettings, ChartState } from './settings';
|
|
4
|
+
export type { ChartEvents, ChartLayout, ChartOptions, ChartPaneLayout, IndicatorLegendItem } from './chart';
|
|
5
|
+
export type { CrosshairInfo, PaneId } from './render/renderer';
|
|
6
|
+
export type { Locale } from './model/time-format';
|
|
7
|
+
export type { IndexRange, TimeScaleOptions } from './model/time-scale';
|
|
8
|
+
export type { Bar, BarsRequest, BarsResult, Datafeed, Resolution, SymbolInfo, TickSize, Unsubscribe, SymbolType, SymbolSearchResult, Quote, ConnectionState, } from './types';
|
|
9
|
+
export type { DirectionPreset, ThemeTokens } from './theme';
|
|
10
|
+
export { createTheme, darkTheme, lightTheme } from './theme';
|
|
11
|
+
export type { FormatPriceOptions } from './price';
|
|
12
|
+
export { decimalsOf, formatCompact, formatPrice, krxTickSize, resolveTickSize, roundToTick } from './price';
|
|
13
|
+
export { isIntradayResolution, resolutionToMs } from './resolution';
|
|
14
|
+
export type { ChartType } from './render/renderer';
|
|
15
|
+
export type { Drawing, DrawingPoint, DrawingType } from './objects/drawings';
|
|
16
|
+
export { FIB_LEVELS } from './objects/drawings';
|
|
17
|
+
export { snapToOhlc } from './objects/magnet';
|
|
18
|
+
export type { ExecutionGroup, ExecutionMarker, LineHandle, OrderLineOptions, PositionLineOptions } from './objects/trading';
|
|
19
|
+
export type { Execution, OrderInfo, PositionInfo, TradingAdapter, TradingCallbacks } from './objects/trading-sync';
|
|
20
|
+
export { bucketStart, TickAggregator, timeZoneOffset } from './realtime';
|
|
21
|
+
export type { Tick } from './realtime';
|
|
22
|
+
export { INDICATORS, SERIES_COLORS } from './indicators/definitions';
|
|
23
|
+
export type { IndicatorDefinition, IndicatorOutput, IndicatorParams, IndicatorParamSpec, IndicatorSeries, IndicatorType, } from './indicators/definitions';
|
|
24
|
+
export type { IndicatorConfig, IndicatorPatch } from './indicators/manager';
|
|
25
|
+
export { maLines, PRICE_SOURCES, priceSource } from './indicators/definitions';
|
|
26
|
+
export type { MaLine, PriceSource, SeriesStyle } from './indicators/definitions';
|
|
27
|
+
/** Indicator math, reusable in strategy/backtest code. */
|
|
28
|
+
export { bollinger, ema, macd, rsi, sma, stdev } from './indicators/math';
|
|
29
|
+
export { sessionStatus } from './session';
|
|
30
|
+
export type { SessionStatus } from './session';
|
|
31
|
+
/** Exchange-agnostic realtime helpers for writing your own Datafeed. */
|
|
32
|
+
export { ReconnectingWebSocket, toConnectionStatus } from './datafeed/socket';
|
|
33
|
+
export type { ReconnectingWebSocketOptions, SocketStatus } from './datafeed/socket';
|
|
34
|
+
export { monitorLatency } from './datafeed/latency';
|
|
35
|
+
export { combineDatafeeds } from './datafeed/combine';
|