Choose the contract and check the schema
Open the public schema to check available columns, then run this discovery query in the Outcome playground. Copy venue and ticker from the contract you want; review its title, rules, and dates. The discovery query spends credits. Reading GET /v1/schema is free and needs no key.
SELECT venue, ticker, title, yes_sub_title, no_sub_title,
open_time, close_time, rules_primary
FROM markets FINAL
WHERE is_deleted = 0
ORDER BY volume_24h DESC
LIMIT 20Save the extract as trades.sql
Replace YOUR_VENUE and YOUR_TICKER with those exact values and choose dates inside the contract's history. Save this SQL in trades.sql. The half-open interval includes the start and excludes the next day's boundary, so adjacent daily extracts do not overlap. The timestamp column is Unix milliseconds; yes_price is on the 0–1 scale and count is Kalshi contracts or Polymarket outcome shares. For Polymarket, YES means the first outcome slot, which may have a label such as Up or a team name; check the market labels before interpreting it.
There is deliberately no LIMIT: the export should include every matching row. Exporting bypasses the JSON endpoint's 10,000-row and 8 MiB response caps. Time, query-memory, and individual-row limits still apply; split large extracts by date if needed. Available history can be incomplete, so a successful export does not establish full venue coverage.
SELECT venue, ticker, trade_id,
toUnixTimestamp64Milli(created_time) AS timestamp_ms,
yes_price, no_price, count
FROM trades
WHERE venue = 'YOUR_VENUE'
AND ticker = 'YOUR_TICKER'
AND is_deleted = 0
AND created_time >= toDateTime('2026-10-01 00:00:00', 'UTC')
AND created_time < toDateTime('2026-10-02 00:00:00', 'UTC')
ORDER BY created_time, trade_idCreate the CSV and download it
Create an API key, set OUTCOME_API_KEY in your shell, and run sh export.sh beside trades.sql in a fresh directory. The script refuses existing export files. POST /v1/exports is synchronous: keep the connection open until it returns a completed export. There is no background-job status to poll. Creation allows 61 minutes; downloading allows 15 minutes and promotes trades.csv.part only after success.
Creation runs a billed SQL query. This example enables final to deduplicate trades before export; it can scan more data. Successful queries cost one base credit plus scan and duration charges; 1,000 credits equal $1. Inspect completion.credits_used in the saved receipt. Narrowing returned columns and dates helps control work; an output LIMIT does not guarantee a cheap scan.
#!/bin/sh
set -eu
umask 077
: "${OUTCOME_API_KEY:?Set OUTCOME_API_KEY first}"
for file in export-id.txt trade-export.json trades.csv trades.csv.part; do
if [ -e "$file" ]; then
echo "Existing $file: use a fresh directory or the recovery script." >&2
exit 1
fi
done
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
jq -Rs '{query: ., format: "csv", final: true, name: "trade-history"}' \
trades.sql > "$tmp/request.json"
if ! curl --silent --show-error --fail-with-body --max-time 3660 \
--proto '=https' --dump-header "$tmp/headers" \
--output "$tmp/export.json" \
-H "Authorization: Bearer $OUTCOME_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @"$tmp/request.json" https://api.outcome.sh/v1/exports; then
awk 'tolower($1)=="x-export-id:" {gsub("\r", "", $2); print $2}' \
"$tmp/headers" > export-id.txt
echo 'Creation failed. Check export-id.txt and Exports before rerunning.' >&2
exit 1
fi
jq -e '.format == "csv" and .completion.type == "complete"
and .completion.success == true and (.id | type == "string")' \
"$tmp/export.json" > /dev/null
jq -r '.id' "$tmp/export.json" > export-id.txt
jq 'del(.download_url)' "$tmp/export.json" > trade-export.json
url=$(jq -er '.download_url' "$tmp/export.json")
# The signed storage URL needs no Outcome Authorization header.
curl --silent --show-error --fail --max-time 900 --proto '=https' \
--url "$url" --output trades.csv.part
mv trades.csv.part trades.csv
echo 'Saved trades.csv and trade-export.json'Check the saved rows before analyzing them
This streaming check compares the CSV count with the server's completion record and prints the first and last observed UTC timestamps. An empty result often means a wrong identifier or date range. Preserve trades.sql and the receipt with your dataset. CSV turns nulls into empty cells and prefixes formula-like strings for spreadsheet safety; choose ndjson when exact original string values matter.
import csv
import json
from datetime import datetime, timezone
with open("trade-export.json") as f:
receipt = json.load(f)
rows, first, last = 0, None, None
with open("trades.csv", newline="") as f:
for row in csv.DictReader(f):
timestamp = int(row["timestamp_ms"])
first = timestamp if first is None else min(first, timestamp)
last = timestamp if last is None else max(last, timestamp)
rows += 1
completion = receipt.get("completion", {})
expected_rows = completion.get("row_count")
if expected_rows is not None and rows != expected_rows:
raise RuntimeError("CSV row count does not match export receipt")
if expected_rows is None:
print("Recovered export: original server row count unavailable")
print("Rows:", rows, "Credits:", completion.get("credits_used", "unavailable"))
for label, timestamp in (("First", first), ("Last", last)):
if timestamp is not None:
print(label, datetime.fromtimestamp(timestamp / 1000, timezone.utc).isoformat())Recover a download without buying the same query again
If downloading fails or a link expires, run recovery.sh below instead of export.sh. It renews the saved export ID without rerunning SQL. For a creation failure, use any X-Export-ID saved in export-id.txt, or find the completed file's ID in Exports and save it there. A 404 means no completed file is available to your team, not a pending job. Fix 401 authentication or 402 credit errors before retrying; never automatically repeat creation after an ambiguous failure.
Recovery preserves the original receipt when available. If creation's response was lost, the renewed response does not contain the original row count or credits; the Python check reports those as unavailable. Signed links grant file access, so keep them out of logs and public notebooks. Links last up to one hour and files are retained for seven days.
#!/bin/sh
set -eu
umask 077
: "${OUTCOME_API_KEY:?Set OUTCOME_API_KEY first}"
id=$(cat export-id.txt)
printf '%s' "$id" | grep -Eq '^[0-9a-fA-F-]{36}$' || exit 1
if [ -f trade-export.json ]; then
jq -e --arg id "$id" '.id == $id and .format == "csv"' \
trade-export.json > /dev/null
elif [ -e trades.csv ]; then
echo 'CSV exists without a matching receipt; recover in a fresh directory.' >&2
exit 1
fi
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
curl --silent --show-error --fail-with-body --max-time 60 --proto '=https' \
-H "Authorization: Bearer $OUTCOME_API_KEY" \
--output "$tmp/export.json" "https://api.outcome.sh/v1/exports/$id"
jq -e --arg id "$id" '.id == $id and .format == "csv"' \
"$tmp/export.json" > /dev/null
url=$(jq -er '.download_url' "$tmp/export.json")
curl --silent --show-error --fail --max-time 900 --proto '=https' \
--url "$url" --output trades.csv.part
if [ ! -f trade-export.json ]; then
jq 'del(.download_url)' "$tmp/export.json" > trade-export.json
fi
mv trades.csv.part trades.csv
echo 'Recovered trades.csv without rerunning SQL'