# # Order Binary Format

Learn more about order.

An exchange transaction of version 3 can accept orders of versions 1–4.

An exchange transaction of version 2 can accept orders of versions 1–3.

An exchange transaction of version 1 can accept orders of version 1 only.

## # Version 4

Binary format of order version 4 is defined in order.proto protobuf scheme. For information about protobuf see Protocol Buffers Developer Guide.

Version 4 is enabled by feature #15 “Ride V4, VRF, Protobuf, Failed transactions”.

```
message AssetPair {
bytes amount_asset_id = 1;
bytes price_asset_id = 2;
};
message Order {
enum Side {
BUY = 0;
SELL = 1;
};
enum PriceMode {
DEFAULT = 0;
FIXED_DECIMALS = 1;
ASSET_DECIMALS = 2;
};
int32 chain_id = 1;
bytes matcher_public_key = 3;
AssetPair asset_pair = 4;
Side order_side = 5;
int64 amount = 6;
int64 price = 7;
int64 timestamp = 8;
int64 expiration = 9;
Amount matcher_fee = 10;
int32 version = 11;
repeated bytes proofs = 12;
PriceMode price_mode = 14;
bytes attachment = 15;
oneof sender {
bytes sender_public_key = 2;
bytes eip712_signature = 13;
}
};
message Amount {
bytes asset_id = 1;
int64 amount = 2;
};
```

Field | Size | Description |
---|---|---|

chain_id | 1 byte | Chain ID |

matcher_public_key | 32 bytes | Public key of matcher |

asset_pair.amount_asset_id | • 32 bytes for asset • 0 for WAVES | ID of the amount asset |

asset_pair.price_asset_id | • 32 bytes for asset • 0 for WAVES | ID of the price asset |

order_side | 1 byte | Order type: buy or sell |

amount | 8 bytes | Amount of the amount asset, specified in the minimum fraction (“cent”) of asset |

price | 8 bytes | Price for the amount asset nominated in the price asset, multiplied by the factor: • 10 ^{8} for order version 4 with `priceMode = DEFAULT` or `priceMode = FIXED_DECIMALS` ;• 10 ^{8 + priceAssetDecimals – amountAssetDecimals} for order version 4 with `priceMode = ASSET_DECIMALS` , where `amountAssetDecimals` and `priceAssetDecimals` are the number of decimal places of amount asset and price asset respectively (token parameter) |

timestamp | 8 bytes | Order timestamp: Unix time in milliseconds |

expiration | 8 bytes | Unix time in milliseconds when the order will be expired |

matcher_fee.asset_id | • 32 bytes for asset • 0 for WAVES | Matcher fee token ID |

matcher_fee.amount | 8 bytes | Matcher fee |

version | 1 byte | Order version: 4 |

proofs | Each proof up to 64 bytes, up to 8 proofs | Order proofs that are used to check the validity of the order |

price_mode | 1 byte | Mode of specifying the `price` field. The field is enabled by feature #17 |

sender | • 32 bytes for the order with Waves signature • 65 bytes for the order signed in MetaMask | • For the order with Waves signature: the public key of the order sender • For the order signed in MetaMask: the ECDSA signature. MetaMask support is enabled by feature #17 “Ride V6, MetaMask support”. See details in the Sign transactions and orders in MetaMask article. |

attachment | 1024 bytes | Arbitrary data. The field is enabled by feature #22 “Light Node” |

## # Version 3

# | Field name | JSON field name | Field type | Length in bytes | Value |
---|---|---|---|---|---|

1 | Order binary format version number | version | Byte | 1 | must be 3 |

2 | Order sender public key | senderPublicKey | Array[Byte] | 32 | |

3 | Matcher public key | matcherPublicKey | Array[Byte] | 32 | |

4.1 | Asset B (amount asset) flag | Byte | 1 | If token is WAVES, then value is 0, else 1 | |

4.2 | Asset B (amount Asset) ID | amountAsset | Array[Byte] | `S` | If token is not WAVES, then `S` = 32, else the field should be absent |

5.1 | Asset A (price asset) flag | Byte | 1 | If token is WAVES, then value is 0, else 1 | |

5.2 | Asset A (price asset) ID | priceAsset | Array[Byte] | `S` | If token is not WAVES, then `S` = 32, else the field should be absent |

6 | Order type | orderType | Byte | 1 | If order is for buying, then value is 0, if order is for selling, then value is 1 |

7 | Amount of asset B (amount asset), which the order sender offers for one price asset(asset A) | price | Long | 8 | bytes in big-endian notation |

8 | Amount of asset B (price asset), which the order sender wants to buy or send depending on order type | amount | Long | 8 | bytes in big-endian notation |

9 | Amount of milliseconds from the beginning of Unix epoch till the moment of validation of order by matcher | timestamp | Long | 8 | bytes in big-endian notation |

10 | Amount of milliseconds from the beginning of Unix epoch till the unfulfilled order cancellation | expiration | Long | 8 | bytes in big-endian notation |

