Skip to main content

RateLimitedClient

Struct RateLimitedClient 

Source
pub struct RateLimitedClient<C> { /* private fields */ }
Expand description

A rate-limited wrapper around any KrakenClient implementation.

This wrapper automatically handles:

  • Public endpoint rate limits (sliding window)
  • Private endpoint rate limits (token bucket, tier-based)
  • Trading rate limits with order lifetime penalties

§Example

use kraken_api_client::spot::rest::SpotRestClient;
use kraken_api_client::rate_limit::{RateLimitedClient, RateLimitConfig};

let client = SpotRestClient::new();
let rate_limited = RateLimitedClient::new(client, RateLimitConfig::default());

// Requests are automatically rate limited
let time = rate_limited.get_server_time().await?;

Implementations§

Source§

impl<C> RateLimitedClient<C>

Source

pub fn new(inner: C, config: RateLimitConfig) -> Self

Create a new rate-limited client wrapper.

Source

pub fn with_tier(inner: C, tier: VerificationTier) -> Self

Create a new rate-limited client with a specific verification tier.

Source

pub fn inner(&self) -> &C

Get a reference to the inner client.

Source

pub fn config(&self) -> &RateLimitConfig

Get the current configuration.

Source

pub fn set_enabled(&mut self, enabled: bool)

Enable or disable rate limiting.

Trait Implementations§

Source§

impl<C: Clone> Clone for RateLimitedClient<C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug> Debug for RateLimitedClient<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: KrakenClient> KrakenClient for RateLimitedClient<C>

Source§

async fn get_server_time(&self) -> Result<ServerTime, KrakenError>

Get the server time.
Source§

async fn get_system_status(&self) -> Result<SystemStatus, KrakenError>

Get the system status.
Source§

async fn get_assets( &self, request: Option<&AssetInfoRequest>, ) -> Result<HashMap<String, AssetInfo>, KrakenError>

Get asset information.
Source§

async fn get_asset_pairs( &self, request: Option<&AssetPairsRequest>, ) -> Result<HashMap<String, AssetPair>, KrakenError>

Get tradable asset pairs.
Source§

async fn get_ticker( &self, pairs: &str, ) -> Result<HashMap<String, TickerInfo>, KrakenError>

Get ticker information for one or more pairs.
Source§

async fn get_ohlc( &self, request: &OhlcRequest, ) -> Result<OhlcResponse, KrakenError>

Get OHLC (candlestick) data.
Source§

async fn get_order_book( &self, request: &OrderBookRequest, ) -> Result<HashMap<String, OrderBook>, KrakenError>

Get order book for a pair.
Source§

async fn get_recent_trades( &self, request: &RecentTradesRequest, ) -> Result<RecentTradesResponse, KrakenError>

Get recent trades for a pair.
Source§

async fn get_recent_spreads( &self, request: &RecentSpreadsRequest, ) -> Result<RecentSpreadsResponse, KrakenError>

Get recent spreads for a pair.
Source§

async fn get_account_balance( &self, ) -> Result<HashMap<String, Decimal>, KrakenError>

Get account balance.
Source§

async fn get_extended_balance(&self) -> Result<ExtendedBalances, KrakenError>

Get extended balance with hold amounts.
Source§

async fn get_trade_balance( &self, request: Option<&TradeBalanceRequest>, ) -> Result<TradeBalance, KrakenError>

Get trade balance (margin account details).
Source§

async fn get_open_orders( &self, request: Option<&OpenOrdersRequest>, ) -> Result<OpenOrders, KrakenError>

Get open orders.
Source§

async fn get_closed_orders( &self, request: Option<&ClosedOrdersRequest>, ) -> Result<ClosedOrders, KrakenError>

Get closed orders.
Source§

async fn query_orders( &self, request: &QueryOrdersRequest, ) -> Result<HashMap<String, Order>, KrakenError>

Query specific orders by ID.
Source§

async fn get_trades_history( &self, request: Option<&TradesHistoryRequest>, ) -> Result<TradesHistory, KrakenError>

Get trades history.
Source§

async fn get_open_positions( &self, request: Option<&OpenPositionsRequest>, ) -> Result<HashMap<String, Position>, KrakenError>

Get open positions.
Source§

async fn get_ledgers( &self, request: Option<&LedgersRequest>, ) -> Result<LedgersInfo, KrakenError>

Get ledger entries.
Source§

async fn get_trade_volume( &self, request: Option<&TradeVolumeRequest>, ) -> Result<TradeVolume, KrakenError>

Get trade volume and fee info.
Source§

