Struct SwapSpaceApi

Source
pub struct SwapSpaceApi {
    pub client: Client,
    pub base_url: Url,
}

Fields§

§client: Client§base_url: Url

Implementations§

Source§

impl SwapSpaceApi

Source

pub fn new(api_key: String) -> Result<Self, Error>

create a new instance of the SwapSpaceApi client using new or use the default method to create a new instance it would read the api key from the environment variable SWAPSPACE_API_KEY

use swapspace_api::SwapSpaceApi;
let api = SwapSpaceApi::new("api_key".to_string());
assert_eq!(api.is_ok(), true);
let api = SwapSpaceApi::default();
Source

pub async fn get_currencies(&self) -> Result<Currencies, Error>

Get all available currencies https://swapspace.co/api/v2/currencies This API endpoint returns the list of available currencies.

use swapspace_api::SwapSpaceApi;
let response = SwapSpaceApi::default().get_currencies().await.unwrap();
assert_eq!(response.len() > 0, true);
Source

pub async fn get_amounts( &self, get_amounts: &GetAmounts, ) -> Result<Amounts, Error>

Get all available amounts https://swapspace.co/api/v2/amounts This endpoint has five required (fromCurrency, fromNetwork, toCurrency , toNetwork and amount) and three optional parameters (partner, fixed and float). If you create a request containing only five required parameters, it will return the list of all the available amounts from all the partners. If you fill in the partner parameter, it will return the list of amounts available for a specific partner. If you fill in the fixed field with a true value, the request will return a list of amounts for fixed rate exchanges. If you fill in the float field with a true value, the request will return a list of amounts for floating rate exchanges. If you fill in a true value both for fixed and float fields, the request will return amounts both for fixed and floating rate exchanges. The unit for duration is the minute. The range of values for the supportRate field is from 0 to 3.

use swapspace_api::{SwapSpaceApi, GetAmounts};
let amounts = GetAmounts {
  from_currency: "btc".to_string(),
  from_network: "btc".to_string(),
  to_currency: "eth".to_string(),
  to_network: "eth".to_string(),
  amount: 0.1,
  partner: None,
  fixed: false,
  float: false,
};
let response = SwapSpaceApi::default().get_amounts(&amounts).await.unwrap();
assert_eq!(response.len() > 0, true);
Source

pub async fn get_amounts_best( &self, get_amounts: &GetAmounts, ) -> Result<AmountResponse, Error>

Get the best amount https://swapspace.co/api/v2/amounts/best This endpoint has five required (fromCurrency, fromNetwork, toCurrency , toNetwork and amount) and three optional parameters (partner, fixed and float). If you create a request containing only five required parameters, it will return the best of all the available amounts from all the partners. If you fill in the partner parameter, it will return the best amount available for a specific partner. If you fill in the fixed field with a true value, the request will return a best amount for fixed rate exchanges. If you fill in the float field with a true value, the request will return a best amount for floating rate exchanges. If you fill in a true value both for fixed and float fields, the request will return the best amount both for fixed and floating rate exchanges. The unit for duration is the minute. The range of values for the supportRate field is from 0 to 3.

use swapspace_api::{SwapSpaceApi, GetAmounts};
let amounts = GetAmounts {
 from_currency: "btc".to_string(),
 from_network: "btc".to_string(),
 to_currency: "eth".to_string(),
 to_network: "eth".to_string(),
 amount: 0.1,
 partner: None,
 fixed: false,
 float: false,
 };
 let response = SwapSpaceApi::default().get_amounts_best(&amounts).await.unwrap();
 assert_eq!(response.exists, true);
Source

pub async fn get_partners(&self) -> Result<Partners, Error>

Get all available partners https://swapspace.co/api/v2/partners This API endpoint returns the list of available partners.

use swapspace_api::SwapSpaceApi;
let response = SwapSpaceApi::default().get_partners().await.unwrap();
assert_eq!(response.len() > 0, true);
Source

pub async fn post_exchange( &self, data: ExchangeRequest, ) -> Result<ExchangeResponse, Error>

Post an exchange https://swapspace.co/api/v2/exchange All the fields mentioned in body are required. Field extraId is required only if the currency you want to receive has hasExtraId: true property (you get this info via the List of currencies endpoint). If hasExtraId: false, use empty string in the extraId field. All the fields mentioned in body are required. Field extraId must be filled in if the value of the hasExtraId field is true in the endpoint List of currencies for this currency. Otherwise, fill in the extraId field with an empty string. After userIp fill in the user’s IP in IPv4 or IPv6 format. Refund field is required if fixed: true and reqFixedRefund: true for relevant partner and float: true and reqFloatRefund: true for relevant partner (look List of partners example response). But we strongly recommend that you specify refund when creating an exchange, even if it is not required (if a refund is not required or you cannot specify it, then it is permissible to use a refund: ‘’).

use swapspace_api::{SwapSpaceApi, ExchangeRequest, Address};
 let data = ExchangeRequest {
    partner: "simpleswap".to_string(),
    from_currency: "btc".to_string(),
    from_network: "btc".to_string(),
    to_currency: "eth".to_string(),
    to_network: "eth".to_string(),
    address: Address("0x32be343b94f860124dc4fee278fdcbd38c102d88".to_string()),
    amount: 2.0,
    fixed: true,
    extra_id: "".to_string(),
    rate_id: "".to_string(),
    user_ip: "8.8.8.8".to_string(),
    refund: Address("1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX".to_string()),
 };
 let response = SwapSpaceApi::default().post_exchange(data).await.unwrap();
 assert_eq!(response.id.len() > 0, true);
Source

pub async fn get_exchange_status( &self, id: &str, ) -> Result<ExchangeResponse, Error>

Get exchange status https://swapspace.co/api/v2/exchange/{id} Use the Exchange status endpoint to get the current exchange status. As a request data, use path parameter id, which is to be filled in with exchange id you get with the other data for the successful Create new exchange request.

use swapspace_api::SwapSpaceApi;
let id = "-9mVIXNbYZcG";
let response = SwapSpaceApi::default().get_exchange_status(id).await.unwrap();
assert_eq!(response.id, id);

Trait Implementations§

Source§

impl Default for SwapSpaceApi

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> 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, 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<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
Source§

impl<T> ErasedDestructor for T
where T: 'static,