# Trades

Real-time tick data feed of any trade executed across all of sFOX’s integrated liquidity providers. Please note that this feed does not only represent trades executed on sFOX.

### **Subscribing**

<table data-header-hidden><thead><tr><th width="100">Feed</th><th>Example</th></tr></thead><tbody><tr><td>Feed</td><td><strong><code>trades.sfox.&#x3C;basequote></code></strong></td></tr><tr><td>Example</td><td><strong><code>trades.sfox.btcusd</code></strong></td></tr></tbody></table>

```json
// Request -> orders feed
{
    "type": "subscribe", 
    "feeds": ["trades.sfox.btcusd"]
}
```

### **Trades Message**

#### Trades Object

<table><thead><tr><th width="100">Key</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>buyOrderId</code></strong></td><td>Order ID of the buy trade</td></tr><tr><td><strong><code>sellOrderId</code></strong></td><td>Order ID of the sell trade</td></tr><tr><td><strong><code>pair</code></strong></td><td>The currency pair of this trade</td></tr><tr><td><strong><code>price</code></strong></td><td>Price of this trade</td></tr><tr><td><strong><code>quantity</code></strong></td><td>Quantity traded</td></tr><tr><td><strong><code>side</code></strong></td><td>Side taken buy or sell</td></tr><tr><td><strong><code>exchange</code></strong></td><td>Location of the trade</td></tr><tr><td><strong><code>exchange_id</code></strong></td><td>ID of the trade location</td></tr><tr><td><strong><code>timestamp</code></strong></td><td>Time of the trade</td></tr></tbody></table>

#### Trades Message

```json
// Trades feed message
{
  "sequence": 24,
  "recipient": "trades.sfox.btcusd",
  "timestamp": 1649901441593380244,
  "payload": {
    "id": "1062696823",
    "quantity": "0.005",
    "price": "41492",
    "exchange": "bitfinex",
    "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
  }
}
```

### Example Code

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

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

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

ws.on('message', function(data) {
    console.log(data);
});

ws.on('open', function() {
  const subscribeMsg = {
    type: 'subscribe',
    feeds: ['trades.sfox.btcusd']
  }
  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": "subscribe",
            "feeds": [
                "trades.sfox.btcusd",
            ],
        }))
        async for msg in ws:
            print(msg)


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

{% endtab %}
{% endtabs %}
