funhi-chart 1.3.0 → 1.3.2
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/dist/dts/adapters/CandleStorageAdapter.d.ts +14 -0
- package/dist/dts/components/FunhiChart.d.ts +4 -0
- package/dist/dts/components/FunhiChartOOP.d.ts +8 -0
- package/dist/dts/core/CandleManager.d.ts +73 -0
- package/dist/dts/core/ChartRenderer.d.ts +46 -0
- package/dist/dts/core/FunhiChartController.d.ts +61 -0
- package/dist/dts/core/TimeframeManager.d.ts +42 -0
- package/dist/dts/core/index.d.ts +8 -0
- package/dist/dts/core/types.d.ts +33 -0
- package/dist/dts/handlers/RealTimeUpdateHandler.d.ts +29 -0
- package/dist/dts/validators/CandleValidator.d.ts +38 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +10 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CandleStorageAdapter - Handles loading/saving candles (wrapper around existing service)
|
|
3
|
+
*/
|
|
4
|
+
import { CandleData } from '../core/types';
|
|
5
|
+
export declare class CandleStorageAdapter {
|
|
6
|
+
/**
|
|
7
|
+
* Loads candles from storage
|
|
8
|
+
*/
|
|
9
|
+
loadCandles(mint: string, timeframeSeconds: number, limit?: number): Promise<CandleData[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Saves candles to storage (if needed in future)
|
|
12
|
+
*/
|
|
13
|
+
saveCandles(mint: string, timeframeSeconds: number, candles: CandleData[]): Promise<void>;
|
|
14
|
+
}
|
|
@@ -9,5 +9,9 @@ export interface ChartProps {
|
|
|
9
9
|
analyticsConnected?: boolean;
|
|
10
10
|
analyticsLoading?: boolean;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* FunhiChart - OOP-based implementation using FunhiChartController
|
|
14
|
+
* This version eliminates code duplication and uses clean OOP architecture
|
|
15
|
+
*/
|
|
12
16
|
declare const FunhiChart: React.FC<ChartProps>;
|
|
13
17
|
export default FunhiChart;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartProps } from './FunhiChart';
|
|
3
|
+
/**
|
|
4
|
+
* FunhiChartOOP - OOP-based implementation using FunhiChartController
|
|
5
|
+
* This version eliminates code duplication and uses clean OOP architecture
|
|
6
|
+
*/
|
|
7
|
+
declare const FunhiChartOOP: React.FC<ChartProps>;
|
|
8
|
+
export default FunhiChartOOP;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CandleManager - Manages candle creation, updates, and validation for a single timeframe
|
|
3
|
+
* This class eliminates code duplication by handling all timeframe logic generically
|
|
4
|
+
*/
|
|
5
|
+
import { CandleData, CandleUpdateResult } from './types';
|
|
6
|
+
export declare class CandleManager {
|
|
7
|
+
private timeframeSeconds;
|
|
8
|
+
private candles;
|
|
9
|
+
private currentCandle;
|
|
10
|
+
private lastCandleTime;
|
|
11
|
+
private lastProcessedTimestamp;
|
|
12
|
+
private readonly debounceMs;
|
|
13
|
+
constructor(timeframeSeconds: number);
|
|
14
|
+
/**
|
|
15
|
+
* Main method: Creates a new candle or updates the current one
|
|
16
|
+
*/
|
|
17
|
+
createOrUpdate(price: number, timestamp: number): CandleUpdateResult | null;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new candle at bucket boundary
|
|
20
|
+
*/
|
|
21
|
+
private createNewCandle;
|
|
22
|
+
/**
|
|
23
|
+
* Updates the current candle with new price data
|
|
24
|
+
*/
|
|
25
|
+
private updateCurrentCandle;
|
|
26
|
+
/**
|
|
27
|
+
* Updates candle price while preserving minimum body size
|
|
28
|
+
*/
|
|
29
|
+
private updateCandlePrice;
|
|
30
|
+
/**
|
|
31
|
+
* Builds a new candle with minimum body size enforcement
|
|
32
|
+
*/
|
|
33
|
+
private buildNewCandle;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the previous candle's close price
|
|
36
|
+
*/
|
|
37
|
+
private getPreviousCandleClose;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the previous candle's direction (1 for bullish, -1 for bearish)
|
|
40
|
+
*/
|
|
41
|
+
private getPreviousCandleDirection;
|
|
42
|
+
/**
|
|
43
|
+
* Calculates bucket start time for a given timestamp
|
|
44
|
+
*/
|
|
45
|
+
private calculateBucketStart;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a candle has valid data
|
|
48
|
+
*/
|
|
49
|
+
private isValidCandle;
|
|
50
|
+
/**
|
|
51
|
+
* Adds a candle to history
|
|
52
|
+
*/
|
|
53
|
+
private addCandleToHistory;
|
|
54
|
+
/**
|
|
55
|
+
* Updates a candle in history (only if it matches current bucket)
|
|
56
|
+
*/
|
|
57
|
+
private updateCandleInHistory;
|
|
58
|
+
getCandles(): CandleData[];
|
|
59
|
+
getCurrentCandle(): CandleData | null;
|
|
60
|
+
getLastCandleTime(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Loads candles from storage
|
|
63
|
+
*/
|
|
64
|
+
loadCandles(candles: CandleData[]): void;
|
|
65
|
+
/**
|
|
66
|
+
* Directly updates candle from external source (e.g., WebSocket)
|
|
67
|
+
*/
|
|
68
|
+
updateFromExternal(candle: CandleData, currentBucket: number): void;
|
|
69
|
+
/**
|
|
70
|
+
* Resets the manager (useful for cleanup)
|
|
71
|
+
*/
|
|
72
|
+
reset(): void;
|
|
73
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChartRenderer - Manages the lightweight-charts instance and rendering
|
|
3
|
+
*/
|
|
4
|
+
import { IChartApi, ISeriesApi } from 'lightweight-charts';
|
|
5
|
+
import { CandleData, TimeFrame } from './types';
|
|
6
|
+
export interface ChartOptions {
|
|
7
|
+
ticker?: string;
|
|
8
|
+
mint: string;
|
|
9
|
+
formatPrice: (value: number) => string;
|
|
10
|
+
height?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class ChartRenderer {
|
|
13
|
+
private chart;
|
|
14
|
+
private series;
|
|
15
|
+
private container;
|
|
16
|
+
private options;
|
|
17
|
+
constructor(container: HTMLDivElement, options: ChartOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the chart
|
|
20
|
+
*/
|
|
21
|
+
initialize(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Updates chart data
|
|
24
|
+
*/
|
|
25
|
+
updateData(candles: CandleData[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the current timeframe (for future use if needed)
|
|
28
|
+
*/
|
|
29
|
+
setTimeframe(timeframe: TimeFrame): void;
|
|
30
|
+
/**
|
|
31
|
+
* Resizes the chart
|
|
32
|
+
*/
|
|
33
|
+
resize(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Destroys the chart instance
|
|
36
|
+
*/
|
|
37
|
+
destroy(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the chart instance (for advanced operations)
|
|
40
|
+
*/
|
|
41
|
+
getChart(): IChartApi | null;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the series instance (for advanced operations)
|
|
44
|
+
*/
|
|
45
|
+
getSeries(): ISeriesApi<"Candlestick"> | null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CandleData, TimeFrame } from './types';
|
|
2
|
+
export interface ControllerConfig {
|
|
3
|
+
mint: string;
|
|
4
|
+
ticker?: string;
|
|
5
|
+
tokenName?: string;
|
|
6
|
+
timeframes: TimeFrame[];
|
|
7
|
+
container: HTMLDivElement;
|
|
8
|
+
formatPrice: (value: number) => string;
|
|
9
|
+
}
|
|
10
|
+
export declare class FunhiChartController {
|
|
11
|
+
private chartRenderer;
|
|
12
|
+
private timeframeManager;
|
|
13
|
+
private storageAdapter;
|
|
14
|
+
private updateHandler;
|
|
15
|
+
private currentTimeframe;
|
|
16
|
+
private config;
|
|
17
|
+
constructor(config: ControllerConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the chart and loads initial data
|
|
20
|
+
*/
|
|
21
|
+
initialize(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Loads candles for a specific timeframe
|
|
24
|
+
*/
|
|
25
|
+
loadTimeframeData(timeframeSeconds: number): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Updates price for all timeframes
|
|
28
|
+
*/
|
|
29
|
+
updatePrice(price: number): void;
|
|
30
|
+
/**
|
|
31
|
+
* Handles WebSocket update
|
|
32
|
+
*/
|
|
33
|
+
handleSocketUpdate(data: {
|
|
34
|
+
mint: string;
|
|
35
|
+
candles: Record<string, any>;
|
|
36
|
+
}): void;
|
|
37
|
+
/**
|
|
38
|
+
* Switches to a different timeframe
|
|
39
|
+
*/
|
|
40
|
+
switchTimeframe(seconds: number): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets candles for current timeframe
|
|
43
|
+
*/
|
|
44
|
+
getCurrentCandles(): CandleData[];
|
|
45
|
+
/**
|
|
46
|
+
* Gets current timeframe
|
|
47
|
+
*/
|
|
48
|
+
getCurrentTimeframe(): TimeFrame;
|
|
49
|
+
/**
|
|
50
|
+
* Gets current candle for a specific timeframe
|
|
51
|
+
*/
|
|
52
|
+
getCurrentCandle(seconds: number): CandleData | null;
|
|
53
|
+
/**
|
|
54
|
+
* Resizes the chart
|
|
55
|
+
*/
|
|
56
|
+
resize(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Destroys the controller and cleans up resources
|
|
59
|
+
*/
|
|
60
|
+
destroy(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimeframeManager - Orchestrates multiple timeframes and coordinates updates
|
|
3
|
+
*/
|
|
4
|
+
import { CandleManager } from './CandleManager';
|
|
5
|
+
import { CandleData, TimeFrame } from './types';
|
|
6
|
+
export declare class TimeframeManager {
|
|
7
|
+
private managers;
|
|
8
|
+
private timeframes;
|
|
9
|
+
constructor(timeframes: TimeFrame[]);
|
|
10
|
+
/**
|
|
11
|
+
* Gets the manager for a specific timeframe
|
|
12
|
+
*/
|
|
13
|
+
getManager(seconds: number): CandleManager | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Updates all timeframes with new price data
|
|
16
|
+
*/
|
|
17
|
+
updateAll(price: number, timestamp: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Gets candles for a specific timeframe
|
|
20
|
+
*/
|
|
21
|
+
getCandles(seconds: number): CandleData[];
|
|
22
|
+
/**
|
|
23
|
+
* Gets current candle for a specific timeframe
|
|
24
|
+
*/
|
|
25
|
+
getCurrentCandle(seconds: number): CandleData | null;
|
|
26
|
+
/**
|
|
27
|
+
* Loads candles for a specific timeframe
|
|
28
|
+
*/
|
|
29
|
+
loadCandles(seconds: number, candles: CandleData[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* Updates candle from external source (e.g., WebSocket)
|
|
32
|
+
*/
|
|
33
|
+
updateFromExternal(seconds: number, candle: CandleData, currentBucket: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* Gets all available timeframes
|
|
36
|
+
*/
|
|
37
|
+
getTimeframes(): TimeFrame[];
|
|
38
|
+
/**
|
|
39
|
+
* Resets all managers
|
|
40
|
+
*/
|
|
41
|
+
reset(): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for FunhiChart OOP architecture
|
|
3
|
+
*/
|
|
4
|
+
export interface CandleData {
|
|
5
|
+
time: number;
|
|
6
|
+
open: number;
|
|
7
|
+
high: number;
|
|
8
|
+
low: number;
|
|
9
|
+
close: number;
|
|
10
|
+
volume: number;
|
|
11
|
+
}
|
|
12
|
+
export interface TimeFrame {
|
|
13
|
+
label: string;
|
|
14
|
+
value: string;
|
|
15
|
+
seconds: number;
|
|
16
|
+
}
|
|
17
|
+
export type { TimeFrame as TimeFrameType };
|
|
18
|
+
export interface ChartConfig {
|
|
19
|
+
mint: string;
|
|
20
|
+
ticker?: string;
|
|
21
|
+
tokenName?: string;
|
|
22
|
+
timeframes: TimeFrame[];
|
|
23
|
+
container: HTMLDivElement;
|
|
24
|
+
}
|
|
25
|
+
export interface CandleManagerConfig {
|
|
26
|
+
timeframeSeconds: number;
|
|
27
|
+
mint: string;
|
|
28
|
+
}
|
|
29
|
+
export interface CandleUpdateResult {
|
|
30
|
+
candle: CandleData | null;
|
|
31
|
+
isNewCandle: boolean;
|
|
32
|
+
wasUpdated: boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RealTimeUpdateHandler - Handles real-time price updates and WebSocket events
|
|
3
|
+
*/
|
|
4
|
+
import { TimeframeManager } from '../core/TimeframeManager';
|
|
5
|
+
export declare class RealTimeUpdateHandler {
|
|
6
|
+
private timeframeManager;
|
|
7
|
+
private debounceMs;
|
|
8
|
+
private lastUpdate;
|
|
9
|
+
constructor(timeframeManager: TimeframeManager);
|
|
10
|
+
/**
|
|
11
|
+
* Handles price update from real-time data
|
|
12
|
+
*/
|
|
13
|
+
handlePriceUpdate(price: number, timestamp: number): void;
|
|
14
|
+
/**
|
|
15
|
+
* Handles WebSocket update with pre-calculated candles
|
|
16
|
+
*/
|
|
17
|
+
handleSocketUpdate(data: {
|
|
18
|
+
mint: string;
|
|
19
|
+
candles: Record<string, any>;
|
|
20
|
+
}, mint: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Debounce check
|
|
23
|
+
*/
|
|
24
|
+
private debounce;
|
|
25
|
+
/**
|
|
26
|
+
* Converts timeframe key to seconds
|
|
27
|
+
*/
|
|
28
|
+
private getTimeframeSeconds;
|
|
29
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CandleValidator - Validates and enforces candle data integrity
|
|
3
|
+
*/
|
|
4
|
+
import { CandleData } from '../core/types';
|
|
5
|
+
export declare class CandleValidator {
|
|
6
|
+
/**
|
|
7
|
+
* Minimum body size as percentage of price (0.01%)
|
|
8
|
+
*/
|
|
9
|
+
private static readonly MIN_BODY_PERCENTAGE;
|
|
10
|
+
/**
|
|
11
|
+
* Absolute minimum body size in price units
|
|
12
|
+
*/
|
|
13
|
+
private static readonly MIN_BODY_ABSOLUTE;
|
|
14
|
+
/**
|
|
15
|
+
* Validates if a candle has valid OHLC data
|
|
16
|
+
*/
|
|
17
|
+
static validate(candle: CandleData): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Ensures candle has minimum body size for visibility
|
|
20
|
+
*/
|
|
21
|
+
static ensureMinimumBodySize(candle: CandleData, minBodySize?: number): CandleData;
|
|
22
|
+
/**
|
|
23
|
+
* Validates and corrects OHLC data integrity
|
|
24
|
+
*/
|
|
25
|
+
static validateOHLC(candle: CandleData): CandleData;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a candle belongs to the current time bucket
|
|
28
|
+
*/
|
|
29
|
+
static isCurrentBucket(candle: CandleData, timeframeSeconds: number, timestamp: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Validates price data
|
|
32
|
+
*/
|
|
33
|
+
static validatePrice(price: number): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Calculates minimum body size for a given price
|
|
36
|
+
*/
|
|
37
|
+
static calculateMinBodySize(price: number): number;
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ interface ChartProps {
|
|
|
12
12
|
analyticsConnected?: boolean;
|
|
13
13
|
analyticsLoading?: boolean;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* FunhiChart - OOP-based implementation using FunhiChartController
|
|
17
|
+
* This version eliminates code duplication and uses clean OOP architecture
|
|
18
|
+
*/
|
|
15
19
|
declare const FunhiChart: React.FC<ChartProps>;
|
|
16
20
|
|
|
17
21
|
interface OHLCVCandle {
|