Skip to content

Commit

Permalink
feat(launch-market): Add LineSeries chart (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredvu authored Oct 3, 2024
1 parent 635f31c commit bd21ff3
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/components/visx/TimeSeriesChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type ElementProps<Datum extends {}> = {
onVisibleDataChange?: (data: Datum[]) => void;
onZoom?: (_: { zoomDomain: number | undefined }) => void;
slotEmpty: React.ReactNode;
children: React.ReactNode;
children?: React.ReactNode;
className?: string;
};

Expand Down
46 changes: 46 additions & 0 deletions src/constants/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,49 @@ export enum FundingDirection {
export const PREDICTION_MARKET = {
TRUMPWIN: 'TRUMPWIN-USD',
};

// Liquidity Tiers
export const LIQUIDITY_TIERS = {
0: {
label: 'Large-cap',
initialMarginFraction: 0.05,
maintenanceMarginFraction: 0.03,
impactNotional: 10_000,
},
1: {
label: 'Small-cap',
initialMarginFraction: 0.1,
maintenanceMarginFraction: 0.05,
impactNotional: 5_000,
},
2: {
label: 'Long-tail',
initialMarginFraction: 0.2,
maintenanceMarginFraction: 0.1,
impactNotional: 2_500,
},
3: {
label: 'Safety',
initialMarginFraction: 1,
maintenanceMarginFraction: 0.2,
impactNotional: 2_500,
},
4: {
label: 'Isolated',
initialMarginFraction: 0.05,
maintenanceMarginFraction: 0.03,
impactNotional: 2_500,
},
5: {
label: 'Mid-cap',
initialMarginFraction: 0.05,
maintenanceMarginFraction: 0.03,
impactNotional: 5_000,
},
6: {
label: 'FX',
initialMarginFraction: 0.01,
maintenanceMarginFraction: 0.0005,
impactNotional: 2_500,
},
};
25 changes: 24 additions & 1 deletion src/hooks/useLaunchableMarkets.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useMemo } from 'react';

import { useQueries } from '@tanstack/react-query';
import { useQueries, useQuery } from '@tanstack/react-query';
import { shallowEqual } from 'react-redux';

import {
MetadataServiceAsset,
MetadataServiceCandlesTimeframes,
MetadataServiceInfoResponse,
MetadataServicePricesResponse,
} from '@/constants/assetMetadata';
Expand All @@ -16,6 +17,7 @@ import { getMarketIds } from '@/state/perpetualsSelectors';
import metadataClient from '@/clients/metadataService';
import { getAssetFromMarketId } from '@/lib/assetUtils';
import { getTickSizeDecimalsFromPrice } from '@/lib/numbers';
import { mapMetadataServiceCandles } from '@/lib/tradingView/utils';

export const useMetadataService = () => {
const metadataQuery = useQueries({
Expand Down Expand Up @@ -116,3 +118,24 @@ export const useLaunchableMarkets = () => {
data: filteredPotentialMarkets,
};
};

export const useMetadataServiceCandles = (
asset?: string,
timeframe?: MetadataServiceCandlesTimeframes
) => {
const candlesQuery = useQuery({
enabled: !!asset && !!timeframe,
queryKey: ['candles', asset, timeframe],
queryFn: async () => {
return metadataClient.getCandles({ asset: asset!, timeframe: timeframe! });
},
refetchInterval: timeUnits.minute * 5,
refetchOnMount: false,
refetchOnWindowFocus: false,
});

return {
...candlesQuery,
data: candlesQuery.data?.[asset ?? ''].map(mapMetadataServiceCandles),
};
};
46 changes: 2 additions & 44 deletions src/hooks/usePotentialMarkets.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, useContext, useEffect, useMemo, useState } from 'react';

import { STRING_KEYS } from '@/constants/localization';
import { LIQUIDITY_TIERS } from '@/constants/markets';
import type { NewMarketProposal } from '@/constants/potentialMarkets';

import { log } from '@/lib/telemetry';
Expand All @@ -10,50 +11,7 @@ import { useStringGetter } from './useStringGetter';
const PotentialMarketsContext = createContext<ReturnType<typeof usePotentialMarketsContext>>({
potentialMarkets: undefined,
hasPotentialMarketsData: false,
liquidityTiers: {
0: {
label: 'Large-cap',
initialMarginFraction: 0.05,
maintenanceMarginFraction: 0.03,
impactNotional: 10_000,
},
1: {
label: 'Small-cap',
initialMarginFraction: 0.1,
maintenanceMarginFraction: 0.05,
impactNotional: 5_000,
},
2: {
label: 'Long-tail',
initialMarginFraction: 0.2,
maintenanceMarginFraction: 0.1,
impactNotional: 2_500,
},
3: {
label: 'Safety',
initialMarginFraction: 1,
maintenanceMarginFraction: 0.2,
impactNotional: 2_500,
},
4: {
label: 'Isolated',
initialMarginFraction: 0.05,
maintenanceMarginFraction: 0.03,
impactNotional: 2_500,
},
5: {
label: 'Mid-cap',
initialMarginFraction: 0.05,
maintenanceMarginFraction: 0.03,
impactNotional: 5_000,
},
6: {
label: 'FX',
initialMarginFraction: 0.01,
maintenanceMarginFraction: 0.0005,
impactNotional: 2_500,
},
},
liquidityTiers: LIQUIDITY_TIERS,
});

PotentialMarketsContext.displayName = 'PotentialMarkets';
Expand Down
4 changes: 1 addition & 3 deletions src/pages/vaults/VaultPnlChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ export const VaultPnlChart = ({ className }: VaultPnlChartProps) => {
numGridLines={0}
tickSpacingX={210}
tickSpacingY={75}
>
{undefined}
</TimeSeriesChart>
/>
</$ChartContainer>
</div>
);
Expand Down
7 changes: 2 additions & 5 deletions src/views/MarketDetails/LaunchableMarketDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { STRING_KEYS } from '@/constants/localization';
import { LIQUIDITY_TIERS } from '@/constants/markets';

import { useMetadataServiceAssetFromId } from '@/hooks/useLaunchableMarkets';
import { useStringGetter } from '@/hooks/useStringGetter';
Expand All @@ -11,11 +12,7 @@ import { BIG_NUMBERS } from '@/lib/numbers';

import { MarketDetails } from './MarketDetails';

const ISOLATED_LIQUIDITY_TIER_INFO = {
initialMarginFraction: 0.05,
maintenanceMarginFraction: 0.03,
impactNotional: 2_500,
};
const ISOLATED_LIQUIDITY_TIER_INFO = LIQUIDITY_TIERS[4];

export const LaunchableMarketDetails = ({ launchableMarketId }: { launchableMarketId: string }) => {
const stringGetter = useStringGetter();
Expand Down
Loading

0 comments on commit bd21ff3

Please sign in to comment.