-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] add band source #139
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2615a7e
add band source
8a884c9
run fmt
7a69183
run clippy
4b46e81
fix band source doc
f206690
add band source test
abc79f7
minor fix
05c07db
fix band config
0b941e9
fix fmt and test
910116c
remove unused and refactor code
66fe88e
fix comments
86870ba
update band source
da46f56
update proto
d759c30
format code
e555bb0
add band source config example
dfd1e2d
add band query command and fix doc
1b097d6
run lint
e756ee8
fix price parse error
c26e0ac
fix bitfinex source
a31eaa4
run lint
f9eac84
fix comments
8b1fd79
add test
c48b039
add default band worker opts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| [package] | ||
| name = "bothan-band" | ||
| version = "0.0.1" | ||
| description = "Rust client for the Band source with Bothan integration" | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
|
|
||
| [dependencies] | ||
| bothan-lib = { workspace = true } | ||
|
|
||
| async-trait = { workspace = true } | ||
| chrono = { workspace = true } | ||
| humantime-serde = { workspace = true } | ||
| itertools = { workspace = true } | ||
| reqwest = { workspace = true } | ||
| rust_decimal = { workspace = true } | ||
| serde = { workspace = true } | ||
| serde_json = { workspace = true } | ||
| thiserror = { workspace = true } | ||
| tokio = { workspace = true } | ||
| tokio-util = { workspace = true } | ||
| tracing = { workspace = true } | ||
| url = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| mockito = { workspace = true } | ||
|
|
||
|
|
||
| [package.metadata.cargo-machete] | ||
| ignored = ["humantime-serde"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //! Band REST API client implementation. | ||
| //! | ||
| //! This module provides types and utilities for interacting with the Band REST API, | ||
| //! including configuration, request execution, error handling, and response deserialization. | ||
| //! | ||
| //! The module provides: | ||
| //! | ||
| //! - [`builder`] — A builder pattern for creating [`RestApi`] clients with optional parameters like base URL and API key. | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! - [`rest`] — Core API client implementation, including HTTP request logic and integration with Bothan's `AssetInfoProvider` trait. | ||
| //! - [`types`] — Data types that represent Band REST API responses such as [`Price`](types::Price) | ||
| //! - [`error`] — Custom error types used during API client configuration and request processing. | ||
| //! | ||
| //! # Integration with Workers | ||
| //! | ||
| //! This module is intended to be used by worker implementations (such as [`Worker`](`crate::worker::Worker`)) | ||
| //! that periodically query Band for asset data. The [`RestApi`] implements the | ||
| //! [`AssetInfoProvider`](bothan_lib::worker::rest::AssetInfoProvider) trait, which allows | ||
| //! Band responses to be translated into Bothan-compatible asset updates. | ||
|
|
||
| pub use builder::RestApiBuilder; | ||
| pub use rest::RestApi; | ||
|
|
||
| pub mod builder; | ||
| pub mod error; | ||
| pub mod rest; | ||
| pub mod types; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| //! Builder for configuring and constructing `BandAPI`. | ||
| //! | ||
| //! This module provides a builder for constructing [`RestApi`] clients used | ||
| //! to interact with the Band REST API. The builder supports optional configuration | ||
| //! of base URL. | ||
| //! | ||
| //! The module provides: | ||
| //! | ||
| //! - The [`RestApiBuilder`] for REST API building | ||
| //! - Supports setting the API base URL | ||
| //! - Automatically uses the default Band URL when parameters are omitted during the [`build`](`RestApiBuilder::build`) call | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| use reqwest::ClientBuilder; | ||
| use reqwest::header::HeaderMap; | ||
| use url::Url; | ||
|
|
||
| use crate::api::RestApi; | ||
| use crate::api::error::BuildError; | ||
| use crate::api::types::DEFAULT_URL; | ||
|
|
||
| /// Builder for creating instances of [`RestApi`]. | ||
| /// | ||
| /// The `RestApiBuilder` provides a builder pattern for setting up a [`RestApi`] instance | ||
| /// by allowing users to specify optional configuration parameters such as the base URL. | ||
| /// | ||
| /// # Example | ||
| /// ``` | ||
| /// use bothan_band::api::RestApiBuilder; | ||
| /// | ||
| /// #[tokio::main] | ||
| /// async fn main() { | ||
| /// let api = RestApiBuilder::default() | ||
| /// .with_url("https://bandsource-url.com") | ||
| /// .build() | ||
| /// .unwrap(); | ||
| /// } | ||
| /// ``` | ||
| pub struct RestApiBuilder { | ||
| /// Base URL of the Band REST API. | ||
| url: String, | ||
| } | ||
|
|
||
| impl RestApiBuilder { | ||
| /// Creates a new `RestApiBuilder` with the specified configuration. | ||
| /// | ||
| /// This method allows manual initialization of the builder using | ||
| /// a required URL string. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use bothan_band::api::RestApiBuilder; | ||
| /// | ||
| /// let builder = RestApiBuilder::new( | ||
| /// "https://bandsource-url.com", | ||
| /// ); | ||
| /// ``` | ||
| pub fn new<T>(url: T) -> Self | ||
| where | ||
| T: Into<String>, | ||
| { | ||
| RestApiBuilder { url: url.into() } | ||
| } | ||
|
|
||
| /// Sets the URL for the Band API. | ||
| /// The default URL is `DEFAULT_URL`. | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub fn with_url(mut self, url: &str) -> Self { | ||
| self.url = url.into(); | ||
| self | ||
| } | ||
|
|
||
| /// Builds the [`RestApi`] instance. | ||
| /// | ||
| /// This method consumes the builder and attempts to create a fully configured client. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns a [`BuildError`] if: | ||
| /// - The URL is invalid | ||
| /// - The HTTP client fails to build | ||
| pub fn build(self) -> Result<RestApi, BuildError> { | ||
| let headers = HeaderMap::new(); | ||
|
|
||
| let parsed_url = Url::parse(&self.url)?; | ||
|
|
||
| let client = ClientBuilder::new().default_headers(headers).build()?; | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Ok(RestApi::new(parsed_url, client)) | ||
| } | ||
| } | ||
|
|
||
| impl Default for RestApiBuilder { | ||
| /// Creates a new `BandRestAPIBuilder` with the | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// default URL. | ||
| fn default() -> Self { | ||
| RestApiBuilder { | ||
| url: DEFAULT_URL.into(), | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| //! Error types for Band REST API client operations. | ||
| //! | ||
| //! This module provides custom error types used throughout the Band REST API integration, | ||
| //! particularly for REST API client configuration and concurrent background data fetching. | ||
|
|
||
| use thiserror::Error; | ||
|
|
||
| /// Errors from initializing the Band REST API builder. | ||
| /// | ||
| /// These errors can occur during the initialization and configuration of the HTTP client | ||
| /// or while constructing request parameters. | ||
| #[derive(Debug, Error)] | ||
| pub enum BuildError { | ||
| /// Indicates the provided URL was invalid. | ||
| #[error("invalid url")] | ||
| InvalidURL(#[from] url::ParseError), | ||
|
|
||
| /// Indicates an HTTP header value was invalid or contained prohibited characters. | ||
| #[error("invalid header value")] | ||
| InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue), | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Represents general failures during HTTP client construction (e.g., TLS configuration issues). | ||
| #[error("reqwest error: {0}")] | ||
| FailedToBuild(#[from] reqwest::Error), | ||
| } | ||
|
|
||
| /// General errors from Band API operations. | ||
| /// | ||
| /// These errors typically occur during API calls, response parsing, or data validation. | ||
| #[derive(Debug, Error)] | ||
| pub enum Error { | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Indicates the requested limit is too high (must be <= 5000). | ||
| #[error("limit must be lower or equal to 5000")] | ||
| LimitTooHigh, | ||
|
|
||
| /// Indicates an HTTP request failure due to network issues or HTTP errors. | ||
| #[error("failed request: {0}")] | ||
| FailedRequest(#[from] reqwest::Error), | ||
| } | ||
|
|
||
| /// Errors from fetching and handling data from the Band REST API. | ||
| /// | ||
| /// These errors typically occur during API calls, response parsing, or data validation. | ||
| #[derive(Debug, Error)] | ||
| pub enum ProviderError { | ||
| /// Indicates that an ID in the request is not a valid integer. | ||
| #[error("ids contains non integer value")] | ||
| InvalidId, | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Indicates HTTP request failure due to network issues or HTTP errors. | ||
| #[error("failed to fetch tickers: {0}")] | ||
Marca23 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| RequestError(#[from] reqwest::Error), | ||
|
|
||
| /// Indicates a failure to parse the API response. | ||
| #[error("parse error: {0}")] | ||
| ParseError(#[from] ParseError), | ||
| } | ||
|
|
||
| /// Errors that can occur while parsing Band API responses. | ||
| #[derive(Debug, Error)] | ||
| pub enum ParseError { | ||
| /// Indicates that the price value is not a valid number (NaN). | ||
| #[error("price is NaN")] | ||
| InvalidPrice, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.