Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use data from S3 instead of API #34

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NEXT_PUBLIC_API_URL = https://stats-api.hyperliquid.xyz
NEXT_PUBLIC_DAT_URL = https://d2v1fiwobg9w6.cloudfront.net
NEXT_PUBLIC_GOOGLE_ANALYTICS_CONFIG = G-8GN39Z428L

104 changes: 51 additions & 53 deletions constants/api.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@
export const total_users = '/hyperliquid/total_users'; // Retrieves the total number of users.
export const total_usd_volume = '/hyperliquid/total_usd_volume'; // Retrieves the total USD trading volume.
export const total_deposits = '/hyperliquid/total_deposits'; // Retrieves the total amount of deposits.
export const total_withdrawals = '/hyperliquid/total_withdrawals'; // Retrieves the total amount of withdrawals.
export const total_notional_liquidated = '/hyperliquid/total_notional_liquidated'; // Retrieves the total notional value liquidated.
export const cumulative_usd_volume = '/hyperliquid/cumulative_usd_volume'; // Retrieves the cumulative USD trading volume over time.
export const daily_usd_volume = '/hyperliquid/daily_usd_volume'; // Retrieves the daily USD trading volume over time.
export const daily_usd_volume_by_coin = '/hyperliquid/daily_usd_volume_by_coin'; // Retrieves the daily USD trading volume by coin over time.
export const daily_usd_volume_by_crossed = '/hyperliquid/daily_usd_volume_by_crossed'; // Retrieves the daily USD trading volume by crossed over time.
export const daily_usd_volume_by_user = '/hyperliquid/daily_usd_volume_by_user'; // Retrieves the daily USD trading volume by top 10 user and the rest are summed and marked as other.

export const cumulative_trades = '/hyperliquid/cumulative_trades'; // Retrieves the cumulative number of trades over time. The line chart of Cumulative total trades chart.

export const daily_trades = '/hyperliquid/daily_trades'; // Retrieves the daily number of trades.
export const daily_trades_by_coin = '/hyperliquid/daily_trades_by_coin'; // Retrieves the daily number of trades by coin.
export const daily_trades_by_crossed = '/hyperliquid/daily_trades_by_crossed'; // Retrieves the daily number of trades by crossed.
export const daily_trades_by_user = '/hyperliquid/daily_trades_by_user'; // Retrieves the daily number of trades by top 10 user and the rest are summed and marked as other.
export const user_pnl = '/hyperliquid/user_pnl'; // Retrieves the profit and loss (PnL) for all users daily.
export const cumulative_user_pnl = '/hyperliquid/cumulative_user_pnl'; // Retrieves the cumulative PnL for all users over time.
export const hlp_liquidator_pnl = '/hyperliquid/hlp_liquidator_pnl'; // Retrieves the PnL for liquidators daily.
export const hlp_liquidator_pnl_false = '/hyperliquid/hlp_liquidator_pnl?is_hlp=false'; // Retrieves the PnL for liquidators daily.

export const cumulative_hlp_liquidator_pnl = '/hyperliquid/cumulative_hlp_liquidator_pnl'; // Retrieves the cumulative PnL for liquidators over time.

export const cumulative_hlp_liquidator_pnl_false =
'/hyperliquid/cumulative_hlp_liquidator_pnl?is_hlp=false'; // Retrieves the cumulative PnL for liquidators over time.

export const cumulative_liquidated_notional = '/hyperliquid/cumulative_liquidated_notional'; // Retrieves the cumulative liquidated notional value over time.
export const daily_unique_users = '/hyperliquid/daily_unique_users'; // Retrieves the daily number of unique users.
export const cumulative_users = '/hyperliquid/cumulative_users'; // Retrieves the cumulative number of users over time

export const daily_unique_users_by_coin = '/hyperliquid/daily_unique_users_by_coin';

