Developers

API Documentation

Programmatic access to our normalized market-data feed and the metrics engine behind our open-source order-flow library. Built for low-latency research and backtesting.

Market Data Streams (WebSockets)

Our WebSocket API provides ultra-low latency, real-time market data directly from our normalized feed. Subscribe to multiple channels (L1, L2 order books, trades) across different venues over a single connection. The feed is optimized for minimal bandwidth footprint and maximum speed.

connect_websocket.py
import asyncio
import websockets
import json

async def stream_market_data():
    uri = "wss://data.twowaymind.com/v1/stream"
    async with websockets.connect(uri) as ws:
        # Subscribe to ES (S&P 500) Level 2 Order Book
        sub_msg = {
            "action": "subscribe",
            "channel": "l2_book",
            "symbols": ["CME:ES"]
        }
        await ws.send(json.dumps(sub_msg))

        while True:
            data = await ws.recv()
            print(data)

Metrics Engine (REST / FIX)

Submit a window of trades or book snapshots via REST or FIX Protocol 4.4 and receive computed microstructure metrics — order-flow imbalance, VPIN, effective spread — in a single round trip. Every computation mirrors a function in our dependency-free open-source library, so results are fully reproducible offline. Standard rate limits apply for REST, while FIX sessions offer dedicated bandwidth.

compute_metrics.cpp
// C++ Low-Latency Metrics Request (cURL)
#include <iostream>
#include <curl/curl.h>

int main() {
    CURL *curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.twowaymind.com/v1/metrics/ofi");
        
        // Payload: a trade window to score for order-flow imbalance
        const char* json = "{\"symbol\": \"CME:ES\", \"window\": \"5m\", \"bucket\": \"volume\", \"metric\": \"ofi\"}";
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);

        CURLcode res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    return 0;
}

Endpoint Reference (REST)

The base URL for all REST API endpoints is https://api.twowaymind.com/v1/. All requests must be authenticated using a JWT token in the Authorization: Bearer header. Every endpoint mirrors a function in our open-source library, so you can prototype locally with no credentials before moving to the hosted feed.

Method Endpoint Description Rate Limit
GET /markets/symbols List all tradable instruments. 100/sec
POST /metrics/ofi Compute order-flow imbalance over a submitted trade / book window. 1000/sec
POST /metrics/vpin Compute VPIN flow-toxicity over a volume-bucketed window. 1000/sec
GET /data/l2 Fetch a Level-2 order-book snapshot for a symbol. 50/sec

Payload Structure & Types

Metric requests accept strictly typed JSON payloads. The metric field supports ofi, vpin, effective_spread, and kyle_lambda. For volume-clock metrics we recommend setting the bucket parameter (volume, dollar, or tick) to match the sampling used in your research.

Responses are returned in JSON format with a standard wrapper containing a success boolean, an error_code (if applicable), and a data object.