Services
Trading Tools v2

Trading Tools v2

Repo: /opt/tradingtools-v2 (pnpm monorepo, package tradingtools-v2) Server: Cherry (84.32.176.16), co-located with insiders-api · PM2 user: root Control API: tradingv2.polyinsiders.com127.0.0.1:9110 (token-gated)

Trading Tools v2 is a headless internal system and the production copy-trading engine as of the 2026-05-31 cutover — it replaced the old /opt/copytrading stack (see Copy Trading (Legacy)). There is no public-facing trading API; all user interaction goes through the Insiders backend as a proxy.

Design principles

  • Built from scratch. The only thing carried over from /opt/copytrading is the websocket listener.
  • Execution is orchestration. All buys/sells/redeems go through the insiders-api HTTP layer — no Polymarket SDK in v2.
  • Crash-isolated. One process per layer (PM2), queue-backed (Redis Streams + BullMQ), idempotent, circuit-broken.
  • Speed. Target ws_recv → submit < 250ms, end-to-end fill 1–2s (old listener was 6–7s).
  • One TP/SL for both products — shared by the trading terminal and the copy-trade bot.

Pipeline

Polymarket WS → tt-ingest → tt-router → tt-executor → tt-confirm → register TP/SL (tt-tpsl / GUARD)
                              └── idempotency: (leaderTx, followerWallet, assetId)

PM2 processes (Cherry, root)

Defined in ops/pm2/ecosystem.config.cjs — one process per layer, independent crash domains.

ProcessPackageRole
tt-ingestpackages/ingestCarried-over WS → normalized LeaderTradeEvent
tt-bookfeedpackages/ingest (bookfeed.cjs)CLOB book → mark.prices + bid/ask snapshot
tt-routerpackages/routerMatch + sizing + parallel fanout + idempotency
tt-executorpackages/executorExecution workers over insiders-api
tt-confirmpackages/confirmFill confirmation + TP/SL registration
tt-tpslpackages/tpsl (GUARD)Standalone price-reactive rule engine (TP/SL, ladders, trailing)
tt-enrichmentpackages/enrichmentRead-only ClickHouse → Redis cache builder
tt-perfmonpackages/perfmonPerformance-triggered rules (loss-stop / profit-scale)
tt-control-apiapps/control-apiHTTP control surface :9110
packages/sharedShared types, insiders-api client, db (prisma), redis, config, logger

control-api · :9110

Source: /opt/tradingtools-v2/apps/control-api/src/index.ts

Exposed at tradingv2.polyinsiders.com via nginx (enabled 2026-06-01). Token-gated:

  • All routes require Authorization: Bearer <CONTROL_API_TOKEN> (64-hex, set in /opt/tradingtools-v2/.env).
  • /health + /ready stay unauthed for nginx/pm2 probes.
  • The two internal endpoints (/subscriptions/funding, /subscriptions/:id/perf-action) are edge-denied (404) on top of the token.
  • Identity is body-asserted (caller states followerUserId/WalletId/Proxy), so token + network-reach = full impersonation — only the Insiders backend proxy should call it.

Full route docs:

Quick reference

MethodPathCategory
POST/subscriptionsSubscription
GET/subscriptions?followerProxy=0x…Subscription
GET/subscriptions/:idSubscription
GET/subscriptions/:id/fillsSubscription
PATCH/subscriptions/:idSubscription
POST/subscriptions/:id/pauseSubscription
POST/subscriptions/:id/resumeSubscription
DELETE/subscriptions/:idSubscription
POST/subscriptions/fundingInternal (edge-denied)
POST/subscriptions/:id/perf-actionInternal (edge-denied)
POST/triggersTPSL (GUARD)
PATCH/triggers/:idTPSL (GUARD)
DELETE/triggers/:idTPSL (GUARD)
GET/triggers?wallet=0x…TPSL (GUARD)
GET/triggers/:idTPSL (GUARD)
GET/healthInfra
GET/readyInfra

Data stores

  • PostgreSQL (db/schema.prisma) — durable: subscriptions, copy_fills, tpsl_triggers, audit_log
  • Redis — hot subscription index, BullMQ queues, dedupe (SETNX), trigger set, breaker state
  • No SQLite.

Build & ops

CommandPurpose
pnpm buildesbuild bundle → dist/main.cjs per layer (see scripts/build.mjs)
pnpm typechecktsc -b gate
pnpm pm2:start / pnpm pm2:stoppm2 start/delete ops/pm2/ecosystem.config.cjs

Key docs in codebase (/opt/tradingtools-v2/docs)

FileContents
control_api_wire_spec_v1.mdFull wire-true API spec (captured live 2026-05-30)
control_api_nginx_handoff_v1.mdEdge-exposure / TLS / IP-allowlist handoff
tpsl_control_api_v1.mdGUARD TPSL full schema
migration_dryrun_2026-05-30/cutover_report_2026-05-31.mdv1→v2 cutover (212 subs)
v1_subs_migration_plan_v1.mdV1→V2 subscription migration plan
TRADINGTOOLS_V2_ARCHITECTURE.mdSystem architecture overview (repo root)