Skip to content

Raw Market Data

The cmdtyView Desktop API streams market data as Openfeed messages. The cmdtyView Desktop SDK turns those messages into ready-to-use quotes, order books, and cumulative volume. Sometimes you need the messages themselves, for example:

  • data the Desktop SDK doesn’t model, such as trades or OHLC bars
  • your own market state, built your own way
  • porting an existing Openfeed integration

This page shows two ways to get raw messages in JavaScript. Both connect to the same local endpoint and receive the same messages.

Desktop SDK raw APIOpenfeed SDK
Package@barchart/desktop-sdk-js@openfeed/sdk-js
Connection, login, reconnectsHandled by the SDKHandled by the client
Mix raw and ready-made data in one connectionYesNo
Instrument lookup, one-off snapshotsBuilt-in helpersBuild the requests yourself
Market stateYou keep itYou keep it

If you already use the Desktop SDK, use its raw API. Use the Openfeed SDK directly if you only need raw messages, or if you are porting an existing Openfeed integration.

Message flow

Whichever SDK you use, after you subscribe to a symbol, the messages arrive in this order:

  1. subscriptionResponse: the server accepted or refused the subscription.
  2. instrumentDefinition: metadata about the instrument, including priceDenominator.
  3. marketSnapshot: the complete current state of the market.
  4. marketUpdate: incremental changes, as they happen.

Prices in Openfeed messages are integers. Divide them by the instrument’s priceDenominator to get the real price. For where each quote field lives in these messages, see the Market Data Field Reference.

Using the Desktop SDK raw API

Install the Desktop SDK and its peer dependencies:

Terminal window
npm install @barchart/desktop-sdk-js @openfeed/sdk-js long

sdk.raw.subscribe opens any Openfeed subscription and passes you its messages without building any state. The listener also gets the subscription’s symbol names and its instrument definition, so you don’t have to map market IDs to symbols yourself.

import { DesktopSdk } from "@barchart/desktop-sdk-js";
import { SubscriptionType } from "@openfeed/sdk-js";
const sdk = new DesktopSdk();
sdk.login({
url: "ws://localhost:9000",
username: "{username-placeholder}",
password: "{password-placeholder}",
});
// A raw Openfeed subscription. The SDK still handles login, reconnects and
// resubscribing, but it keeps no state for this subscription: you get each
// Openfeed message as it arrives and process it yourself.
const subscription = sdk.raw.subscribe("ESZ26", SubscriptionType.ALL, {
onMessage(message, { symbolNames, definition }) {
const symbol = symbolNames[0];
// Openfeed prices are integers; divide by the instrument's price denominator.
const denominator = definition?.priceDenominator || 1;
if (message.instrumentDefinition) {
console.log(`[Definition] ${symbol} - ${message.instrumentDefinition.description}`);
} else if (message.marketSnapshot?.last?.price) {
console.log(`[Snapshot] ${symbol} - Last: ${message.marketSnapshot.last.price.toNumber() / denominator}`);
} else if (message.marketUpdate?.last?.price) {
console.log(`[Update] ${symbol} - Last: ${message.marketUpdate.last.price.toNumber() / denominator}`);
}
},
onError(error) {
console.error(error.message);
},
});
await sdk.whenConnected();
// A one-off snapshot: resolves with the instrument definition and the first
// snapshot, then closes its subscription.
const { instrumentDefinition, marketSnapshot } = await sdk.raw.requestSnapshot("ZCZ26");
console.log(instrumentDefinition?.description, marketSnapshot.last?.price.toString());
// Later: subscription.close(); sdk.dispose();

sdk.raw also has:

  • requestSnapshot(symbol): one snapshot, as a promise.
  • lookupInstruments(request): the gateway’s instrument lookup.
  • onMessage(listener): every message on the connection.
  • send(request): any Openfeed request the SDK doesn’t model.

You can use sdk.raw alongside subscribeQuote, subscribeDepth, and subscribeCumulativeVolume on the same connection. See the Desktop SDK reference for details.

Using the Openfeed SDK

Install the Openfeed JavaScript SDK:

Terminal window
npm install @openfeed/sdk-js

With the Openfeed SDK, you create the client, subscribe, and process every message yourself. This example keeps the last price per symbol and logs it only when it changes.

import {
OpenFeedClient,
OpenFeedListeners,
Service,
SubscriptionType
} from "@openfeed/sdk-js";
const openfeedUrl = "ws://localhost:9000";
const openfeedUsername = "{username-placeholder}";
const openfeedPassword = "{password-placeholder}";
// Global state management
const marketState = {}; // Store state by symbol (includes price denominator and last price)
const openfeedListeners = new OpenFeedListeners();
openfeedListeners.onConnected = (connection) => {
console.log("Connected to OpenFeed");
};
openfeedListeners.onMessageWithMetadata = (message, symbolNames, instrument) => {
const symbol = symbolNames[0]; // Get the symbol from the provided list
// Handle subscription response
if (message.subscriptionResponse) {
console.log(`Subscription confirmed: ${message.subscriptionResponse.symbol}`);
return;
}
// Handle instrument definition - Initialize state with metadata
if (message.instrumentDefinition) {
const def = message.instrumentDefinition;
// Initialize state with price denominator
marketState[symbol] = {
priceDenominator: def.priceDenominator || 1,
lastPrice: null
};
console.log(`\n[Definition] ${symbol} - ${def.description}`);
console.log(` Price Denominator: ${def.priceDenominator}`);
return;
}
// Handle market snapshot - Populate initial state
if (message.marketSnapshot) {
// Make sure state exists
if (!marketState[symbol]) {
return;
}
// Populate initial values
if (message.marketSnapshot.last?.price) {
const price = message.marketSnapshot.last.price.toNumber();
const denominator = marketState[symbol].priceDenominator;
marketState[symbol].lastPrice = price / denominator;
console.log(`[Snapshot] ${symbol} initialized - Last: ${marketState[symbol].lastPrice}`);
}
return;
}
// Handle market update - Update existing state and log only on change
if (message.marketUpdate) {
const update = message.marketUpdate;
// Make sure state exists (definition and snapshot must arrive first)
if (!marketState[symbol]) {
return; // Silently ignore updates before state is initialized
}
// Track if state changed
const oldPrice = marketState[symbol].lastPrice;
const denominator = marketState[symbol].priceDenominator;
let newPrice = oldPrice;
// Update state with new data
if (update.trades && update.session?.last?.price) {
newPrice = update.session.last.price.toNumber() / denominator;
marketState[symbol].lastPrice = newPrice;
} else if (update.last?.price) {
newPrice = update.last.price.toNumber() / denominator;
marketState[symbol].lastPrice = newPrice;
}
// Only log if price changed
if (newPrice !== null && newPrice !== oldPrice) {
console.log(`[Update] ${symbol} - Last: ${newPrice}`);
}
return;
}
};
openfeedListeners.onDisconnected = () => {
console.log("Disconnected from OpenFeed");
};
openfeedListeners.onCredentialsRejected = () => {
console.log("Invalid credentials - check username/password");
};
const openFeedClient = new OpenFeedClient(
openfeedUrl,
openfeedUsername,
openfeedPassword,
openfeedListeners,
console
);
openFeedClient.subscribe(
Service.REAL_TIME,
SubscriptionType.ALL,
1,
["ZCN26", "ZLN26"],
null,
null,
null
);

Openfeed SDKs are also available for Python, Go, Java, and C#. See the Getting Started guide for installation steps and examples, and the Openfeed SDKs on GitHub for full documentation.