pub struct BinanceAuth { /* private fields */ }Expand description
Binance authentication implementation for Spot API
Implementations§
Source§impl BinanceAuth
impl BinanceAuth
Sourcepub const fn new_hmac(api_key: SmartString, secret_key: SmartString) -> Self
pub const fn new_hmac(api_key: SmartString, secret_key: SmartString) -> Self
Create new Binance auth with HMAC key
Sourcepub fn new_ed25519(
api_key: SmartString,
private_key: SmartString,
) -> Result<Self>
pub fn new_ed25519( api_key: SmartString, private_key: SmartString, ) -> Result<Self>
Create new Binance auth with Ed25519 key
Supports two private key formats (base64-encoded):
§Format 1: Raw 32-byte key
- Direct 32-byte Ed25519 private key
- Example: “AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=”
§Format 2: DER-encoded key (PKCS#8 format)
- ASN.1 DER structure per RFC 8410
- Structure: SEQUENCE { version, algorithm, privateKey }
- Example: “MC4CAQAwBQYDK2VwBCIEINTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU1NTU”
§Errors
Returns CommonError::Auth if:
- Base64 decoding fails
- Key format is not recognized
- DER structure is malformed
Sourcepub fn get_ed25519_public_key(&self) -> Result<SmartString>
pub fn get_ed25519_public_key(&self) -> Result<SmartString>
Generate Ed25519 public key for API registration
Sourcepub fn build_query_string_optimized(params: &[(&str, &str)]) -> SmartString
pub fn build_query_string_optimized(params: &[(&str, &str)]) -> SmartString
Optimized parameter string building using SmallVec for stack allocation Uses SmallVec<[SmartString; 8]> to avoid heap allocation for typical parameter counts Enhanced with auth module’s optimized implementation
Sourcepub fn encode_params_zero_copy(
params: &str,
buffer: &mut SmartString,
) -> Result<()>
pub fn encode_params_zero_copy( params: &str, buffer: &mut SmartString, ) -> Result<()>
URL-encode the provided parameter string using a pre-allocated buffer.
This performs zero-copy encoding to avoid unpredictable heap allocations on critical paths.
Sourcepub fn generate_headers(
&self,
method: &str,
_path: &str,
_params: Option<&[(&str, &str)]>,
body: Option<&str>,
) -> Result<FxHashMap<SmartString, SmartString>>
pub fn generate_headers( &self, method: &str, _path: &str, _params: Option<&[(&str, &str)]>, body: Option<&str>, ) -> Result<FxHashMap<SmartString, SmartString>>
Generate REST API authentication headers (optimized for performance) Returns headers directly as HashMap to avoid conversion overhead in hot paths
Sourcepub fn generate_signed_query_string(
&self,
params: Option<&[(&str, &str)]>,
) -> Result<SmartString>
pub fn generate_signed_query_string( &self, params: Option<&[(&str, &str)]>, ) -> Result<SmartString>
Generate signed query string for REST API requests This includes the signature and should be appended to the URL
Sourcepub fn generate_signed_params(
&self,
params: &[(&str, &str)],
) -> Result<SmartString>
pub fn generate_signed_params( &self, params: &[(&str, &str)], ) -> Result<SmartString>
Generate parameters with signature for signed requests
Source§impl BinanceAuth
impl BinanceAuth
Sourcepub fn generate_ws_logon_message(&self) -> Result<BinanceWsLogonMessage>
pub fn generate_ws_logon_message(&self) -> Result<BinanceWsLogonMessage>
Generate WebSocket session logon message
Sourcepub fn generate_ws_auth(&self) -> Result<SmartString>
pub fn generate_ws_auth(&self) -> Result<SmartString>
Generate WebSocket authentication message
Sourcepub fn generate_timestamp() -> Result<u64>
pub fn generate_timestamp() -> Result<u64>
Generate timestamp in milliseconds
Sourcepub fn generate_timestamp_nanos() -> Result<u128>
pub fn generate_timestamp_nanos() -> Result<u128>
Generate timestamp in nanoseconds for high-precision timing
Sourcepub fn param_count(params: Option<&[(&str, &str)]>) -> usize
pub fn param_count(params: Option<&[(&str, &str)]>) -> usize
Fast parameter count for pre-allocation decisions
Sourcepub fn generate_joined_param(params: &[(&str, &str)]) -> Option<SmartString>
pub fn generate_joined_param(params: &[(&str, &str)]) -> Option<SmartString>
Generate joined parameter string (for backward compatibility)
Trait Implementations§
Source§impl Clone for BinanceAuth
impl Clone for BinanceAuth
Source§fn clone(&self) -> BinanceAuth
fn clone(&self) -> BinanceAuth
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read more