|
| 1 | +# Monitoring Orders |
| 2 | + |
| 3 | +Once an order has been successfully created on-chain, its state can be monitored using several available methods, depending on the use case. For a full overview of order states and their transitions, refer to the [Order States](order-states.md) documentation.  |
| 4 | + |
| 5 | +## Key Completion States |
| 6 | + |
| 7 | +Orders progress through multiple internal states. However, from the perspective of the end-user experience, the following states indicate successful completion: |
| 8 | + |
| 9 | +* `Fulfilled`  |
| 10 | +* `SentUnlock`  |
| 11 | +* `ClaimedUnlock` |
| 12 | + |
| 13 | +{% hint style="success" %} |
| 14 | +Any of these states can be treated as successfully completed final state for application-level logic. |
| 15 | +{% endhint %} |
| 16 | + |
| 17 | +## Quick Start |
| 18 | + |
| 19 | +* **Base URL:**`https://stats-api.dln.trade`  |
| 20 | +* **Full endpoint reference:** [Swagger](https://dln-api.debridge.finance/swagger/index.html#/Orders/Orders_GetOrderByCreationTx) and [Redoc](https://stats-api.dln.trade/redoc/index.html?url=/swagger/v1/swagger.json#tag/Orders/operation/Orders_GetOrders) |
| 21 | +* **Examples**: See the implementation examples in [this GitHub repository](https://github.com/debridge-finance/api-integrator-example/tree/master/src/scripts/orders/queries). |
| 22 | + |
| 23 | +## Querying Orders |
| 24 | + |
| 25 | +### By Wallet Address |
| 26 | + |
| 27 | +The [`POST /api/Orders/filteredList`](https://stats-api.dln.trade/redoc/index.html?url=/swagger/v1/swagger.json#tag/Orders/operation/Orders_GetOrders) endpoint retrieves the current state and historical data for all orders associated with a wallet address. This endpoint is also used to populate the trade history view in [deExplorer](https://app.debridge.finance/orders), which can serve as a reference implementation. Pagination is supported via `skip` and `take` parameters. |
| 28 | + |
| 29 | +#### Example: Fetching Completed Orders for a Wallet |
| 30 | + |
| 31 | +```typescript |
| 32 | +const URL = 'https://stats-api.dln.trade/api/Orders/filteredList'; |
| 33 | + |
| 34 | +const requestBody = { |
| 35 | + orderStates: ['Fulfilled', 'SentUnlock', 'ClaimedUnlock' ], |
| 36 | + externalCallStates: ['NoExtCall'], |
| 37 | + skip: 0, |
| 38 | + take: 10, |
| 39 | + maker: '0x441bc84aa07a71426f4d9a40bc40ac7183d124b9', |
| 40 | +}; |
| 41 | + |
| 42 | +const data = await post(URL, requestBody); |
| 43 | +``` |
| 44 | + |
| 45 | +#### Example: Filtering Completed Orders by Destination Chain (e.g. HyperEVM) |
| 46 | + |
| 47 | +```typescript |
| 48 | +const requestBody = { |
| 49 | + giveChainIds: [], |
| 50 | + takeChainIds: [100000022], // HyperEVM Chain Id |
| 51 | + orderStates: ['Fulfilled', 'SentUnlock', 'ClaimedUnlock' ], |
| 52 | + externalCallStates: ['NoExtCall'], |
| 53 | + skip: 0, |
| 54 | + take: 10, |
| 55 | + maker: '0x441bc84aa07a71426f4d9a40bc40ac7183d124b9', |
| 56 | + }; |
| 57 | +``` |
| 58 | + |
| 59 | +## By Transaction Hash |
| 60 | + |
| 61 | +For inspecting a specific order, the [`GET /api/Orders/creationTxHash/{hash}`](https://dln-api.debridge.finance/swagger/index.html#/Orders/Orders_GetOrderByCreationTx) endpoint returns full order details as shown on the [deExplorer order page](https://app.debridge.finance/order?orderId=0x87daf0659e138c13aecb59e1b044c5e296d2811188cd6812c78425273ebd064e). |
| 62 | + |
| 63 | +**Example:** |
| 64 | + |
| 65 | +> [https://stats-api.dln.trade/api/Orders/creationTxHash/0x3fe11542154f53dcf3134eacb30ea5ca586c9e134c223e56bbe1893862469bc5](https://stats-api.dln.trade/api/Orders/creationTxHash/0x3fe11542154f53dcf3134eacb30ea5ca586c9e134c223e56bbe1893862469bc5) |
| 66 | +
|
| 67 | +{% hint style="warning" %} |
| 68 | +If multiple orders were created in a single transaction, this endpoint returns data only for the first order. |
| 69 | +{% endhint %} |
| 70 | + |
| 71 | +### Multiple orders created in the same transaction |
| 72 | + |
| 73 | +In cases where multiple orders are created in a single transaction, retrieve all order IDs using [`GET /api/Transaction/{hash}/orderIds`](https://dln-api.debridge.finance/swagger/index.html#/Orders/Orders_GetOrderByCreationTx) . |
| 74 | + |
| 75 | +For example, the transaction[`0x40ee524d5bb9c4ecd8e55d23c66c5465a3f137be7ae24df366c3fd06daf7de7e`](https://bscscan.com/tx/0x40ee524d5bb9c4ecd8e55d23c66c5465a3f137be7ae24df366c3fd06daf7de7e) has been submitted to the BNB Chain. Calling the endpoint: |
| 76 | + |
| 77 | +> [`https://stats-api.dln.trade/api/Transaction/0x40ee524d5bb9c4ecd8e55d23c66c5465a3f137be7ae24df366c3fd06daf7de7e/orderIds`](https://stats-api.dln.trade/api/Transaction/0x40ee524d5bb9c4ecd8e55d23c66c5465a3f137be7ae24df366c3fd06daf7de7e/orderIds) |
| 78 | +
|
| 79 | +The response is an array, even if the transaction resulted in only one order: |
| 80 | + |
| 81 | +```json |
| 82 | +{ |
| 83 | + "orderIds": [ |
| 84 | + "0x9ee6c3d0aa68a7504e619b02df7c71539d0ce10e27f593bf8604b62e51955a01" |
| 85 | + ] |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +{% hint style="info" %} |
| 90 | +An array instead of a single `orderId` is returned because a top-level transaction may perform several calls to DLN, thus leading to multiple orders being created. |
| 91 | +{% endhint %} |
| 92 | + |
| 93 | +#### Example: |
| 94 | + |
| 95 | +```typescript |
| 96 | +export async function getOrderIdByTransactionHash(txHash: string) { |
| 97 | + const URL = `https://stats-api.dln.trade/api/Transaction/${txHash}/orderIds`; |
| 98 | + |
| 99 | + const response = await fetch(URL); |
| 100 | + |
| 101 | + if (!response.ok) { |
| 102 | + const errorText = await response.text(); |
| 103 | + throw new Error( |
| 104 | + `Failed to get orderIds by transaction hash: ${response.statusText}. ${errorText}`, |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + const data = await response.json(); |
| 109 | + |
| 110 | + if (data.error) { |
| 111 | + throw new Error(`DeBridge API Error: ${data.error}`); |
| 112 | + } |
| 113 | + |
| 114 | + return data; |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +## By orderId |
| 119 | + |
| 120 | +The `orderId` is a deterministic identifier returned in the `create-tx` [response ](../creating-an-order/api-response/)or retrievable via the transaction hash.  |
| 121 | + |
| 122 | +An order state can be monitored directly by using [`GET /api/Orders/{orderId}`](https://stats-api.dln.trade/swagger/index.html#/Orders/Orders_GetOrder) . |
| 123 | + |
| 124 | +**Example:** |
| 125 | + |
| 126 | +> [`https://stats-api.dln.trade/api/Orders/0x9ee6c3d0aa68a7504e619b02df7c71539d0ce10e27f593bf8604b62e51955a01`](https://stats-api.dln.trade/api/Orders/0x9ee6c3d0aa68a7504e619b02df7c71539d0ce10e27f593bf8604b62e51955a01) |
| 127 | +
|
| 128 | +**Response:** |
| 129 | + |
| 130 | +```typescript |
| 131 | +{ |
| 132 | + "status": "ClaimedUnlock" |
| 133 | +} |
| 134 | +``` |
| 135 | + |
| 136 | +#### Example: |
| 137 | + |
| 138 | +```typescript |
| 139 | +export async function getOrderStatusByOrderId(orderId: string) { |
| 140 | + const URL = `https://stats-api.dln.trade/api/Orders/${orderId}` |
| 141 | + |
| 142 | + const response = await fetch(URL); |
| 143 | + |
| 144 | + if (!response.ok) { |
| 145 | + const errorText = await response.text(); |
| 146 | + throw new Error( |
| 147 | + `Failed to get order status by orderId: ${response.statusText}. ${errorText}`, |
| 148 | + ); |
| 149 | + } |
| 150 | + |
| 151 | + const data = await response.json(); |
| 152 | + |
| 153 | + if (data.error) { |
| 154 | + throw new Error(`DeBridge API Error: ${data.error}`); |
| 155 | + } |
| 156 | + |
| 157 | + return data; |
| 158 | +} |
| 159 | +``` |
| 160 | + |
| 161 | +## Affiliate Fee Settlement |
| 162 | + |
| 163 | +If set during order creation, the [affiliate fee](../../affiliate-fees/) is automatically transferred to the `affiliateFeeRecipient` once the order reaches the `ClaimedUnlock` status. |
0 commit comments