feat(client): GetMarketsRequest builder type to allow customizable queries#86
feat(client): GetMarketsRequest builder type to allow customizable queries#86
Conversation
8d05a8c to
9cc7cb7
Compare
| GetMarketsRequest::new() | ||
| .with_spot_markets() | ||
| .with_perp_markets() |
There was a problem hiding this comment.
As a user I would expect that calling BpxClient::get_markets would be equivalent to invoking https://api.bpx.dev/api/v1/markets.
IMO we should not specify defaults here - the exchange backend already has defaults specified if no types are provided in the query:
let market_types = market_type.unwrap_or_else(|| vec![MarketType::SPOT, MarketType::PERP]);
| pub fn new() -> Self { | ||
| Self::default() | ||
| } |
There was a problem hiding this comment.
Could we add an additional overload that allows the user to pass a market type? This way if a new market type becomes available in the API it's still possible to query it without us having to add another method here.
| } | ||
|
|
||
| #[derive(Debug, Default, Clone)] | ||
| pub struct GetMarketsRequest(Vec<String>); |
There was a problem hiding this comment.
Not that performance really matters here, but could use Cow<'static, str> here since the market types are mostly going to be static str.
|
|
||
| fn validate(&self) -> Result<()>; | ||
|
|
||
| fn send(self, client: &BpxClient) -> impl Future<Output = Result<Response>> |
There was a problem hiding this comment.
Could we have a method on BpxClient like:
pub async fn send<R>(&self, request: R) -> impl Future<Output = Result<R::Response>> where R: BpxClientRequestThen users can do:
let req = GetMarketsRequest::new();
let response = client.send(req).await?;Feels a little more ergonomic than req.send(client).await
No description provided.