@@ -3,19 +3,6 @@ import { useEffect, useRef, useState, useCallback } from 'react';
33
44const 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-
196export 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 ) ;
0 commit comments