Websocket service

The events websocket service emits a live stream of backpack.tf system events. You can use this to gather up-to-date information about Classifieds listings.

Be warned that the websocket server will emit a large amount of data and does not provide any event filtering -- use your own tools to process the data you need. This could be as simple as piping all events into a database that you can query in another part of your application.

Connection URI

wss://ws.backpack.tf/events

Events

The following events are provided by the websocket:

listing-update

Fired whenever a listing is created or updated. The exception to this is whenever listings are bumped, or when currency values are updated from a price suggestion (this causes all listings to have their value recalculated).

Re-publishing an archived listing is considered an update.

listing-delete

Fired whenever a listing is deleted. Moving a listing to the archive is also considered to be deleting the listing.

Event IDs

Each event has a unique 12-byte alphanumeric ID. The first four bytes of the ID is a 32-bit timestamp. Check here for more information on this format.

Quick Start

Requires a websocket library.

import WebSocket from 'ws';

const ws = new WebSocket('wss://ws.backpack.tf/events');

ws.on('open', function open() {
    console.log("websocket running")
})

ws.on('message', function message(data) {
  const json = JSON.parse(data)

  switch (json.event) {
    case 'listing-update':
      console.log(`listing ${json.payload.id} by ${json.payload.user.id} was updated (or created).`)
      break;
    case 'listing-delete':
      console.log(`listing ${json.payload.id} by ${json.payload.user.id} was deleted.`)
      break;
  }
})

Handling connection loss

On occasion, the websocket server may restart. Assume this might happen, as we may update or perform maintenance on the websocket server at any moment.

If using Node.js, you can use reconnecting-websocket to gracefully manage the websocket connection.