Exchanging crypto

The SDK allows you to exchange cryptocurrencies using a CrypteriumExchange class.

In this class, we have implemented several methods for conducting exchange operations:

  • The pairs method is responsible for the list of available cryptocurrencies.

  • Once a cryptocurrency has been selected, you can use the averageRate method to get its approximate exchange rate of conversion.

  • The limits method returns the allowed minimum and maximum of the cryptocurrency you can exchange. Limits are determined by the KYC level.

  • Check the possibility of exchanging using the check method.

  • If an exchange with the given parameters is possible, run the execute method to confirm the transaction.

See more details in the description of each method.


CrypteriumExchange class

The CrypteriumExchange class has been implemented for exchanging crypto. To manage the process, initialize the CrypteriumExchange object:

let exchange: CrypteriumEnxchange = CrypteriumAPI.exchange()
exchange: ICrypteriumExchange = CrypteriumAPI.exchange()

Methods

pairs

Use the pairs method to get the array of cryptocurrencies available for exchanging. The method calls a completion closure and puts an object of CRPTLoadDualPairsResult type as an argument of the closure.

exchange.pairs(completion: (CRPTLoadDualPairsResult) -> Void)

enum CRPTLoadDualPairsResult {
	case success([(CRPTCurrency, CRPTCurrency)])
	case failure(CRPTError)
}
exchange.loadPairs(completion: (CRPTLoadDualPairsResult) -> Unit)
  
sealed class CRPTLoadDualPairsResult {
    data class success(val pair: List<Pair<CRPTCurrency?, CRPTCurrency?>>) : CRPTLoadDualPairsResult()
    data class failure(val error: CRPTError) : CRPTLoadDualPairsResult()
}

CRPTLoadDualPairsResult

The CRPTLoadDualPairsResult object value is attached to a success or a failure case:

casevariablevariable typedescription
successpair[(CRPTCurrency, CRPTCurrency)]array of pairs of cryptocurrencies to exchange (from, to)
failureerrorCRPTErrorerror details

CRPTError

The type property of the CRPTError object may have the value below:

valuedescription
AUTHORIZATIONauthorization error

averageRate

The averageRate method gives the approximate rate for the selected cryptocurrencies to exchange. It calls a completion closure and puts an object of CRPTRateResult type as an argument of the closure.

exchange.averageRate(from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTRateResult) -> Void)

enum CRPTRateResult {
	case success(Decimal)
	case failure(CRPTError)
}
exchange.averageRate(from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTRatesResult) -> Unit)
  
sealed class CRPTRatesResult {
    data class success(val rate: BigDecimal) : CRPTRatesResult()
    data class failure(val error: CRPTError) : CRPTRatesResult()
}

Income parameters

parameter nameparameter typedescription
fromCRPTCurrencycryptocurrency to sell
toCRPTCurrencycryptocurrency to buy

CRPTRateResult

The CRPTRateResult object value is attached to a success or a failure case:

casevariablevariable typedescription
successrateDecimalrate of cryptocurrency
failureerrorCRPTErrorerror details

CRPTError

The type property of the CRPTError object may have one of the values below:

valueerror description
AUTHORIZATIONauthorization error
VALIDATIONcoin is not in the list of available pairs
BACKENDbackend error

limits

The limits method allows you to get the exact maximum and minimum amount of the crypto a user can exchange. The method calls a completion closure and puts an object of CRPTDualLimitsResult type as an argument of the closure.

exchange.limits(from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTDualLimitsResult) -> Void)

enum CRPTDualLimitsResult {
	case success((from: CRPTLimits, to: CRPTLimits))
	case failure(CRPTError)
}
exchange.limits(from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTDualLimitsResult) -> Unit)
  
sealed class CRPTDualLimitsResult {
    data class success(val from: CRPTLimits, val to: CRPTLimits) : CRPTDualLimitsResult()
    data class failure(val error: CRPTError) : CRPTDualLimitsResult()
}

Income parameters

