trade_preimage
**trade_preimage (deprecated) **
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_methodisbuyorsell, then the result will include thetaker_feeand thefee_to_send_taker_fee. Thetaker_feeamount is paid from thebasecoin balance if theswap_methodissell, else it is paid from therelcoin balance; - If the
maxfield is true, then the result will include thevolume.
Arguments
| Structure | Type | Description |
|---|---|---|
| base | string | the base currency of the request |
| rel | string | the rel currency of the request |
| swap_method | string | the name of the method whose preimage is requested. Possible values: buy, sell, setprice |
| price | numeric string or rational | the price in rel the user is willing to pay per one unit of the base coin |
| volume | numeric string or rational (optional) | the amount the user is willing to trade; ignored if max = true and swap_method = setprice, otherwise, it must be set |
| max | bool (optional) | whether to return the maximum available volume for setprice method; must not be set or false if swap_method is buy or sell |
Response
| Structure | Type | Description |
|---|---|---|
| result | object | an object containing the relevant information |
| base_coin_fee | object | A standard ExtendedFeeInfo object. The approximate miner fee is paid per the whole swap concerning the base coin |
| rel_coin_fee | object | A standard ExtendedFeeInfo object. The approximate miner fee is paid per the whole swap concerning the rel coin |
| volume | string (numeric) | Optional. The max available volume that can be traded (in decimal representation); empty if the max argument is missing or false |
| volume_rat | rational | Optional. The max available volume that can be traded represented as a standard RationalValue object.; empty if the max argument is missing or false |
| volume_fraction | fraction | Optional. The max available volume that can be traded represented as a standard fractionalValue object.; empty if the max argument is missing or false |
| taker_fee | object | A standard ExtendedFeeInfo object. The dex fee to be paid by Taker; empty if swap_method is setprice |
| fee_to_send_taker_fee | object | A standard ExtendedFeeInfo object. The approximate miner fee is paid to send the dex fee; empty if swap_method is setprice |
| total_fees | array of objects | A 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 |
📌 Examples
Command (setprice)
POST trade_preimage
{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "DOC",
"rel": "BTC",
"price": "1",
"volume": "0.1",
"swap_method": "setprice"
} curl --url "http://127.0.0.1:7783" --data '{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "DOC",
"rel": "BTC",
"price": "1",
"volume": "0.1",
"swap_method": "setprice"
}' import requests
import json
url = "http://127.0.0.1:7783"
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "DOC",
"rel": "BTC",
"price": "1",
"volume": "0.1",
"swap_method": "setprice"
}
response = requests.post(url, json=payload)
print(json.dumps(response.json(), indent=2)) const payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "DOC",
"rel": "BTC",
"price": "1",
"volume": "0.1",
"swap_method": "setprice"
};
const response = await fetch("http://127.0.0.1:7783", {
method: "POST",
body: JSON.stringify(payload),
});
console.log(await response.json()); <?php
$payload = <<<'JSON'
{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "DOC",
"rel": "BTC",
"price": "1",
"volume": "0.1",
"swap_method": "setprice"
}
JSON;
$ch = curl_init("http://127.0.0.1:7783");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
echo $response; package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{"userpass":"RPC_UserP@SSW0RD","method":"trade_preimage","base":"DOC","rel":"BTC","price":"1","volume":"0.1","swap_method":"setprice"}`)
resp, err := http.Post("http://127.0.0.1:7783", "application/json", bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
} require 'net/http'
require 'json'
require 'uri'
uri = URI("http://127.0.0.1:7783")
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "DOC",
"rel": "BTC",
"price": "1",
"volume": "0.1",
"swap_method": "setprice"
}
response = Net::HTTP.post(uri, payload.to_json, 'Content-Type' => 'application/json')
puts JSON.pretty_generate(JSON.parse(response.body)) Show Response
Response
{
"result": {
"base_coin_fee": {
"coin": "DOC",
"amount": "0.00001",
"amount_fraction": {
"numer": "1",
"denom": "100000"
},
"amount_rat": [
[1, [1]],
[1, [100000]]
],
"paid_from_trading_vol": false
},
"rel_coin_fee": {
"coin": "BTC",
"amount": "0.00029211",
"amount_fraction": {
"numer": "29211",
"denom": "100000000"
},
"amount_rat": [
[1, [29211]],
[1, [100000000]]
],
"paid_from_trading_vol": true
},
"total_fees": [
{
"coin": "DOC",
"amount": "0.00001",
"amount_fraction": {
"numer": "1",
"denom": "100000"
},
"amount_rat": [
[1, [1]],
[1, [100000]]
],
"required_balance": "0.00001",
"required_balance_fraction": {
"numer": "1",
"denom": "100000"
},
"required_balance_rat": [
[1, [1]],
[1, [100000]]
]
},
{
"coin": "BTC",
"amount": "0.00029211",
"amount_fraction": {
"numer": "29211",
"denom": "100000000"
},
"amount_rat": [
[1, [29211]],
[1, [100000000]]
],
"required_balance": "0",
"required_balance_fraction": {
"numer": "0",
"denom": "1"
},
"required_balance_rat": [
[0, []],
[1, [1]]
]
}
]
}
} Command (buy)
POST trade_preimage
{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BTC",
"rel": "DOC",
"price": "1",
"volume": "0.1",
"swap_method": "buy"
} curl --url "http://127.0.0.1:7783" --data '{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BTC",
"rel": "DOC",
"price": "1",
"volume": "0.1",
"swap_method": "buy"
}' import requests
import json
url = "http://127.0.0.1:7783"
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BTC",
"rel": "DOC",
"price": "1",
"volume": "0.1",
"swap_method": "buy"
}
response = requests.post(url, json=payload)
print(json.dumps(response.json(), indent=2)) const payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BTC",
"rel": "DOC",
"price": "1",
"volume": "0.1",
"swap_method": "buy"
};
const response = await fetch("http://127.0.0.1:7783", {
method: "POST",
body: JSON.stringify(payload),
});
console.log(await response.json()); <?php
$payload = <<<'JSON'
{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BTC",
"rel": "DOC",
"price": "1",
"volume": "0.1",
"swap_method": "buy"
}
JSON;
$ch = curl_init("http://127.0.0.1:7783");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
echo $response; package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{"userpass":"RPC_UserP@SSW0RD","method":"trade_preimage","base":"BTC","rel":"DOC","price":"1","volume":"0.1","swap_method":"buy"}`)
resp, err := http.Post("http://127.0.0.1:7783", "application/json", bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
} require 'net/http'
require 'json'
require 'uri'
uri = URI("http://127.0.0.1:7783")
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BTC",
"rel": "DOC",
"price": "1",
"volume": "0.1",
"swap_method": "buy"
}
response = Net::HTTP.post(uri, payload.to_json, 'Content-Type' => 'application/json')
puts JSON.pretty_generate(JSON.parse(response.body)) Show Response
Response
{
"result": {
"base_coin_fee": {
"coin": "BTC",
"amount": "0.00029211",
"amount_fraction": {
"numer": "29211",
"denom": "100000000"
},
"amount_rat": [
[1, [29211]],
[1, [100000000]]
],
"paid_from_trading_vol": true
},
"rel_coin_fee": {
"coin": "DOC",
"amount": "0.00001",
"amount_fraction": {
"numer": "1",
"denom": "100000"
},
"amount_rat": [
[1, [1]],
[1, [100000]]
],
"paid_from_trading_vol": false
},
"taker_fee": {
"coin": "DOC",
"amount": "0.0001287001287001287001287001287001287001287001287001287001287001287001287001287001287001287001287001287",
"amount_fraction": {
"numer": "1",
"denom": "7770"
},
"amount_rat": [
[1, [1]],
[1, [7770]]
],
"paid_from_trading_vol": false
},
"fee_to_send_taker_fee": {
"coin": "DOC",
"amount": "0.00001",
"amount_fraction": {
"numer": "1",
"denom": "100000"
},
"amount_rat": [
[1, [1]],
[1, [100000]]
],
"paid_from_trading_vol": false
},
"total_fees": [
{
"coin": "BTC",
"amount": "0.00029211",
"amount_fraction": {
"numer": "29211",
"denom": "100000000"
},
"amount_rat": [
[1, [29211]],
[1, [100000000]]
],
"required_balance": "0",
"required_balance_fraction": {
"numer": "0",
"denom": "1"
},
"required_balance_rat": [
[0, []],
[1, [1]]
]
},
{
"coin": "DOC",
"amount": "0.0001487001287001287001287001287001287001287001287001287001287001287001287001287001287001287001287001287",
"amount_fraction": {
"numer": "5777",
"denom": "38850000"
},
"amount_rat": [
[1, [5777]],
[1, [38850000]]
],
"required_balance": "0.0001487001287001287001287001287001287001287001287001287001287001287001287001287001287001287001287001287",
"required_balance_fraction": {
"numer": "5777",
"denom": "38850000"
},
"required_balance_rat": [
[1, [5777]],
[1, [38850000]]
]
}
]
}
} Command (ERC20 and QRC20)
POST trade_preimage
{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BAT",
"rel": "QC",
"price": "1",
"volume": "2.21363478",
"swap_method": "setprice"
} curl --url "http://127.0.0.1:7783" --data '{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BAT",
"rel": "QC",
"price": "1",
"volume": "2.21363478",
"swap_method": "setprice"
}' import requests
import json
url = "http://127.0.0.1:7783"
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BAT",
"rel": "QC",
"price": "1",
"volume": "2.21363478",
"swap_method": "setprice"
}
response = requests.post(url, json=payload)
print(json.dumps(response.json(), indent=2)) const payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BAT",
"rel": "QC",
"price": "1",
"volume": "2.21363478",
"swap_method": "setprice"
};
const response = await fetch("http://127.0.0.1:7783", {
method: "POST",
body: JSON.stringify(payload),
});
console.log(await response.json()); <?php
$payload = <<<'JSON'
{
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BAT",
"rel": "QC",
"price": "1",
"volume": "2.21363478",
"swap_method": "setprice"
}
JSON;
$ch = curl_init("http://127.0.0.1:7783");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
echo $response; package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{"userpass":"RPC_UserP@SSW0RD","method":"trade_preimage","base":"BAT","rel":"QC","price":"1","volume":"2.21363478","swap_method":"setprice"}`)
resp, err := http.Post("http://127.0.0.1:7783", "application/json", bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
} require 'net/http'
require 'json'
require 'uri'
uri = URI("http://127.0.0.1:7783")
payload = {
"userpass": "RPC_UserP@SSW0RD",
"method": "trade_preimage",
"base": "BAT",
"rel": "QC",
"price": "1",
"volume": "2.21363478",
"swap_method": "setprice"
}
response = Net::HTTP.post(uri, payload.to_json, 'Content-Type' => 'application/json')
puts JSON.pretty_generate(JSON.parse(response.body)) Show Response
Response
{
"result": {
"base_coin_fee": {
"amount": "0.0045",
"amount_fraction": {
"denom": "2000",
"numer": "9"
},
"amount_rat": [
[1, [9]],
[1, [2000]]
],
"coin": "ETH",
"paid_from_trading_vol": false
},
"rel_coin_fee": {
"amount": "0.00325",
"amount_fraction": {
"denom": "4000",
"numer": "13"
},
"amount_rat": [
[0, [13]],
[1, [4000]]
],
"coin": "QTUM",
"paid_from_trading_vol": false
},
"total_fees": [
{
"amount": "0.003",
"amount_fraction": {
"denom": "1000",
"numer": "3"
},
"amount_rat": [
[1, [3]],
[1, [1000]]
],
"required_balance": "0.003",
"required_balance_fraction": {
"denom": "1000",
"numer": "3"
},
"required_balance_rat": [
[1, [3]],
[1, [1000]]
],
"coin": "ETH"
},
{
"amount": "0.00325",
"amount_fraction": {
"denom": "4000",
"numer": "13"
},
"amount_rat": [
[0, [13]],
[1, [4000]]
],
"required_balance": "0.00325",
"required_balance_fraction": {
"denom": "4000",
"numer": "13"
},
"required_balance_rat": [
[0, [13]],
[1, [4000]]
],
"coin": "QTUM"
}
]
}
}