pub struct KrakenCredential { /* private fields */ }Expand description
API credentials for Kraken authentication.
Implementations§
Source§impl KrakenCredential
impl KrakenCredential
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
Creates a new credential with the given API key and secret.
Sourcepub fn from_env_spot() -> Option<Self>
pub fn from_env_spot() -> Option<Self>
Load credentials from environment variables for Kraken Spot.
Looks for KRAKEN_SPOT_API_KEY and KRAKEN_SPOT_API_SECRET.
Note: Kraken Spot does not have a testnet environment.
Returns None if either key or secret is not set.
Sourcepub fn from_env_futures(demo: bool) -> Option<Self>
pub fn from_env_futures(demo: bool) -> Option<Self>
Load credentials from environment variables for Kraken Futures.
Looks for KRAKEN_FUTURES_API_KEY and KRAKEN_FUTURES_API_SECRET (mainnet)
or KRAKEN_FUTURES_DEMO_API_KEY and KRAKEN_FUTURES_DEMO_API_SECRET (demo).
Returns None if either key or secret is not set.
Sourcepub fn resolve_spot(
api_key: Option<String>,
api_secret: Option<String>,
) -> Option<Self>
pub fn resolve_spot( api_key: Option<String>, api_secret: Option<String>, ) -> Option<Self>
Resolves credentials from provided values or environment for Spot.
If both api_key and api_secret are provided, uses those.
Otherwise falls back to loading from environment variables.
Sourcepub fn resolve_futures(
api_key: Option<String>,
api_secret: Option<String>,
demo: bool,
) -> Option<Self>
pub fn resolve_futures( api_key: Option<String>, api_secret: Option<String>, demo: bool, ) -> Option<Self>
Resolves credentials from provided values or environment for Futures.
If both api_key and api_secret are provided, uses those.
Otherwise falls back to loading from environment variables.
Sourcepub fn into_parts(&self) -> (String, String)
pub fn into_parts(&self) -> (String, String)
Returns the API key and secret as cloned strings.
Sourcepub fn sign_spot(
&self,
path: &str,
nonce: u64,
params: &HashMap<String, String>,
) -> Result<(String, String)>
pub fn sign_spot( &self, path: &str, nonce: u64, params: &HashMap<String, String>, ) -> Result<(String, String)>
Sign a request for Kraken Spot REST API.
Kraken Spot uses HMAC-SHA512 with the following message:
- path + SHA256(nonce + POST data)
- The secret is base64 decoded before signing
Note: “nonce + POST data” means the nonce value string is prepended to the URL-encoded POST body, e.g., “1234567890nonce=1234567890¶m=value”.
Sourcepub fn sign_spot_json(
&self,
path: &str,
nonce: u64,
json_body: &str,
) -> Result<String>
pub fn sign_spot_json( &self, path: &str, nonce: u64, json_body: &str, ) -> Result<String>
Sign a JSON request for Kraken Spot API (used for CancelOrderBatch, AddOrderBatch).
These endpoints use JSON body instead of form-encoded. Signature: HMAC-SHA512(path + SHA256(nonce + json_body))
Sourcepub fn sign_futures(
&self,
path: &str,
post_data: &str,
nonce: u64,
) -> Result<String>
pub fn sign_futures( &self, path: &str, post_data: &str, nonce: u64, ) -> Result<String>
Sign a request for Kraken Futures API v3.
Kraken Futures authentication steps:
- Strip “/derivatives” prefix from endpoint path
- Concatenate:
postData + nonce + endpointPath - SHA-256 hash the concatenation
- Base64 decode the API secret
- HMAC-SHA-512 of the SHA-256 hash using decoded secret
- Base64 encode the result
§References
Sourcepub fn sign_ws_challenge(&self, challenge: &str) -> Result<String>
pub fn sign_ws_challenge(&self, challenge: &str) -> Result<String>
Sign a WebSocket challenge for Kraken Futures private feeds.
The signing process is similar to REST API authentication:
- SHA-256 hash the challenge string
- HMAC-SHA-512 of the hash using decoded API secret
- Base64 encode the result
Sourcepub fn api_key_masked(&self) -> String
pub fn api_key_masked(&self) -> String
Returns a masked version of the API key for logging purposes.
Shows first 4 and last 4 characters with ellipsis in between. For keys shorter than 8 characters, shows asterisks only.
Trait Implementations§
Source§impl Clone for KrakenCredential
impl Clone for KrakenCredential
Source§fn clone(&self) -> KrakenCredential
fn clone(&self) -> KrakenCredential
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KrakenCredential
impl Debug for KrakenCredential
Source§impl Drop for KrakenCredential
impl Drop for KrakenCredential
Auto Trait Implementations§
impl Freeze for KrakenCredential
impl RefUnwindSafe for KrakenCredential
impl Send for KrakenCredential
impl Sync for KrakenCredential
impl Unpin for KrakenCredential
impl UnwindSafe for KrakenCredential
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more