LogoLogo
  • SWAPPLE API
    • Changelog
      • 2022, 26 January
      • 2022, 29 December
      • 2022, 14 June
      • 2024, 11 March
      • 2024, 27 June
      • 2024, 31 July
      • 2024, 27 August
      • 2024, 3 September
    • API Reference
      • Authorization
      • Orders
      • Statuses
      • Currencies
      • Webhook
      • Sandbox
    • Examples and sample usages
      • Sample usage
      • Merchant User Flow
      • Fixed Rate Order Guide
    • FAQ
  • CRYPTO ACQUIRING API
Powered by GitBook
On this page
  • 1A. First let's take a look at the FLOATING option
  • 1B. Now let's take a look at the FIXED option
  • Creating an order
  1. SWAPPLE API
  2. Examples and sample usages

Sample usage

Before showing your client a page where he can exchange currencies, you want to make sure that we have that pair available. Feel free to use this request as often as you need. In the future, we will provide you with a callback if a pair is added or removed

get_pairs_info_response = requests.get(
    f"https://api.swapple.org/api/v3/get-pairs-info",
    headers=get_authorization_headers({})
)

After your client selects a currency pair and an amount he wishes to exchange from or exchange to, you need to send the estimate amount request. You have two options here FIXED rate or FLOATING rate

1A. First let's take a look at the FLOATING option

body = {
    "from": "CARDUAH",
    "to": "USDT",
    "toNetwork": "TRX",
    "fromAmount": 3000,
    "rateType": "FLOATING",
}
estimate_amount_response = requests.post(
    f"https://api.swapple.org/api/v3/estimate-amount",
    json=body,
    headers=get_authorization_headers(body)
)

If the amount your client has asked for is bigger than we can exchange momentarily but not too big, you will have an option of creating a delayed order. For this take a look at the

During a normal flow you will receive the following:

# Example data
assert estimate_amount_response == {
    "extraFromFee": 0.0,
    "extraToFee": 0.0,
    "from": "CARDUAH",
    "fromAmount": 3000.0,
    "fromFee": 6.0,
    "fromNetwork": None,
    "fromRate": 37.45992,
    "fromRevenueShare": 12.0,
    "rateType": "FLOATING",
    "rateId": "PGRgFD88smBFYvmjbHgDfJ",
    "side": "BUY",
    "to": "USDT",
    "toAmount": 78.605082,
    "toFee": 1.0,
    "toNetwork": "TRX",
    "toRate": 1,
    "toRevenueShare": 0.0,
}

1B. Now let's take a look at the FIXED option

Here you get a field that is specific to the rate type: rateIdExpirationTimestamp. As you might have guessed, you are only able to use this rate before it expires.

Creating an order

With this information you are ready to create an order

body = {
    "from": "CARDUAH",
    "to": "USDT",
    "toNetwork": "TRX",
    "fromAmount": 3000,
    "toPaymentDetails": "TX3QisjigSnQkb3GBTTqdWDb6g2M9xPxqd",
    "redirectUrl": "https://our_awesome_partner.com/payment_completed/",
    "userId": "your_client_id",
    "rateId": estimate_amount_response.json()['rateId'],
}

create_order_response = requests.post(
    f"https://api.swapple.org/api/v3/create-order",
    json=body,
    headers=get_authorization_headers(body),
)

You might want to add some additional parameters based on your specific use-cases so feel free to look at the API Reference

order_id = create_order_response.json()['id']

In case you need to check information or update status of the order, you can use the check order request:

get_order_info_response = requests.get(
    f"https://api.swapple.org/api/v3/create-order",
    params={"id": order_id},
    headers=get_authorization_headers({}),
)

Sometimes you might want to cancel your order before your client started depositing:

body = {'id': order_id}
cancel_order_response = requests.post(
    f"https://api.swapple.org/api/v3/cancel-order",
    json=body,
    headers=get_authorization_headers(body),
)
PreviousExamples and sample usagesNextMerchant User Flow

Last updated 8 months ago