parameter nameparameter typedescription
fromCRPTCurrencycryptocurrency to sell
toCRPTCurrencycryptocurrency to buy

CRPTDualLimitsResult

The CRPTDualLimitsResult object value is attached to success or failure case:

casevariablevariable typedescription
successfrom, to(from: CRPTLimits, to: CRPTLimits)limits for crypto exchange pair
failureerrorCRPTErrorerror details

CRPTError

The type property of the CRPTError object may have one of the values below:

valueerror description
AUTHORIZATIONauthorization error
VALIDATIONcoin is not in the list of available pairs
BACKENDbackend error

check

Use the check method to check if a user can exchange selected cryptocurrencies. The balance must be sufficient. FROM and TO cryptocurrencies must be available. The method calls a completion closure and puts an object of CRPTExchangeCheckResult type as an argument of the closure.

exchange.check(amount: Decimal, from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTExchangeCheckResult) -> Void)

enum CRPTExchangeCheckResult {
	case success()
	case failure(CRPTError)
}
exchange.check(amount: BigDecimal, from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTExchangeCheckResult) -> Unit)
  
sealed class CRPTExchangeCheckResult {
    object success : CRPTExchangeCheckResult()
    data class failure(val error: CRPTError) : CRPTExchangeCheckResult()
}

Income parameters

parameter nameparameter typedescription
amountDecimalamount of crypto to exchange
fromCRPTCurrencycryptocurrency to sell
toCRPTCurrencycryptocurrency to buy

CRPTExchangeCheckResult

The CRPTExchangeCheckResult object value is attached to success or failure case:

casevariablevariable typedescription
successvoid
failureerrorCRPTErrorerror details

CRPTError

The type property of the CRPTError object may have one of the values below:

valueerror description
AUTHORIZATIONauthorization error
VALIDATIONcoin is not in the list of available pairs
BACKENDbackend error
MAINTENANCEmaintenance error
UPDATEupdate error
LIMITSexceeding transaction or card limits
KYC0exceeding monthly limits, KYC0 verification required
KYC1exceeding monthly limits, KYC1 verification required
KYC2exceeding monthly limits, KYC2 verification required

execute

The execute method commits the crypto exchange transaction. It calls a completion closure and puts an object of CRPTExchangeExecuteResult type as an argument of the closure.

exchange.execute(amount: Decimal, from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTExchangeExecuteResult) -> Void)

enum CRPTExchangeExecuteResult {
	case success(CRPTTransactionStatus)
	case failure(CRPTError)
}
exchange.execute(amount: BigDecimal, from: CRPTCurrency, to: CRPTCurrency, completion: (CRPTExchangeExecuteResult) -> Unit)
  
sealed class CRPTExchangeExecuteResult {
    data class success(val status: CRPTTransactionStatus) : CRPTExchangeExecuteResult()
    data class failure(val error: CRPTError) : CRPTExchangeExecuteResult()
}

Income parameters

parameter nameparameter typedescription
amountDecimalamount of crypto to exchange
fromCRPTCurrencycryptocurrency to sell
toCRPTCurrencycryptocurrency to buy

CRPTExchangeExecuteResult

The CRPTExchangeExecuteResult object value is attached to a success or a failure case:

casevariablevariable typedescription
successstatusCRPTTransactionStatustransaction status
failureerrorCRPTErrorerror details

CRPTTransactionStatus

The CRPTTransactionStatus object may have one of the values below:

valuedescription
SUCCESStransaction committed
FAILUREtransaction failed

CRPTError

The type property of the CRPTError object may have one of the values below:

valueerror description
AUTHORIZATIONauthorization failed
VALIDATIONvalidation error
BACKENDbackend error
MAINTENANCEmaintenance error
UPDATEupdate error
LIMITSexceeding the transaction or card limits
KYC0exceeding the monthly limits, KYC0 verification required
KYC1exceeding the monthly limits, KYC1 verification required
KYC2exceeding the monthly limits, KYC2 verification required