SPB Git

Repository Public

record-fixtures-remote.sh 9.9 KB 120 lines shellscript

1#!/bin/bash2# Runs ON the node that hosts the frozen test backend (port 5058). Called by Scripts/record-fixtures.sh.3# Writes raw responses to /tmp/vqkit-fx. Never prints the token.4set -u5B=http://localhost:50586OUT=/tmp/vqkit-fx; rm -rf "$OUT"; mkdir -p "$OUT"7H="Authorization: Bearer $(cat /tmp/vq-api-token)"8C="X-VQ-Client: vquant-macos/2.0.0"9g() { curl -s -m 60 -H "$H" -H "$C" "$B$1" -o "$OUT/$2" -w "%{http_code} $2\n"; }10send() { curl -s -m 60 -X "$1" -H "$H" -H "$C" -H "Content-Type: application/json" -d "$3" "$B$2" -o "$OUT/$4" -w "%{http_code} $4\n"; }1112g /api/config config.json13g /api/v2/models models.json14g "/api/v2/models/route?mode=deep&vision=false&q=Compare%20AAPL%20and%20MSFT%20margins" route.json15g /api/v2/market/overview market_overview.json16g /api/v2/data/health data_health.json17g "/api/v2/data/bars/AAPL?interval=1d" bars_aapl_1d.json18g "/api/v2/data/bars/EURUSD?interval=1d" bars_eurusd_1d.json19g "/api/v2/data/bars/AAPL?interval=5m" bars_aapl_5m.json20g "/api/v2/data/bars/ZZZZNOPE?interval=1d" bars_error.json21g "/api/v2/data/quotes?symbols=AAPL,MSFT,EURUSD,BTCUSD,%5EGSPC,ZZZZNOPE" quotes.json22g "/api/v2/data/statements/AAPL?period=annual&limit=4" statements_aapl.json23g "/api/v2/search?q=apple&limit=12" search_apple.json24g "/api/v2/search?q=" search_empty.json25g /api/quant/tools quant_tools.json26curl -s -m 60 -H "$H" -H "X-VQ-Client: vquant-macos/1.0.1" "$B/api/quant/tools" -o "$OUT/quant_tools_legacy_client.json" -w "%{http_code} quant_tools_legacy_client.json\n"27g "/api/v2/usage?days=30" usage.json28g "/api/v2/audit?limit=15" audit.json29g /api/v2/memory memory.json30g /api/quant/jobs quant_jobs_list.json3132# ── objects (ids prefixed kit-test-) ─────────────────────────────────────────33put() { # kind id data — creates, or recreates over a tombstone / updates at the current rev34  local code35  code=$(curl -s -m 30 -X PUT -H "$H" -H "$C" -H "Content-Type: application/json" -d "{\"data\":$3,\"baseRev\":0}" "$B/api/v2/objects/$1/$2" -o "$OUT/put_$1.json" -w "%{http_code}")36  if [ "$code" = "409" ]; then37    cp "$OUT/put_$1.json" "$OUT/conflict_$1.json"38    local rev del39    rev=$(python3 -c "import json,sys;d=json.load(open('$OUT/put_$1.json'))['current'];print(d['rev'] if not d['deleted'] else 0)")40    code=$(curl -s -m 30 -X PUT -H "$H" -H "$C" -H "Content-Type: application/json" -d "{\"data\":$3,\"baseRev\":$rev}" "$B/api/v2/objects/$1/$2" -o "$OUT/put_$1.json" -w "%{http_code}")41  fi42  echo "$code put_$1.json"43}44put watchlist kit-test-watchlist '{"name":"Kit test — megacaps","symbols":["AAPL","MSFT","NVDA","GOOGL"],"note":"fixture","kitFutureField":{"a":[1,2,{"b":null}]}}'45put portfolio kit-test-portfolio '{"name":"Kit test portfolio","baseCurrency":"USD","benchmark":"SPY","cash":[{"currency":"USD","amount":1500.5},{"currency":"CAD","amount":200}],"positions":[{"symbol":"AAPL","quantity":10,"costBasis":150.25,"currency":"USD","note":"core","openedAt":1700000000000,"updatedAt":1700000001000},{"symbol":"SHOP.TO","quantity":4,"costBasis":98,"currency":"CAD"}]}'46put workspace kit-test-workspace '{"name":"Kit test workspace","icon":"chart","layout":{"type":"split","direction":"row","sizes":[0.6,0.4],"children":[{"type":"panel","panelId":"p1"},{"type":"split","direction":"column","sizes":[0.5,0.5],"children":[{"type":"panel","panelId":"p2"},{"type":"panel","panelId":"p3"}]}]},"panels":{"p1":{"type":"chart","title":"AAPL","config":{"chartId":"kit-test-chart"}},"p2":{"type":"watchlist","title":"Megacaps","config":{"watchlistId":"kit-test-watchlist"}},"p3":{"type":"quote","title":"MSFT","config":{"symbol":"MSFT"}}}}'47put chart kit-test-chart '{"symbol":"AAPL","interval":"1d","range":"1y","chartType":"candles","logScale":false,"adjust":"split_div","indicators":[{"id":"i1","type":"sma","params":{"period":50},"pane":"price"},{"id":"i2","type":"rsi","params":{"period":14},"pane":"lower"}],"compare":["MSFT"],"drawings":[{"id":"d1","type":"trendline","points":[{"t":1730419200,"p":220.5},{"t":1733011200,"p":240}],"style":{"color":"cat-1","width":1.5},"text":"trend"}],"events":true}'48put note kit-test-note '{"title":"Kit test note","body":"# Thesis\n\nMargins **expand** when $r_t$ falls.","projectId":"kit-test-project"}'49put project kit-test-project '{"title":"Kit test project","question":"Does volatility cluster in AAPL?","hypotheses":[{"id":"h1","text":"GARCH persistence above 0.9","status":"open"}],"status":"active","dataSources":[{"id":"s1","provider":"fmp","description":"Daily bars"}],"items":[{"id":"it1","type":"note","ref":"kit-test-note","title":"Thesis","addedAt":1763600000000},{"id":"it2","type":"watchlist","ref":"kit-test-watchlist","title":"Megacaps","addedAt":1763600001000},{"id":"it3","type":"chart","ref":"kit-test-chart","addedAt":1763600002000},{"id":"it4","type":"notebook","ref":"nb-none","title":"A notebook"}],"summary":"Fixture project."}'50# an update (rev 2) and a stale write (409) on the watchlist, then a delete of a scratch object51REV=$(python3 -c "import json;print(json.load(open('$OUT/put_watchlist.json'))['object']['rev'])")52send PUT /api/v2/objects/watchlist/kit-test-watchlist "{\"data\":{\"name\":\"Kit test — megacaps\",\"symbols\":[\"AAPL\",\"MSFT\",\"NVDA\",\"GOOGL\",\"AMZN\"],\"note\":\"fixture\",\"kitFutureField\":{\"a\":[1,2,{\"b\":null}]}},\"baseRev\":$REV}" put_watchlist_update.json53send PUT /api/v2/objects/watchlist/kit-test-watchlist "{\"data\":{\"name\":\"stale\",\"symbols\":[]},\"baseRev\":$REV}" conflict_stale.json54put watchlist kit-test-scratch '{"name":"scratch","symbols":["SPY"]}'55REV=$(python3 -c "import json;print(json.load(open('$OUT/put_watchlist.json'))['object']['rev'])")56curl -s -m 30 -X DELETE -H "$H" -H "$C" "$B/api/v2/objects/watchlist/kit-test-scratch?baseRev=$REV" -o "$OUT/delete_watchlist.json" -w "%{http_code} delete_watchlist.json\n"57send PUT /api/v2/objects/review/kit-test-review '{"data":{},"baseRev":0}' error_review_forbidden.json58send PUT /api/v2/objects/watchlist/kit-test-bad '{"data":{"symbols":"nope"},"baseRev":0}' error_validation.json59for k in watchlist portfolio workspace chart project note review preference; do g /api/v2/objects/$k objects_$k.json; done60g /api/v2/objects/watchlist/kit-test-watchlist object_watchlist.json61g /api/v2/objects/note/kit-test-note/versions versions_note.json62g /api/v2/objects/watchlist/kit-test-scratch error_not_found.json63g "/api/v2/sync/changes?since=0&limit=1000" sync_changes_all.json64g "/api/v2/sync/changes?since=0&limit=3" sync_changes_page.json65g "/api/v2/sync/changes?since=0&kinds=watchlist,project&limit=50" sync_changes_kinds.json66g /api/v2/projects/kit-test-project/bundle project_bundle.json67( curl -s -N -m 4 -H "$H" -H "$C" "$B/api/v2/sync/stream" > "$OUT/sync_stream.txt" ) 2>/dev/null; echo "sse sync_stream.txt"6869# ── quant jobs: one per engine ───────────────────────────────────────────────70job() { # name tool params71  local id st72  id=$(curl -s -m 30 -X POST -H "$H" -H "$C" -H "Content-Type: application/json" -d "{\"tool\":\"$2\",\"params\":$3}" "$B/api/quant/jobs" | tee "$OUT/job_start_$1.json" | python3 -c "import json,sys;d=json.load(sys.stdin);print(d.get('job',{}).get('id',''))")73  if [ -z "$id" ]; then echo "START-FAILED $1: $(head -c 300 "$OUT/job_start_$1.json")"; return; fi74  for i in $(seq 1 150); do75    curl -s -m 30 -H "$H" -H "$C" "$B/api/quant/jobs/$id" -o "$OUT/job_$1.json"76    st=$(python3 -c "import json;d=json.load(open('$OUT/job_$1.json'));print(d.get('job',d).get('status'))")77    [ "$i" = "2" ] && cp "$OUT/job_$1.json" "$OUT/job_running_$1.json"78    [ "$st" != "running" ] && break79    sleep 280  done81  echo "$st job_$1.json ($(wc -c < "$OUT/job_$1.json") bytes)"82}83job volatility_lab volatility_lab '{"symbol":"AAPL","compare":true}' &84job risk_lab risk_lab '{"symbols":["AAPL","MSFT","TLT"]}' &85job regression regression '{"symbol":"AAPL","regressors":["SPY"]}' &86wait87job time_series time_series '{"symbol":"AAPL"}' &88job options_strategy options_lab '{"symbol":"SPY","mode":"strategy","template":"straddle"}' &89job backtest backtest '{"symbols":["SPY"],"sensitivity":true}' &90wait91job portfolio_lab portfolio_lab '{"symbols":["SPY","TLT","GLD"]}' &92job var_model var_model '{"symbols":["SPY","TLT"]}' &93job pca pca '{"symbols":["AAPL","MSFT","NVDA","GOOGL","AMZN","JPM"]}' &94wait95job factor_model factor_model '{"symbols":["AAPL"]}' &96job bootstrap bootstrap '{"symbol":"AAPL"}' &97job panel panel '{"symbols":["AAPL","MSFT","NVDA","GOOGL","AMZN","JPM"]}' &98wait99job event_study event_study '{"symbols":["AAPL"]}' &100job options_chain options_lab '{"symbol":"SPY","mode":"chain"}' &101job options_price options_lab '{"symbol":"SPY","mode":"price"}' &102wait103job legacy_garch garch '{"symbol":"AAPL"}' &104job failure regression '{"symbol":"ZZZZNOPE"}' &105wait106# a cancelled job107CID=$(curl -s -m 30 -X POST -H "$H" -H "$C" -H "Content-Type: application/json" -d '{"tool":"bootstrap","params":{"symbol":"MSFT","replications":20000}}' "$B/api/quant/jobs" | python3 -c "import json,sys;print(json.load(sys.stdin)['job']['id'])")108sleep 1109send POST "/api/quant/jobs/$CID/cancel" '{}' job_cancel.json110g "/api/quant/jobs/$CID" job_cancelled.json111send POST "/api/quant/jobs/$CID/cancel" '{}' job_cancel_not_running.json112# ── one real fast generation (a cent of model usage): stream events, then the stored session and its trace ──113SID=$(python3 -c "import uuid;print(uuid.uuid4())")114curl -s -N -m 170 -X POST -H "$H" -H "$C" -H "Content-Type: application/json" -H "Accept: text/event-stream" \115  -d "{\"query\":\"Quel est le dernier cours de clôture de AAPL ? Une seule phrase.\",\"mode\":\"fast\",\"model\":\"auto\",\"sessionId\":\"$SID\",\"budget\":{\"maxCostUsd\":0.5,\"maxMinutes\":3}}" \116  "$B/api/chat" -o "$OUT/generation_stream.txt" -w "%{http_code} generation_stream.txt\n"117g "/api/sessions/$SID" session_with_provenance.json118g "/api/v2/generations/x/trace?sessionId=$SID" generation_trace.json119ls -la "$OUT" | awk '{print $5, $9}'120
Files main
Menu

Theme