# Exchange Transaction
Exchange transaction exchanges two different tokens between two accounts.
The Exchange transaction contains two counter orders: a buy order and a sell order. The blockchain guarantees that the terms of the exchange are not worse than those indicated in each order.
An order can be filled partially. An order can participate in several Exchange transactions, with different counter orders.
Commonly the Exchange transaction is created by the matcher service that executes orders to buy and sell tokens. An example of a matcher is the WX Network matcher, developed by a third-party team from the community, see the WX Network documentation.
In a pair of tokens to exchange, one is the amount asset (aka base currency) and the other is the price asset (aka quote currency). The Exchange transaction and included orders indicate the amount of the amount asset and its price in the price asset. For example, in the WAVES/XTN pair, the amount asset is WAVES and the price asset is XTN, so the transaction indicates the WAVES amount to exchange and the WAVES price nominated in XTN.
The amount of the price asset exchanged for the amount asset is calculated similarly to an order, see formulas and an example in the Order article.
# Transaction Fee
The minimum fee for an Exchange transaction is 0.003 WAVES. In case of exchange of a smart asset for an ordinary asset the minimum fee is 0.007 WAVES, in case of exchange of two smart assets the minimum fee is 0.011 WAVES.
If the transaction sender is a dApp or smart account, and the complexity of the account script or dApp script verifier function exceeds the sender complexity threshold, the minimum fee is increased by 0.004 WAVES. (Before activation of feature #16 “Ride V5, dApp-to-dApp invocations”, the extra fee of 0.004 WAVES was required regardless of the complexity of the account script or the presence and complexity of the dApp script verifier function.)
⚠️ The minimum fee is not increased if the order is sent from a smart account or dApp, or the matcher fee is specified in a smart asset.
# Matcher Fee
The matcher receives a fee for order execution from each order senders. The minimum matcher fee is set by the matcher. The order sender specifies the fee not less than the minimum amount.
If the order is fully filled with one Exchange transaction, the matcher receives the entire fee specified in the order. If the order is partially filled, the matcher receives a part of the fee. The blockchain guarantees that the total matcher fee received from the order sender in all Exchange transactions does not exceed the fee specified in the order.
# JSON Representation
{
"senderPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
"amount": 100000000,
"fee": 300000,
"type": 7,
"version": 2,
"sellMatcherFee": 750,
"sender": "3PEjHv3JGjcWNpYEEkif2w8NXV4kbhnoGgu",
"feeAssetId": null,
"proofs": [
"LQD8VoFhHEW2b6o2e2ujzDHdZatwMMwigC2tmoSHcFNRGXrowA1yyVxD6nZBNeABLWjs59dnuLhgNP7UMfFKDuR"
],
"price": 1134500,
"id": "EHLccXcemZPEvUpM9UkASG1GciwMt9R5B3QuYFxywj9g",
"order2": {
"version": 3,
"id": "JCiF3gmprLc8u7xdWR7KUkJ3YfM6yfgxB6CvhJYGJFAa",
"sender": "3PRBeeFD64wvTMfS3HEoDDFPXfJs3gFdAxk",
"senderPublicKey": "ytgWVbKG9e6TSsQ5buMryr2QyxNoL3RezXP3f9RJ2As",
"matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
"assetPair": {
"amountAsset": null,
"priceAsset": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"
},
"orderType": "sell",
"amount": 40000000000,
"price": 1134500,
"timestamp": 1591356602063,
"expiration": 1593862202062,
"matcherFee": 300000,
"matcherFeeAssetId": null,
"signature": "3D2Ngr7H6MQRs1izMQSix3dMHmDfg4bcRjxamFXFsb4Ku28neNWHdtwE6LtR3eq69Jqr1CvEsAKCWkQEeEEomcoK",
"proofs": [
"3D2Ngr7H6MQRs1izMQSix3dMHmDfg4bcRjxamFXFsb4Ku28neNWHdtwE6LtR3eq69Jqr1CvEsAKCWkQEeEEomcoK"
]
},
"order1": {
"version": 3,
"id": "FNvEGPgUqEWnrnpxevZQnaZS3DUTBGE2wa6L75xCw7mo",
"sender": "3PDxxx7eSeYLgzTAtuAV7gUCtHeeXeU85fP",
"senderPublicKey": "3WEkbavP3Sw4y5tsgxbZvKkWh87BdB3CPVVxhcRUDBsJ",
"matcherPublicKey": "9cpfKN9suPNvfeUNphzxXMjcnn974eme8ZhWUjaktzU5",
"assetPair": {
"amountAsset": null,
"priceAsset": "DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p"
},
"orderType": "buy",
"amount": 100000000,
"price": 1134500,
"timestamp": 1591356752271,
"expiration": 1593862352271,
"matcherFee": 300000,
"matcherFeeAssetId": null,
"signature": "2gvqaYy2BFbK4BJZS8taRJnhgfQ1z2CytF2RqjcyEfzFiu9tkTjN5q4UyFXpPqS3E6eD2WQBUaYCTYDKv98iW1sy",
"proofs": [
"2gvqaYy2BFbK4BJZS8taRJnhgfQ1z2CytF2RqjcyEfzFiu9tkTjN5q4UyFXpPqS3E6eD2WQBUaYCTYDKv98iW1sy"
]
},
"buyMatcherFee": 300000,
"timestamp": 1591356752456,
"height": 2093333
}
Field | Description |
---|---|
amount | Amount of the amount asset: an integer value specified in the minimum fraction (“cent”) of asset |
price | Price for the amount asset nominated in the price asset, multiplied by the factor: - 108 for the Exchange transaction version 3; - 108 + priceAssetDecimals – amountAssetDecimals, where amountAssetDecimals , priceAssetDecimals are decimals of the assets, for the Exchange transaction version 2 or 1 |
buyMatcherFee | Matcher fee for the buy order execution. The fee token ID is indicated in buy order |
sellMatcherFee | Matcher fee for the sell order execution. The fee token ID is indicated in sell order |
order1, order2 | Buy and sell orders. See the Order article for details |
The fields that are common to all types of transactions are described in the Transaction article.
# Binary Format
See the Exchange Transaction Binary Format article.
# Ride Structure
The ExchangeTransaction structure is used for transaction handling in smart contracts.