Skip to content

Latest commit

 

History

History
128 lines (105 loc) · 3.04 KB

swap.md

File metadata and controls

128 lines (105 loc) · 3.04 KB

Swap

First create an instance of swap controller to call all methods below.

const sdk = new CryptumSdk({
  environment: 'testnet',
  apiKey: 'YOUR-API-KEY'
})

Get supported currencies

Get a list of all supported currencies to swap to and from. Examples: BTC, ETH, XLM, XRP, BNB, USDT and others.

Examples:

sdk.swap.getSupportedCurrencies().then((curencies) => {
   console.log(curencies);
})

Get minimum amount

Get the minimum amount to swap.

sdk.swap.getMinimumAmount(opts)

Params:

  • opts.currencyFrom (string) (required) criptocurrency to swap from.
  • opts.currencyTo (string) (required) criptocurrency to swap to.

Examples:

sdk.swap.getMinimumAmount({
   currencyFrom: "DASH",
   currencyTo: "BTC"
}).then((minimumAmount) => {
   console.log(minimumAmount);
})

Get estimate amount

Get estimate amount to receive from the swap.

sdk.swap.getEstimateAmount(opts)

Params:

  • opts.currencyFrom (string) (required) criptocurrency to swap from.
  • opts.currencyTo (string) (required) criptocurrency to swap to.
  • opts.amount (string) (required) criptocurrency amount to estimate.

Examples:

sdk.swap.getEstimateAmount({
  currencyFrom: "BTC",
  currencyTo: "ETH",
  amount: "0.06"
}).then((estimateAmount) => {
  console.log(estimateAmount);
})

Get order

Get the swap order by its id.

sdk.swap.getOrder(id)

Params:

  • id (string) (required) swap order id.

Example:

sdk.swap.getOrder('41c62023-ec12-4d5c-8ea3-b1b93a4d63ac').then((order) => {
  console.log(order);
})

Create order

Create new swap order.

sdk.swap.createOrder(opts)

Params:

  • opts.currencyFrom (string) (required) currency to swap from
  • opts.currencyTo (string) (required) currency to swap to
  • opts.amount (string) (required) amount to swap from
  • opts.addressTo (string) (required) address to swap to
  • opts.memoTo (string) (required) memo or extra id string to pass along with the addressTo (only for some currencies like XLM, XRP, etc)
  • opts.refundAddress (string) (required) address to return funds to the user in case the swapping goes wrong
  • opts.refundMemo (string) (required) memo or extra id string to pass along with the refundAddress (only for some currencies like XLM, XRP, etc)

Example:

sdk.swap.createOrder({
  currencyFrom: "SOL",
  currencyTo: "ETH",
  amountFrom: "5.81",
  addressTo: "0x0Cbed4D3f2...d8b1A7B5185",
  memoTo: null,
  refundAddress: null,
  refundMemo: null,
}).then((order) => {
  console.log(order);
})

Get orders

Get all swap orders.

sdk.swap.getOrders(opts)

Params:

  • opts.limit (number) (required)
  • opts.offset (number) (required)

Example

sdk.swap.getOrders({
   limit: 10,
   offset: 1
}).then((orders) => {
   console.log(orders);
})