# Trades

Receive real-time streaming updates regarding completed trades across your users' accounts.

{% 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 information for 1 or more trades that have completed in the account.
{% endhint %}

### Subscription Instructions

| Feed Name                             |
| ------------------------------------- |
| **`private.enterprise.users.trades`** |

<table><thead><tr><th width="213">Value</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>trade_id</code></strong></td><td>The ID of the trade</td></tr><tr><td><strong><code>order_id</code></strong></td><td>The ID of the order that this trade is associated with</td></tr><tr><td><strong><code>date_updated</code></strong></td><td>The date and time the trade was completed</td></tr><tr><td><strong><code>action</code></strong></td><td>Buy or Sell</td></tr><tr><td><strong><code>currency_pair</code></strong></td><td>The currency pair this trade was executed on</td></tr><tr><td><strong><code>quantity</code></strong></td><td>The base currency quantity bought or sold in this trade</td></tr><tr><td><strong><code>amount</code></strong></td><td>The gross quote currency amount cost or proceeds from this trade</td></tr><tr><td><strong><code>price</code></strong></td><td>The fill price of this trade</td></tr><tr><td><strong><code>fees</code></strong></td><td>The fees charged on this trade (always in the quote currency)</td></tr><tr><td><strong><code>net_amount</code></strong></td><td>The net quote currency amount cost or proceeds from this trade (<code>amount</code> net fees)</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 trades feed
const subscribeMsg = {
  type: 'subscribe',
  feeds: ['private.enterprise.users.trades']
}

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 users feed
        await ws.send(json.dumps({
            "type": "subscribe",
            "feeds": ["private.enterprise.users"]
        }))
        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.trades",
    "timestamp": 1710367225302228171,
    "payload": {
        "user_id": "test3",                        //Unique shared ID you generated for the End User account
        "updates": [
            {
                "trade_id": 830151520,
                "order_id": 759514460,
                "date_updated": "2024-02-22T19:28:06.000Z",
                "action": "Sell",
                "currency_pair": "compusd",
                "quantity": "1.65911629",
                "amount": "99.47066469",
                "price": "59.954004",
                "fees": "0.04973533",
                "net_amount": "99.42092936"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}
