pub struct Credentials { /* private fields */ }Expand description
API credentials for authenticated Binance endpoints.
Supports three authentication methods:
- HMAC-SHA256 (default): Most common, uses API secret key
- RSA-SHA256: For institutional accounts with RSA key pairs
- Ed25519: Modern, fast signature algorithm
§Examples
§HMAC-SHA256 (Default)
use binance_api_client::Credentials;
let creds = Credentials::new("api_key", "secret_key");§RSA-SHA256
use binance_api_client::Credentials;
let pem = std::fs::read_to_string("private_key.pem")?;
let creds = Credentials::with_rsa_key("api_key", &pem)?;§Ed25519
use binance_api_client::Credentials;
let private_key_bytes = std::fs::read("ed25519_private_key.der")?;
let creds = Credentials::with_ed25519_key("api_key", &private_key_bytes)?;Implementations§
Source§impl Credentials
impl Credentials
Sourcepub fn new(api_key: impl Into<String>, secret_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>, secret_key: impl Into<String>) -> Self
Create new credentials with HMAC-SHA256 signing.
This is the default and most common authentication method.
Sourcepub fn with_rsa_key(
api_key: impl Into<String>,
private_key_pem: &str,
) -> Result<Self>
pub fn with_rsa_key( api_key: impl Into<String>, private_key_pem: &str, ) -> Result<Self>
Create credentials with an RSA private key for RSA-SHA256 signing.
RSA signatures are commonly used for institutional/enterprise API keys. The private key should be in PKCS#8 PEM format.
§Arguments
api_key- The API keyprivate_key_pem- RSA private key in PKCS#8 PEM format
§Example
let pem = r#"-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBg...
-----END PRIVATE KEY-----"#;
let creds = Credentials::with_rsa_key("api_key", pem)?;Sourcepub fn with_ed25519_key(
api_key: impl Into<String>,
private_key_bytes: &[u8],
) -> Result<Self>
pub fn with_ed25519_key( api_key: impl Into<String>, private_key_bytes: &[u8], ) -> Result<Self>
Create credentials with an Ed25519 private key.
Ed25519 is a modern, fast signature algorithm. The private key should be the raw 32-byte seed or a PKCS#8 DER-encoded key.
§Arguments
api_key- The API keyprivate_key_bytes- Ed25519 private key bytes (seed or PKCS#8 DER)
§Example
// From raw 32-byte seed
let seed: [u8; 32] = [...];
let creds = Credentials::with_ed25519_key("api_key", &seed)?;
// From PKCS#8 DER file
let der_bytes = std::fs::read("private_key.der")?;
let creds = Credentials::with_ed25519_key("api_key", &der_bytes)?;Sourcepub fn with_ed25519_pem(api_key: impl Into<String>, pem: &str) -> Result<Self>
pub fn with_ed25519_pem(api_key: impl Into<String>, pem: &str) -> Result<Self>
Create credentials with an Ed25519 private key from a PEM file.
§Arguments
api_key- The API keypem- Ed25519 private key in PKCS#8 PEM format
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Load credentials from environment variables.
Expects BINANCE_API_KEY and BINANCE_SECRET_KEY environment variables.
Uses HMAC-SHA256 signing.
Sourcepub fn from_env_with_prefix(prefix: &str) -> Result<Self>
pub fn from_env_with_prefix(prefix: &str) -> Result<Self>
Load credentials from environment variables with custom names.
Uses HMAC-SHA256 signing.
Sourcepub fn signature_type(&self) -> SignatureType
pub fn signature_type(&self) -> SignatureType
Get the signature type being used.
Trait Implementations§
Source§impl Clone for Credentials
impl Clone for Credentials
Source§fn clone(&self) -> Credentials
fn clone(&self) -> Credentials
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more