11 | Matcher fee | matcherFee | Long | 8 | bytes in big-endian notation |

12 | Matcher fee token flag | Byte | 1 | If token is WAVES, then value is 0, else 1 | |

13 | Matcher fee token | matcherFeeAssetId | Array[Byte] | `F` | If token is not WAVES, then `F` = 32, else the field should be absent |

14 | Proofs | proofs | Array[Proof] | `S` | If the array is empty, then `S` = 3.If the array is not empty, then `S` = 3 + 2 × `N` + (`P` _{1} + `P` _{2} + ... + `P` _{n}),where `N` is amount of proofs in the array,`P` _{n} — size N-th proof in bytes.Maximum amount of proofs in the array is 8. Maximum length of each proof is 64 bytes |

### # JSON Representation of Order Version 3

```
{
"version": 3,
"senderPublicKey": "FMc1iASTGwTC1tDwiKtrVHtdMkrVJ1S3rEBQifEdHnT2",
"matcherPublicKey": "7kPFrHDiGw1rCm7LPszuECwWYL3dMf6iMifLRDJQZMzy",
"assetPair": {
"amountAsset": "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa",
"priceAsset": null
},
"orderType": "buy",
"amount": 150000000,
"timestamp": 1548660872383,
"expiration": 1551252872383,
"matcherFee": 300000,
"proofs": [
"YNPdPqEUGRW42bFyGqJ8VLHHBYnpukna3NSin26ERZargGEboAhjygenY67gKNgvP5nm5ZV8VGZW3bNtejSKGEa"
],
"id": "Ho6Y16AKDrySs5VTa983kjg3yCx32iDzDHpDJ5iabXka",
"sender": "3PEFvFmyyZC1n4sfNWq6iwAVhzUT87RTFcA",
"price": 1799925005,
}
```

## # Version 2

# | Field name | Type | Length in Bytes |
---|---|---|---|

1 | Version | Byte (constant, value = 2) | 1 |

2 | Sender's public key | PublicKey (Array[Byte]) | 32 |

3 | Matcher's public key | PublicKey (Array[Byte]) | 32 |

4.1 | Amount asset flag (1 - asset, 0 - Waves) | Byte | 1 |

4.2 | Amount asset | AssetId (ByteStr = Array[Byte]) | 32 or 0 (depends on the byte in 4.1) |

5.1 | Price asset flag (1 - asset, 0 - Waves) | Byte | 1 |

5.2 | Price asset | AssetId (ByteStr = Array[Byte]) | 32 or 0 (depends on the byte in 5.1) |

6 | Order type (0 - Buy, 1 - Sell) | Byte | 1 |

7 | Price | Long | 8 |

8 | Amount | Long | 8 |

9 | Timestamp | Long | 8 |

10 | Expiration | Long | 8 |

11 | Matcher's fee | Long | 8 |

12 | Proofs | Proofs | See Proofs structure |

## # Version 1

# | Field name | Type | Length in Bytes |
---|---|---|---|

1 | Sender's public key | PublicKey (Array[Byte]) | 32 |

2 | Matcher's public key | PublicKey (Array[Byte]) | 32 |

3.1 | Amount asset flag (1 - asset, 0 - Waves) | 1 | |

3.2 | Amount asset | AssetId (ByteStr = Array[Byte]) | 32 or 0 (depends on the byte in 3.1) |

4.1 | Price asset flag (1 - asset, 0 - Waves) | 1 | |

4.2 | Price asset | AssetId (ByteStr = Array[Byte]) | 32 or 0 (depends on the byte in 4.1) |

5 | Order type (0 - Buy, 1 - Sell) | Byte | 1 |

6 | Price | Long | 8 |

7 | Amount | Long | 8 |

8 | Timestamp | Long | 8 |

9 | Expiration | Long | 8 |

10 | Matcher fee | Long | 8 |

11 | Signature | Bytes | 64 |

The price listed for amount asset in price asset * 10^8.

Expiration is order time to live, timestamp in future, max = 30 days in future.

The signature is calculated from the following bytes:

# | Field name | Type | Length in Bytes |
---|---|---|---|

1 | Sender's public key | PublicKey (Array[Byte]) | 32 |

2 | Matcher's public key | PublicKey (Array[Byte]) | 32 |

3.1 | Amount asset flag (1 - asset, 0 - Waves) | 1 | |

3.2 | Amount asset | AssetId (ByteStr = Array[Byte]) | 32 or 0 (depends on the byte in 3.1) |

4.1 | Price asset flag (1 - asset, 0 - Waves) | 1 | |

4.2 | Price asset | AssetId (ByteStr = Array[Byte]) | 32 or 0 (depends on the byte in 4.1) |

5 | Order type (0 - Buy, 1 - Sell) | Bytes | 1 |

6 | Price | Long | 8 |

7 | Amount | Long | 8 |

8 | Timestamp | Long | 8 |

9 | Expiration | Long | 8 |

10 | Matcher fee | Long | 8 |