export const cumulative_inflow = '/hyperliquid/cumulative_inflow'; // Retrieves the cumulative inflow of funds over time.
export const open_interest = '/hyperliquid/open_interest'; // Retrieves the open interest data.
export const funding_rate = '/hyperliquid/funding_rate'; // Retrieves the funding rate data.
export const cumulative_new_users = '/hyperliquid/cumulative_new_users'; // Retrieves the cumulative number of unique users over time.
export const daily_inflow = '/hyperliquid/daily_inflow'; // Retrieves the daily inflow of funds.
export const liquidity_per_symbol = '/hyperliquid/liquidity_per_symbol'; // Retrieves the liquidity data per symbol.
export const largest_users_by_usd_volume = '/hyperliquid/largest_users_by_usd_volume'; // Retrieves the largest users by USD trading volume.
export const largest_user_depositors = '/hyperliquid/largest_user_depositors'; // Retrieves the largest user depositors.
export const largest_liquidated_notional_by_user =
'/hyperliquid/largest_liquidated_notional_by_user'; // Retrieves the largest liquidated notional by user.
export const largest_user_trade_count = '/hyperliquid/largest_user_trade_count'; // Retrieves the users with the highest trade counts.

export const daily_notional_liquidated_total = '/hyperliquid/daily_notional_liquidated_total';
export const total_users = 'total_users'; // Retrieves the total number of users.
export const total_usd_volume = 'total_usd_volume'; // Retrieves the total USD trading volume.
export const total_deposits = 'total_deposits'; // Retrieves the total amount of deposits.
export const total_withdrawals = 'total_withdrawals'; // Retrieves the total amount of withdrawals.
export const total_notional_liquidated = 'total_notional_liquidated'; // Retrieves the total notional value liquidated.
export const cumulative_usd_volume = 'cumulative_usd_volume'; // Retrieves the cumulative USD trading volume over time.
export const daily_usd_volume = 'daily_usd_volume'; // Retrieves the daily USD trading volume over time.
export const daily_usd_volume_by_coin = 'daily_usd_volume_by_coin'; // Retrieves the daily USD trading volume by coin over time.
export const daily_usd_volume_by_crossed = 'daily_usd_volume_by_crossed'; // Retrieves the daily USD trading volume by crossed over time.
export const daily_usd_volume_by_user = 'daily_usd_volume_by_user'; // Retrieves the daily USD trading volume by top 10 user and the rest are summed and marked as other.

export const cumulative_trades = 'cumulative_trades'; // Retrieves the cumulative number of trades over time. The line chart of Cumulative total trades chart.

export const daily_trades = 'daily_trades'; // Retrieves the daily number of trades.
export const daily_trades_by_coin = 'daily_trades_by_coin'; // Retrieves the daily number of trades by coin.
export const daily_trades_by_crossed = 'daily_trades_by_crossed'; // Retrieves the daily number of trades by crossed.
export const daily_trades_by_user = 'daily_trades_by_user'; // Retrieves the daily number of trades by top 10 user and the rest are summed and marked as other.
export const user_pnl = 'user_pnl'; // Retrieves the profit and loss (PnL) for all users daily.
export const cumulative_user_pnl = 'cumulative_user_pnl'; // Retrieves the cumulative PnL for all users over time.
export const hlp_liquidator_pnl = 'hlp_liquidator_pnl'; // Retrieves the PnL for liquidators daily.
export const hlp_liquidator_pnl_false = 'hlp_liquidator_pnl?is_hlp=false'; // Retrieves the PnL for liquidators daily.

export const cumulative_hlp_liquidator_pnl = 'cumulative_hlp_liquidator_pnl'; // Retrieves the cumulative PnL for liquidators over time.

export const cumulative_hlp_liquidator_pnl_false = 'cumulative_hlp_liquidator_pnl?is_hlp=false'; // Retrieves the cumulative PnL for liquidators over time.

export const cumulative_liquidated_notional = 'cumulative_liquidated_notional'; // Retrieves the cumulative liquidated notional value over time.
export const daily_unique_users = 'daily_unique_users'; // Retrieves the daily number of unique users.
export const cumulative_users = 'cumulative_users'; // Retrieves the cumulative number of users over time

export const daily_unique_users_by_coin = 'daily_unique_users_by_coin';

