openapi: 3.1.0 info: # Do not change the title, if the title changes, the import paths will be broken title: Api version: 0.1.0 description: CANTEX-SWAP bot management API servers: - url: /api description: Base API path tags: - name: health description: Health operations - name: accounts description: Cantex account management - name: settings description: Bot configuration - name: bot description: Bot status, control and live data - name: swaps description: Swap history and activity paths: /healthz: get: operationId: healthCheck tags: [health] summary: Health check description: Returns server health status responses: "200": description: Healthy content: application/json: schema: $ref: "#/components/schemas/HealthStatus" /accounts: get: operationId: listAccounts tags: [accounts] summary: List all linked Cantex accounts responses: "200": description: List of accounts with current balances content: application/json: schema: type: array items: $ref: "#/components/schemas/Account" post: operationId: createAccount tags: [accounts] summary: Add a new Cantex account requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateAccountBody" responses: "201": description: Account created content: application/json: schema: $ref: "#/components/schemas/Account" /accounts/{id}: parameters: - name: id in: path required: true schema: type: string delete: operationId: deleteAccount tags: [accounts] summary: Unlink a Cantex account responses: "204": description: Account removed /accounts/{id}/pause: parameters: - name: id in: path required: true schema: type: string post: operationId: toggleAccountPause tags: [accounts] summary: Pause or resume bot activity on this account requestBody: required: true content: application/json: schema: type: object required: [paused] properties: paused: type: boolean responses: "200": description: Account updated content: application/json: schema: $ref: "#/components/schemas/Account" /accounts/{id}/reset-count: parameters: - name: id in: path required: true schema: type: string post: operationId: resetAccountCount tags: [accounts] summary: Reset today's swap counter for this account responses: "200": description: Counter reset content: application/json: schema: $ref: "#/components/schemas/Account" /settings: get: operationId: getSettings tags: [settings] summary: Get the current bot configuration responses: "200": description: Current settings content: application/json: schema: $ref: "#/components/schemas/BotSettings" put: operationId: updateSettings tags: [settings] summary: Save bot configuration requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateBotSettingsBody" responses: "200": description: Updated settings content: application/json: schema: $ref: "#/components/schemas/BotSettings" /bot/status: get: operationId: getBotStatus tags: [bot] summary: Live bot status (running, uptime, fee, totals) responses: "200": description: Bot status snapshot content: application/json: schema: $ref: "#/components/schemas/BotStatus" /bot/toggle: post: operationId: toggleBot tags: [bot] summary: Pause or resume the entire bot requestBody: required: true content: application/json: schema: type: object required: [running] properties: running: type: boolean responses: "200": description: Updated bot status content: application/json: schema: $ref: "#/components/schemas/BotStatus" /bot/sync-balances: post: operationId: syncBalances tags: [bot] summary: Request an immediate balance refresh for all accounts description: Sets a flag in bot_state; the worker picks it up on its next tick (within fee_watch_interval seconds) and refreshes all account balances from the Cantex API. responses: "200": description: Sync queued content: application/json: schema: $ref: "#/components/schemas/SyncBalancesResult" /swaps: get: operationId: listSwaps tags: [swaps] summary: Paginated swap history parameters: - name: limit in: query required: false schema: type: integer minimum: 1 maximum: 500 default: 100 - name: offset in: query required: false schema: type: integer minimum: 0 default: 0 - name: accountId in: query required: false schema: type: string responses: "200": description: Page of swaps content: application/json: schema: $ref: "#/components/schemas/SwapsPage" /swaps/{id}/reconcile: post: operationId: reconcileSwap tags: [swaps] summary: Manually reconcile a pending swap that missed the 240s confirmation window description: | Fetches current account balances from the DB and applies the same heuristic used by the background reconciler: if the buy-token balance is above dust OR the sell-token balance dropped below 50% of the sell amount, the swap is marked success. Returns `not_landed` if the balance check shows the swap has not yet settled. parameters: - name: id in: path required: true schema: type: string responses: "200": description: Reconcile result content: application/json: schema: $ref: "#/components/schemas/ReconcileResult" "404": description: Swap or account not found "409": description: Swap is not pending or not old enough yet /activity: get: operationId: listActivity tags: [bot] summary: Paginated bot activity log parameters: - name: limit in: query required: false schema: type: integer minimum: 1 maximum: 500 default: 100 - name: offset in: query required: false schema: type: integer minimum: 0 default: 0 - name: accountId in: query required: false schema: type: string responses: "200": description: Page of activity events content: application/json: schema: $ref: "#/components/schemas/ActivityPage" components: schemas: HealthStatus: type: object properties: status: type: string required: [status] Account: type: object required: - id - name - paused - createdAt - swapsToday - totalSwaps - balanceUsdcx - balanceCc - balanceCbtc - status properties: id: type: string name: type: string paused: type: boolean status: type: string description: connection / authentication status enum: [unknown, ok, error] statusMessage: type: string nullable: true partyAddress: type: string nullable: true createdAt: type: string format: date-time lastCheckedAt: type: string format: date-time nullable: true swapsToday: type: integer totalSwaps: type: integer balanceUsdcx: type: string description: Decimal as string balanceCc: type: string balanceCbtc: type: string CreateAccountBody: type: object required: [name, operatorKey, tradingKey] properties: name: type: string minLength: 1 maxLength: 80 operatorKey: type: string description: Hex-encoded Ed25519 operator private key minLength: 32 tradingKey: type: string description: Hex-encoded secp256k1 intent trading private key minLength: 32 BotSettings: type: object required: - maxTradesPerDay - swapMode - pollIntervalSec - takeProfitPct - stopLossPct - dailyDrawdownLimitCc - maxCcPerTrade - gasReservedCc - maxCantonGasFeeCc - maxSlippagePct - feeWatchIntervalSec - randomDelayMinSec - randomDelayMaxSec properties: maxTradesPerDay: type: integer swapMode: type: string enum: [USDCx_CBTC_BACK_AND_FORTH] pollIntervalSec: type: number takeProfitPct: type: number stopLossPct: type: number dailyDrawdownLimitCc: type: number maxCcPerTrade: type: number gasReservedCc: type: number maxCantonGasFeeCc: type: number maxSlippagePct: type: number description: Max acceptable slippage on the live re-quote vs the pre-flight quote (e.g. 0.02 = 2%) feeWatchIntervalSec: type: number randomDelayMinSec: type: number randomDelayMaxSec: type: number UpdateBotSettingsBody: type: object required: - maxTradesPerDay - swapMode - pollIntervalSec - takeProfitPct - stopLossPct - dailyDrawdownLimitCc - maxCcPerTrade - gasReservedCc - maxCantonGasFeeCc - maxSlippagePct - feeWatchIntervalSec - randomDelayMinSec - randomDelayMaxSec properties: maxTradesPerDay: type: integer minimum: 0 swapMode: type: string enum: [USDCx_CBTC_BACK_AND_FORTH] pollIntervalSec: type: number minimum: 1 takeProfitPct: type: number minimum: 0 stopLossPct: type: number minimum: 0 dailyDrawdownLimitCc: type: number minimum: 0 maxCcPerTrade: type: number minimum: 0 gasReservedCc: type: number minimum: 0 maxCantonGasFeeCc: type: number minimum: 0 maxSlippagePct: type: number minimum: 0 maximum: 1 feeWatchIntervalSec: type: number minimum: 1 randomDelayMinSec: type: number minimum: 0 randomDelayMaxSec: type: number minimum: 0 BotStatus: type: object required: - running - startedAt - currentGasFeeCc - gasFeeOk - maxGasFeeCc - totalAccounts - activeAccounts - swapsToday - totalSwaps - swapsDeferredToday - totalSwapsDeferred - lastSwapAt - workerOnline - lastWorkerHeartbeatAt properties: running: type: boolean startedAt: type: string format: date-time nullable: true currentGasFeeCc: type: number nullable: true gasFeeOk: type: boolean maxGasFeeCc: type: number totalAccounts: type: integer activeAccounts: type: integer swapsToday: type: integer totalSwaps: type: integer swapsDeferredToday: type: integer description: Trades held back today by gas-ceiling, gas-reserve, or slippage guardrails (never submitted) totalSwapsDeferred: type: integer description: All-time deferred (held-back) trade count lastSwapAt: type: string format: date-time nullable: true workerOnline: type: boolean lastWorkerHeartbeatAt: type: string format: date-time nullable: true lastGasDropAt: type: string format: date-time nullable: true description: When the gas-watch task last detected gas crossing below the ceiling lastGasDropReactionMs: type: integer nullable: true description: Milliseconds from gas-drop detection to trading batch completion warmQuoteHits: type: integer description: All-time count of swaps that used a pre-cached quote (fast path) warmQuoteMisses: type: integer description: All-time count of swaps that had to fetch a live quote (slow path) gasDropsToday: type: integer description: Number of times gas crossed below the ceiling today (resets at UTC midnight) SwapEvent: type: object required: - id - accountId - accountName - leg - status - createdAt properties: id: type: string accountId: type: string accountName: type: string leg: type: string description: Which leg of the 2-leg swap enum: [USDCx_TO_CC, CC_TO_CBTC, CBTC_TO_CC, CC_TO_USDCx] status: type: string enum: [pending, success, failed] sellAmount: type: string nullable: true receivedAmount: type: string nullable: true gasFeeCc: type: string nullable: true error: type: string nullable: true createdAt: type: string format: date-time ActivityEvent: type: object required: - id - level - message - createdAt properties: id: type: string accountId: type: string nullable: true accountName: type: string nullable: true level: type: string enum: [info, warn, error] message: type: string createdAt: type: string format: date-time SwapsPage: type: object required: [items, total, limit, offset] properties: items: type: array items: $ref: "#/components/schemas/SwapEvent" total: type: integer minimum: 0 limit: type: integer minimum: 1 offset: type: integer minimum: 0 ReconcileResult: type: object required: [outcome, message] properties: outcome: type: string enum: [success, not_landed] message: type: string swap: $ref: "#/components/schemas/SwapEvent" nullable: true SyncBalancesResult: type: object required: [queued] properties: queued: type: boolean ActivityPage: type: object required: [items, total, limit, offset] properties: items: type: array items: $ref: "#/components/schemas/ActivityEvent" total: type: integer minimum: 0 limit: type: integer minimum: 1 offset: type: integer minimum: 0