emberwick 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 +530 -0
- package/index.d.ts +257 -0
- package/index.js +1310 -0
- package/index.js.map +1 -0
- package/package.json +56 -0
- package/react.d.ts +31 -0
- package/react.js +76 -0
- package/react.js.map +1 -0
- package/umd/emberwick.umd.js +2 -0
- package/umd/emberwick.umd.js.map +1 -0
- package/webcomponent.d.ts +16 -0
- package/webcomponent.js +75 -0
- package/webcomponent.js.map +1 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emberwick — type declarations for the public API.
|
|
3
|
+
*
|
|
4
|
+
* Hand-written against the actual implementation (the core is plain JS).
|
|
5
|
+
* Only what is exported from src/chart/index.js is described here.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** A single OHLCV bar. `time` is ms since epoch. */
|
|
9
|
+
export interface Bar {
|
|
10
|
+
time: number
|
|
11
|
+
open: number
|
|
12
|
+
high: number
|
|
13
|
+
low: number
|
|
14
|
+
close: number
|
|
15
|
+
volume?: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type PriceMode = 'linear' | 'log'
|
|
19
|
+
|
|
20
|
+
export interface Theme {
|
|
21
|
+
background: string
|
|
22
|
+
grid: string
|
|
23
|
+
axisLine: string
|
|
24
|
+
text: string
|
|
25
|
+
textStrong: string
|
|
26
|
+
up: string
|
|
27
|
+
down: string
|
|
28
|
+
upFill: string
|
|
29
|
+
downFill: string
|
|
30
|
+
wickUp: string
|
|
31
|
+
wickDown: string
|
|
32
|
+
volumeUp: string
|
|
33
|
+
volumeDown: string
|
|
34
|
+
crosshair: string
|
|
35
|
+
labelBg: string
|
|
36
|
+
labelText: string
|
|
37
|
+
tagText: string
|
|
38
|
+
font: string
|
|
39
|
+
priceAxisWidth: number
|
|
40
|
+
timeAxisHeight: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface TimeScaleOptions {
|
|
44
|
+
/** Pixels per bar. Default 9. */
|
|
45
|
+
spacing?: number
|
|
46
|
+
/** Default 0.8. */
|
|
47
|
+
minSpacing?: number
|
|
48
|
+
/** Default 160. */
|
|
49
|
+
maxSpacing?: number
|
|
50
|
+
/** Bars of empty space kept at the right edge. Default 12. */
|
|
51
|
+
rightOffset?: number
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PriceScaleOptions {
|
|
55
|
+
/** Default 'linear'. */
|
|
56
|
+
mode?: PriceMode
|
|
57
|
+
/** Autoscale easing time constant in ms. Default 120. */
|
|
58
|
+
tau?: number
|
|
59
|
+
/** Headroom above the high, as a fraction. Default 0.12. */
|
|
60
|
+
marginTop?: number
|
|
61
|
+
/** Headroom below the low, as a fraction. Default 0.12. */
|
|
62
|
+
marginBottom?: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ChartOptions {
|
|
66
|
+
/** Partial theme merged over defaultTheme. */
|
|
67
|
+
theme?: Partial<Theme>
|
|
68
|
+
/** Share of plot height used by the volume strip. Default 0.18. */
|
|
69
|
+
volumeRatio?: number
|
|
70
|
+
/** Crosshair snaps to the nearest OHLC value. Default true. */
|
|
71
|
+
magnet?: boolean
|
|
72
|
+
/** Master switch for tick/candle animation. Default true. */
|
|
73
|
+
animate?: boolean
|
|
74
|
+
/** Bars requested from the feed on setFeed(). Default 1500. */
|
|
75
|
+
initialBars?: number
|
|
76
|
+
timeScale?: TimeScaleOptions
|
|
77
|
+
priceScale?: PriceScaleOptions
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Payload of the 'crosshair' event. `null` when the cursor leaves the plot. */
|
|
81
|
+
export interface CrosshairPayload {
|
|
82
|
+
index: number
|
|
83
|
+
bar: Bar
|
|
84
|
+
price: number
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface GetBarsRequest {
|
|
88
|
+
symbol: string
|
|
89
|
+
timeframe: number
|
|
90
|
+
/** Fetch bars ending before this ms timestamp. `null` means "latest". */
|
|
91
|
+
to: number | null
|
|
92
|
+
limit: number
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type FeedMessage =
|
|
96
|
+
| { type: 'update'; bar: Bar }
|
|
97
|
+
| { type: 'append'; bar: Bar }
|
|
98
|
+
|
|
99
|
+
export type FeedHandler = (msg: FeedMessage) => void
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The seam of the library. Implement this to plug in any data source.
|
|
103
|
+
* Extend the DataFeed base class, or supply any object with this shape.
|
|
104
|
+
*/
|
|
105
|
+
export interface Feed {
|
|
106
|
+
symbol: string
|
|
107
|
+
timeframe: number
|
|
108
|
+
getBars(req: GetBarsRequest): Promise<Bar[]>
|
|
109
|
+
subscribe(handler: FeedHandler): () => void
|
|
110
|
+
/** Optional: called once with the newest bar after initial load. */
|
|
111
|
+
prime?(bar: Bar | undefined): void
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export declare class DataFeed implements Feed {
|
|
115
|
+
constructor(opts?: { symbol?: string; timeframe?: number })
|
|
116
|
+
symbol: string
|
|
117
|
+
timeframe: number
|
|
118
|
+
getBars(req: GetBarsRequest): Promise<Bar[]>
|
|
119
|
+
subscribe(handler: FeedHandler): () => void
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface RandomFeedOptions {
|
|
123
|
+
/** Default 'EMBR'. */
|
|
124
|
+
symbol?: string
|
|
125
|
+
/** Bar duration in ms. Default 60000. */
|
|
126
|
+
timeframe?: number
|
|
127
|
+
/** PRNG seed — same seed gives the same market. Default 7. */
|
|
128
|
+
seed?: number
|
|
129
|
+
/** Starting price. Default 100. */
|
|
130
|
+
start?: number
|
|
131
|
+
/** Per-tick volatility. Default 0.0022. */
|
|
132
|
+
volatility?: number
|
|
133
|
+
/** Per-tick drift. Default 0.00002. */
|
|
134
|
+
drift?: number
|
|
135
|
+
/** Live ticks emitted per second. Default 8. */
|
|
136
|
+
ticksPerSecond?: number
|
|
137
|
+
/** Wall-clock multiplier for candle formation. Default 1. */
|
|
138
|
+
speed?: number
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export declare class RandomFeed extends DataFeed {
|
|
142
|
+
constructor(opts?: RandomFeedOptions)
|
|
143
|
+
setSpeed(speed: number): void
|
|
144
|
+
setTicksPerSecond(n: number): void
|
|
145
|
+
setPaused(paused: boolean): void
|
|
146
|
+
readonly paused: boolean
|
|
147
|
+
stop(): void
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export declare class TimeScale {
|
|
151
|
+
constructor(opts?: TimeScaleOptions)
|
|
152
|
+
visibleRange(): { from: number; to: number }
|
|
153
|
+
barWidth(): number
|
|
154
|
+
x(index: number): number
|
|
155
|
+
index(x: number): number
|
|
156
|
+
panBy(dx: number): void
|
|
157
|
+
zoomAt(x: number, factor: number): void
|
|
158
|
+
snapToRealtime(): void
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export declare class PriceScale {
|
|
162
|
+
constructor(opts?: PriceScaleOptions)
|
|
163
|
+
y(price: number): number
|
|
164
|
+
price(y: number): number
|
|
165
|
+
setMode(mode: PriceMode): void
|
|
166
|
+
resetAuto(): void
|
|
167
|
+
readonly lo: number
|
|
168
|
+
readonly hi: number
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export declare class Chart {
|
|
172
|
+
constructor(container: HTMLElement, options?: ChartOptions)
|
|
173
|
+
|
|
174
|
+
/** Replace the whole dataset. Resets zoom to the right edge. */
|
|
175
|
+
setData(bars: Bar[]): void
|
|
176
|
+
/** Merge a tick into the forming candle (animated). */
|
|
177
|
+
update(bar: Bar): void
|
|
178
|
+
/** Open a new candle; the previous one is closed. */
|
|
179
|
+
append(bar: Bar): void
|
|
180
|
+
/** Load history from a feed and subscribe to live updates. */
|
|
181
|
+
setFeed(feed: Feed): Promise<void>
|
|
182
|
+
detachFeed(): void
|
|
183
|
+
|
|
184
|
+
setTheme(theme: Partial<Theme>): void
|
|
185
|
+
setPriceMode(mode: PriceMode): void
|
|
186
|
+
setAnimate(on: boolean): void
|
|
187
|
+
setMagnet(on: boolean): void
|
|
188
|
+
snapToRealtime(): void
|
|
189
|
+
|
|
190
|
+
/** PNG data URL of all layers composited. */
|
|
191
|
+
toImage(): string
|
|
192
|
+
/** Rolling frames-per-second of the render loop. */
|
|
193
|
+
readonly fps: number
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Subscribe to a chart event. Returns an unsubscribe function.
|
|
197
|
+
* NOTE: 'visibleRange' is accepted but is not currently emitted.
|
|
198
|
+
*/
|
|
199
|
+
subscribe(event: 'crosshair', fn: (payload: CrosshairPayload | null) => void): () => void
|
|
200
|
+
subscribe(event: 'visibleRange', fn: (range: { from: number; to: number }) => void): () => void
|
|
201
|
+
|
|
202
|
+
/** Removes listeners, canvases and the render loop. */
|
|
203
|
+
destroy(): void
|
|
204
|
+
|
|
205
|
+
readonly bars: Bar[]
|
|
206
|
+
readonly ts: TimeScale
|
|
207
|
+
readonly ps: PriceScale
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Preferred entry point. */
|
|
211
|
+
export declare function createChart(container: HTMLElement, options?: ChartOptions): Chart
|
|
212
|
+
|
|
213
|
+
export declare const defaultTheme: Theme
|
|
214
|
+
export declare const lightTheme: Theme
|
|
215
|
+
export declare const version: string
|
|
216
|
+
|
|
217
|
+
/** Seeded PRNG used by RandomFeed. */
|
|
218
|
+
export declare function mulberry32(seed: number): () => number
|
|
219
|
+
|
|
220
|
+
export declare class Smoothed {
|
|
221
|
+
constructor(value?: number, tau?: number)
|
|
222
|
+
value: number
|
|
223
|
+
target: number
|
|
224
|
+
tau: number
|
|
225
|
+
set(target: number): void
|
|
226
|
+
jump(v: number): void
|
|
227
|
+
tick(dt: number): boolean
|
|
228
|
+
readonly settled: boolean
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export declare class Tween {
|
|
232
|
+
constructor(duration?: number, ease?: (t: number) => number)
|
|
233
|
+
restart(): void
|
|
234
|
+
tick(dt: number): boolean
|
|
235
|
+
readonly progress: number
|
|
236
|
+
readonly done: boolean
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export declare class Inertia {
|
|
240
|
+
constructor(opts?: { friction?: number; min?: number })
|
|
241
|
+
sample(dx: number, dt: number): void
|
|
242
|
+
release(): void
|
|
243
|
+
stop(): void
|
|
244
|
+
tick(dt: number): number
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export declare class LiveCandle {
|
|
248
|
+
constructor(tau?: number)
|
|
249
|
+
enabled: boolean
|
|
250
|
+
setTarget(bar: Bar | null): void
|
|
251
|
+
reset(): void
|
|
252
|
+
tick(dt: number): boolean
|
|
253
|
+
read(bar: Bar): Bar
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export declare function easeOutCubic(t: number): number
|
|
257
|
+
export declare function easeInOutCubic(t: number): number
|