File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ interface EndpointInterface {
2
+ name : string ;
3
+ values : {
4
+ ask : number ;
5
+ totalAsk : number ;
6
+ bid : number ;
7
+ totalBid : number ;
8
+ time : number ;
9
+ } ;
10
+ }
11
+
12
+ interface PricesInterface {
13
+ success : boolean ;
14
+ data ?: Array < EndpointInterface > ;
15
+ }
16
+
17
+ export async function getPrices ( ) : Promise < PricesInterface > {
18
+ const currency = 'usd' ;
19
+ const tokens = [ 'eth' , 'dai' ] ;
20
+
21
+ let promises = [ ] ;
22
+
23
+ tokens . map ( ( token ) => {
24
+ promises . push ( { name : token , url : `https://criptoya.com/api/tiendacrypto/${ token } /${ currency } /0.5` } ) ;
25
+ } ) ;
26
+
27
+ const data = await Promise . all (
28
+ promises . map ( async ( { name, url } ) => {
29
+ const resp = await fetch ( url ) ;
30
+ const body = await resp . text ( ) ;
31
+
32
+ return { name, values : JSON . parse ( body ) } ;
33
+ } ) ,
34
+ ) ;
35
+
36
+ if ( data ) {
37
+ return {
38
+ success : true ,
39
+ data,
40
+ } ;
41
+ } else {
42
+ return {
43
+ success : false ,
44
+ } ;
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments