WebSockets

Receive real-time order updates on your server without polling.

OZZOBiT WebSockets provide a real-time, bidirectional communication channel for receiving order status updates instantly. Unlike webhooks which require you to manage an HTTP endpoint, WebSocket connections allow your application to subscribe to order events and receive updates as they happen.

Overview

The WebSocket API is ideal for applications that need real-time order tracking, such as dashboards, trading interfaces, or any scenario where immediate feedback is critical. You can connect to our WebSocket server and receive push notifications for specific orders or all orders associated with your partner account.

Connection Details

PropertyValue
WebSocket URLwss://OZZOBiT.com/ws
ProtocolWSS (Secure WebSocket)
AuthenticationAPI Key in connection params
Message FormatJSON
Heartbeat30 seconds interval
Max Reconnect Attempts5
ℹ️
When to Use WebSockets vs Webhooks
  • Use WebSockets: Real-time dashboards, live order tracking UIs, client-side applications
  • Use Webhooks: Server-side processing, database updates, payment confirmations, compliance logging

Supported Events

EventDescriptionData Included
ORDER_CREATEDNew order initiatedorderId, amount, currency
ORDER_PROCESSINGPayment being processedorderId, current step
ORDER_COMPLETEDOrder finished successfullyorderId, txHash, amounts
ORDER_FAILEDOrder failedorderId, reason, errorCode
ORDER_CANCELLEDOrder was cancelledorderId, cancelledBy
KYC_STATUS_CHANGEDKYC verification updateduserId, newStatus
PONGResponse to heartbeat pingtimestamp

Connecting to WebSocket

websocket-connection.jsjavascript
// Browser / Node.js example
import { io } from 'socket.io-client'

const socket = io('wss://OZZOBiT.com/ws', {
  auth: {
    apiKey: 'YOUR_API_KEY'
  },
  transports: ['websocket'],
  reconnection: true,
  reconnectionAttempts: 5,
  reconnectionDelay: 1000,
})

socket.on('connect', () => {
  console.log('Connected to OZZOBiT WebSocket:', socket.id)
  
  // Subscribe to a specific order
  socket.emit('subscribe:order', { orderId: 'your-order-id' })
  
  // Or subscribe to all orders for this partner
  socket.emit('subscribe:partner')
})

socket.on('order:update', (data) => {
  console.log('Order update received:', data)
  
  switch (data.event) {
    case 'ORDER_COMPLETED':
      // Handle successful completion
      break
    case 'ORDER_FAILED':
      // Handle failure
      break
    case 'ORDER_PROCESSING':
      // Update UI with processing state
      break
  }
})

socket.on('disconnect', (reason) => {
  console.log('Disconnected:', reason)
})

socket.on('connect_error', (error) => {
  console.error('Connection error:', error.message)
})

Authentication

WebSocket connections require authentication using your OZZOBiT API key. Pass the API key in the auth object during connection setup as shown above.

Auth ParameterTypeRequiredDescription
apiKeystringYesYour OZZOBiT partner API key
envstringNoEnvironment: 'STAGING' or 'PRODUCTION' (default: PRODUCTION)
⚠️
Security Best Practices
  • Never expose your API key in client-side code for production applications
  • Use environment variables or server-side proxy for API key management
  • Validate all incoming messages on your server before acting on them
  • Implement rate limiting on your WebSocket message handlers