pub struct SpotRestClient { /* private fields */ }Expand description
The Kraken Spot REST API client.
This client provides access to all Kraken Spot trading REST endpoints. It handles authentication, rate limiting, and automatic retries.
§Example
use kraken_api_client::spot::rest::SpotRestClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client for public endpoints only
let client = SpotRestClient::new();
// Get server time
let time = client.get_server_time().await?;
println!("Server time: {:?}", time);
Ok(())
}For private endpoints, provide credentials:
use kraken_api_client::spot::rest::SpotRestClient;
use kraken_api_client::auth::StaticCredentials;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credentials = Arc::new(StaticCredentials::new("api_key", "api_secret"));
let client = SpotRestClient::builder()
.credentials(credentials)
.build();
let balance = client.get_account_balance().await?;
println!("Balance: {:?}", balance);
Ok(())
}Implementations§
Source§impl SpotRestClient
impl SpotRestClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new client with default settings.
This client can only access public endpoints.
Use SpotRestClient::builder() to configure credentials for private endpoints.
Sourcepub fn builder() -> SpotRestClientBuilder
pub fn builder() -> SpotRestClientBuilder
Create a new client builder.
Source§impl SpotRestClient
impl SpotRestClient
Sourcepub async fn get_account_balance(
&self,
) -> Result<HashMap<String, Decimal>, KrakenError>
pub async fn get_account_balance( &self, ) -> Result<HashMap<String, Decimal>, KrakenError>
Get account balance.
Returns the balances of all assets in the account.
§Example
use kraken_api_client::spot::rest::SpotRestClient;
use kraken_api_client::auth::StaticCredentials;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credentials = Arc::new(StaticCredentials::new("key", "secret"));
let client = SpotRestClient::builder().credentials(credentials).build();
let balances = client.get_account_balance().await?;
for (asset, balance) in balances {
println!("{}: {}", asset, balance);
}
Ok(())
}Sourcepub async fn get_extended_balance(
&self,
) -> Result<ExtendedBalances, KrakenError>
pub async fn get_extended_balance( &self, ) -> Result<ExtendedBalances, KrakenError>
Get extended balance with hold amounts.
Sourcepub async fn get_trade_balance(
&self,
request: Option<&TradeBalanceRequest>,
) -> Result<TradeBalance, KrakenError>
pub async fn get_trade_balance( &self, request: Option<&TradeBalanceRequest>, ) -> Result<TradeBalance, KrakenError>
Get trade balance.
Returns margin account details including equity, margin, and P&L.
Sourcepub async fn get_open_orders(
&self,
request: Option<&OpenOrdersRequest>,
) -> Result<OpenOrders, KrakenError>
pub async fn get_open_orders( &self, request: Option<&OpenOrdersRequest>, ) -> Result<OpenOrders, KrakenError>
Get open orders.
Sourcepub async fn get_closed_orders(
&self,
request: Option<&ClosedOrdersRequest>,
) -> Result<ClosedOrders, KrakenError>
pub async fn get_closed_orders( &self, request: Option<&ClosedOrdersRequest>, ) -> Result<ClosedOrders, KrakenError>
Get closed orders.
Sourcepub async fn query_orders(
&self,
request: &QueryOrdersRequest,
) -> Result<HashMap<String, Order>, KrakenError>
pub async fn query_orders( &self, request: &QueryOrdersRequest, ) -> Result<HashMap<String, Order>, KrakenError>
Query specific orders by ID.
Sourcepub async fn get_trades_history(
&self,
request: Option<&TradesHistoryRequest>,
) -> Result<TradesHistory, KrakenError>
pub async fn get_trades_history( &self, request: Option<&TradesHistoryRequest>, ) -> Result<TradesHistory, KrakenError>
Get trades history.
Sourcepub async fn get_open_positions(
&self,
request: Option<&OpenPositionsRequest>,
) -> Result<HashMap<String, Position>, KrakenError>
pub async fn get_open_positions( &self, request: Option<&OpenPositionsRequest>, ) -> Result<HashMap<String, Position>, KrakenError>
Get open positions.
Sourcepub async fn get_ledgers(
&self,
request: Option<&LedgersRequest>,
) -> Result<LedgersInfo, KrakenError>
pub async fn get_ledgers( &self, request: Option<&LedgersRequest>, ) -> Result<LedgersInfo, KrakenError>
Get ledger entries.
Sourcepub async fn get_trade_volume(
&self,
request: Option<&TradeVolumeRequest>,
) -> Result<TradeVolume, KrakenError>
pub async fn get_trade_volume( &self, request: Option<&TradeVolumeRequest>, ) -> Result<TradeVolume, KrakenError>
Get trade volume and fee info.
Sourcepub async fn get_deposit_methods(
&self,
request: &DepositMethodsRequest,
) -> Result<Vec<DepositMethod>, KrakenError>
pub async fn get_deposit_methods( &self, request: &DepositMethodsRequest, ) -> Result<Vec<DepositMethod>, KrakenError>
Get available deposit methods for an asset.
Sourcepub async fn get_deposit_addresses(
&self,
request: &DepositAddressesRequest,
) -> Result<Vec<DepositAddress>, KrakenError>
pub async fn get_deposit_addresses( &self, request: &DepositAddressesRequest, ) -> Result<Vec<DepositAddress>, KrakenError>
Get deposit addresses for an asset and method.
Sourcepub async fn get_deposit_status(
&self,
request: Option<&DepositStatusRequest>,
) -> Result<DepositWithdrawStatusResponse, KrakenError>
pub async fn get_deposit_status( &self, request: Option<&DepositStatusRequest>, ) -> Result<DepositWithdrawStatusResponse, KrakenError>
Get deposit status.
Sourcepub async fn get_withdraw_methods(
&self,
request: Option<&WithdrawMethodsRequest>,
) -> Result<Vec<WithdrawMethod>, KrakenError>
pub async fn get_withdraw_methods( &self, request: Option<&WithdrawMethodsRequest>, ) -> Result<Vec<WithdrawMethod>, KrakenError>
Get available withdrawal methods.
Sourcepub async fn get_withdraw_addresses(
&self,
request: Option<&WithdrawAddressesRequest>,
) -> Result<Vec<WithdrawalAddress>, KrakenError>
pub async fn get_withdraw_addresses( &self, request: Option<&WithdrawAddressesRequest>, ) -> Result<Vec<WithdrawalAddress>, KrakenError>
Get withdrawal addresses.
Sourcepub async fn get_withdraw_info(
&self,
request: &WithdrawInfoRequest,
) -> Result<WithdrawInfo, KrakenError>
pub async fn get_withdraw_info( &self, request: &WithdrawInfoRequest, ) -> Result<WithdrawInfo, KrakenError>
Get withdrawal info (limits and fees).
Sourcepub async fn withdraw_funds(
&self,
request: &WithdrawRequest,
) -> Result<ConfirmationRefId, KrakenError>
pub async fn withdraw_funds( &self, request: &WithdrawRequest, ) -> Result<ConfirmationRefId, KrakenError>
Withdraw funds.
Sourcepub async fn get_withdraw_status(
&self,
request: Option<&WithdrawStatusRequest>,
) -> Result<DepositWithdrawStatusResponse, KrakenError>
pub async fn get_withdraw_status( &self, request: Option<&WithdrawStatusRequest>, ) -> Result<DepositWithdrawStatusResponse, KrakenError>
Get withdrawal status.
Sourcepub async fn withdraw_cancel(
&self,
request: &WithdrawCancelRequest,
) -> Result<bool, KrakenError>
pub async fn withdraw_cancel( &self, request: &WithdrawCancelRequest, ) -> Result<bool, KrakenError>
Cancel a withdrawal.
Sourcepub async fn wallet_transfer(
&self,
request: &WalletTransferRequest,
) -> Result<ConfirmationRefId, KrakenError>
pub async fn wallet_transfer( &self, request: &WalletTransferRequest, ) -> Result<ConfirmationRefId, KrakenError>
Transfer funds between wallets (e.g., Spot to Futures).
Sourcepub async fn earn_allocate(
&self,
request: &EarnAllocateRequest,
) -> Result<bool, KrakenError>
pub async fn earn_allocate( &self, request: &EarnAllocateRequest, ) -> Result<bool, KrakenError>
Allocate funds to an earn strategy.
Sourcepub async fn earn_deallocate(
&self,
request: &EarnAllocateRequest,
) -> Result<bool, KrakenError>
pub async fn earn_deallocate( &self, request: &EarnAllocateRequest, ) -> Result<bool, KrakenError>
Deallocate funds from an earn strategy.
Sourcepub async fn get_earn_allocation_status(
&self,
request: &EarnAllocationStatusRequest,
) -> Result<AllocationStatus, KrakenError>
pub async fn get_earn_allocation_status( &self, request: &EarnAllocationStatusRequest, ) -> Result<AllocationStatus, KrakenError>
Get earn allocation status.
Sourcepub async fn get_earn_deallocation_status(
&self,
request: &EarnAllocationStatusRequest,
) -> Result<AllocationStatus, KrakenError>
pub async fn get_earn_deallocation_status( &self, request: &EarnAllocationStatusRequest, ) -> Result<AllocationStatus, KrakenError>
Get earn deallocation status.
Sourcepub async fn list_earn_strategies(
&self,
request: Option<&EarnStrategiesRequest>,
) -> Result<EarnStrategies, KrakenError>
pub async fn list_earn_strategies( &self, request: Option<&EarnStrategiesRequest>, ) -> Result<EarnStrategies, KrakenError>
List earn strategies.
Sourcepub async fn list_earn_allocations(
&self,
request: Option<&EarnAllocationsRequest>,
) -> Result<EarnAllocations, KrakenError>
pub async fn list_earn_allocations( &self, request: Option<&EarnAllocationsRequest>, ) -> Result<EarnAllocations, KrakenError>
List earn allocations.
Sourcepub async fn add_order(
&self,
request: &AddOrderRequest,
) -> Result<AddOrderResponse, KrakenError>
pub async fn add_order( &self, request: &AddOrderRequest, ) -> Result<AddOrderResponse, KrakenError>
Add a new order.
§Example
use kraken_api_client::spot::rest::{SpotRestClient, private::AddOrderRequest};
use kraken_api_client::{BuySell, OrderType};
use kraken_api_client::auth::StaticCredentials;
use rust_decimal::Decimal;
use std::str::FromStr;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credentials = Arc::new(StaticCredentials::new("key", "secret"));
let client = SpotRestClient::builder().credentials(credentials).build();
let request = AddOrderRequest::new(
"XBTUSD",
BuySell::Buy,
OrderType::Limit,
Decimal::from_str("0.001")?,
)
.price(Decimal::from_str("50000")?)
.validate(true); // Validate only, don't actually place
let result = client.add_order(&request).await?;
println!("Order result: {:?}", result);
Ok(())
}Sourcepub async fn cancel_order(
&self,
request: &CancelOrderRequest,
) -> Result<CancelOrderResponse, KrakenError>
pub async fn cancel_order( &self, request: &CancelOrderRequest, ) -> Result<CancelOrderResponse, KrakenError>
Cancel an order.
Sourcepub async fn cancel_all_orders(
&self,
) -> Result<CancelOrderResponse, KrakenError>
pub async fn cancel_all_orders( &self, ) -> Result<CancelOrderResponse, KrakenError>
Cancel all open orders.
Sourcepub async fn get_websocket_token(&self) -> Result<WebSocketToken, KrakenError>
pub async fn get_websocket_token(&self) -> Result<WebSocketToken, KrakenError>
Get a WebSocket authentication token.
The token is valid for 15 minutes and is used to authenticate WebSocket connections to private channels.
Source§impl SpotRestClient
impl SpotRestClient
Sourcepub async fn get_server_time(&self) -> Result<ServerTime, KrakenError>
pub async fn get_server_time(&self) -> Result<ServerTime, KrakenError>
Get the server time.
This is useful for synchronizing local time and checking API availability.
§Example
use kraken_api_client::spot::rest::SpotRestClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = SpotRestClient::new();
let time = client.get_server_time().await?;
println!("Server time: {} ({})", time.unixtime, time.rfc1123);
Ok(())
}Sourcepub async fn get_system_status(&self) -> Result<SystemStatus, KrakenError>
pub async fn get_system_status(&self) -> Result<SystemStatus, KrakenError>
Get the system status.
Returns the current system status and timestamp.
Sourcepub async fn get_assets(
&self,
request: Option<&AssetInfoRequest>,
) -> Result<HashMap<String, AssetInfo>, KrakenError>
pub async fn get_assets( &self, request: Option<&AssetInfoRequest>, ) -> Result<HashMap<String, AssetInfo>, KrakenError>
Get asset information.
Returns information about the assets available on Kraken.
§Arguments
request- Optional request parameters to filter assets.
Sourcepub async fn get_asset_pairs(
&self,
request: Option<&AssetPairsRequest>,
) -> Result<HashMap<String, AssetPair>, KrakenError>
pub async fn get_asset_pairs( &self, request: Option<&AssetPairsRequest>, ) -> Result<HashMap<String, AssetPair>, KrakenError>
Get tradable asset pairs.
Returns information about the trading pairs available on Kraken.
§Arguments
request- Optional request parameters to filter pairs.
Sourcepub async fn get_ticker(
&self,
pairs: &str,
) -> Result<HashMap<String, TickerInfo>, KrakenError>
pub async fn get_ticker( &self, pairs: &str, ) -> Result<HashMap<String, TickerInfo>, KrakenError>
Get ticker information for one or more pairs.
§Arguments
pairs- Comma-separated list of pairs (e.g., “XBTUSD,ETHUSD”).
Sourcepub async fn get_ohlc(
&self,
request: &OhlcRequest,
) -> Result<OhlcResponse, KrakenError>
pub async fn get_ohlc( &self, request: &OhlcRequest, ) -> Result<OhlcResponse, KrakenError>
Get OHLC (candlestick) data.
Returns up to 720 OHLC data points for the specified pair and interval.
§Arguments
request- OHLC request parameters.
Sourcepub async fn get_order_book(
&self,
request: &OrderBookRequest,
) -> Result<HashMap<String, OrderBook>, KrakenError>
pub async fn get_order_book( &self, request: &OrderBookRequest, ) -> Result<HashMap<String, OrderBook>, KrakenError>
Sourcepub async fn get_recent_trades(
&self,
request: &RecentTradesRequest,
) -> Result<RecentTradesResponse, KrakenError>
pub async fn get_recent_trades( &self, request: &RecentTradesRequest, ) -> Result<RecentTradesResponse, KrakenError>
Sourcepub async fn get_recent_spreads(
&self,
request: &RecentSpreadsRequest,
) -> Result<RecentSpreadsResponse, KrakenError>
pub async fn get_recent_spreads( &self, request: &RecentSpreadsRequest, ) -> Result<RecentSpreadsResponse, KrakenError>
Trait Implementations§
Source§impl Clone for SpotRestClient
impl Clone for SpotRestClient
Source§fn clone(&self) -> SpotRestClient
fn clone(&self) -> SpotRestClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more