# SplitNOW Rust SDK
Rust SDK (API wrapper) for [SplitNOW](https://splitnow.io), the multi-wallet instant crypto exchange. 🪼
**4 Dependencies :**
- `reqwest`
- `serde`
- `tokio`
- `thiserror`
## Install
Add splitnow as a dependency to your `Cargo.toml` file:
```toml
[dependencies]
splitnow = "1.0"
```
## Usage Example
You'll need to create a SplitNOW API key if you don't have one already:
1. Create a SplitNOW account at [https://splitnow.io/auth/register](https://splitnow.io/auth/register)
2. Head to the API keys page on your account dashboard at [https://splitnow.io/account/api-keys](https://splitnow.io/account/api-keys)
3. Copy your account's API key and store it in a safe place.
This example demonstrates splitting **10 SOL** evenly across **2 wallets** through [Binance](https://binance.com/) & [Bybit](https://bybit.com/):
```rust
use splitnow::{AssetId, ExchangerId, NetworkId, SplitNow, WalletDistribution};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get a free API key at: https://splitnow.io/auth/register
const API_KEY: &str = "replace_me";
let splitnow = SplitNow::new(API_KEY.to_string())?;
// Step 1: Create and fetch a quote
let quote = splitnow
.create_and_fetch_quote(
10.0,
AssetId::Sol,
NetworkId::Solana,
AssetId::Sol,
NetworkId::Solana,
)
.await?;
println!("Quote ID: {}", quote.quote_id);
println!("Available rates:");
for rate in "e.rates {
println!(" {}: {}", rate.exchange_id, rate.exchange_rate);
}
// Step 2: Create and fetch an order
let wallet_distributions = vec![
WalletDistribution {
to_address: "7ingPqZUYmuso5HakTLgoXjMpETpbZYzxeQBJChGrQn5".to_string(),
to_pct_bips: 5000,
to_asset_id: AssetId::Sol,
to_network_id: NetworkId::Solana,
to_exchanger_id: ExchangerId::Binance,
},
WalletDistribution {
to_address: "92CzWZt7fD5ffhwkRNBKHxqHahVTPeWedd5UYmdmHjMw".to_string(),
to_pct_bips: 5000,
to_asset_id: AssetId::Sol,
to_network_id: NetworkId::Solana,
to_exchanger_id: ExchangerId::Bybit,
},
];
let order = splitnow
.create_and_fetch_order(
quote.quote_id,
10.0,
AssetId::Sol,
NetworkId::Solana,
wallet_distributions,
)
.await?;
println!("\nOrder ID: {}", order.order_id);
println!("Deposit Address: {}", order.deposit_address);
println!("Deposit Amount: {}", order.deposit_amount);
// Step 3: Get order status
let order_status = splitnow.get_order_status(&order.order_id).await?;
println!("\nOrder Status: {:?}", order_status.order_status);
println!("Status Short: {:?}", order_status.order_status_short);
println!("Status Text: {}", order_status.order_status_text);
Ok(())
}
```
### Understanding The 3-Step Flow
To ensure a seamless SplitNOW API integration for your use case, you must first understand the **3-step flow** when using the SplitNOW API.
Below is a short explainer of each step so that you can best fit each step into your own software & workflows.
#### Step 1/3: `splitnow.create_and_fetch_quote()` - Creating and fetching a quote
```rust
let quote = splitnow
.create_and_fetch_quote(
10.0,
AssetId::Sol,
NetworkId::Solana,
AssetId::Sol,
NetworkId::Solana,
)
.await?;
```
- Save `quote.quote_id` because you need this value to create your order in the next step.
- You'll also probably want to do something such as filter through `quote.rates` to see which exchanges are available and at what rate.
- If the `exchange_rate` field of a rate object in the `quote.rates` vector is `0`, the pair might not be supported on that exchange.
- You can pick any exchange no matter what, though. Our systems fall back to the next best rate if your selection is unavailable!
#### Step 2/3: `splitnow.create_and_fetch_order()` - Creating and fetching an order
```rust
let order = splitnow
.create_and_fetch_order(
quote.quote_id,
10.0,
AssetId::Sol,
NetworkId::Solana,
wallet_distributions,
)
.await?;
```
- Remember to pass in the `quote_id` from the previous step!
- The `order` struct contains important information you'll need for initiating the order: `order.deposit_address` & `order.deposit_amount`.
- Once you've sent the deposit, we take care of everything else automatically!
- Save `order.order_id` so you can check the status of your order anytime.
#### Step 3/3: `splitnow.get_order_status()` - Fetching an order status
```rust
let order_status = splitnow.get_order_status(&order.order_id).await?;
```
- Remember to pass in the `order_id` from the previous step!
- Your 6-digit order ID is returned as `order_status.order_id`.
- You'll probably want to do something with `order_status.order_status` such as update your app's client or trigger a notification once the order status changes.
- If you want a human-readable order status such as for your UI, use `order_status.order_status_text`.
- Once `order_status.order_status` is `OrderStatus::Completed`, it's all done and the wallets are funded as requested! Enjoy!
### Full Reference
This Rust SDK includes **10 functions** that wrap around the [SplitNOW API](https://splitnow.io/api/docs) to help you get up and running with creating quotes & orders quickly, no matter your use case:
#### get_health
```rust
pub async fn get_health(&self) -> Result<bool, SplitNowError>
```
- Checks whether the SplitNOW API is healthy.
- **Returns**: A `Result<bool, SplitNowError>` indicating API health status.
API Reference: [GET /health/](https://splitnow.io/api/docs#tag/default/get/health)
#### get_assets
```rust
pub async fn get_assets(&self) -> Result<Vec<Asset>, SplitNowError>
```
- Gets a list of available asset IDs and network IDs.
- **Returns:** A `Result<Vec<Asset>, SplitNowError>`.
**💡 Pro Tip:** When creating quotes & orders, the `asset_id` field of each `Asset` can be used for `from_asset_id` & `to_asset_id`.
**💡 Pro Tip:** When creating quotes & orders, the `network_id` field of a corresponding `Asset` can be used for `from_network_id` & `to_network_id`.
API Reference: [GET /assets/](https://splitnow.io/api/docs#tag/assets/get/assets)
#### get_asset_prices
```rust
pub async fn get_asset_prices(&self) -> Result<HashMap<String, Option<f64>>, SplitNowError>
```
- Gets the current USD price of each available asset by ID.
- **Returns:** A `Result<HashMap<String, Option<f64>>, SplitNowError>` where each key is an asset ID and each value is its price.
API Reference: [GET /assets/prices/](https://splitnow.io/api/docs#tag/assets/get/assetsprices)
#### get_asset_deposit_limits
```rust
pub async fn get_asset_deposit_limits(&self) -> Result<Vec<AssetLimit>, SplitNowError>
```
- Gets the minimum and maximum deposit (if any) for each available asset.
- **Returns:** A `Result<Vec<AssetLimit>, SplitNowError>`.
API Reference: [GET /assets/limits/](https://splitnow.io/api/docs#tag/assets/get/assetslimits)
#### get_exchangers
```rust
pub async fn get_exchangers(&self) -> Result<Vec<Exchanger>, SplitNowError>
```
- Get a list of available exchanger IDs.
- **Returns:** A `Result<Vec<Exchanger>, SplitNowError>`.
**💡 Pro Tip:** When creating quotes & orders, the `id` field of each `Exchanger` can be used for `to_exchanger_id`.
API Reference: [GET /exchangers/](https://splitnow.io/api/docs#tag/exchangers/get/exchangers)
#### create_and_fetch_quote
```rust
pub async fn create_and_fetch_quote(
&self,
from_amount: f64,
from_asset_id: impl Into<String>,
from_network_id: impl Into<String>,
to_asset_id: impl Into<String>,
to_network_id: impl Into<String>,
) -> Result<QuoteData, SplitNowError>
```
- Creates and fetches a quote.
- **Parameters:**
- `from_amount`: A numerical amount of tokens to split.
- `from_asset_id`: The input asset ID returned from `get_assets`. Accepts `AssetId` enum or `String`.
- `from_network_id`: A corresponding input network ID returned from `get_assets`. Accepts `NetworkId` enum or `String`.
- `to_asset_id`: The output asset ID returned from `get_assets`. Accepts `AssetId` enum or `String`.
- `to_network_id`: A corresponding output network ID returned from `get_assets`. Accepts `NetworkId` enum or `String`.
- **Returns:** A `Result<QuoteData, SplitNowError>`.
API Reference: [POST /quotes/](https://splitnow.io/api/docs#tag/quotes/post/quotes), [GET /quotes/{id}](https://splitnow.io/api/docs#tag/quotes/get/quotesid)
#### create_and_fetch_order
```rust
pub async fn create_and_fetch_order(
&self,
quote_id: impl Into<String>,
from_amount: f64,
from_asset_id: impl Into<String>,
from_network_id: impl Into<String>,
wallet_distributions: Vec<WalletDistribution>,
) -> Result<OrderData, SplitNowError>
```
- Creates and fetches an order.
- **Parameters:**
- `quote_id`: A quote ID returned from `create_and_fetch_quote`.
- `from_amount`: A numerical amount of tokens to split.
- `from_asset_id`: The input asset ID returned from `get_assets`. Accepts `AssetId` enum or `String`.
- `from_network_id`: A corresponding input network ID returned from `get_assets`. Accepts `NetworkId` enum or `String`.
- `wallet_distributions`: A `Vec<WalletDistribution>` containing recipient wallets and distribution preferences.
- **Returns:** A `Result<OrderData, SplitNowError>`.
API Reference: [POST /orders/](https://splitnow.io/api/docs#tag/orders/post/orders), [GET /orders/{id}](https://splitnow.io/api/docs#tag/orders/get/ordersid)
#### get_quote
```rust
pub async fn get_quote(&self, quote_id: &str) -> Result<Quote, SplitNowError>
```
- Fetches a quote by its ID.
- **Parameters:**
- `quote_id`: The quote ID to fetch.
- **Returns:** A `Result<Quote, SplitNowError>`.
API Reference: [GET /quotes/{id}](https://splitnow.io/api/docs#tag/quotes/get/quotesid)
#### get_order
```rust
pub async fn get_order(&self, order_id: &str) -> Result<Order, SplitNowError>
```
- Fetches an order by its ID.
- **Parameters:**
- `order_id`: The order ID to fetch.
- **Returns:** A `Result<Order, SplitNowError>`.
API Reference: [GET /orders/{id}](https://splitnow.io/api/docs#tag/orders/get/ordersid)
#### get_order_status
```rust
pub async fn get_order_status(&self, order_id: &str) -> Result<OrderStatusData, SplitNowError>
```
- Fetches the status of an order by its ID.
- **Parameters:**
- `order_id`: The order ID to fetch.
- **Returns:** A `Result<OrderStatusData, SplitNowError>`.
API Reference: [GET /orders/{id}](https://splitnow.io/api/docs#tag/orders/get/ordersid)
## Rate Limits
The default rate-limit of each API key is 60 requests per minute.
Don't hesitate to [contact SplitNOW](support@splitnow.io) if you need more. We scale to meet any demand instantly!
## Security
Never expose your SplitNOW API key to clients! If you think your API key may have been accidentally leaked, please [contact support](support@splitnow.io) right away so that we can get you set up with a fresh one.
## Compliance & Restricted Regions
Our API services are not available to users in the [Restricted Regions](https://splitnow.io/restricted-regions), directly or indirectly, in accordance with our [Terms of Service](https://splitnow.io/terms).
## Support
- Official API docs: [https://splitnow.io/api/docs](https://splitnow.io/api/docs)
- Free 24/7 email support: [support@splitnow.io](mailto:support@splitnow.io)
- Free community support: [SplitNOW API Developers Chat](https://t.me/splitnow_developers)
## License
Unlicensed (Whitelabelled)
More information: [https://unlicense.org](https://unlicense.org)
---
*© 2025 SplitOTC, Ltd.*