export const cumulative_inflow = 'cumulative_inflow'; // Retrieves the cumulative inflow of funds over time.
export const open_interest = 'open_interest'; // Retrieves the open interest data.
export const funding_rate = 'funding_rate'; // Retrieves the funding rate data.
export const cumulative_new_users = 'cumulative_new_users'; // Retrieves the cumulative number of unique users over time.
export const daily_inflow = 'daily_inflow'; // Retrieves the daily inflow of funds.
export const liquidity_per_symbol = 'liquidity_per_symbol'; // Retrieves the liquidity data per symbol.
export const largest_users_by_usd_volume = 'largest_users_by_usd_volume'; // Retrieves the largest users by USD trading volume.
export const largest_user_depositors = 'largest_user_depositors'; // Retrieves the largest user depositors.
export const largest_liquidated_notional_by_user = 'largest_liquidated_notional_by_user'; // Retrieves the largest liquidated notional by user.
export const largest_user_trade_count = 'largest_user_trade_count'; // Retrieves the users with the highest trade counts.

export const daily_notional_liquidated_total = 'daily_notional_liquidated_total';
export const daily_notional_liquidated_by_leverage_type =
'/hyperliquid/daily_notional_liquidated_by_leverage_type';
'daily_notional_liquidated_by_leverage_type';

export const liquidity_by_coin = '/hyperliquid/liquidity_by_coin';
export const daily_notional_liquidated_by_coin = '/hyperliquid/daily_notional_liquidated_by_coin';
export const liquidity_by_coin = 'liquidity_by_coin';
export const daily_notional_liquidated_by_coin = 'daily_notional_liquidated_by_coin';

export const total_accrued_fees = '/hyperliquid/total_accrued_fees';
export const total_volume = '/hyperliquid/total_volume';
export const hlp_positions = '/hyperliquid/hlp_positions';
export const asset_ctxs = '/hyperliquid/asset_ctxs';
export const total_accrued_fees = 'total_accrued_fees';
export const total_volume = 'total_volume';
export const hlp_positions = 'hlp_positions';
export const asset_ctxs = 'asset_ctxs';
59 changes: 25 additions & 34 deletions hooks/useRequest.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
import { useState, useEffect, useContext } from 'react';
import { useState, useEffect, useContext, useCallback } from 'react';
import { DataContext } from '../contexts/data';

const fetcher = (url: string) => fetch(url).then((res) => res.json());

export function useRequest(url: string, defaultValue: any, key?: string, dontRefetch?: boolean) {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<any>();
const [data, setData] = useState(defaultValue);
const dataContext = useContext(DataContext);
const urlHasParams = url.indexOf('?') !== -1;

let params = '';
if (dataContext.dates.from) {
if (!urlHasParams) {
params += '?';
}
if (urlHasParams) {
params += '&';
}
params += `start_date=${dataContext.dates.from}`;
}
if (dataContext.dates.to) {
params += `&end_date=${dataContext.dates.to}`;
}

const init = async () => {
try {
setLoading(true);
const data = await fetcher(`${process.env.NEXT_PUBLIC_API_URL}${url}${params}`);
if (key && data[key]) {
setData(data[key]);
} else {
setData(data);
}
} catch (error) {
console.error(error);
setError(error);
}
const init = useCallback(async () => {
setLoading(true);
const data = await fetcher(`${process.env.NEXT_PUBLIC_DAT_URL}/${url}`);
const dataFromKey = key ? data[key] : data?.table_data || data?.chart_data || data;
setData(
dataFromKey.filter
? dataFromKey.filter((line: any) => {
if (!line.time) {
return true;
}
if (dataContext.dates.from && new Date(line.time) < new Date(dataContext.dates.from)) {
return false;
}
if (dataContext.dates.to && new Date(line.time) > new Date(dataContext.dates.to)) {
return false;
}
return true;
})
: dataFromKey
);
setLoading(false);
};
}, [dataContext.dates.from, dataContext.dates.to, key, url]);

useEffect(() => {
init();
}, [url]);
}, [init, url]);

useEffect(() => {
if (dontRefetch) return;
init();
}, [dataContext.dates.from, dataContext.dates.to]);
}, [dataContext.dates.from, dataContext.dates.to, dontRefetch, init]);

return [data, loading, error];
return [data, loading];
}
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('next').NextConfig} */

const nextConfig = {
output: 'export',
reactStrictMode: false,
webpack: (config, { isServer, defaultLoaders }) => {
config.module.rules.push({
Expand Down