@@ -21,10 +21,14 @@ import Series from './Series';
2121import ToolTip from './ToolTip' ;
2222
2323import api from '../../api/tradeview.endpoints' ;
24- import { INTERVALS } from '../../const/chart.const' ;
24+ import { INTERVALS , MINUTE } from '../../const/chart.const' ;
2525import usePastTimeData from '../../hooks/usePastTimeData' ;
2626import useRealTimeData from '../../hooks/useRealTimeData' ;
27- import { extractCandlestickData , timestampToISOString } from '../../utils' ;
27+ import {
28+ extractCandlestickData ,
29+ priceFormatter ,
30+ timestampToISOString ,
31+ } from '../../utils' ;
2832import IntervalSelector from '../IntervalSelector' ;
2933
3034type ChartProps = {
@@ -39,13 +43,15 @@ export default function Chart({ ticker = 'BTC', count = 30 }: ChartProps) {
3943 const [ isChartReady , setIsChartReady ] = useState ( false ) ;
4044 const realTimeData = useRealTimeData ( ticker ) ;
4145 const pastTimeData = usePastTimeData ( ticker , selectedInterval , count ) ;
46+ const prevRequestDate = useRef < Time | null > ( null ) ;
4247
4348 const chartOption : DeepPartial < TimeChartOptions > = useMemo ( ( ) => {
4449 return {
4550 timeScale : { timeVisible : true } ,
4651 localization : {
4752 locale : 'kr' ,
4853 dateFormat : 'yyyy-MM-dd' ,
54+ priceFormatter : priceFormatter ( ) ,
4955 } ,
5056 rightPriceScale : {
5157 borderVisible : false ,
@@ -89,6 +95,12 @@ export default function Chart({ ticker = 'BTC', count = 30 }: ChartProps) {
8995 if ( logicalRange . from < - 0.5 ) {
9096 const firstData = seriesRef . current ?. dataByIndex ( 0 ) as CandlestickData ;
9197 if ( ! firstData || ! firstData . time ) return ;
98+ if (
99+ prevRequestDate . current &&
100+ prevRequestDate . current <= firstData . time
101+ )
102+ return ;
103+ prevRequestDate . current = firstData . time ;
92104
93105 const firstDate = timestampToISOString ( firstData . time as number ) ;
94106
@@ -137,12 +149,12 @@ export default function Chart({ ticker = 'BTC', count = 30 }: ChartProps) {
137149
138150 const timeDiff = + realTimeData . time - + latestTime . time ;
139151
140- if ( timeDiff < 60 * selectedInterval ) {
152+ if ( timeDiff < MINUTE * selectedInterval ) {
141153 seriesRef . current ?. update ( { ...realTimeData , time : latestTime . time } ) ;
142154 } else {
143155 seriesRef . current ?. update ( {
144156 ...realTimeData ,
145- time : ( + latestTime . time + 60 * selectedInterval ) as Time ,
157+ time : ( + latestTime . time + MINUTE * selectedInterval ) as Time ,
146158 } ) ;
147159 }
148160 } , [ realTimeData , selectedInterval ] ) ;
0 commit comments