# RFQ

### **Connection and authorization flow:**

{% hint style="info" %}
Read the [](https://faq.finerymarkets.com/api-reference/websocket-api "mention") description first
{% endhint %}

{% hint style="info" %}
Use the auth headers `EFX-Key` and `EFX-Sign` when connecting to the WebSocket. If you sign without them, you will need to authorize afterward
{% endhint %}

1. Connecting to the WS endpoint `wss://trade.finerymarkets.com/ws/rfq`

{% tabs %}
{% tab title="Connection response" %}

```json
{ "event": "CONNECTED" }
```

{% endtab %}
{% endtabs %}

2. Authorize (if authorization headers were not provided in step 1).

{% tabs %}
{% tab title="Authorization request" %}

```json
{
"event": "AUTH",
"key": string,
"signature": string,
"content": string
} 
```

{% hint style="info" %}
For `"content": string` refer to [](https://faq.finerymarkets.com/api-reference/websocket-api "mention") description
{% endhint %}
{% endtab %}

{% tab title="Successful authorization response" %}

```json
{ "event": "AUTHORIZED" }
```

{% endtab %}
{% endtabs %}

### **Trading flow:**

{% hint style="info" %}
Endpoint for trading: `wss://trade.finerymarkets.com/ws/rfq`
{% endhint %}

1. Send the `RFQ session request` event to create an RFQ session. The server responds with `Successful RFQ session response`, indicating that the RFQ session has been created. The service sends requests to external providers (from the list specified by the client in the request). Upon receiving an answer from any provider, the server sends a `Quote response`.

{% tabs %}
{% tab title="RFQ session request" %}

```json
{
"event": "CREATE",
"reqId": int,
"instrument": string,
"providers": int[],
"side": string ("BUY"/"SELL"),
"size": int,
"clientId": int (optional, required only if request is authorized)
}
```

For getting providers use:

{% content-ref url="../rest-api/trading/rfq/getproviders" %}
[getproviders](https://faq.finerymarkets.com/api-reference/rest-api/trading/rfq/getproviders)
{% endcontent-ref %}
{% endtab %}

{% tab title="Successful RFQ session response" %}

```json
{ "event": "CREATED", "reqId": int }
```

{% endtab %}

{% tab title="Quote response" %}
{% code overflow="wrap" %}

```json
{
"event": "QUOTE",
"reqId": int,
"status": string, ("SUCCESS", "REJECT", "ERROR")
"expiresAt": datetime,
"providerId": int,
"quotes": [
   {
     "side": string ("BUY"/"SELL"),
     "price": int 
   } 
 ],
"error": string
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

2. Send an `Order confirmation request`  to approve the deal with the provider specified in the request. The server sends another request to the specified provider, and depending on its response, the server can respond with an `Order confirmation response` with different statuses:
   * `SUCCESS` if the provider approved the deal.
   * `REJECT` if the provider rejected the deal.
   * `ERROR` if there was an error during the request.

{% tabs %}
{% tab title="Order confirmation request" %}

```json
{
"event": "COMMIT",
"reqId": int,
"providerId": int,
"side": string ("BUY"/"SELL")
}
```

{% endtab %}

{% tab title="Order confirmation response" %}

```json
{
"event": "COMMITTED",
"reqId": int,
"status": string, ("SUCCESS", "REJECT", "ERROR"),
"error": string
}
```

{% endtab %}
{% endtabs %}

RFQ session statuses include:

* `CREATED` – The session has been initialized.
* `COMMITTED` – The session has been successfully finished with the committed order.
* `CANCELED` – The session was canceled.
* `EXPIRED` – The session expired without commitment.
* `REJECTED` – Commitment to the LP was rejected due to insufficient trading limits or other risk management checks.
* `FAILED` – The commitment to the LP failed due to technical errors or issues during processing.

3. Send a `Cancel request`  to cancel the RFQ completely. After you will receive `Cancel response` from the server. Then the RFQ session may be restarted.

{% tabs %}
{% tab title="Cancel request" %}

```json
{
"event": "CANCEL",
"reqId": int
}
```

{% endtab %}

{% tab title="Cancel response" %}

```json
{
"event": "CANCELED",
"reqId": int
}
```

{% endtab %}
{% endtabs %}

4. If an internal error occurs, you will receive an `Error response` event.

{% tabs %}
{% tab title="Error response" %}

```json
{
"event": "ERROR",
"reqId": int,
"error": int,
"errors": string
}
```

{% endtab %}
{% endtabs %}
