-
Notifications
You must be signed in to change notification settings - Fork 25
feat(client): GetMarketsRequest builder type to allow customizable queries #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
8d05a8c to
9cc7cb7
Compare
| GetMarketsRequest::new() | ||
| .with_spot_markets() | ||
| .with_perp_markets() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.