diff --git a/backend-api-demo/src/get-asset-prices.ts b/backend-api-demo/src/get-asset-prices.ts index 454dd86..90ca2f7 100644 --- a/backend-api-demo/src/get-asset-prices.ts +++ b/backend-api-demo/src/get-asset-prices.ts @@ -2,18 +2,16 @@ import { CORE_DOMAIN } from "./const"; import axios from "axios"; import { parse } from "csv-string"; -interface GetSpotPriceParam { +interface GetAssetPricesParam { chainId: number; } -interface GetSpotPriceQuery { - address?: string[]; +interface GetAssetPricesQuery { + addresses?: string; // separated by commas, return all asset prices if empty } -interface GetSpotPriceResponse { - total: number; - addresses: string[]; - pricesUsd: (number | null)[]; +interface GetAssetPricesResponse { + prices: Record; } interface GetHistoricalPricesParam { @@ -45,23 +43,31 @@ interface GetHistoricalPricesResponse { } export async function getAssetPrices() { - // This is an example of how to get all spot prices of assets on Ethereum + // This is an example of how to get all spot prices of pendle assets on Ethereum - const param: GetSpotPriceParam = { + const param: GetAssetPricesParam = { chainId: 1, // Ethereum }; - const targetPath = `/v1/${param.chainId}/prices/assets/all`; + const addressPt_USDe = '0xa8778dd6b7f1f61f2cfda5d3cb18be8f99a8db30'; // address of PT-USDe-26DEC2024 + const addressPt_weETH = '0x6ee2b5e19ecba773a352e5b21415dc419a700d1d'; // address of PT-weETH-26DEC2024 + + const addresses = `${addressPt_USDe},${addressPt_weETH}`; - const { data } = await axios.get(CORE_DOMAIN + targetPath); + const query: GetAssetPricesQuery = { + addresses: addresses + } - const {total, pricesUsd, addresses} = data; + const targetPath = `/v1/${param.chainId}/assets/prices`; - console.log('result info', {total}); + const { data } = await axios.get(CORE_DOMAIN + targetPath, { + params: query + }); - const address = addresses[0]; + const {prices: priceUsdMap} = data; - console.log(`prices of ${address} is ${pricesUsd[0] ?? 0} USD`); + console.log(`price of Pt USDe is ${priceUsdMap[addressPt_USDe] ?? 0} USD`); + console.log(`price of Pt weETH is ${priceUsdMap[addressPt_weETH] ?? 0} USD`); } export async function getHistoricalAssetPrices() { diff --git a/backend-api-demo/src/get-list-assets.ts b/backend-api-demo/src/get-list-assets.ts index 0cb169e..78d7590 100644 --- a/backend-api-demo/src/get-list-assets.ts +++ b/backend-api-demo/src/get-list-assets.ts @@ -21,15 +21,12 @@ interface AssetInfo { decimals: number; address: string; symbol: string; - types: string[]; + tags: string[]; expiry: string; } interface Response { - results: AssetInfo[]; - total: number; - limit: number; - skip: number; + assets: AssetInfo[]; } export async function getAssets() { @@ -39,22 +36,11 @@ export async function getAssets() { chainId: 1, // Ethereum } - const query: Query = { - order_by: 'name:1', - skip: 0, - limit: 10, - is_expired: false, - } - - const targetPath = `/v1/${param.chainId}/assets`; - - const { data } = await axios.get(CORE_DOMAIN + targetPath, {params: query}); - - const {total, limit, skip, results: assets} = data; + const targetPath = `/v3/${param.chainId}/assets/all`; - console.log('result info', {limit, total, skip}); + const { data } = await axios.get(CORE_DOMAIN + targetPath); - const {name, address, decimals, expiry, symbol, types} = assets[0]; + const {assets} = data; - console.log('first asset', {name, address, decimals, expiry, symbol, types}); + console.log('first asset', assets[0]); } \ No newline at end of file diff --git a/backend-api-demo/src/get-list-markets.ts b/backend-api-demo/src/get-list-markets.ts index 3fb8bdb..1db7fa0 100644 --- a/backend-api-demo/src/get-list-markets.ts +++ b/backend-api-demo/src/get-list-markets.ts @@ -4,54 +4,18 @@ import { CORE_DOMAIN } from "./const"; interface Param { chainId: number; } - -interface Query { - order_by?: string; - skip?: number; - limit?: number; - is_expired?: boolean; - select?: string; - pt?: string; - yt?: string; - sy?: string; - q?: string; - is_active?: boolean; - categoryId?: string; -} - interface MarketInfo { name: string; address: string; expiry: string; - pt: { - id: string; - }; - yt: { - id: string; - }; - sy: { - id: string; - }; - liquidity: { - usd: number; - acc: number; - }; - underlyingInterestApy: number; - underlyingRewardApy: number, - underlyingApy: number; - impliedApy: number; - ytFloatingApy: number; - aggregatedApy: number; - maxBoostedApy: number; - lpRewardApy: number; - voterApy: number; + pt: string; + yt: string; + sy: string; + underlyingAsset: string; } interface Response { - total: number; - limit: number; - skip: number; - results: MarketInfo[]; + markets: MarketInfo[]; } export async function getMarkets() { @@ -61,27 +25,11 @@ export async function getMarkets() { chainId: 1, // Ethereum } - const query: Query = { - order_by: 'name:1', - skip: 0, - limit: 10, - is_expired: false, - select: 'pro', - } - - const targetPath = `/v1/${param.chainId}/markets`; - - const { data } = await axios.get(CORE_DOMAIN + targetPath, {params: query}); - - const { results: markets, skip, limit, total } = data; + const targetPath = `/v1/${param.chainId}/markets/active`; - console.log('result info', {limit, total, skip}); + const { data } = await axios.get(CORE_DOMAIN + targetPath); - const {name, address, expiry, pt, sy, yt, liquidity, impliedApy, aggregatedApy, underlyingApy, lpRewardApy, underlyingInterestApy, underlyingRewardApy, maxBoostedApy, voterApy, ytFloatingApy} = markets[0]; - const {id: ptId} = pt; - const {id: syId} = sy; - const {id: ytId} = yt; - const {usd: liquidityUSD } = liquidity; + const { markets } = data; - console.log('first active market', {name, address, expiry, ptId, syId, ytId, liquidityUSD, impliedApy, aggregatedApy, underlyingApy, lpRewardApy, underlyingInterestApy, underlyingRewardApy, maxBoostedApy, voterApy, ytFloatingApy }); + console.log('first active market', markets[0]); } \ No newline at end of file