# Trades

### Subscription Instructions

<table><thead><tr><th width="272.75611055915493">Subscription Format</th><th>Example</th></tr></thead><tbody><tr><td><code>trades.sfox.&#x3C;basequote></code></td><td><code>trades.sfox.btcusd</code></td></tr></tbody></table>

### Payload Details

| Key           | Description                     |
| ------------- | ------------------------------- |
| `buyOrderId`  | Order ID of the buy trade       |
| `sellOrderId` | Order ID of the sell trade      |
| `pair`        | The currency pair of this trade |
| `price`       | Price of this trade             |
| `quantity`    | Quantity traded                 |
| `side`        | Side taken buy or sell          |
| `exchange`    | Location of the trade           |
| `exchange_id` | ID of the trade location        |
| `timestamp`   | Time of the trade               |

### Example Code & Trades Message

{% 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: '<ENTERPRISE_API_KEY>',
   enterprise: 'true'
  }
  
  ws.send(JSON.stringify(authMessage))
})

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

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

{% endtab %}

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

```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": "<ENTERPRISE_API_KEY>",
            "enterprise": "true"
        }))

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


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

{% endcode %}
{% endtab %}

{% tab title="Example Message" %}

```json
{
  "sequence": 24,
  "recipient": "trades.sfox.btcusd",
  "timestamp": 1649901441593380244,
  "payload": {
    "id": "1062696823",
    "quantity": "0.005",
    "price": "41492",
    "exchange": "market1",
    "exchange_id": 2,
    "side": "buy",
    "pair": "btcusd",
    "pair_id": 1,
    "timestamp": "2022-04-14T01:57:21.521999872Z",
    "timeStamp": "2022-04-14T01:57:21.521",
    "buyOrderId": "",
    "sellOrderId": "",
    "is_decimal": true
  }
}
```

{% endtab %}
{% endtabs %}
