1 个不稳定版本
0.1.0 | 2024年7月16日 |
---|
#44 在 #env-var
113 每月下载量
30KB
438 行
Swapspace-api rust
创建一个新的客户端
use swapspace_api::SwapSpaceApi;
let api = SwapSpaceApi::new("api_key".to_string()).expect("failed to create client");
或设置SWAPSPACE_API_KEY环境变量并调用默认
use swapspace_api::SwapSpaceApi;
let api = SwapSpaceApi::default();
获取货币
let api = SwapSpaceApi::default();
api.get_currencies().await.unwrap();
获取金额
let api = SwapSpaceApi::default();
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 = api.get_amounts(&amounts).await.unwrap();
获取最佳金额
let api = SwapSpaceApi::default();
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 = api.get_amounts_best(&amounts).await.unwrap();
获取合作伙伴
let api = SwapSpaceApi::default();
let response = api.get_partners().await.unwrap();
发布交换
let api = SwapSpaceApi::default();
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 = api.post_exchange(data).await.unwrap();
获取交换状态
let api = SwapSpaceApi::default();
let id = "id";
let response = api.get_exchange_status(id).await.unwrap();
依赖关系
~8–20MB
~300K SLoC