Skip to content

Commit 4271bde

Browse files
committed
fix
1 parent 577c174 commit 4271bde

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

components/CandlestickChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default function CandlestickChart({
119119
// Update chart data when chartData or period changes
120120
useEffect(() => {
121121
if (candleSeriesRef.current && chartRef.current && chartData.length > 0) {
122-
// For both modes, use setData() to update the chart
122+
// Update the chart
123123
candleSeriesRef.current.setData(chartData);
124124
chartRef.current.timeScale().fitContent();
125125

hooks/useCoinGeckoWebSocket.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ import { useEffect, useRef, useState, useCallback } from 'react';
33

44
const WS_BASE = `${process.env.NEXT_PUBLIC_COINGECKO_WEBSOCKET_URL}?x_cg_pro_api_key=${process.env.NEXT_PUBLIC_COINGECKO_API_KEY}`;
55

6-
interface UseCoinGeckoWebSocketProps {
7-
coinId: string;
8-
poolId: string;
9-
coinOHLCData: OHLCData[];
10-
}
11-
12-
interface UseCoinGeckoWebSocketReturn {
13-
price: ExtendedPriceData | null;
14-
trades: TradeData[];
15-
ohlcv: OHLCData[];
16-
isConnected: boolean;
17-
}
18-
196
export function useCoinGeckoWebSocket({
207
coinId,
218
poolId,
@@ -63,7 +50,7 @@ export function useCoinGeckoWebSocket({
6350
const newTrade: TradeData = {
6451
price: msg.pu,
6552
value: msg.vo,
66-
timestamp: msg.t ?? 0, // Already in milliseconds
53+
timestamp: msg.t ?? 0,
6754
type: msg.ty,
6855
amount: msg.to,
6956
};
@@ -79,7 +66,7 @@ export function useCoinGeckoWebSocket({
7966
if (msg.ch === 'G3') {
8067
setOhlcv((prev) => {
8168
const lastCandle = prev[prev.length - 1];
82-
// WebSocket sends timestamp as integer (already in milliseconds)
69+
8370
const newTimeMs = msg.t ?? 0;
8471
const newCandle: OHLCData = [
8572
newTimeMs,
@@ -96,11 +83,15 @@ export function useCoinGeckoWebSocket({
9683

9784
// Only append if timestamp is newer than the last candle
9885
if (lastCandle && newTimeMs < lastCandle[0]) {
99-
console.warn('Skipping out-of-order candle:', newTimeMs, 'vs', lastCandle[0]);
86+
console.warn(
87+
'Skipping out-of-order candle:',
88+
newTimeMs,
89+
'vs',
90+
lastCandle[0]
91+
);
10092
return prev;
10193
}
10294

103-
// New timestamp, append new candle
10495
// Keep all historical data + last 100 live candles
10596
const historicalCount = historicalDataLength.current;
10697
const liveCandles = prev.slice(historicalCount);

types.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ interface Category {
231231
market_cap: number;
232232
volume_24h: number;
233233
}
234+
235+
interface UseCoinGeckoWebSocketProps {
236+
coinId: string;
237+
poolId: string;
238+
coinOHLCData: OHLCData[];
239+
}
240+
241+
interface UseCoinGeckoWebSocketReturn {
242+
price: ExtendedPriceData | null;
243+
trades: TradeData[];
244+
ohlcv: OHLCData[];
245+
isConnected: boolean;
246+
}

0 commit comments

Comments
 (0)