@@ -40,45 +40,44 @@ export async function getCoinOHLC(
4040 return res . json ( ) ;
4141}
4242
43+ // Get trending coins
44+ export async function getTrendingCoins ( ) {
45+ const res = await fetch ( `${ baseUrl } /search/trending` , header ) ;
4346
44- export async function getCoinList ( page : number = 1 , perPage : number = 50 ) {
45- const params = new URLSearchParams ( {
46- vs_currency : 'usd' ,
47- order : 'market_cap_desc' ,
48- per_page : perPage . toString ( ) ,
49- page : page . toString ( ) ,
50- sparkline : 'false' ,
51- locale : 'en' ,
52- price_change_percentage : '24h' ,
53- } ) ;
54-
55- const res = await fetch ( `${ baseUrl } /coins/markets?${ params } ` , header ) ;
47+ if ( ! res . ok ) throw new Error ( 'Failed to fetch trending coins' ) ;
5648
57- if ( ! res . ok ) throw new Error ( 'Failed to fetch CoinGecko API data' ) ;
58- return res . json ( ) ;
49+ const data = await res . json ( ) ;
50+ return data . coins || [ ] ;
5951}
6052
53+ // Get coin categories
6154export async function getCategories ( ) {
6255 const res = await fetch (
6356 `${ baseUrl } /coins/categories` ,
6457 header
6558 ) ;
6659
67- if ( ! res . ok ) throw new Error ( 'Failed to fetch top gainers/losers ' ) ;
60+ if ( ! res . ok ) throw new Error ( 'Failed to fetch categories ' ) ;
6861
6962 const data = await res . json ( ) ;
7063 return data . slice ( 0 , 10 ) || [ ] ;
7164}
7265
66+ export async function getCoinList ( page : number = 1 , perPage : number = 50 ) {
67+ const params = new URLSearchParams ( {
68+ vs_currency : 'usd' ,
69+ order : 'market_cap_desc' ,
70+ per_page : perPage . toString ( ) ,
71+ page : page . toString ( ) ,
72+ sparkline : 'false' ,
73+ locale : 'en' ,
74+ price_change_percentage : '24h' ,
75+ } ) ;
7376
77+ const res = await fetch ( `${ baseUrl } /coins/markets?${ params } ` , header ) ;
7478
75- export async function getTrendingCoins ( ) {
76- const res = await fetch ( `${ baseUrl } /search/trending` , header ) ;
77-
78- if ( ! res . ok ) throw new Error ( 'Failed to fetch trending coins' ) ;
79-
80- const data = await res . json ( ) ;
81- return data . coins || [ ] ;
79+ if ( ! res . ok ) throw new Error ( 'Failed to fetch CoinGecko API data' ) ;
80+ return res . json ( ) ;
8281}
8382
8483export async function getTopGainersLosers ( ) {
0 commit comments