-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f11bb4
commit 9ba2a43
Showing
4 changed files
with
55 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1 +1,49 @@ | ||
use std::sync::Arc; | ||
|
||
use tokio::sync::Mutex; | ||
|
||
use crate::api::types::DEFAULT_URL; | ||
use crate::error::Error; | ||
use crate::types::DEFAULT_CHANNEL_SIZE; | ||
use crate::{BinanceService, BinanceWebSocketConnector}; | ||
|
||
pub struct BinanceServiceBuilder { | ||
url: String, | ||
cmd_ch_size: usize, | ||
rem_id_ch_size: usize, | ||
} | ||
|
||
impl BinanceServiceBuilder { | ||
pub fn with_cmd_ch_size(mut self, size: usize) -> Self { | ||
self.cmd_ch_size = size; | ||
self | ||
} | ||
|
||
pub fn with_rem_id_ch_size(mut self, size: usize) -> Self { | ||
self.rem_id_ch_size = size; | ||
self | ||
} | ||
|
||
pub async fn build(self) -> Result<BinanceService, Error> { | ||
let connector = BinanceWebSocketConnector::new(self.url); | ||
let connection = connector.connect().await?; | ||
let service = BinanceService::new( | ||
Arc::new(connector), | ||
Arc::new(Mutex::new(connection)), | ||
self.cmd_ch_size, | ||
self.rem_id_ch_size, | ||
) | ||
.await; | ||
Ok(service) | ||
} | ||
} | ||
|
||
impl Default for BinanceServiceBuilder { | ||
fn default() -> Self { | ||
Self { | ||
url: DEFAULT_URL.to_string(), | ||
cmd_ch_size: DEFAULT_CHANNEL_SIZE, | ||
rem_id_ch_size: DEFAULT_CHANNEL_SIZE, | ||
} | ||
} | ||
} |
This file contains 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 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