sFOX API
Sign InOpen Account
Connect API
Connect API
  • Introduction
    • Welcome
    • Getting Started
    • Resources
      • Terminology
      • Systems & Operations
      • Integration Options
    • Guides
      • End User Onboarding & KYC
        • Individuals
        • Businesses
        • Enhanced Due Diligence
  • REST API
    • REST Endpoints
    • Authentication
    • End Users
      • Create End User Account
      • Request Verification Code
      • Confirm Verification Code
      • Create User Auth Token(s)
      • Get End User(s)
      • Get EDD Requests
      • Get EDD Prompts
      • Create EDD Responses
        • Uploading Files as Responses
      • Submit Documents
      • Deactivate User
    • Payments
      • Create Bank Account (Plaid)
      • Create Bank Account
      • Get Bank Account
      • Get Plaid Processors
      • Amend Plaid Processors
      • Verify Bank Account
      • Delete Bank Account
      • Get Wire Instructions
      • Get ACH Agreement Status
      • Request ACH Onboarding
      • Get ACH Deposit Limit
    • Withdrawals
      • Confirm Withdrawal
      • Resend Confirmation Code
      • Cancel Withdrawal
    • Transfers
      • Create Transfer
      • Confirm Transfer
      • Resend Confirmation Code
      • Cancel Transfer
      • Get Transfer Permissions
      • Get Transfer History
    • Monetization
      • Create Setting
      • Update Setting
      • Delete Setting
      • Get Settings
      • Get Permissions
      • Get Monetization History
  • WebSocket API
    • Connecting
    • Authentication
    • Subscribing & Unsubscribing
    • Message Format
    • End Users
      • Onboarding
      • Balances
      • Orders
      • Trades
    • Market Data
      • Order Book
      • Trades
      • Ticker
  • Single Sign-On
    • Overview
      • IdP Initiated SSO
    • IdP Data
    • SAML Response Data
  • Errors
    • Error Codes
Powered by GitBook
On this page
  • Subscription Instructions
  • Payload Details
  • Example Code & Order Book Message
  1. WebSocket API
  2. Market Data

Order Book

Real-time order books for a specified currency pair.

Subscription Instructions

Subscription Format
Example

orderbook.net.<basequote>

orderbook.net.btcusd

Payload Details

Order book subscriptions receive full order book snapshots for the pair. sFOX does not support sending changes at this time.

Key
Description

bids

An array of the bids available in this order book. Each bid is a price, quantity, and liquidity source

asks

An array of the asks available in this order book. Each ask is a price, quantity, and liquidity source

market making

The best bids and offers of the available destinations for maker orders placed on this pair

pair

The currency pair of this order book

lastupdated

The UNIX timestamp this order book was last updated

lastpublished

The UNIX timestamp this order book was last published

Example Code & Order Book Message

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 order book feed
const subscribeMsg = {
  type: 'subscribe',
  feeds: ['orderbook.net.btcusd', 'orderbook.net.ethusd']
}

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

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


asyncio.run(main("wss://ws.sfox.com/ws"))
{
  "sequence": 18,
  "recipient": "orderbook.net.btcusd",
  "timestamp": 1649900198079450163,
  "payload": {
    "bids": [
      [41368.2, 0.3, "market1"],
      [41367.742812, 0.001963, "otc1"],
      [41367.292857, 0.006878, "market2"],
      [41365.91428571, 0.7, "otc2"],
      [41362.1, 2, "market3"],
      [41361.453441, 0.014505, "otc3"]
    ],
    "asks": [
      [41364.5, 0.5, "otc1"],
      [41367.9, 0.5, "market1"],
      [41371.325, 4, "otc2"],
      [41373.322712, 0.03838193, "market2"],
      [41373.332716, 0.01, "otc3"]
    ],
    "market_making": {
      "bids": [
        [41345.224109, 1.27, "market1"],
        [41361.46, 0.39449605, "otc3"],
        [41366.05, 0.0023, "market2"],
        [41371.88, 0.001963, "otc2"],
        [41374, 0.69001372, "market4"],
        [41374.4, 0.00331432, "otc4"]
      ],
      "asks": [
        [41381.49, 0.12087124, "market5"],
        [41375.29, 0.01103, "market7"],
        [41374.5, 2.0260228, "otc3"],
        [41368.5, 0.01005354, "market1"],
        [41352.644322, 0.03838193, "market2"]
      ]
    },
    "pair": "btcusd",
    "lastupdated": 1649900198016,
    "lastpublished": 1649900198017
  }
}

PreviousMarket DataNextTrades

Last updated 1 year ago