Skip to main content

FuturesRestClient

Struct FuturesRestClient 

Source
pub struct FuturesRestClient { /* private fields */ }
Expand description

The Kraken Futures REST API client.

This client provides access to all Kraken Futures trading REST endpoints. It handles authentication, rate limiting, and automatic retries.

§Example

use kraken_api_client::futures::rest::FuturesRestClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a client for public endpoints only
    let client = FuturesRestClient::new();

    // Get all tickers
    let tickers = client.get_tickers().await?;
    for ticker in &tickers {
        println!("{}: {}", ticker.symbol, ticker.last);
    }

    Ok(())
}

For private endpoints, provide credentials:

use kraken_api_client::futures::rest::FuturesRestClient;
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 = FuturesRestClient::builder()
        .credentials(credentials)
        .build();

    let accounts = client.get_accounts().await?;
    println!("Accounts: {:?}", accounts);

    Ok(())
}

Implementations§

Source§

impl FuturesRestClient

Source

pub fn new() -> Self

Create a new client with default settings.

This client can only access public endpoints. Use FuturesRestClient::builder() to configure credentials for private endpoints.

Source

pub fn builder() -> FuturesRestClientBuilder

Create a new client builder.

Source

pub async fn get_tickers(&self) -> Result<Vec<FuturesTicker>, KrakenError>

Get all tickers.

Returns ticker data for all available futures contracts.

Source

pub async fn get_ticker( &self, symbol: &str, ) -> Result<Option<FuturesTicker>, KrakenError>

Get ticker for a specific symbol.

Returns ticker data for the specified symbol, or None if not found.

Source

pub async fn get_orderbook( &self, symbol: &str, ) -> Result<FuturesOrderBook, KrakenError>

Get order book for a symbol.

§Arguments
  • symbol - The futures symbol (e.g., “PI_XBTUSD”)
Source

pub async fn get_trade_history( &self, symbol: &str, last_time: Option<&str>, ) -> Result<Vec<FuturesTrade>, KrakenError>

Get recent trade history for a symbol.

§Arguments
  • symbol - The futures symbol (e.g., “PI_XBTUSD”)
  • last_time - Optional timestamp to get trades before
Source

pub async fn get_instruments( &self, ) -> Result<Vec<FuturesInstrument>, KrakenError>

Get available instruments.

Returns information about all tradeable futures contracts.

Source

pub async fn get_accounts(&self) -> Result<AccountsResponse, KrakenError>

Get account information.

Returns balances, margin info, and PnL for all accounts.

Source

pub async fn get_open_positions( &self, ) -> Result<Vec<FuturesPosition>, KrakenError>

Get open positions.

Returns all open futures positions.

Source

pub async fn get_open_orders(&self) -> Result<Vec<FuturesOrder>, KrakenError>

Get open orders.

Returns all open (unfilled) orders.

Source

pub async fn get_fills( &self, request: Option<&FillsRequest>, ) -> Result<Vec<FuturesFill>, KrakenError>

Get fills (trade history).

Returns fills for all futures contracts or a specific symbol.

§Arguments
  • request - Optional request parameters
Source

pub async fn send_order( &self, request: &SendOrderRequest, ) -> Result<SendOrderResponse, KrakenError>

Send a new order.

§Arguments
  • request - Order parameters
Source

pub async fn edit_order( &self, request: &EditOrderRequest, ) -> Result<EditOrderResponse, KrakenError>

Edit an existing order.

§Arguments
  • request - Edit parameters
Source

pub async fn cancel_order( &self, order_id: &str, ) -> Result<CancelOrderResponse, KrakenError>

Cancel an order.

§Arguments
  • order_id - The order ID to cancel
Source

pub async fn cancel_order_by_cli_ord_id( &self, cli_ord_id: &str, ) -> Result<CancelOrderResponse, KrakenError>

Cancel an order by client order ID.

§Arguments
  • cli_ord_id - The client order ID to cancel
Source

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

Cancel all orders.

Cancels all open orders for the account.

Source

pub async fn cancel_all_orders_for_symbol( &self, symbol: &str, ) -> Result<CancelAllOrdersResponse, KrakenError>

Cancel all orders for a specific symbol.

§Arguments
  • symbol - The futures symbol to cancel orders for
Source

pub async fn cancel_all_orders_after( &self, timeout_seconds: u32, ) -> Result<CancelAllOrdersAfterResponse, KrakenError>

Set dead man’s switch (cancel all orders after timeout).

§Arguments
  • timeout_seconds - Timeout in seconds (0 to disable)
Source

pub async fn batch_order( &self, request: &BatchOrderRequest, ) -> Result<BatchOrderResponse, KrakenError>

Send batch orders.

Allows placing, editing, and cancelling multiple orders in a single request.

§Arguments
  • request - Batch order request

Trait Implementations§

Source§

impl Clone for FuturesRestClient

Source§

fn clone(&self) -> FuturesRestClient

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 Debug for FuturesRestClient

Source§

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

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

impl Default for FuturesRestClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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