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
- averageRate
- limits
- check
- [execute] (doc:exchange#execute)
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:
case | variable | variable type | description |
success | pair | [(CRPTCurrency, CRPTCurrency)] | array of pairs of cryptocurrencies to exchange (from, to) |
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have the value below:
value | description |
AUTHORIZATION | authorization 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 name | parameter type | description |
from | CRPTCurrency | cryptocurrency to sell |
to | CRPTCurrency | cryptocurrency to buy |
CRPTRateResult
The CRPTRateResult
object value is attached to a success or a failure case:
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
VALIDATION | coin is not in the list of available pairs |
BACKEND | backend 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 name | parameter type | description |
from | CRPTCurrency | cryptocurrency to sell |
to | CRPTCurrency | cryptocurrency to buy |
CRPTDualLimitsResult
The CRPTDualLimitsResult
object value is attached to success or failure case:
case | variable | variable type | description |
success | from, to | (from: CRPTLimits, to: CRPTLimits) | limits for crypto exchange pair |
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
VALIDATION | coin is not in the list of available pairs |
BACKEND | backend 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 name | parameter type | description |
amount | Decimal | amount of crypto to exchange |
from | CRPTCurrency | cryptocurrency to sell |
to | CRPTCurrency | cryptocurrency to buy |
CRPTExchangeCheckResult
The CRPTExchangeCheckResult
object value is attached to success or failure case:
case | variable | variable type | description |
success | void | ||
failure | error | CRPTError | error details |
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization error |
VALIDATION | coin is not in the list of available pairs |
BACKEND | backend error |
MAINTENANCE | maintenance error |
UPDATE | update error |
LIMITS | exceeding transaction or card limits |
KYC0 | exceeding monthly limits, KYC0 verification required |
KYC1 | exceeding monthly limits, KYC1 verification required |
KYC2 | exceeding 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 name | parameter type | description |
amount | Decimal | amount of crypto to exchange |
from | CRPTCurrency | cryptocurrency to sell |
to | CRPTCurrency | cryptocurrency to buy |
CRPTExchangeExecuteResult
The CRPTExchangeExecuteResult
object value is attached to a success or a failure case:
case | variable | variable type | description |
success | status | CRPTTransactionStatus | transaction status |
failure | error | CRPTError | error details |
CRPTTransactionStatus
The CRPTTransactionStatus object may have one of the values below:
value | description |
SUCCESS | transaction committed |
FAILURE | transaction failed |
CRPTError
The type
property of the CRPTError object may have one of the values below:
value | error description |
AUTHORIZATION | authorization failed |
VALIDATION | validation error |
BACKEND | backend error |
MAINTENANCE | maintenance error |
UPDATE | update error |
LIMITS | exceeding the transaction or card limits |
KYC0 | exceeding the monthly limits, KYC0 verification required |
KYC1 | exceeding the monthly limits, KYC1 verification required |
KYC2 | exceeding the monthly limits, KYC2 verification required |
Updated over 2 years ago