Docs

API

Protobuf

Ask for application/x-protobuf on the high-volume reads and get compact binary bodies, defined by two public .proto schemas you can generate bindings from.

JSON is the default everywhere. On the high-volume reads you can ask for a protobuf body instead. It is smaller and faster to decode, with the same data. Errors are always JSON.

Content negotiation

Send Accept: application/x-protobuf:

sh
curl --compressed -sS -G "https://api.itmatrixhq.com/v2/gex/SPY/grid" \
  -H "Authorization: Bearer $ITM_API_KEY" \
  -H "Accept: application/x-protobuf" \
  -d "top=20" \
  -o grid.pb

These operations serve protobuf (each reference page says so under Response):

OperationMessage
GET /v2/gex/{symbol}/gridGexGridResponse
GET /v2/chain/{symbol}ChainResponse
GET /v2/stocks/{symbol}/barsBarsResponse
GET /v2/offexchange/{symbol}/activity and the other three off-exchange viewsOffExchange…Response

Any other Accept value gets JSON. A non-2xx answer is always the JSON error envelope. Check the status and Content-Type before decoding.

Compression and bounded reads

Protobuf is a serialization format; HTTP compression is negotiated separately. For bulk reads, send Accept-Encoding: gzip, br or zstd using a client that can decode the selected encoding. curl --compressed negotiates supported encodings and decompresses the downloaded body before you decode the protobuf message. Most HTTP clients handle this automatically; check your client's configuration.

A response larger than 256 KiB before compression requires a supported encoding to be negotiated. Missing compression or requesting identity encoding for that response gets 400 invalid_params. Narrow the range or filters, or retry with compression enabled. JSON and protobuf both follow this rule.

The response ceiling is 8 MiB before compression. Compression does not increase the ceiling. A read exceeding it gets 400 invalid_params; narrow the request rather than retrying it unchanged. GEX grid and history reads accept top up to 120; larger explicit values get 400 invalid_params. Use bounded pages where an operation provides cursors and incremental updates for repeated reads. A single long-running or slowly consumed response does not create an unlimited export allowance.

The schemas

SchemaPackageUsed for
/v2/rest-protocol.protoitmatrixhq.rest.v1Negotiated REST bodies
/v2/ws-protocol.protoitmatrixhq.ws.v1The two GEX book messages of API-key streaming, shown in full below

Conventions in the REST schema: prices are sint32 scaled by 10,000. Timestamps are epoch milliseconds. Strikes are integer thousandths of a dollar. Option right is 0 for a call and 1 for a put. Expiries are days since 1970-01-01. Absent optional fields are unset, not zero. Some counters are uint64, so use a 64-bit integer type in your language.

WebSocket schema

A keyed stream sends two binary messages and nothing else: a GexStrikeBook keyframe and a GexStrikeBookUpdate. This is the whole public schema. Streaming with an API key requires the official SDK, which decodes it for you, so most callers never generate bindings for it. See Streaming.

proto
syntax = "proto3";
package itmatrixhq.ws.v1;

// Each binary WebSocket message is exactly one Frame.
message Frame {
  string symbol = 1;
  reserved 10 to 22;
  oneof payload {
    GexStrikeBook gex_strike_book = 23;
    GexStrikeBookUpdate gex_strike_book_update = 24;
  }
}

enum GexBookReason {
  GEX_BOOK_REASON_UNSPECIFIED = 0;
  GEX_BOOK_REASON_SUBSCRIBE = 1;   // first book after a subscription
  GEX_BOOK_REASON_PERIODIC = 2;    // periodic refresh
  GEX_BOOK_REASON_RESYNC = 3;      // you asked for a resync
  GEX_BOOK_REASON_REBUILD = 4;     // new book_id
  GEX_BOOK_REASON_RECOVERY = 5;    // updates were skipped for you
}

// A full book. Replaces all state for the symbol.
message GexStrikeBook {
  uint64 captured_at_ms = 1;
  fixed64 book_id = 2;             // any change means discard state
  uint32 version = 3;
  double spot = 4;                 // ITMatrixHQ price engine, dollars
  double net_gex = 5;              // whole chain, not the sum of the listed strikes
  optional double flip_point = 6;  // dollars, absent when it cannot be computed
  repeated sint64 strikes = 7;     // thousandths, first absolute then deltas, ascending
  repeated float call_gex = 8;     // dollars per $1 move, aligned with strikes
  repeated float put_gex = 9;      // dollars per $1 move, aligned with strikes
  fixed32 crc = 10;                // checksum of the book
  GexBookReason reason = 11;
}

// The strikes that changed since the previous version.
message GexStrikeBookUpdate {
  uint64 captured_at_ms = 1;
  fixed64 book_id = 2;
  uint32 version = 3;              // exactly one more than the book it applies to
  double spot = 4;
  double net_gex = 5;
  optional double flip_point = 6;
  repeated uint32 index = 7;       // positions into the keyframe's strikes, ascending
  repeated float call_gex = 8;     // new values, aligned with index
  repeated float put_gex = 9;
  fixed32 crc = 10;                // checksum of the book after applying
}

Field numbers 10 to 22 are reserved and never sent. The checksum is CRC-32 as zlib computes it. For each strike in ascending order it covers the strike in thousandths as a little-endian int64, then the call and put values as little-endian float32 bits.

Generate bindings: Python

sh
pip install grpcio-tools protobuf
curl -sS -o rest.proto https://api.itmatrixhq.com/v2/rest-protocol.proto
curl -sS -o ws.proto   https://api.itmatrixhq.com/v2/ws-protocol.proto
python -m grpc_tools.protoc -I. --python_out=. rest.proto ws.proto
import os
import httpx
import rest_pb2

response = httpx.get(
    "https://api.itmatrixhq.com/v2/gex/SPY/grid",
    params={"top": 20},
    headers={
        "Authorization": f"Bearer {os.environ['ITM_API_KEY']}",
        "Accept": "application/x-protobuf",
    },
)
response.raise_for_status()
grid = rest_pb2.GexGridResponse.FromString(response.content)
for row in grid.rows:
    print(row.strike_thousandths / 1000, row.gex)

Generate bindings: TypeScript

With ts-proto and any protoc (the grpcio-tools one above works):

sh
npm install --save-dev ts-proto
npm install @bufbuild/protobuf
python -m grpc_tools.protoc -I. \
  --plugin=protoc-gen-ts_proto=./node_modules/.bin/protoc-gen-ts_proto \
  --ts_proto_out=./gen \
  --ts_proto_opt=forceLong=bigint,esModuleInterop=true \
  rest.proto ws.proto
import { GexGridResponse } from "./gen/rest";

const url = new URL("https://api.itmatrixhq.com/v2/gex/SPY/grid");
url.search = new URLSearchParams({ top: "20" }).toString();

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.ITM_API_KEY}`,
    Accept: "application/x-protobuf",
  },
});
if (!response.ok) throw new Error(JSON.stringify(await response.json()));
const grid = GexGridResponse.decode(new Uint8Array(await response.arrayBuffer()));
console.log(grid.netGex, grid.rows.length);

forceLong=bigint keeps 64-bit fields exact. The SDK tab on each example shows the same read through the SDK, which negotiates protobuf for you.

Keep your copy of the schemas current: re-encoding a decoded message with an older schema drops fields it does not know. See Versioning.