# Order Validation Rules
When a new Order
is submitted to the Matcher the following conditions are validated.
# Matcher Settings Validation
The order is submitted to the matcher with the correct public key -
matcherPublicKey
parameter.The order sender address is not blacklisted by the matcher -
blacklistedAddresses
parameter.The token is not blacklisted by the matcher.
The fee token can be accepted by the matcher.
The order fee is not less than the matcher fee. Currently the fee must be not less than 0.003 WAVES or other token based on current token rates.
Amount and price checks:
0 <
amount
< MaxAmount = 10^180 <
price
0 <
corrected spent amount
< Long.MaxValuewhere
corrected spent amount
:If it is a
buy
order: = truncate(amount
*price
/PriceConstant
)otherwise: =
amount
0 <
corrected received amount
< Long.MaxValuewhere
corrected received amount
:if it is a
buy
order: =amount
otherwise: truncate (
amount
*price
/PriceConstant
)0 <
fee
< Long.MaxValue
PriceConstant
= 10^8
Time checks:
0 < timestamp
The order can be expired in (1 minute; 30 days] based on the matcher time. The
matcher time
in synchronized via NTP.matcher time
+ 60 * 1000 (60000 ms or 1 minute) <expiration
30 * 24 * 60 * 60 * 1000 (2592000000 ms or 30 days) <= (
expiration
-matcher time
)
Tick size checks:
- The order is
SELL
type or its price must be not less than tick size after correction. If there is a tick size the BUY order is placed in the same level with the price that equals the closest smallest multiple of the tick size.
Market checks (disabled by default):
The price of BUY order must be not more than the best buy price, the SELL order price must be not less than the best sell price.
Order fee must match the market, only for percentage matcher operation mode.
The fee must be in deviation bounds, i.e. orders's fee is higher than the specified percentage of fee, that the client would pay for the matching with the best counter order. Only applicable to the percent order fee mode.
For BUY orders: fee >= fs * (1 - fd) * best ask * amount
For SELL orders: fee >= fs * (1 - fd) * best bid * amount
where:
fs = fee in percent from order-fee settings (order-fee.percent.min-fee)/100
fd = max fee deviation / 100
best bid = highest price of buy
best ask = lowest price of sell
# Blockchain Validation
The order version is supported by the blockchain (version 2 requires feature 10 (SmartAccountTrading) enabled, version 3 requires feature 12 (OrderV3) enabled). WX Network Matcher in Mainnet and Testnet supports orders of version 1, 2 and 3.
Note: WX Network Matcher in Mainnet and Testnet operates in dynamic fee mode.
In dynamic fee mode, the fee specified in the order must be not less than minimal. The fee can be different for makers and takers. If the fee is paid in the token (other than WAVES) supported by the matcher, the fee must be not less than minimal in that token. The fee is calculated dynamically based on the
asset rate
(GET /matcher/settings/rates API method) by the following formula:baseFee
+0.004
* (number of involved scripts, excepting the account scripts) *asset rate
rounded up to the minimal decimal of the token. For example, if the fee token has decimals = 2 and the fee is 0.01399, then Matcher will charge 0.02 in the token.For every order the matcher calculates the number of
insignificantDecimals
= (price asset decimals
-amount asset decimals
).max(0)
. The price of the order must be the multiple of 10^insignificantDecimals
. The finalinsignificantDecimals
of the numbers must be zeros.Amount and price of the order must match the matcher's requirements for the max/min value and must be the multiple of
stepAmount
/stepPrice
accordingly (if there are such restrictions for the pair). The restrictions can be received with the endpoint GET /matcher/orderbook/{amountAsset}/{priceAsset}/info, restrictions field.The account script (if there is one) of the order owner must allow placing orders.
Scripts of the amount, price and matcher fee token (if there are any) must allow its usage in the order.
# Balance Validation
The order amount (including the order fee) must be not more that
Tradable Balance
, whereTradable Balance
= (your balance of the sold token and the fee token in the blockchain) - (all the spendings
+the reserved amount
)where:
all the spendings
means all the outgoing leases and all the spendings in UTX including fees. For example, if you transfer 10 WAVES from your address to another and pay 1 XTN fee, then your spendings are 10 WAVES + 1 XTN fee.the reserved amount
means the amount reserved in active orders including fees. For example, if you are selling 5 WAVES for 4 XTN in WAVES/XTN token pair with 0.001 BTC fee, then you have reserved 20 WAVES + 0.001 BTC fee.So, in this case the total of
all the spendings
+the reserved amount
is 30 WAVES, 1 XTN and 0.001 BTC.