# Upcoming Matcher Mechanics (mid February 2022)
Attention: The following article describes mechanics that will be supported in the upcoming version of matcher that is planned to be released in mid February 2022. This info can be used by developers of trading bots etc.
The upcoming version of matcher will have new fee mechanics.
The matcher will charge either dynamic
or percent
type of fee depending on the selected trading pair.
Dynamic fee mode is similar to the old setup. Matcher will charge 0.01 WAVES fixed fee for trade orders.
Percent fee mode is the mechanic when matcher charges 0.1% of the exchange transaction amount but not less than equivalent of 0.01 WAVES. WX Network matcher will charge percent fee in the token that you spend. For example, if you exchange XTN to get BTC (you spend XTN), you pay the fee in XTN. Or if you exchange BTC to get XTN (you spend BTC), then you pay fee in BTC.
Important: Both types of fee (dynamic and percent) can be optionally paid in WX token at 75% of the normal price.
You can use POST /matcher/orderbook/calculateFee method to calculate fees for a pair.
GET /matcher/settings method allows to find out the type of fee (dynamic or percent) that is used for a trading pair and other matcher setting.
Note: We recommend to request settings at least once per minute, so that you don't miss the changes of percent pairs.
Request example (testnet):
curl -X 'GET' 'https://matcher-testnet.waves.exchange/matcher/settings' -H 'accept: application/json'
Matcher settings response example (testnet):
"orderFee": {
"composite": {
"default": {
"dynamic": {
"baseFee": 1000000
}
},
"custom": {
"5Sh9KghfkZyhjwuodovDhB6PghDUGBHiAPZ4MkrPgKtX-25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT": {
"percent": {
"type": "spending",
"minFee": 0.1,
"minFeeInWaves": 1000000
}
},
"WAVES-25FEqEjRkqK6yCkiT7Lz6SAYz7gUFCtxfCChnrVFD5AT": {
"percent": {
"type": "spending",
"minFee": 0.1,
"minFeeInWaves": 1000000
}
}
},
"discount": {
"assetId": "EMAMLxDnv3xiz8RXg8Btj33jcEw3wLczL3JKYYmuubpc",
"value": 50
}
}
}
orderFee
is one of the fields returned by GET /matcher/settings
method.
As you can see, in the example there can be pairs that have dynamic
fee mode and a pairs that have percent
fee mode.
See percent
mode parameters:
type
- type of asset that should be used to pay fee. Can beamount
- theamountAsset
,price
- thepriceAsset
,spending
- the asset being spent,receiving
- the received token. WX Network matcher usesspending
type.minFee
- minimal fraction of the order amount that should be payed as fee. Where 0.14 is 0.14%minFeeInWaves
- minimal value of fee in WAVES (regardless of the order amount, the fee should be greater than or equalminFeeInWaves
)
Also, note the discount
section that describes parameters of discount on fees paid with discountAsset
:
asset
- is the ID ofdiscountAsset
.value
indicates50
percent discount.
# Calculating minimal fees for different fee types
Depending on the fee mode matcher charges fees in various tokens.
For trading pairs with
Dynamic
fee mode the fees can be paid inWAVES
or inWX
(discountAsset
) token.For trading pairs with
Percent
fee mode the fees can be paid either inpriceAsset
(for buy orders) or inamountAsset
(for sell orders) or otherwise inWX
(discountAsset
) token.
The fee rates used in the following calculations can be obtained by means of GET /matcher/settings/rates method.
Request example:
curl -X 'GET' 'https://matcher.waves.exchange/matcher/rates' -H 'accept: application/json
# Constants
PriceConstantExp = 8
PriceConstant = 10 ** PriceConstantExp
# Functions
correctedRate(rate, assetDecimals) = rate * 10 ** (assetDecimals - PriceConstantExp)
scripts_count
is the number of smart script runs that are required to validate the order.
# Calculation of minimal fee for Dynamic fee mode
Using WAVES
:
baseFee + 400000 * scripts_count
Using discountAsset
:
rate = correctedRate(rates[discountAsset], discountAssetDecimals)
(baseFee + 400000 * scripts_count) * correctedRate * (100 - discount) / 100
# Calculation of minimal fee for Percent fee with the following settings:
{
"percent" : {
"type" : "spending",
"minFee" : 0.14,
"minFeeInWaves" : 300000
}
}
Selling fee:
Using amountAsset
:
rate = correctedRate(rates[amountAsset], amountAssetDecimals)
order.amount * minFee / 100
Using discountAsset
:
discountAssetRate = correctedRate(rates[discountAsset], discountAssetDecimals)
amountAssetRate = correctedRate(rates[amountAsset], amountAssetDecimals)
order.amount * minFee / 100 * (discountAssetRate / amountAssetRate) * (100 - discount) / 100
Buying fee:
Using priceAsset
:
rate = correctedRate(rates[priceAsset], priceAssetDecimals)
order.amount * order.price / PriceConstant * minFee / 100
Using discountAsset
:
discountAssetRate = correctedRate(rates[discountAsset], discountAssetDecimals)
priceAssetRate = correctedRate(rates[priceAsset], priceAssetDecimals)
order.amount * order.price / PriceConstant * minFee / 100 * (discountAssetRate / priceAssetRate) * (100 - discount) / 100
You should check that the fee is not less than minFeeInWaves
, to do so multiply minFeeInWaves
by the adjusted FeeAssetRate
and
compare with your fee. The discount also applies to minFeeInWaves
when using discountAsset
to pay fees.
# Example
Note: In this example no script runs are required to validate order.
Lets trade 0.00032173 BTC by 42611.43
pair
= BTC/XTN
price
= 42611430000
amount
= 32173
order amount in:
price assets = 13.709237 XTN
amount assets = 0.00032173 BTC
rates[BTC] = 0.000329
rates[XTN] = 13.9
rates[discountAsset] = 10.534
corrected rates:
priceAsset
= rates[XTN] * 10 ** (-2) = 0.1390amountAsset
= rates[BTC] = 0.000329discountAsset
= rates[discountAsset] = 10.534
minFee
= 0.14%
minFeeInWaves
= 300000
discount
= 50%
priceAssetDecimals
= 6
amountAssetDecimals
= 8
discountAssetDecimals
= 8
minFeeInWaves
converted:
priceAsset
= 41700amountAsset
= 98discountAsset
= 3160200
# Calculating the fees
Selling fee in Percent fee mode:
Using amountAsset
:
32173 * 0.14 / 100 = 45 (0.00000045 BTC ~ 0.019 XTN)
Using discountAsset
:
32173 * 0.14 / 100 * (10.534 / 0.000329) * (100 - 50) / 100 = 721085
Buying fee:
Using priceAsset
:
32173 * 42611430000 / 100000000 * 0.14 / 100 = 19193 (0.019 XTN)
Using discountAsset
:
32173 * 42611430000 / 100000000 * 0.14 / 100 * (10.534 / 0.139) * (100 - 50) / 100 = 727267
# Check minFeeInWaves
When paying in priceAsset
:
300000 * 0.139 = 41700 (0,041700 XTN)
When paying in amountAsset
:
300000 * 0.000329 = 99 (0,00000099 BTC)
When paying in discountAsset
:
300000 * 10.534 * (100 - 50) / 100 = 1580100 (0,015801 discountAsset)
Note: In all the example scenarios above the fee is less than minFeeInWaves
.