cURL · REST + WebSocket · NinjaTrader 8

cURL NinjaTrader 8 API examples

Hit the CrossTrade NinjaTrader API from any shell. curl for REST, wscat for WebSocket testing. Zero language overhead.

Why cURL

Using cURL against the CrossTrade NinjaTrader API

cURL is the universal CLI. Test the entire CrossTrade REST surface from any shell with one binary. For WebSocket, wscat (or websocat) gives you an interactive session. Best for debugging, smoke tests, and scripted CI checks.

REST curl (preinstalled on macOS / Linux)
WebSocket wscat (npm install -g wscat) or websocat
REST · animated

Watch the request get written

A pseudo-developer types out a real GET GetQuote call against your NinjaTrader 8 account. The animation runs on a loop; the static snippet below is yours to copy.

getquote.sh
Copy this

Complete cURL GetQuote example

TOKEN="your-bearer-token"

# GET a quote
curl -s "https://app.crosstrade.io/v1/api/accounts/Sim101/instruments/ES%2012-25/quote" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  | jq '.quote'

# POST place an order
curl -s -X POST "https://app.crosstrade.io/v1/api/accounts/Sim101/orders/place" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "instrument": "MES 12-25",
    "action": "BUY",
    "orderType": "MARKET",
    "quantity": 1,
    "timeInForce": "DAY"
  }'
WebSocket · animated

Streaming data with wscat (npm install -g wscat) or websocat

Same flow on a persistent connection: open the socket, send a subscribe message, receive market data or P&L pushes in real time. CrossTrade's WebSocket is at wss://app.crosstrade.io/ws/stream with the same Bearer token in the request header.

stream.sh
Copy this

Complete cURL WebSocket example

# Install once
npm install -g wscat

# Connect with bearer token header
wscat -c wss://app.crosstrade.io/ws/stream \
  -H "Authorization: Bearer YOUR_TOKEN"

# Then paste messages interactively
> {"action":"subscribe","instruments":["ES 12-25"]}
> {"action":"rpc","api":"ListAccounts","args":{}}
> {"action":"streamPnl","enabled":true}

The full cURL-compatible API surface

Every endpoint documented with request/response schemas, error codes, rate-limit notes, and language-specific code samples.

FAQ

Common questions

Is curl actually production-ready for trading?

Yes, for the right use cases. Cron-scheduled risk reports, CI smoke tests, ops debugging, and webhook integrations work great with curl. For long-running stateful logic (strategy execution, backtest sweeps) you'd use a real language. The cleanest production pattern is: curl scripts for ops + cron, Python/Go/Node for the trading bot itself.

Why URL-encode the instrument name?

NT8 instrument names contain spaces (e.g., "ES 12-25"). URL paths need %20 instead. Most HTTP clients do this automatically; curl does not. Either use --data-urlencode for query params or manually escape (ES%2012-25). jq doesn't mind, neither does CrossTrade — the encoding is only required in transit.

Do I need jq?

Technically optional, but practically yes — CrossTrade responses are JSON and curl prints them raw, which is unreadable for anything non-trivial. jq makes filtering and extracting fields a one-liner. Install via brew install jq or apt install jq.

Windows PowerShell equivalent?

Yes — use Invoke-RestMethod (built into PowerShell, no install) for REST. It auto-parses JSON into objects. For WebSocket on Windows, use the WindowsClient class from System.Net.WebSockets or run WSL with wscat. The Authorization header pattern is identical: -Headers @{Authorization="Bearer $token"}.

Running curl in cron?

Yes, with these conventions: put the script in /etc/cron.d/, source secrets from a file with mode 0600 (don't embed the token in the script), redirect stdout to a log file, add set -euo pipefail at the top so failures actually fail. Mail-on-failure via MAILTO= in the crontab.

WebSocket via curl directly?

curl 7.86+ has experimental WebSocket support (CURLOPT_WS_RAW_MODE), but it's rough. The standard pattern is wscat (Node-based) or websocat (Rust binary). websocat composes better with shell pipes; wscat is more interactive.

curl vs HTTPie?

HTTPie (http command) has prettier output and simpler syntax for JSON bodies. If your shell scripts will be edited by humans, HTTPie is more readable. For automation, curl's ubiquity wins — it's on every Unix system without an install step.

Can I use curl from a CI pipeline to verify CrossTrade connectivity?

Yes, exactly. A two-line script that calls any read endpoint (e.g., GetAccountSummary) and checks the exit code is a perfect post-deploy smoke test. CrossTrade 200 responses include a "success": true field that you can grep / jq for.

Securing the bearer token in shell scripts?

Source it from a separate file: source ~/.crosstrade-secrets (which contains export TOKEN="..."), and chmod 600 that file. Never commit the token to git, never embed it in the script itself. Use a secret manager (AWS SSM, Vault, age-encrypted files) for production / shared environments.

Build your first NinjaTrader 8 trading bot in cURL

One bearer token, one URL, every NinjaTrader endpoint. Ship to Sim101 first.