async fn get_deposit_methods( &self, request: &DepositMethodsRequest, ) -> Result<Vec<DepositMethod>, KrakenError>

Get available deposit methods.
Source§

async fn get_deposit_addresses( &self, request: &DepositAddressesRequest, ) -> Result<Vec<DepositAddress>, KrakenError>

Get deposit addresses.
Source§

async fn get_deposit_status( &self, request: Option<&DepositStatusRequest>, ) -> Result<DepositWithdrawStatusResponse, KrakenError>

Get deposit status.
Source§

async fn get_withdraw_methods( &self, request: Option<&WithdrawMethodsRequest>, ) -> Result<Vec<WithdrawMethod>, KrakenError>

Get available withdrawal methods.
Source§

async fn get_withdraw_addresses( &self, request: Option<&WithdrawAddressesRequest>, ) -> Result<Vec<WithdrawalAddress>, KrakenError>

Get withdrawal addresses.
Source§

async fn get_withdraw_info( &self, request: &WithdrawInfoRequest, ) -> Result<WithdrawInfo, KrakenError>

Get withdrawal info.
Source§

async fn withdraw_funds( &self, request: &WithdrawRequest, ) -> Result<ConfirmationRefId, KrakenError>

Withdraw funds.
Source§

async fn get_withdraw_status( &self, request: Option<&WithdrawStatusRequest>, ) -> Result<DepositWithdrawStatusResponse, KrakenError>

Get withdrawal status.
Source§

async fn withdraw_cancel( &self, request: &WithdrawCancelRequest, ) -> Result<bool, KrakenError>

Cancel a withdrawal.
Source§

async fn wallet_transfer( &self, request: &WalletTransferRequest, ) -> Result<ConfirmationRefId, KrakenError>

Transfer funds between wallets.
Source§

async fn earn_allocate( &self, request: &EarnAllocateRequest, ) -> Result<bool, KrakenError>

Allocate funds to an earn strategy.
Source§

async fn earn_deallocate( &self, request: &EarnAllocateRequest, ) -> Result<bool, KrakenError>

Deallocate funds from an earn strategy.
Source§

async fn get_earn_allocation_status( &self, request: &EarnAllocationStatusRequest, ) -> Result<AllocationStatus, KrakenError>

Get earn allocation status.
Source§

async fn get_earn_deallocation_status( &self, request: &EarnAllocationStatusRequest, ) -> Result<AllocationStatus, KrakenError>

Get earn deallocation status.
Source§

async fn list_earn_strategies( &self, request: Option<&EarnStrategiesRequest>, ) -> Result<EarnStrategies, KrakenError>

List earn strategies.
Source§

async fn list_earn_allocations( &self, request: Option<&EarnAllocationsRequest>, ) -> Result<EarnAllocations, KrakenError>

List earn allocations.
Source§

async fn add_order( &self, request: &AddOrderRequest, ) -> Result<AddOrderResponse, KrakenError>

Add a new order.
Source§

async fn cancel_order( &self, request: &CancelOrderRequest, ) -> Result<CancelOrderResponse, KrakenError>

Cancel an order.
Source§

async fn cancel_all_orders(&self) -> Result<CancelOrderResponse, KrakenError>

Cancel all open orders.
Source§

async fn get_websocket_token(&self) -> Result<WebSocketToken, KrakenError>

Get a WebSocket authentication token.

Auto Trait Implementations§

§

impl<C> Freeze for RateLimitedClient<C>
where C: Freeze,

§

impl<C> !RefUnwindSafe for RateLimitedClient<C>

§

impl<C> Send for RateLimitedClient<C>
where C: Send,

§

impl<C> Sync for RateLimitedClient<C>
where C: Sync,

§

impl<C> Unpin for RateLimitedClient<C>
where C: Unpin,

§

impl<C> !UnwindSafe for RateLimitedClient<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> KrakenClientExt for T
where T: KrakenClient,

Source§

async fn get_server_time(&self) -> Result<ServerTime, KrakenError>

Source§

async fn get_system_status(&self) -> Result<SystemStatus, KrakenError>

Source§

async fn get_assets( &self, request: Option<&AssetInfoRequest>, ) -> Result<HashMap<String, AssetInfo>, KrakenError>

Source§

async fn get_asset_pairs( &self, request: Option<&AssetPairsRequest>, ) -> Result<HashMap<String, AssetPair>, KrakenError>

Source§

async fn get_ticker( &self, pairs: &str, ) -> Result<HashMap<String, TickerInfo>, KrakenError>

Source§

async fn get_ohlc( &self, request: &OhlcRequest, ) -> Result<OhlcResponse, KrakenError>

Source§

