pub struct BitgetAuth { /* private fields */ }Expand description
Bitget API authenticator.
Handles request signing using HMAC-SHA256 and header construction for authenticated API requests.
Implementations§
Source§impl BitgetAuth
impl BitgetAuth
Sourcepub fn new(api_key: String, secret: String, passphrase: String) -> Self
pub fn new(api_key: String, secret: String, passphrase: String) -> Self
Creates a new BitgetAuth instance.
§Arguments
api_key- The API key from Bitget.secret- The secret key from Bitget.passphrase- The passphrase set when creating the API key.
§Example
use ccxt_exchanges::bitget::BitgetAuth;
let auth = BitgetAuth::new(
"your-api-key".to_string(),
"your-secret".to_string(),
"your-passphrase".to_string(),
);Sourcepub fn passphrase(&self) -> &str
pub fn passphrase(&self) -> &str
Returns the passphrase.
Sourcepub fn build_sign_string(
&self,
timestamp: &str,
method: &str,
path: &str,
body: &str,
) -> String
pub fn build_sign_string( &self, timestamp: &str, method: &str, path: &str, body: &str, ) -> String
Builds the signature string for HMAC signing.
The signature string format is: timestamp + method + path + body
§Arguments
timestamp- Unix timestamp in milliseconds as string.method- HTTP method (GET, POST, DELETE, etc.).path- Request path including query string (e.g., “/api/v2/spot/account/assets”).body- Request body (empty string for GET requests).
§Returns
The concatenated string to be signed.
Sourcepub fn sign(
&self,
timestamp: &str,
method: &str,
path: &str,
body: &str,
) -> String
pub fn sign( &self, timestamp: &str, method: &str, path: &str, body: &str, ) -> String
Signs a request using HMAC-SHA256.
§Arguments
timestamp- Unix timestamp in milliseconds as string.method- HTTP method (GET, POST, DELETE, etc.).path- Request path including query string.body- Request body (empty string for GET requests).
§Returns
Base64-encoded HMAC-SHA256 signature.
§Example
use ccxt_exchanges::bitget::BitgetAuth;
let auth = BitgetAuth::new(
"api-key".to_string(),
"secret".to_string(),
"passphrase".to_string(),
);
let signature = auth.sign("1234567890", "GET", "/api/v2/spot/account/assets", "");
assert!(!signature.is_empty());Sourcepub fn add_auth_headers(
&self,
headers: &mut HeaderMap,
timestamp: &str,
sign: &str,
)
pub fn add_auth_headers( &self, headers: &mut HeaderMap, timestamp: &str, sign: &str, )
Adds authentication headers to a HeaderMap.
Adds the following headers:
- ACCESS-KEY: API key
- ACCESS-SIGN: HMAC-SHA256 signature
- ACCESS-TIMESTAMP: Unix timestamp
- ACCESS-PASSPHRASE: API passphrase
§Arguments
headers- Mutable reference to HeaderMap to add headers to.timestamp- Unix timestamp in milliseconds as string.sign- Pre-computed signature fromsign()method.
§Example
use ccxt_exchanges::bitget::BitgetAuth;
use reqwest::header::HeaderMap;
let auth = BitgetAuth::new(
"api-key".to_string(),
"secret".to_string(),
"passphrase".to_string(),
);
let mut headers = HeaderMap::new();
let timestamp = "1234567890";
let signature = auth.sign(timestamp, "GET", "/api/v2/spot/account/assets", "");
auth.add_auth_headers(&mut headers, timestamp, &signature);
assert!(headers.contains_key("ACCESS-KEY"));
assert!(headers.contains_key("ACCESS-SIGN"));
assert!(headers.contains_key("ACCESS-TIMESTAMP"));
assert!(headers.contains_key("ACCESS-PASSPHRASE"));Sourcepub fn create_auth_headers(
&self,
timestamp: &str,
method: &str,
path: &str,
body: &str,
) -> HeaderMap
pub fn create_auth_headers( &self, timestamp: &str, method: &str, path: &str, body: &str, ) -> HeaderMap
Creates authentication headers for a request.
This is a convenience method that combines sign() and add_auth_headers().
§Arguments
timestamp- Unix timestamp in milliseconds as string.method- HTTP method (GET, POST, DELETE, etc.).path- Request path including query string.body- Request body (empty string for GET requests).
§Returns
A HeaderMap containing all authentication headers.
Trait Implementations§
Source§impl Clone for BitgetAuth
impl Clone for BitgetAuth
Source§fn clone(&self) -> BitgetAuth
fn clone(&self) -> BitgetAuth
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BitgetAuth
impl RefUnwindSafe for BitgetAuth
impl Send for BitgetAuth
impl Sync for BitgetAuth
impl Unpin for BitgetAuth
impl UnwindSafe for BitgetAuth
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