{
  "openapi": "3.1.0",
  "info": {
    "title": "TRADING4AI Strategy API",
    "version": "0.2.0",
    "description": "Machine-callable strategy, payment, entitlement, and AI guidance endpoints for TRADING4AI."
  },
  "servers": [
    {
      "url": "https://trading4ai.com"
    }
  ],
  "paths": {
    "/api/v1": {
      "get": {
        "summary": "Get API root metadata",
        "responses": {
          "200": {
            "description": "API root metadata"
          }
        }
      }
    },
    "/api/v1/health": {
      "get": {
        "summary": "Get service health and runtime capabilities",
        "responses": {
          "200": {
            "description": "Health response"
          }
        }
      }
    },
    "/api/v1/strategies": {
      "get": {
        "summary": "List launch strategies",
        "responses": {
          "200": {
            "description": "Strategy catalog"
          }
        }
      }
    },
    "/api/v1/strategies/{slug}": {
      "get": {
        "summary": "Get strategy details",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Strategy detail"
          },
          "404": {
            "description": "Strategy not found"
          }
        }
      }
    },
    "/api/v1/strategies/{slug}/invoke": {
      "post": {
        "summary": "Invoke a free callable strategy",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/MarketRegimeFilterRequest"
                  },
                  {
                    "$ref": "#/components/schemas/BtcBreakoutContinuationRequest"
                  },
                  {
                    "$ref": "#/components/schemas/BtcBulltrapDetectorRequest"
                  },
                  {
                    "$ref": "#/components/schemas/EthBreakoutVsReversalRequest"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Structured strategy output"
          },
          "400": {
            "description": "Invalid request payload"
          },
          "402": {
            "description": "Paid strategy requires purchase"
          },
          "404": {
            "description": "Strategy not found"
          }
        }
      }
    },
    "/api/v1/products": {
      "get": {
        "summary": "List paid strategy artifacts that can be ordered",
        "responses": {
          "200": {
            "description": "Product catalog"
          }
        }
      }
    },
    "/api/v1/orders": {
      "post": {
        "summary": "Create a new payment order",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order created"
          },
          "400": {
            "description": "Invalid order request"
          }
        }
      }
    },
    "/api/v1/orders/{order_id}": {
      "get": {
        "summary": "Get an order by id",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "order_token",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional signed token for stateless order lookup."
          }
        ],
        "responses": {
          "200": {
            "description": "Order detail"
          },
          "404": {
            "description": "Order not found"
          }
        }
      }
    },
    "/api/v1/orders/{order_id}/payment": {
      "get": {
        "summary": "Get payment instructions and latest payment state for an order",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "order_token",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Payment instructions"
          },
          "404": {
            "description": "Order not found"
          }
        }
      }
    },
    "/api/v1/orders/{order_id}/payment/verify": {
      "post": {
        "summary": "Verify an on-chain payment for an order using a transaction hash",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentVerifyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification result"
          },
          "400": {
            "description": "Invalid verification payload"
          },
          "404": {
            "description": "Order not found"
          },
          "503": {
            "description": "Ethereum RPC is not configured"
          }
        }
      }
    },
    "/api/v1/claims/{claim_token}": {
      "post": {
        "summary": "Redeem a claim token and return the entitlement payload",
        "parameters": [
          {
            "name": "claim_token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Claimed entitlement"
          },
          "404": {
            "description": "Claim token not found"
          }
        }
      }
    },
    "/api/v1/entitlements/{token}": {
      "get": {
        "summary": "Inspect an entitlement token",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Entitlement detail"
          },
          "404": {
            "description": "Entitlement not found"
          }
        }
      }
    },
    "/api/v1/ai/strategy-advice": {
      "post": {
        "summary": "Generate AI-assisted strategy guidance",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StrategyAdviceRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "AI advice response"
          },
          "400": {
            "description": "Invalid AI request payload"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "MarketRegimeFilterRequest": {
        "type": "object",
        "required": ["btc_price", "eth_price"],
        "properties": {
          "btc_price": {
            "type": "number"
          },
          "eth_price": {
            "type": "number"
          },
          "timeframe": {
            "type": "string",
            "default": "4h"
          }
        }
      },
      "BtcBreakoutContinuationRequest": {
        "type": "object",
        "required": ["price", "support_band"],
        "properties": {
          "price": {
            "type": "number"
          },
          "support_band": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "number"
            }
          },
          "timeframe": {
            "type": "string",
            "default": "4h"
          }
        }
      },
      "BtcBulltrapDetectorRequest": {
        "type": "object",
        "required": ["price", "volume_trend", "channel_status"],
        "properties": {
          "price": {
            "type": "number"
          },
          "volume_trend": {
            "type": "string"
          },
          "channel_status": {
            "type": "string"
          }
        }
      },
      "EthBreakoutVsReversalRequest": {
        "type": "object",
        "required": ["price", "close_4h", "liquidity_sweep"],
        "properties": {
          "price": {
            "type": "number"
          },
          "close_4h": {
            "type": "number"
          },
          "liquidity_sweep": {
            "type": "boolean"
          }
        }
      },
      "OrderCreateRequest": {
        "type": "object",
        "required": ["product_slug"],
        "properties": {
          "product_slug": {
            "type": "string",
            "enum": ["eth-breakout-playbook", "btc-trap-playbook"]
          },
          "asset": {
            "type": "string",
            "enum": ["USDT", "ETH"],
            "default": "USDT"
          },
          "buyer_reference": {
            "type": "string"
          },
          "buyer_wallet_address": {
            "type": "string"
          },
          "callback_url": {
            "type": "string",
            "format": "uri"
          },
          "external_agent_id": {
            "type": "string"
          }
        }
      },
      "PaymentVerifyRequest": {
        "type": "object",
        "required": ["tx_hash"],
        "properties": {
          "tx_hash": {
            "type": "string"
          },
          "order_token": {
            "type": "string",
            "description": "Optional signed order token for stateless verification flows."
          }
        }
      },
      "StrategyAdviceRequest": {
        "type": "object",
        "properties": {
          "strategy_slug": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "goal": {
            "type": "string"
          },
          "response_style": {
            "type": "string",
            "enum": ["concise", "detailed"],
            "default": "concise"
          },
          "market_context": {
            "description": "Free-form string or structured JSON market context.",
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              }
            ]
          }
        }
      }
    }
  }
}
