# On-chain Trading

Endpoints to manage trading via the Deposit‑Trade‑Withdraw (DTW) on‑chain mechanism.

## Get Order Status

`GET /v2/order/{source}/{instructionId}`

Check the status of an order.

**Parameters**

| Name | In | Required | Type | Description |
|------|-----|----------|------|-------------|
| `source` | path | Yes | string | If trading via API use OFFCHAIN, else specify the blockchain you want to check your order status on |
| `instructionId` | path | Yes | string | Instruction Id - If order placed via api this is the client specified id. If placed on chain this is the transaction id (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |
| `type` | query | No | string | The type of order you wish to retrieve the status for. Available options are 'SWAP' & 'RFQ'. If not specified, defaults to 'SWAP'. |

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `instructionId` | string | Instruction Id (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |
  | `orderSource` | string | Order Source |
  | `sellingAsset` | string | Selling Asset (e.g. `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48`) |
  | `buyingAsset` | string | Buying Asset (e.g. `0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE`) |
  | `amountToSell` | string | Amount To Sell (e.g. `5.67`) |
  | `limitAmountToReceive` | string | Limit Amount To Receive (e.g. `10433.1`) |
  | `status` | string | Status (e.g. `COMPLETED`) |
  | `rejectionReason` | string | Rejection reason |
  | `amountReceived` | string | Amount Received (e.g. `12932.1`) |
  | `feePaid` | string | Fee Paid (e.g. `0.042`) |
  | `transactionId` | string | Transaction Id (e.g. `0x99687859ddbe6050ca9615b7a5ae7b202f856ff289255758216b16887cd072f6`) |


  Example (Chain order response):
  ```json
  {"instructionId":"375b23de-febf-4a6e-a517-e7b5dfa9357c","orderSource":"ETHEREUM","sellingAsset":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","buyingAsset":"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE","amountToSell":"5.67","limitAmountToReceive":"10433.1","status":"COMPLETED","amountReceived":"12932.1","feePaid":"0.042","transactionId":"0x99687859ddbe6050ca9615b7a5ae7b202f856ff289255758216b16887cd072f6"}
  ```
- **400**: Bad request

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Insufficient funds):
  ```json
  {"code":"INSUFFICIENT_FUNDS","description":"Insufficient funds"}
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid JWT):
  ```json
  {"code":"INVALID_JWT_TOKEN","description":"Invalid JWT"}
  ```
- **403**: Invalid permissions

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid permissions):
  ```json
  {"code":"INVALID_PERMISSIONS","description":"Invalid permissions"}
  ```

**Example**

```bash
curl "https://api.demo.omniaexchange.com/api/v2/order/{source}/{instructionId}" \
  -H "Authorization: Bearer <token>"
```

---

## Submit DTW order

`POST /v2/order`

Swap assets using a market or limit order. Specify how much of a given asset you want to sell. This utilises the deposit trade withdraw mechanism of Alice.

**Request Body** _(required)_

  | Field | Type | Description |
  |-------|------|-------------|
  | `instructionId` | string | This is your client reference id for the order. This can be any string less than 64 in length and needs to be unique per order (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |
  | `orderSource` | string | Order Source |
  | `sellingAsset` | string | Selling Asset (e.g. `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48`) |
  | `buyingAsset` | string | Buying Asset (e.g. `0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE`) |
  | `amountToSell` | string | Amount to sell of the selling asset (e.g. `5.67`) |
  | `limitAmountToReceive` | string | The minimum amount of the buying asset you want to receive (e.g. `12932.1`) |
  | `deadline` | integer | Deadline for the order (e.g. `1653480000000`) |
  | `signature` | string | Signature for the order request (e.g. `0xc2d0018de1528b8dab42e85482263060903ec1fec13768f66977f9b7b37333a3f2a1bbf42`) |

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `instructionId` | string | Instruction Id (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |
  | `orderSource` | string | Order Source |
  | `sellingAsset` | string | Selling Asset (e.g. `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48`) |
  | `buyingAsset` | string | Buying Asset (e.g. `0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE`) |
  | `amountToSell` | string | Amount To Sell (e.g. `5.67`) |
  | `limitAmountToReceive` | string | Limit Amount To Receive (e.g. `10433.1`) |
  | `status` | string | Status (e.g. `COMPLETED`) |
  | `rejectionReason` | string | Rejection reason |
  | `amountReceived` | string | Amount Received (e.g. `12932.1`) |
  | `feePaid` | string | Fee Paid (e.g. `0.042`) |
  | `transactionId` | string | Transaction Id (e.g. `0x99687859ddbe6050ca9615b7a5ae7b202f856ff289255758216b16887cd072f6`) |


  Example (Chain order response):
  ```json
  {"instructionId":"375b23de-febf-4a6e-a517-e7b5dfa9357c","orderSource":"ETHEREUM","sellingAsset":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","buyingAsset":"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE","amountToSell":"5.67","limitAmountToReceive":"10433.1","status":"COMPLETED","amountReceived":"12932.1","feePaid":"0.042","transactionId":"0x99687859ddbe6050ca9615b7a5ae7b202f856ff289255758216b16887cd072f6"}
  ```
- **400**: Bad request

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Asset not supported):
  ```json
  {"code":"ASSET_IS_NOT_SUPPORTED","description":"Asset is not supported"}
  ```
- **401**: Unauthorized

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid JWT):
  ```json
  {"code":"INVALID_JWT_TOKEN","description":"Invalid JWT"}
  ```
- **403**: Invalid permissions

  | Field | Type | Description |
  |-------|------|-------------|
  | `code` | string | Error code |
  | `description` | string | Error description |


  Example (Invalid permissions):
  ```json
  {"code":"INVALID_PERMISSIONS","description":"Invalid permissions"}
  ```

**Example**

```bash
curl -X POST "https://api.demo.omniaexchange.com/api/v2/order" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"instructionId": "375b23de-febf-4a6e-a517-e7b5dfa9357c", "orderSource": "<orderSource>", "sellingAsset": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "buyingAsset": "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE", "amountToSell": "5.67", "limitAmountToReceive": "12932.1", "deadline": 1653480000000, "signature": "0xc2d0018de1528b8dab42e85482263060903ec1fec13768f66977f9b7b37333a3f2a1bbf42"}'
```

---

