@@ -29,6 +29,7 @@ pub async fn get_kgau_nanoerg() -> Result<AssetsExchangeRate<KgAu, NanoErg>, Dat
2929 }
3030}
3131
32+ #[ cfg( not( test) ) ]
3233pub async fn get_usd_nanoerg ( ) -> Result < AssetsExchangeRate < Usd , NanoErg > , DataPointSourceError > {
3334 let url = "https://api.coingecko.com/api/v3/simple/price?ids=ergo&vs_currencies=USD" ;
3435 let resp = reqwest:: get ( url) . await ?;
@@ -50,6 +51,19 @@ pub async fn get_usd_nanoerg() -> Result<AssetsExchangeRate<Usd, NanoErg>, DataP
5051 }
5152}
5253
54+ #[ cfg( test) ]
55+ pub async fn get_usd_nanoerg ( ) -> Result < AssetsExchangeRate < Usd , NanoErg > , DataPointSourceError > {
56+ // Convert from price Erg/USD to nanoErgs per 1 USD
57+ let nanoerg_per_usd = NanoErg :: from_erg ( 1.0 / 1.67 ) ;
58+ let rate = AssetsExchangeRate {
59+ per1 : Usd { } ,
60+ get : NanoErg { } ,
61+ rate : nanoerg_per_usd,
62+ } ;
63+ Ok ( rate)
64+ }
65+
66+ #[ cfg( not( test) ) ]
5367pub async fn get_usd_lovelace ( ) -> Result < AssetsExchangeRate < Usd , Lovelace > , DataPointSourceError > {
5468 let url = "https://api.coingecko.com/api/v3/simple/price?ids=cardano&vs_currencies=USD" ;
5569 let resp = reqwest:: get ( url) . await ?;
@@ -71,6 +85,19 @@ pub async fn get_usd_lovelace() -> Result<AssetsExchangeRate<Usd, Lovelace>, Dat
7185 }
7286}
7387
88+ #[ cfg( test) ]
89+ pub async fn get_usd_lovelace ( ) -> Result < AssetsExchangeRate < Usd , Lovelace > , DataPointSourceError > {
90+ // Convert from price Erg/USD to nanoErgs per 1 USD
91+ let lovelace_price = Lovelace :: from_ada ( 1.0 / 0.606545 ) ;
92+ let rate = AssetsExchangeRate {
93+ per1 : Usd { } ,
94+ get : Lovelace { } ,
95+ rate : lovelace_price,
96+ } ;
97+ Ok ( rate)
98+ }
99+
100+ #[ cfg( not( test) ) ]
74101pub async fn get_btc_nanoerg ( ) -> Result < AssetsExchangeRate < Btc , NanoErg > , DataPointSourceError > {
75102 let url = "https://api.coingecko.com/api/v3/simple/price?ids=ergo&vs_currencies=BTC" ;
76103 let resp = reqwest:: get ( url) . await ?;
@@ -92,6 +119,18 @@ pub async fn get_btc_nanoerg() -> Result<AssetsExchangeRate<Btc, NanoErg>, DataP
92119 }
93120}
94121
122+ #[ cfg( test) ]
123+ pub async fn get_btc_nanoerg ( ) -> Result < AssetsExchangeRate < Btc , NanoErg > , DataPointSourceError > {
124+ // Convert from price BTC/ERG to nanoERG/BTC
125+ let erg_per_usd = NanoErg :: from_erg ( 1.0 / 0.00003791 ) ;
126+ let rate = AssetsExchangeRate {
127+ per1 : Btc { } ,
128+ get : NanoErg { } ,
129+ rate : erg_per_usd,
130+ } ;
131+ Ok ( rate)
132+ }
133+
95134#[ cfg( test) ]
96135mod tests {
97136 use super :: * ;
0 commit comments