Skip to content

Commit

Permalink
fix: price scale didn't change with market/actual tick size decimals (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka authored Oct 15, 2024
1 parent 1e71d56 commit f0dcd93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 17 additions & 8 deletions src/hooks/tradingView/useTradingViewDatafeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ import { useAppSelector } from '@/state/appTypes';
import { getAppColorMode, getAppTheme } from '@/state/configsSelectors';
import { getSelectedLocale } from '@/state/localizationSelectors';
import { setCandles } from '@/state/perpetuals';
import { getMarketData, getPerpetualBarsForPriceChart } from '@/state/perpetualsSelectors';
import {
getMarketConfig,
getMarketData,
getPerpetualBarsForPriceChart,
} from '@/state/perpetualsSelectors';

import { objectKeys } from '@/lib/objectHelpers';
import { log } from '@/lib/telemetry';
import { lastBarsCache } from '@/lib/tradingView/dydxfeed/cache';
import { subscribeOnStream, unsubscribeFromStream } from '@/lib/tradingView/dydxfeed/streaming';
import { getMarkForOrderFills } from '@/lib/tradingView/dydxfeed/utils';
import { getHistorySlice, getSymbol, mapCandle } from '@/lib/tradingView/utils';
import { orEmptyObj } from '@/lib/typeUtils';

import { useLocaleSeparators } from '../useLocaleSeparators';
import { useStringGetter } from '../useStringGetter';
Expand All @@ -65,12 +70,10 @@ const configurationData: DatafeedConfiguration = {
],
};

type Props = {
orderbookCandlesToggleOn: boolean;
tickSizeDecimals?: number;
};

export const useTradingViewDatafeed = ({ tickSizeDecimals, orderbookCandlesToggleOn }: Props) => {
export const useTradingViewDatafeed = (
orderbookCandlesToggleOn: boolean,
initialTickSizeDecimals?: number
) => {
const resetCacheRef = useRef<() => void | undefined>();

const dispatch = useDispatch();
Expand Down Expand Up @@ -104,6 +107,12 @@ export const useTradingViewDatafeed = ({ tickSizeDecimals, orderbookCandlesToggl

resolveSymbol: async (symbolName: string, onSymbolResolvedCallback: ResolveCallback) => {
const symbolItem = getSymbol(symbolName || DEFAULT_MARKETID);

const { tickSizeDecimals: tickSizeDecimalsAbacus } = orEmptyObj(
getMarketConfig(store.getState(), symbolName)
);

const tickSizeDecimals = tickSizeDecimalsAbacus ?? initialTickSizeDecimals;
const initialPriceScale = BigNumber(10)
.exponentiatedBy(tickSizeDecimals ?? 2)
.toNumber();
Expand Down Expand Up @@ -282,6 +291,6 @@ export const useTradingViewDatafeed = ({ tickSizeDecimals, orderbookCandlesToggl
},
},
}),
[tickSizeDecimals !== undefined, orderbookCandlesToggleOn]
[initialTickSizeDecimals !== undefined, orderbookCandlesToggleOn]
);
};
6 changes: 3 additions & 3 deletions src/views/charts/TradingView/TvChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export const TvChart = () => {
buySellMarksToggleOn,
} = useTradingViewToggles();

const { datafeed, resetCache } = useTradingViewDatafeed({
const { datafeed, resetCache } = useTradingViewDatafeed(
orderbookCandlesToggleOn,
tickSizeDecimals,
});
tickSizeDecimals
);

const { savedResolution } = useTradingView({
tvWidgetRef,
Expand Down

0 comments on commit f0dcd93

Please sign in to comment.