pub struct Config {
pub api_key: String,
pub api_secret: String,
pub rest_url: String,
pub ws_url: String,
pub ws_ha: WebSocketHighAvailability,
pub ws_max_reconnect: usize,
pub insecure_skip_verify: InsecureSkipVerify,
pub inspect_http_response: Option<fn(&Response)>,
}Expand description
Config specifies the client configuration and dependencies.
Fields§
§api_key: StringClient API key
api_secret: StringClient API secret
rest_url: StringREST API URL
ws_url: StringWebSocket API URL
ws_ha: WebSocketHighAvailabilityHigh Availability Mode: Use concurrent connections to multiple Streams servers
ws_max_reconnect: usizeMaximum number of reconnection attempts for underlying WebSocket connections
insecure_skip_verify: InsecureSkipVerifySkip server certificate chain and host name verification
inspect_http_response: Option<fn(&Response)>Function to inspect HTTP responses for REST requests. The response object must not be modified.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new(
api_key: String,
api_secret: String,
rest_url: String,
ws_url: String,
) -> ConfigBuilder
pub fn new( api_key: String, api_secret: String, rest_url: String, ws_url: String, ) -> ConfigBuilder
Creates a new Config instance with the provided parameters. (Builder pattern)
§Arguments
api_key- Client API key for authentication.api_secret- Client API secret for signing requests.rest_url- REST API base URL.ws_url- WebSocket API base URL.ws_ha- Enable high availability for WebSocket connections.ws_max_reconnect- Maximum reconnection attempts for WebSocket (optional, defaults to 5).insecure_skip_verify- Skip TLS certificate verification (use with caution).inspect_http_response- Optional callback to inspect HTTP responses.
§Errors
Returns ConfigError if any of the provided parameters are invalid.
§Example
use chainlink_data_streams_sdk::config::{Config, WebSocketHighAvailability, InsecureSkipVerify};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let api_key = "YOUR_API_KEY_GOES_HERE";
let user_secret = "YOUR_USER_SECRET_GOES_HERE";
let rest_url = "https://api.testnet-dataengine.chain.link";
let ws_url = "wss://api.testnet-dataengine.chain.link/ws";
// Initialize the basic configuration
let config = Config::new(
api_key.to_string(),
user_secret.to_string(),
rest_url.to_string(),
ws_url.to_string(),
)
.build()?;
// If you want to customize the configuration further, use the builder pattern
// In HA mode, provide a single WebSocket URL — origins are discovered automatically
// via a HEAD request to the server (X-Cll-Available-Origins header).
let config_custom = Config::new(
api_key.to_string(),
user_secret.to_string(),
rest_url.to_string(),
ws_url.to_string(),
)
.with_ws_ha(WebSocketHighAvailability::Enabled) // Enable WebSocket High Availability Mode
.with_ws_max_reconnect(10) // Set maximum reconnection attempts to 10, instead of the default 5.
.with_insecure_skip_verify(InsecureSkipVerify::Enabled) // Skip TLS certificate verification, use with caution. This is disabled by default.
.with_inspect_http_response(|response| {
// Custom logic to inspect the HTTP response here
println!("Received response with status: {}", response.status());
})
.build()?;
Ok(())
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more