pub struct BybitConfig {
pub api_key: String,
pub api_secret: String,
pub env: BybitEnv,
pub http_base_url: String,
pub ws_public_base_url: String,
pub ws_private_base_url: String,
pub request_timeout: Duration,
pub recv_window_ms: u64,
pub category: Category,
pub settle_coin: String,
}Expand description
Settings of the client: the key pair, the contour and the addresses.
The secret never appears in Debug output.
Fields§
§api_key: StringThe API key (public half).
api_secret: StringThe API secret (signs requests).
env: BybitEnvThe contour.
http_base_url: StringREST base URL, without a trailing slash.
ws_public_base_url: StringBase URL of the public streams (the path /v5/public/<category> is added).
ws_private_base_url: StringBase URL of the private streams (the path /v5/private is added).
request_timeout: DurationTimeout of one HTTP request.
recv_window_ms: u64The receive window sent with every private request, in milliseconds.
category: CategoryThe product category.
settle_coin: StringThe settle coin used to list orders and positions of a whole category (USDT for linear).
Implementations§
Source§impl BybitConfig
impl BybitConfig
Sourcepub fn new(api_key: impl Into<String>, api_secret: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>, api_secret: impl Into<String>) -> Self
A config for the main contour.
§Examples
use brokapi_bybit_protocol::config::{BybitConfig, BybitEnv};
let cfg = BybitConfig::new("key", "secret");
assert_eq!(cfg.env, BybitEnv::Mainnet);
assert_eq!(cfg.http_base_url, "https://api.bybit.com");
assert_eq!(format!("{cfg:?}").contains("secret\""), false, "the secret is never printed");Sourcepub fn from_env() -> Result<Self, String>
pub fn from_env() -> Result<Self, String>
Reads the key pair and the contour from the environment (after loading .env from the current directory).
BYBIT_ENV is mainnet (default), demo or testnet. The key pair is BYBIT_API_KEY and BYBIT_API_SECRET,
and for the demo contour BYBIT_DEMO_API_KEY and BYBIT_DEMO_API_SECRET: a demo key is not valid on the main
host, so the two pairs can live in one .env.
§Errors
The name of the missing variable. An unknown BYBIT_ENV is an error too.
Sourcepub fn from_env_file(path: impl AsRef<Path>) -> Result<Self, String>
pub fn from_env_file(path: impl AsRef<Path>) -> Result<Self, String>
Like BybitConfig::from_env, with the .env file at path.
Sourcepub fn with_env(self, env: BybitEnv) -> Self
pub fn with_env(self, env: BybitEnv) -> Self
Points the config at a contour: the hosts of the contour replace the current ones.
§Examples
use brokapi_bybit_protocol::config::{BybitConfig, BybitEnv};
let cfg = BybitConfig::new("key", "secret").with_env(BybitEnv::Demo);
assert_eq!(cfg.http_base_url, "https://api-demo.bybit.com");
// The demo host has no public streams: they come from the main host.
assert_eq!(cfg.ws_public_base_url, "wss://stream.bybit.com");
assert_eq!(cfg.ws_private_base_url, "wss://stream-demo.bybit.com");Sourcepub fn with_recv_window_ms(self, ms: u64) -> Self
pub fn with_recv_window_ms(self, ms: u64) -> Self
Sets the receive window in milliseconds.
Sourcepub fn for_mock(
api_key: impl Into<String>,
api_secret: impl Into<String>,
http_base_url: impl Into<String>,
) -> Self
pub fn for_mock( api_key: impl Into<String>, api_secret: impl Into<String>, http_base_url: impl Into<String>, ) -> Self
A config for the in-process imitation: every host is http_base_url (the streams use ws://).
The config is marked as demo, so a connector built from it reports a virtual account.
Sourcepub fn ws_public_url(&self) -> String
pub fn ws_public_url(&self) -> String
The URL of the public stream of the category.
Sourcepub fn ws_private_url(&self) -> String
pub fn ws_private_url(&self) -> String
The URL of the private stream.
Trait Implementations§
Source§impl Clone for BybitConfig
impl Clone for BybitConfig
Source§fn clone(&self) -> BybitConfig
fn clone(&self) -> BybitConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more