owned this note
owned this note
Published
Linked with GitHub
## X2Y2 order APIS
#### API endpoint
- https://api.x2y2.org
#### AUTH Header
- 'X-API-KEY: xxxx'
#### Rate limit
- 10-20 qps
#### call example
```
curl --header "X-API-KEY: xxxx" https://api.x2y2.org/api/orders
```
### get orders
#### GET /api/orders
params
- created_after (unix timestamp and only used with open orders)
- updated_after (unix timestamp and only user with finished orders)
- offset (max 2000)
- limit (max 50)
- status (open/finished)
- contract
- contract + token_id
- contract + token_ids (send with comma-separated tokenId like `123,124,125`)
- maker
params info
- when status is `open`: return `open` orders listed after `created_after` (order by order created time)
- when status is `finished`: return `cancelled`/`done`orders after `updated_after` (order by order updated time)
- when `contract` exist: return contract `open` orders listed after `created_after` (order by order created time)
- when `contract` and `token_id` exist: return contract nft `open` orders
- when `contract` and `token_ids` exist: return contract nfts `open` orders
- when `maker` exist: return maker `open` orders listed after `created_after` (order by order created time)
how to use
- get open orders for all contract (order by order created time)
`GET /api/orders?status=open&created_after=1649660000`
- get open orders for a certain contract (order by order created time)
`GET /api/orders?status=open&contract=<contract_address>&created_after=1649660000`
- get open orders for one NFT (order by order created time)
`GET /api/orders?status=open&contract=<contract_address>&token_id=1&created_after=1649660000`
- get open orders for multiple NFT in same contract (order by order created time) deprecated and will remove later
`GET /api/orders?status=open&contract=<contract_address>&token_ids=1,2&created_after=1649660000`
- get open orders for user (sell orders only and order by order created time)
`GET /api/orders?status=open&maker=<maker_address>&created_after=1649660000`
- get done/cancelled orders for all contracts (sync order cancel and done events and order by order's update time)
`GET /api/orders?status=finished&updated_after=1649660000`
how to get all orders in one contract
using `/api/orders?status=open&contract=<contract_address>&offest=0&limit=50` to get orders page by page
how to sync latest orders for all contracts
using `/api/orders?status=open&created_after=1649660000`, in next query, your need to update the created_after with previous query's last order's created_at time. No orders returns means no new orders.
notice
- `contract` and `maker` filter can only be queried individually
- when `contract` or `maker` param exist, `status` can only be `open`
example response
```
{
"data": [
{
"id": 998522,
"side": 1,
"type": "sell", # maybe sell/auction
"status": "cancelled", # maybe open/done/cancelled
"currency": "0x0000000000000000000000000000000000000000",
"price": "7900000000000000000000",
"maker": "0xf69db6498a257701af68722280aa4193e5bfe76b",
"taker": null,
"end_at": 1646372611, # order expire time
"created_at": 1646113415, # order create time
"updated_at": 1646372643, # order update time(cancel/purchase will change this time)
"is_bundle": false,
"item_hash": "0x31fbe52206ab73c3e7fa1572cc05144fa17bfe158287bc1acaa347ee648a1ec5",
"nft": {
"token": "0x3702f4c46785bbd947d59a2516ac1ea30f2babf2",
"token_id": "1984"
}
}
],
"success": true
}
```
#### POST /api/orders/sign
```
{
"caller": "0x2794731a276e4446809E06C45C859797542d7D7f",
"op": 1,
"amountToEth": "0",
"amountToWeth": "0",
"items": [
{
"orderId": 990845,
"currency": "0x0000000000000000000000000000000000000000",
"price": "100000000000000000"
},
{
"orderId": 990840,
"currency": "0x0000000000000000000000000000000000000000",
"price": "190000000000000000"
}
]
}
```
- `caller` is wallet address making the purchase(this case is your contract address)
- op/amountToEth/amountToWeth fixed to given value
- items is orders to sign
response
```
{
"data": [
{
"input": "0x0000....",
"order_id": 990845
},
{
"input": "0x0000....",
"order_id": 990840
}
],
"success": true
}
```
response has error
```
{
"errors": [
{
"code": 2020,
"order_id": 1015421
}
],
"success": false
}
```
error_codes
- 2020: order cancelled
- 2021: order purchased
- 2028: contract/nft not allowed to trade(rug or hacked nft)
- 2030: order expired
#### POST /api/orders/cancel
```
{
"sign_message": "0x00..."
"sign": "0x00..."
"caller": "0x2794731a276e4446809E06C45C859797542d7D7f",
"op": 3,
"items": [
{
"orderId": 990845
},
{
"orderId": 990840
}
]
}
```
- `sign_message` keccak hex of the message to be signed by the maker
- `sign` message signature
- `caller` is the order maker(might not be your contract's address)
- op fixed to given value
- items is orders to sign
response
```
{
"data":{
"input": "0x0000....",
},
"success": true
}
```
response has error
```
{
"errors": [
{
"code": 2020,
"order_id": 1015421
}
],
"success": false
}
```
error_codes
- 2020: order cancelled
- 2021: order purchased
- 2028: contract/nft not allowed to trade(rug or hacked nft)
- 2030: order expired
#### POST /api/contracts/payment_info
```
{
"contracts": ["0x00", "0x01"],
"network_id": 1
}
```
response
base rate is 1e6
```
{
"code": 0,
"data": {
"0x00":{
"royalty_fee_rate": 50000,
}
},
"success": true
}
```
#### POST /api/orders/add
```
{
"order": "0x......",
"isBundle": false,
"bundleName": "",
"bundleDesc": "",
"orderIds": [],
"changePrice": false,
"isCollection": false,
}
```
- `order`: encoded Order Data(include signature data)
- isBundle/bundleName/bundleDesc/orderIds/changePrice/isCollection fixed to given value
response
```
{
"success": true
}
```
response has error
```
{
"error": 3002,
"success": false
}
```
error_codes
- 3002: intention sig error
- 3004: currency error(currently ETH for sell orders only)
- 2028: contract/nft not allowed to trade(rug or hacked nft)
- 2012: nft listing order already exist
- 1006: user banned from listing(rug/hacker address)
### x2y2-listing
Code examples: [x2y2-listing.md](https://gist.github.com/tp-x2y2/86643a0d5457e4ee648e2b195241b582)
### x2y2-buying
Code examples: [x2y2-buying.md](https://gist.github.com/zhangshenjie/3919eceb4aa67a07de80e58ea50ff864)
### x2y2-collection-offer
Code examples: [x2y2-collection-offer.md](https://gist.github.com/zhangshenjie/050f217a5e61b92ceafa3fee16304117)