pub mod get;
pub mod post;
mod request;
use crate::constants::{
TESTNET_API_URL,
MAINNET_API_URL,
DEFAULT_RECV_WINDOW,
};
#[derive(Debug, Clone)]
pub struct BybitApi {
base_url: &'static str,
api_key: Option<String>,
api_secret: Option<String>,
recv_window: String,
}
impl BybitApi {
pub fn base_url(&self) -> &'static str {
self.base_url
}
pub fn api_key(&self) -> Option<&String> {
self.api_key.as_ref()
}
pub fn api_secret(&self) -> Option<&String> {
self.api_secret.as_ref()
}
pub fn recv_window(&self) -> &String {
&self.recv_window
}
pub fn new() -> Self {
Self {
..Default::default()
}
}
pub fn with_api_key(mut self, api_key: String) -> Self {
self.api_key = Some(api_key);
self
}
pub fn with_api_secret(mut self, api_secret: String) -> Self {
self.api_secret = Some(api_secret);
self
}
pub fn with_recv_window(mut self, recv_window: String) -> Self {
self.recv_window = recv_window;
self
}
pub fn with_testnet(mut self) -> Self {
self.base_url = TESTNET_API_URL;
self
}
pub fn with_mainnet(mut self) -> Self {
self.base_url = MAINNET_API_URL;
self
}
}
impl Default for BybitApi {
fn default() -> Self {
Self {
base_url: TESTNET_API_URL,
api_key: None,
api_secret: None,
recv_window: DEFAULT_RECV_WINDOW.to_string(),
}
}
}