On this page

latest contributor to this doc

Last Edit:

@smk762

Komodo DeFi Framework Method: Trade Preimage

API-v2trade_preimage

The trade_preimage method returns the approximate fee amounts that are paid per the whole swap. Depending on the parameters, the function returns different results:

  • If the swap_method is buy or sell, then the result will include the taker_fee and the fee_to_send_taker_fee. The taker_fee amount is paid from the base coin balance if the swap_method is sell, else it is paid from the rel coin balance;
  • If the max field is true, then the result will include the volume.

This method can be used instead of max_taker_vol, if the max field is true and the swap_method is buy or sell. Use the resulting volume as an argument of the buy or sell requests.

Use the trade_preimage request with max = true and swap_method = "setprice" arguments to approximate the fee amounts only. Do not use the resulting volume as an argument of the setprice.

ParameterTypeRequiredDefaultDescription
basestring-The base currency of the request.
relstring-The rel currency of the request.
swap_methodstring-The name of the method whose preimage is requested. Possible values: buy, sell, setprice. See SwapMethodEnum.
pricenumeric string or rational-The price in rel the user is willing to pay per one unit of the base coin.
maxboolfalseWhether to return the maximum available volume for setprice method; must not be set or false if swap_method is buy or sell.
volumenumeric string or rational-The amount the user is willing to trade; ignored if max = true and swap_method = setprice, otherwise, it must be set.

ParameterTypeDescription
base_coin_feeobjectA standard ExtendedFeeInfo object. The approximate miner fee is paid per the whole swap concerning the base coin.
rel_coin_feeobjectA standard ExtendedFeeInfo object. The approximate miner fee is paid per the whole swap concerning the rel coin.
volumestring (numeric)Optional. The max available volume that can be traded (in decimal representation); empty if the max argument is missing or false.
volume_ratrationalOptional. The max available volume that can be traded represented as a standard RationalValue object.; empty if the max argument is missing or false.
volume_fractionfractionOptional. The max available volume that can be traded represented as a standard fractionalValue object.; empty if the max argument is missing or false.
taker_feeobjectA standard ExtendedFeeInfo object. The dex fee to be paid by Taker; empty if swap_method is setprice.
fee_to_send_taker_feeobjectA standard ExtendedFeeInfo object. The approximate miner fee is paid to send the dex fee; empty if swap_method is setprice.
total_feesarray of objectsA standard TotalFeeInfo object. Each element is a sum of fees required to be paid from user's balance of corresponding ExtendedFeeInfo.coin; the elements are unique by coin.

The available balance of the coin is not sufficient to start the swap.

ParameterTypeDescription
coinstringthe name of the coin which balance is not sufficient
availablestring (numeric)the balance available for swap, including the amount locked by other swaps
requiredstring (numeric)the amount required to start the swap. This amount is necessary but may not be sufficient
locked_by_swapsstring (numeric, optional)the amount locked by other swaps

The available balance of the base coin is not sufficient to pay transaction fees.

For example, ERC20 fees are paid by ETH (gas), and this error type is returned if the ETH coin balance is not sufficient to start the swap.

ParameterTypeDescription
coinstringthe name of the base coin which balance is not sufficient
availablestring (numeric)the balance available for swap, including the amount locked by other swaps
requiredstring (numeric)the amount required to start the swap. This amount is necessary but may not be sufficient
locked_by_swapsstring (numeric, optional)the amount is locked by other swaps

The specified volume is too low. Required at least threshold.

If the coin field returned in Response is the same as the rel argument in Request, then the base volume threshold can be calculated as follows: base_coin_threshold = rel_vol_threshold / price

ParameterTypeDescription
coinstringeither base or rel coin specified in Request
volumestring (numeric)the amount the user was willing to trade in coin
thresholdstring (numeric)the volume has not to be less than this amount

The specified coin was not found or is not activated yet.

ParameterTypeDescription
coinstringeither base or rel coin specified in Request

The specified coin is wallet only and cannot be participated in the swap.

ParameterTypeDescription
coinstringeither base or rel coin specified in Request

The coin is wallet only and cannot be participated in the swap.

ParameterTypeDescription
(none)

Incorrect use of the param parameter in Request.

ParameterTypeDescription
paramstringthe name of the parameter in Request
reasonstringthe reason why the parameter is used incorrectly

The specified price is too low.

ParameterTypeDescription
pricestring (numeric)the price in rel the user was willing to receive per one unit of the base coin
thresholdstring (numeric)the price has not to be less than this amount

The request was failed due to a network error.

ParameterTypeDescription
(none)stringthe transport error description

The request was failed due to a Komodo DeFi Framework API internal error.

ParameterTypeDescription
(none)stringthe internal error description

Trade Preimage (setprice)

POST
trade_preimage
{
  "mmrpc": "2.0",
  "userpass": "RPC_UserP@SSW0RD",
  "method": "trade_preimage",
  "params": {
    "base": "BTC",
    "rel": "DOC",
    "price": "1",
    "volume": "0.1",
    "swap_method": "setprice"
  },
  "id": 0
}

Trade Preimage (buy)

POST
trade_preimage
{
  "mmrpc": "2.0",
  "userpass": "RPC_UserP@SSW0RD",
  "method": "trade_preimage",
  "params": {
    "base": "BTC",
    "rel": "DOC",
    "price": "1",
    "volume": "0.1",
    "swap_method": "buy"
  },
  "id": 0
}

Trade Preimage (sell, max)

POST
trade_preimage
{
  "mmrpc": "2.0",
  "userpass": "RPC_UserP@SSW0RD",
  "method": "trade_preimage",
  "params": {
    "base": "BTC",
    "rel": "DOC",
    "price": "1",
    "volume": "2.21363478",
    "swap_method": "sell"
  },
  "id": 0
}

Trade Preimage (ERC20 and QRC20)

POST
trade_preimage
{
  "mmrpc": "2.0",
  "userpass": "RPC_UserP@SSW0RD",
  "method": "trade_preimage",
  "params": {
    "base": "BAT",
    "rel": "QC",
    "price": "1",
    "volume": "2.21363478",
    "swap_method": "setprice"
  },
  "id": 0
}