# Trades

Receive real-time updates regarding completed trades in your account–fills on orders you've placed. Complete trade history can also be retrieved from the REST API. See [Get All Trades](/rest-api/orders/get-all-trades.md) for details.

### **Subscribing**&#x20;

<table data-header-hidden><thead><tr><th width="100"></th><th>Feed Name</th></tr></thead><tbody><tr><td>Feed name</td><td><strong><code>private.user.trades</code></strong> </td></tr></tbody></table>

```json
// Request -> trades feed
{
    "type": "subscribe", 
    "feeds": ["private.user.trades"]
}
```

### Trades Message

#### Trade Object

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

#### Trades Message

{% hint style="info" %}
Payload will contain a list of one or more trade objects, each representing a unique, completed trade.
{% endhint %}

```json
// Trades feed message
{
    "sequence": 3,
    "recipient": "private.user.trades",
    "timestamp": 1708630086193678496,
    "payload": [
        {
            "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"
        }
    ]
}
```

### 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: '<API_KEY>'
  }
  
  ws.send(JSON.stringify(authMessage))
})

// After successful authentication, subscribe to trades feed
const subscribeMsg = {
  type: 'subscribe',
  feeds: ['private.user.trades']
}

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

{% endtab %}

{% tab title="Python" %}

```python
import asyncio
import json

import websockets


async def main(uri):
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps({
            "type": "authenticate",
            "apiKey": "<API_KEY>"
        }))

        # After successful authentication message, subscribe to trades feed
        await ws.send(json.dumps({
            "type": "subscribe",
            "feeds": ["private.user.trades"]
        }))
        async for msg in ws:
            print(msg)


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

{% 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/websocket-api/orders-and-account-data/trades.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.