async fn get_order_book( &self, request: &OrderBookRequest, ) -> Result<HashMap<String, OrderBook>, KrakenError>

Source§

async fn get_recent_trades( &self, request: &RecentTradesRequest, ) -> Result<RecentTradesResponse, KrakenError>

Source§

async fn get_recent_spreads( &self, request: &RecentSpreadsRequest, ) -> Result<RecentSpreadsResponse, KrakenError>

Source§

async fn get_account_balance( &self, ) -> Result<HashMap<String, Decimal>, KrakenError>

Source§

async fn get_extended_balance(&self) -> Result<ExtendedBalances, KrakenError>

Source§

async fn get_trade_balance( &self, request: Option<&TradeBalanceRequest>, ) -> Result<TradeBalance, KrakenError>

Source§

async fn get_open_orders( &self, request: Option<&OpenOrdersRequest>, ) -> Result<OpenOrders, KrakenError>

Source§

async fn get_closed_orders( &self, request: Option<&ClosedOrdersRequest>, ) -> Result<ClosedOrders, KrakenError>

Source§

async fn query_orders( &self, request: &QueryOrdersRequest, ) -> Result<HashMap<String, Order>, KrakenError>

Source§

async fn get_trades_history( &self, request: Option<&TradesHistoryRequest>, ) -> Result<TradesHistory, KrakenError>

Source§

async fn get_open_positions( &self, request: Option<&OpenPositionsRequest>, ) -> Result<HashMap<String, Position>, KrakenError>

Source§

async fn get_ledgers( &self, request: Option<&LedgersRequest>, ) -> Result<LedgersInfo, KrakenError>

Source§

async fn get_trade_volume( &self, request: Option<&TradeVolumeRequest>, ) -> Result<TradeVolume, KrakenError>

Source§

async fn get_deposit_methods( &self, request: &DepositMethodsRequest, ) -> Result<Vec<DepositMethod>, KrakenError>

Source§

async fn get_deposit_addresses( &self, request: &DepositAddressesRequest, ) -> Result<Vec<DepositAddress>, KrakenError>

Source§

async fn get_deposit_status( &self, request: Option<&TransferStatusRequest>, ) -> Result<DepositWithdrawStatusResponse, KrakenError>

Source§

async fn get_withdraw_methods( &self, request: Option<&WithdrawMethodsRequest>, ) -> Result<Vec<WithdrawMethod>, KrakenError>

Source§

async fn get_withdraw_addresses( &self, request: Option<&WithdrawAddressesRequest>, ) -> Result<Vec<WithdrawalAddress>, KrakenError>

Source§

async fn get_withdraw_info( &self, request: &WithdrawInfoRequest, ) -> Result<WithdrawInfo, KrakenError>

Source§

async fn withdraw_funds( &self, request: &WithdrawRequest, ) -> Result<ConfirmationRefId, KrakenError>

Source§

async fn get_withdraw_status( &self, request: Option<&TransferStatusRequest>, ) -> Result<DepositWithdrawStatusResponse, KrakenError>

Source§

async fn withdraw_cancel( &self, request: &WithdrawCancelRequest, ) -> Result<bool, KrakenError>

Source§

async fn wallet_transfer( &self, request: &WalletTransferRequest, ) -> Result<ConfirmationRefId, KrakenError>

Source§

async fn earn_allocate( &self, request: &EarnAllocateRequest, ) -> Result<bool, KrakenError>

Source§

async fn earn_deallocate( &self, request: &EarnAllocateRequest, ) -> Result<bool, KrakenError>

Source§

async fn get_earn_allocation_status( &self, request: &EarnAllocationStatusRequest, ) -> Result<AllocationStatus, KrakenError>

Source§

async fn get_earn_deallocation_status( &self, request: &EarnAllocationStatusRequest, ) -> Result<AllocationStatus, KrakenError>

Source§

async fn list_earn_strategies( &self, request: Option<&EarnStrategiesRequest>, ) -> Result<EarnStrategies, KrakenError>

Source§

async fn list_earn_allocations( &self, request: Option<&EarnAllocationsRequest>, ) -> Result<EarnAllocations, KrakenError>

Source§

async fn add_order( &self, request: &AddOrderRequest, ) -> Result<AddOrderResponse, KrakenError>

Source§

async fn cancel_order( &self, request: &CancelOrderRequest, ) -> Result<CancelOrderResponse, KrakenError>

Source§

async fn cancel_all_orders(&self) -> Result<CancelOrderResponse, KrakenError>

Source§

async fn get_websocket_token(&self) -> Result<WebSocketToken, KrakenError>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more