Skip to content

Commit

Permalink
fix: ticker - support dex-screener pair (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
anhnh12 authored Mar 26, 2024
1 parent 3fe6998 commit d734f24
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
9 changes: 9 additions & 0 deletions src/adapters/defi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ class Defi extends Fetcher {
},
})
}

async searchDexScreenerPairs(query: {
token_address: string
symbol: string
}) {
return await this.jsonFetch(`${API_BASE_URL}/dexes/dex-screener/search`, {
query,
})
}
}

export default new Defi()
46 changes: 35 additions & 11 deletions src/commands/ticker/index/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ export async function renderSingle(
value: current_price[CURRENCY] ?? 0,
subscript: true,
})

// dexscreener data
const { data: dexScreenerData }: any = await defi.searchDexScreenerPairs({
token_address: coin.contract_address,
symbol: coin.symbol,
})
const pair = dexScreenerData?.pairs?.[0]
const marketCap = market_cap[CURRENCY] ?? 0
const embed = composeEmbedMessage(null, {
color: getChartColorConfig(coin.id).borderColor as HexColorString,
author: [coin.name, coin.image.small],
image: "attachment://chart.png",
}).addFields([
const fields = [
{
name: `${getEmoji("CHART")} Market cap`,
value: `${utils.formatUsdDigit(marketCap)} ${
Expand Down Expand Up @@ -213,15 +216,19 @@ export async function renderSingle(
},
{
name: `${getEmoji("ANIMATED_FLASH")} ATH`,
value: `${utils.formatUsdPriceDigit({
value: ath[CURRENCY] ?? 0,
subscript: true,
})}`,
value: ath
? `${utils.formatUsdPriceDigit({
value: ath[CURRENCY] ?? 0,
subscript: true,
})}`
: "N/A",
inline: true,
},
{
name: `${getEmoji("ANIMATED_FLASH")} Volume (24h)`,
value: `${utils.formatUsdDigit(total_volume[CURRENCY])}`,
value: total_volume
? `${utils.formatUsdDigit(total_volume[CURRENCY])}`
: "N/A",
inline: true,
},
{
Expand Down Expand Up @@ -264,7 +271,24 @@ export async function renderSingle(
},
]
: []),
])
...(pair
? [
{
name: "Dex Screener",
value: `[${pair.name}](${pair.url.dexscreener})`,
inline: false,
},
]
: []),
].map((item) => ({
...item,
value: item.value || "N/A",
}))
const embed = composeEmbedMessage(null, {
color: getChartColorConfig(coin.id).borderColor as HexColorString,
author: [coin.name, coin.image.small],
image: "attachment://chart.png",
}).addFields(fields)

const chart = await renderHistoricalMarketChart({
coinId: coin.id,
Expand Down

0 comments on commit d734f24

Please sign in to comment.