sFOX API
Sign InOpen Account
sFOX API
sFOX API
  • Introduction
    • Welcome
    • Getting Started
    • Systems & Operations
    • Rate Limits
  • REST API
    • REST Endpoints
    • Authentication
    • Rate Limits
    • Account Management
      • Get All Balances
      • Get All Currencies
      • Get All Currency Pairs
      • Get All Transactions
      • Get Fees
    • Orders
      • Order Types
      • Create Order
      • Cancel Order
      • Cancel Multiple Orders
      • Cancel All Orders
      • Amend Order
      • Get Single Order
      • Get All Open Orders
      • Get All Done Orders
      • Get All Trades
    • Request for Quote (RFQ)
    • Post-Trade Settlement (PTS)
      • Get Account Risk Metrics
      • Get All Positions
      • Get All Funding Transactions
      • Get All Funding Rates
      • Get All Risk Modes
      • Create Transfer
    • Shorting
      • Get Account Risk Metrics
      • Get All Positions
    • Transfers
      • Get All Deposit Addresses
      • Get Single Deposit Address
      • Create Deposit Address
      • Deposit From Bank Account
      • Withdraw From Account
      • Get Single Withdrawal Fee
      • Create Transfer
    • Custody (sFOX SAFE)
      • Get Whitelisted Addresses
      • Add Whitelisted Address
      • Delete Whitelisted Address
      • Get Approval Rules
      • Create Approval Rule
      • Edit Approval Rule
      • Get Approval Requests
      • Respond to Approval Request
    • Staking
      • Get Staking Currencies
      • Get All Staking Transactions
      • Create Stake
      • Cancel Stake
      • Unstake
    • Market Data
      • Get Candlesticks
      • Get Volume Analytics
      • Get Order Estimate
      • Get Order Book
    • Reporting
      • Get Orders Report
      • Get Monthly Summary
      • Get Portfolio Valuation
      • Get All Transactions
  • WebSocket API
    • Introduction
    • Connecting
    • Rate Limits
    • Authentication
    • Subscribing & Unsubscribing
    • Message Format
    • Market Data
      • Order Book
      • Trades
      • Ticker
    • Orders & Account Data
      • Orders
      • Trades
      • Balances
      • Post-Trade Settlement
  • FIX API
    • FIX Order Entry
    • FIX Market Data
    • QuickFIX Guide
  • Errors
    • Error Codes
Powered by GitBook
On this page
  • Subscribing
  • Trades Message
  • Example Code
  1. WebSocket API
  2. Orders & Account Data

Trades

PreviousOrdersNextBalances

Last updated 7 months ago

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 for details.

Subscribing

Feed name

private.user.trades

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

Trades Message

Trade Object

Value
Description

trade_id

The ID of the trade

order_id

The ID of the order that this trade is associated with

date_updated

The date and time the trade was completed

action

Buy or Sell

currency_pair

The currency pair this trade was executed on

quantity

The base currency quantity bought or sold in this trade

amount

The gross quote currency amount cost or proceeds from this trade

price

The fill price of this trade

fees

The fees charged on this trade (always in the quote currency)

net_amount

The net quote currency amount cost or proceeds from this trade (amount net fees)

Trades Message

Payload will contain a list of one or more trade objects, each representing a unique, completed trade.

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

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))
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"))
Get All Trades