# API Trading

API endpoints for initiating trades.
There are two options: Swaps and RFQ (Request for Quote).
Swaps (Submit Order) - This is for when you want to sell some asset for another asset and just want to best available price at that point in time.
RFQ (Request Quote + Action Quote) - This is if you need to fix the price. You specify how much you need to buy and we will give you a fixed price for 5 seconds, you can accept or reject this. This price will be slightly less competitive than doing a swap as the price has to be held.

## Action Quote

`POST /v2/action-quote`

Action a previously received quote.

**Request Body** _(required)_

  | Field | Type | Description |
  |-------|------|-------------|
  | `instructionId` | string | This is your client reference id that you supplied when requesting the specific quote that you wish to action. (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |

**Responses**

- **204**: Ok
- **400**: Bad request

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


  Example (No available market date):
  ```json
  {"code":"NO_MARKET_DATA_FOUND","description":"No market data found"}
  ```
- **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/action-quote" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"instructionId": "375b23de-febf-4a6e-a517-e7b5dfa9357c"}'
```

---

## 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 Order

`POST /v2/orders`

Swap assets using a market or limit order. Specify how much of a given asset you want to sell.

**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`) |
  | `sellingAsset` | string | Asset you wish to sell (e.g. `USD`) |
  | `buyingAsset` | string | Asset you wish to buy (e.g. `EUR`) |
  | `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. `5.5`) |

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `instructionId` | string | Instruction Id (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |
  | `sellingAsset` | string | Selling Asset (e.g. `btc`) |
  | `buyingAsset` | string | Buying Asset (e.g. `usd`) |
  | `amountToSell` | string | Amount To Sell (e.g. `5.1`) |
  | `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`) |


  Example (Offchain order response):
  ```json
  {"instructionId":"375b23de-febf-4a6e-a517-e7b5dfa9357c","sellingAsset":"usd","buyingAsset":"xrp","amountToSell":"5602.01","limitAmountToReceive":"2400","status":"COMPLETED","amountReceived":"2424.06","feePaid":"0.56"}
  ```
- **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/orders" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"instructionId": "375b23de-febf-4a6e-a517-e7b5dfa9357c", "sellingAsset": "USD", "buyingAsset": "EUR", "amountToSell": "5.67", "limitAmountToReceive": "5.5"}'
```

---

## Request Quote

`POST /v2/request-quote`

Request a firm quote to swap some assets, the quote is inclusive of commission. Specify how much of an asset you want to receive. Quote is valid for 5 seconds.

**Request Body** _(required)_

  | Field | Type | Description |
  |-------|------|-------------|
  | `instructionId` | string | This is your client reference id for the quote. This can be any string less than 64 in length and needs to be unique. (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |
  | `sellingAsset` | string | Selling Asset (e.g. `USD`) |
  | `buyingAsset` | string | Buying Asset (e.g. `EUR`) |
  | `amountToBuy` | string | Amount of buying asset you want (e.g. `5.67`) |

**Responses**

- **200**: Ok

  | Field | Type | Description |
  |-------|------|-------------|
  | `instructionId` | string | Instruction Id - the id you specified on the request (e.g. `375b23de-febf-4a6e-a517-e7b5dfa9357c`) |
  | `sellingAsset` | string | Selling Asset (e.g. `USD`) |
  | `buyingAsset` | string | Buying Asset (e.g. `EUR`) |
  | `amountToBuy` | string | Amount To Buy (e.g. `5.67`) |
  | `amountToSell` | string | Amount To Sell (e.g. `12932.1`) |
  | `expiryTimestampMillis` | string | Time the quote expires - Epoch milliseconds (e.g. `1653480000000`) |

- **400**: Bad request

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


  Example (Invalid instruction id length):
  ```json
  {"code":"INVALID_INSTRUCTION_ID_LENGTH","description":"Invalid instructionId length"}
  ```
- **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/request-quote" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"instructionId": "375b23de-febf-4a6e-a517-e7b5dfa9357c", "sellingAsset": "USD", "buyingAsset": "EUR", "amountToBuy": "5.67"}'
```

---

