@@ -10,16 +10,17 @@ use serde_derive::Deserialize;
1010pub struct HistoricalPriceData {
1111 pub timestamp : DateTime < Utc > ,
1212 pub price : f64 ,
13- pub high : f64 ,
14- pub low : f64 ,
15- pub open : f64 ,
16- pub close : f64 ,
13+ pub high : Option < f64 > ,
14+ pub low : Option < f64 > ,
15+ pub open : Option < f64 > ,
16+ pub close : Option < f64 > ,
1717}
18+
1819impl fmt:: Display for HistoricalPriceData {
1920 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2021 write ! (
2122 f,
22- "Timestamp: {}, Price: {}, High: {}, Low: {}, Open: {}, Close: {}" ,
23+ "Timestamp: {}, Price: {}, High: {:? }, Low: {:? }, Open: {:? }, Close: {:? }" ,
2324 self . timestamp, self . price, self . high, self . low, self . open, self . close
2425 )
2526 }
@@ -139,8 +140,8 @@ impl PricesClient {
139140 Ok ( response)
140141 }
141142
142- pub async fn get_prices ( & self , pair : & str ) -> Result < LatestPricesResponse , Box < dyn Error > > {
143- let mut url = format ! ( "{}/v1/prices?pairs={}" , self . base_url, pair ) ;
143+ pub async fn get_prices ( & self , pairs : & [ & str ] ) -> Result < LatestPricesResponse , Box < dyn Error > > {
144+ let url = format ! ( "{}/v1/prices?pairs={}" , self . base_url, pairs . join ( "," ) ) ;
144145
145146 let resp = self . add_headers ( self . client . get ( & url) ) . send ( ) . await ?;
146147 match resp. status ( ) {
@@ -170,23 +171,26 @@ impl PricesClient {
170171 pub async fn get_historical_prices (
171172 & self ,
172173 pairs : & [ & str ] ,
173- start : Option < i64 > ,
174- end : Option < i64 > ,
174+ start : Option < DateTime < Utc > > ,
175+ end : Option < DateTime < Utc > > ,
175176 granularity : Option < & str > ,
176177 ) -> Result < HashMap < String , Vec < HistoricalPriceData > > , Box < dyn Error > > {
177178 let mut url = format ! (
178179 "{}/v1/prices/historical?pairs={}" ,
179180 self . base_url,
180181 pairs. join( "," )
181182 ) ;
182-
183+
183184 if let Some ( start_time) = start {
184- url. push_str ( & format ! ( "&start={}" , start_time) ) ;
185+ let timestamp = start_time. timestamp ( ) ;
186+ url. push_str ( & format ! ( "&start={}" , timestamp) ) ;
185187 }
186-
188+
187189 if let Some ( end_time) = end {
188- url. push_str ( & format ! ( "&end={}" , end_time) ) ;
190+ let timestamp = end_time. timestamp ( ) ;
191+ url. push_str ( & format ! ( "&end={}" , timestamp) ) ;
189192 }
193+
190194
191195 if let Some ( gran) = granularity {
192196 url. push_str ( & format ! ( "&granularity={}" , gran) ) ;
0 commit comments