Skip to content

Commit

Permalink
SOV-4332: Use Sovryn indexer for chart data (#2607)
Browse files Browse the repository at this point in the history
* SOV-4497: Fix FastBTC fee (#2611)

Fix FastBTC fee

* Use Sovryn indexer for chart data
  • Loading branch information
tiltom authored Oct 30, 2024
1 parent 7b93601 commit a25db44
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 620 deletions.
8 changes: 8 additions & 0 deletions src/app/components/TradingChart/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const SOVRYN_INDEXER_MAINNET =
'https://indexer.sovryn.app/chart?chainId=30&';

export const SOVRYN_INDEXER_TESTNET =
'https://indexer.test.sovryn.app/chart?chainId=31&';

// maximum number of candles that should be loaded in one request
export const CHUNK_SIZE = 1000;
8 changes: 1 addition & 7 deletions src/app/components/TradingChart/datafeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import {
resolutionMap,
supportedResolutions,
} from 'app/pages/PerpetualPage/components/TradingChart/helpers';
import {
getTokensFromSymbol,
hasDirectFeed,
queryPairByChunks,
} from './helpers';
import { getTokensFromSymbol, queryPairByChunks } from './helpers';
import { CandleDuration } from 'app/pages/PerpetualPage/hooks/graphql/useGetCandles';
import { TradingCandleDictionary } from './dictionary';
import { pushPrice } from 'utils/pair-price-tracker';
Expand Down Expand Up @@ -114,15 +110,13 @@ const tradingChartDataFeeds = (
const { baseToken, quoteToken } = getTokensFromSymbol(symbolInfo.name);

let items = await queryPairByChunks(
graphqlClient,
candleDetails,
baseToken,
quoteToken,
fromTime(),
Math.floor(
Math.min(to + candleDetails.candleSeconds, Date.now() / 1e3),
),
hasDirectFeed(symbolInfo.name),
);

if (!items || items.length === 0) {
Expand Down
76 changes: 71 additions & 5 deletions src/app/components/TradingChart/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,89 @@ export class TradingCandleDictionary {
>([
[
CandleDuration.M_1,
new CandleDetails('candleStickMinutes', 'D', 1, 5, 60),
new CandleDetails('candleSticksMinutes', 'D', 1, 5, 60, '1m'),
],
[
CandleDuration.M_10,
new CandleDetails('candleSticksTenMinutes', 'D', 3, 5, 60 * 10, '10m'),
],
[
CandleDuration.M_15,
new CandleDetails('candleStickFifteenMinutes', 'D', 3, 5, 60 * 15),
new CandleDetails(
'candleSticksFifteenMinutes',
'D',
3,
5,
60 * 15,
'15m',
),
],
[
CandleDuration.M_30,
new CandleDetails('candleSticksThirtyMinutes', 'D', 3, 5, 60 * 30, '30m'),
],
[
CandleDuration.H_1,
new CandleDetails('candleStickHours', 'D', 5, 5, 60 * 60),
new CandleDetails('candleSticksHours', 'D', 5, 5, 60 * 60, '1h'),
],
[
CandleDuration.H_4,
new CandleDetails('candleStickFourHours', 'D', 10, 10, 60 * 60 * 4),
new CandleDetails(
'candleSticksFourHours',
'D',
10,
10,
60 * 60 * 4,
'4h',
),
],
[
CandleDuration.H_12,
new CandleDetails(
'candleSticksTwelveHours',
'D',
10,
10,
60 * 60 * 12,
'12h',
),
],
[
CandleDuration.D_1,
new CandleDetails('candleStickDays', 'D', 90, 90, 60 * 60 * 24),
new CandleDetails('candleSticksDays', 'D', 90, 90, 60 * 60 * 24, '1d'),
],
[
CandleDuration.D_3,
new CandleDetails(
'candleSticksThreeDays',
'D',
90,
90,
60 * 60 * 24 * 3,
'3d',
),
],
[
CandleDuration.W_1,
new CandleDetails(
'candleSticksOneWeek',
'D',
90,
90,
60 * 60 * 24 * 7,
'1w',
),
],
[
CandleDuration.D_30,
new CandleDetails(
'candleSticksOneMonth',
'D',
90,
90,
60 * 60 * 24 * 30,
'30d',
),
],
]);

Expand Down
Loading

0 comments on commit a25db44

Please sign in to comment.