pub struct SwapSpaceApi {
pub client: Client,
pub base_url: Url,
}
Fields§
§client: Client
§base_url: Url
Implementations§
Source§impl SwapSpaceApi
impl SwapSpaceApi
Sourcepub fn new(api_key: String) -> Result<Self, Error>
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();
Sourcepub async fn get_currencies(&self) -> Result<Currencies, Error>
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);
Sourcepub async fn get_amounts(
&self,
get_amounts: &GetAmounts,
) -> Result<Amounts, Error>
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);
Sourcepub async fn get_amounts_best(
&self,
get_amounts: &GetAmounts,
) -> Result<AmountResponse, Error>
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);
Sourcepub async fn get_partners(&self) -> Result<Partners, Error>
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);
Sourcepub async fn post_exchange(
&self,
data: ExchangeRequest,
) -> Result<ExchangeResponse, Error>
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);
Sourcepub async fn get_exchange_status(
&self,
id: &str,
) -> Result<ExchangeResponse, Error>
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);