Skip to main content

RestClient

Struct RestClient 

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

REST client for the Coinbase Advanced Trade API.

Implementations§

Source§

impl RestClient

Source

pub fn builder() -> RestClientBuilder

Create a new client builder.

Source

pub fn has_credentials(&self) -> bool

Check if the client has credentials configured.

Source

pub fn accounts(&self) -> AccountsApi<'_>

Access the Accounts API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let accounts = client.accounts().list_all().await?;
Source

pub fn products(&self) -> ProductsApi<'_>

Access the Products API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let products = client.products().list_all().await?;
Source

pub fn public(&self) -> PublicApi<'_>

Access the Public API.

These endpoints do not require authentication.

§Example
let client = RestClient::builder().build()?;

let time = client.public().get_time().await?;
println!("Server time: {}", time.iso);
Source

pub fn orders(&self) -> OrdersApi<'_>

Access the Orders API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let orders = client.orders().list_all().await?;
Source

pub fn fees(&self) -> FeesApi<'_>

Access the Fees API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let summary = client.fees().get_transaction_summary().await?;
println!("Fee tier: {}", summary.fee_tier.pricing_tier);
Source

pub fn data(&self) -> DataApi<'_>

Access the Data API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let permissions = client.data().get_key_permissions().await?;
println!("Can trade: {}", permissions.can_trade);
Source

pub fn payment_methods(&self) -> PaymentMethodsApi<'_>

Access the Payment Methods API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let payment_methods = client.payment_methods().list().await?;
for pm in payment_methods {
    println!("{}: {}", pm.name, pm.payment_type);
}
Source

pub fn portfolios(&self) -> PortfoliosApi<'_>

Access the Portfolios API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let portfolios = client.portfolios().list().await?;
for portfolio in portfolios {
    println!("{}: {}", portfolio.uuid, portfolio.name);
}
Source

pub fn convert(&self) -> ConvertApi<'_>

Access the Convert API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let request = CreateConvertQuoteRequest::new("USD-account", "USDC-account", "100.00");
let quote = client.convert().create_quote(request).await?;
Source

pub fn perpetuals(&self) -> PerpetualsApi<'_>

Access the Perpetuals (INTX) API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let response = client.perpetuals().list_positions("portfolio-uuid").await?;
Source

pub fn futures(&self) -> FuturesApi<'_>

Access the Futures (CFM) API.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let positions = client.futures().list_positions().await?;
Source

pub fn base_url(&self) -> &str

Get the base URL.

Source

pub async fn get<T: DeserializeOwned>(&self, endpoint: &str) -> Result<T>

Make a GET request to an authenticated endpoint.

Source

pub async fn get_with_query<Q: Serialize, T: DeserializeOwned>( &self, endpoint: &str, query: &Q, ) -> Result<T>

Make a GET request with query parameters.

Source

pub async fn post<B: Serialize, T: DeserializeOwned>( &self, endpoint: &str, body: &B, ) -> Result<T>

Make a POST request.

Source

pub async fn put<B: Serialize, T: DeserializeOwned>( &self, endpoint: &str, body: &B, ) -> Result<T>

Make a PUT request.

Source

pub async fn delete<T: DeserializeOwned>(&self, endpoint: &str) -> Result<T>

Make a DELETE request.

Source

pub async fn public_get<T: DeserializeOwned>(&self, endpoint: &str) -> Result<T>

Make a public (unauthenticated) GET request.

Source

pub async fn public_get_with_query<Q: Serialize, T: DeserializeOwned>( &self, endpoint: &str, query: &Q, ) -> Result<T>

Make a public GET request with query parameters.

Source§

impl RestClient

Source

pub fn market_order(&self) -> MarketOrderBuilder<'_>

Create a market order builder.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

// Buy $100 of BTC
let response = client.market_order()
    .buy("BTC-USD")
    .quote_size("100.00")
    .send()
    .await?;

// Sell 0.001 BTC
let response = client.market_order()
    .sell("BTC-USD")
    .base_size("0.001")
    .send()
    .await?;
Source

pub fn limit_order_gtc(&self) -> LimitOrderGtcBuilder<'_>

Create a limit order (GTC) builder.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let response = client.limit_order_gtc()
    .buy("BTC-USD")
    .base_size("0.001")
    .limit_price("50000.00")
    .post_only(true)
    .send()
    .await?;
Source

pub fn limit_order_gtd(&self) -> LimitOrderGtdBuilder<'_>

Create a limit order (GTD) builder.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let response = client.limit_order_gtd()
    .buy("BTC-USD")
    .base_size("0.001")
    .limit_price("50000.00")
    .end_time("2024-12-31T23:59:59Z")
    .send()
    .await?;
Source

pub fn stop_limit_order_gtc(&self) -> StopLimitOrderGtcBuilder<'_>

Create a stop-limit order (GTC) builder.

§Example
let client = RestClient::builder()
    .credentials(Credentials::from_env()?)
    .build()?;

let response = client.stop_limit_order_gtc()
    .sell("BTC-USD")
    .base_size("0.001")
    .limit_price("49000.00")
    .stop_price("50000.00")
    .stop_direction(StopDirection::StopDirectionStopDown)
    .send()
    .await?;

Trait Implementations§

Source§

impl Clone for RestClient

Source§

fn clone(&self) -> RestClient

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

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