# Orders

The open orders feed tracks updates to all of your users' open orders.

{% hint style="info" %}
An update from this feed will include the `user_id` of the user to identify which user's account the update is for, as well as, the latest information for 1 or more open orders in the account.
{% endhint %}

### Subscription Instructions

| Feed Name                                  |
| ------------------------------------------ |
| **`private.enterprise.users.open-orders`** |

#### Order Object

Order updates received will include the following object per order:

<table data-full-width="false"><thead><tr><th width="220">Field</th><th width="105">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>id</code></strong></td><td>int</td><td>sFOX-generated order ID, assigned on order creation.</td></tr><tr><td><strong><code>action</code></strong></td><td>string</td><td>Order side. Possible values: <code>buy</code> (buy order), <code>sell</code> (sell order)</td></tr><tr><td><strong><code>algorithm_id</code></strong></td><td>int</td><td>Order type / algorithm ID. Possible values: <a href="https://docs.sfox.com/rest-api/orders/algorithms-and-routing-types">Order Types &#x26; Algorithms</a>.</td></tr><tr><td><strong><code>type</code></strong></td><td>string</td><td>Order type / algorithm name. Possible values: <a href="https://docs.sfox.com/rest-api/orders/algorithms-and-routing-types">Order Types &#x26; Algorithms</a>.</td></tr><tr><td><strong><code>pair</code></strong></td><td>string</td><td>Pair or product in the format <code>basequote</code> . e.g. <code>btcusd</code>, <code>ethbtc</code>, <code>ethusdc</code></td></tr><tr><td><strong><code>quantity</code></strong></td><td>number</td><td>Order size in base currency quantity.</td></tr><tr><td><strong><code>price</code></strong></td><td>number</td><td>Order limit price.</td></tr><tr><td><strong><code>amount</code></strong></td><td>number</td><td>Amount (quote currency) to spend when buying.</td></tr><tr><td><strong><code>net_market_amount</code></strong></td><td>number</td><td><code>amount</code> net fees for Market (<code>100</code>) orders.</td></tr><tr><td><strong><code>filled</code></strong></td><td>number</td><td>Unsigned, cumulative base currency quantity filled.</td></tr><tr><td><strong><code>vwap</code></strong></td><td>number</td><td>Cumulative volume-weighted average fill price of the order.</td></tr><tr><td><strong><code>filled_amount</code></strong></td><td>number</td><td>Unsigned, cumulative quote currency amount filled.</td></tr><tr><td><strong><code>fees</code></strong></td><td>number</td><td>Unsigned, cumulative quote currency fee amount accrued to this order.</td></tr><tr><td><strong><code>net_proceeds</code></strong></td><td>number</td><td>Signed, cumulative quote currency proceeds amount net fees.</td></tr><tr><td><strong><code>status</code></strong></td><td>string</td><td>Status name. Possible values: <a href="#order-statuses">Order Statuses</a>.</td></tr><tr><td><strong><code>routing_option</code></strong></td><td>string</td><td>Special order routing instructions. </td></tr><tr><td><strong><code>routing_type</code></strong></td><td>string</td><td>Order routing type.</td></tr><tr><td><strong><code>time_in_force</code></strong></td><td>string</td><td>Order time in force specified at order creation.</td></tr><tr><td><strong><code>expires</code></strong></td><td>datetime</td><td>Expiration date of the order (for <code>time_in_force</code> = <code>GTD</code> orders)</td></tr><tr><td><strong><code>dateupdated</code></strong></td><td>datetime</td><td>Date of the most recent update to this order.</td></tr><tr><td><strong><code>date_added</code></strong></td><td>datetime</td><td>Date the order was created.</td></tr><tr><td><strong><code>client_order_id</code></strong></td><td>string</td><td>User-specified ID for this order.</td></tr><tr><td><strong><code>algorithm_options</code></strong></td><td>string[]</td><td>Additional object specifying special order parameters.</td></tr><tr><td><strong><code>destination</code></strong></td><td>string</td><td>Order destination.</td></tr></tbody></table>

#### Order Statuses

Orders may have any of the following statuses.

<table><thead><tr><th width="151">Status</th><th width="127">Status Code</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>Started</code></strong></td><td><code>100</code></td><td><ul><li>The order is open and active</li><li>Filled quantity may be >= 0</li><li>Filled quantity is &#x3C; the order quantity</li></ul></td></tr><tr><td><strong><code>Cancel Pending</code></strong></td><td><code>90</code></td><td><ul><li>The order is in the process of being canceled but cancellation has not been completed</li><li>The order may still receive fills</li></ul></td></tr><tr><td><strong><code>Canceled</code></strong></td><td><code>10</code></td><td><ul><li>The order was successfully canceled</li><li><strong>Order may have been partially filled prior to cancellation</strong></li></ul></td></tr><tr><td><strong><code>Filled</code></strong></td><td><code>210</code></td><td><ul><li>The order has fully filled </li><li>The order has not yet settled</li></ul></td></tr><tr><td><strong><code>Done</code></strong></td><td><code>300</code></td><td><ul><li>The order was is completed, no longer active, and settled successfully</li><li>Filled quantity = order quantity</li><li>The order will not receive new fills</li></ul></td></tr></tbody></table>

### Example Code

{% tabs %}
{% tab title="NodeJS" %}

```javascript
const WebSocket = require('ws')

const ws = new WebSocket('wss://ws.sfox.com/ws')

ws.on('open', function() {
  const authMessage = {
   type: 'authenticate',
   apiKey: `${process.env.ENTERPRISE_API_KEY}`,
   enterprise: 'true'
  }
  
  ws.send(JSON.stringify(authMessage))
})

// After successful authentication, subscribe to user open orders feed
const subscribeMsg = {
  type: 'subscribe',
  feeds: ['private.enterprise.users.open-orders']
}

ws.send(JSON.stringify(subscribeMsg))
```

{% endtab %}

{% tab title="Python" %}
{% code overflow="wrap" %}

```python
import asyncio
import json
import websockets
import os

async def main(uri):
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps({
            "type": "authenticate",
            "apiKey": f"{os.environ['ENTERPRISE_API_KEY']}",
            "enterprise": "true"
        }))

        # After successful authentication message, subscribe to the open orders feed
        await ws.send(json.dumps({
            "type": "subscribe",
            "feeds": ["private.enterprise.users.open-orders"]
        }))
        async for msg in ws:
            print(msg)


asyncio.run(main("wss://ws.sfox.com/ws"))
```

{% endcode %}
{% endtab %}

{% tab title="Example Message" %}

```json
{
    "sequence": 22,
    "recipient": "private.enterprise.users.open-orders",
    "timestamp": 1710367225302228171,
    "payload": {
        "user_id": "test3",                        //Unique shared ID you generated for the End User account
        "updates": [
            {
                    "id": 693291242,
                    "client_order_id": "577ab261-9dfc-415a-ba61-a54a18c1942c",
                    "date_added": "2023-11-14T22:08:53.000Z",
                    "status": "Started",
                    "filled": "0.00035333",
                    "filled_amount": "14.61628778",
                    "vwap": "41367.24246455",
                    "price": "37227.82",
                    "quantity": "0.05",
                    "pair": "btcusd",
                    "action": "Sell",
                    "type": "TWAP",
                    "algorithm_id": 307,
                    "fees": "0.02850176"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sfox.com/connect/websocket-api/end-users/users-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
