{
  "openapi": "3.1.0",
  "info": {
    "title": "Venym DeFi — the agent layer for DeFi",
    "version": "0.1.0",
    "description": "Real-time market data, perps, pair trades, and cross-chain swaps. Public reads need no key; execution uses a scoped venym_sk_ agent key with a server-side risk policy."
  },
  "servers": [
    {
      "url": "https://defi.venym.io/api"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {}
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Venym agent key: venym_sk_live_..."
      }
    },
    "schemas": {
      "Envelope": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "data": {},
          "error": {
            "type": "string"
          },
          "timestamp": {
            "type": "integer"
          }
        }
      },
      "PlaceOrder": {
        "type": "object",
        "required": [
          "symbol",
          "side",
          "type",
          "quantity"
        ],
        "properties": {
          "symbol": {
            "type": "string",
            "example": "BTC"
          },
          "side": {
            "type": "string",
            "enum": [
              "BUY",
              "SELL"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "MARKET",
              "LIMIT",
              "STOP_MARKET",
              "STOP_LIMIT"
            ]
          },
          "quantity": {
            "type": "string",
            "example": "0.01"
          },
          "price": {
            "type": "string"
          },
          "triggerPrice": {
            "type": "string"
          },
          "reduceOnly": {
            "type": "boolean"
          },
          "preferredExchange": {
            "type": "string",
            "enum": [
              "hyperliquid",
              "aster",
              "lighter"
            ]
          }
        }
      },
      "OpenPair": {
        "type": "object",
        "required": [
          "longSymbol",
          "shortSymbol",
          "notionalUsd",
          "leverage"
        ],
        "properties": {
          "longSymbol": {
            "type": "string",
            "example": "ETH"
          },
          "shortSymbol": {
            "type": "string",
            "example": "BTC"
          },
          "notionalUsd": {
            "type": "number",
            "example": 1000
          },
          "leverage": {
            "type": "number",
            "example": 3
          },
          "slippage": {
            "type": "number"
          },
          "venue": {
            "type": "string",
            "enum": [
              "lighter",
              "hyperliquid"
            ]
          }
        }
      },
      "SwapQuote": {
        "type": "object",
        "required": [
          "fromChain",
          "toChain",
          "fromToken",
          "toToken",
          "fromAmount"
        ],
        "properties": {
          "fromChain": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          },
          "toChain": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "integer"
              }
            ]
          },
          "fromToken": {
            "type": "string"
          },
          "toToken": {
            "type": "string"
          },
          "fromAmount": {
            "type": "string",
            "description": "Amount in the smallest unit (wei/lamports)."
          },
          "fromAddress": {
            "type": "string"
          },
          "toAddress": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/token-pairs": {
      "get": {
        "operationId": "getMarkets",
        "summary": "List tradable markets",
        "security": [
          {}
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/aggregated/book": {
      "get": {
        "operationId": "getOrderbook",
        "summary": "Aggregated orderbook",
        "security": [
          {}
        ],
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/aggregated/candles": {
      "get": {
        "operationId": "getCandles",
        "summary": "Aggregated OHLCV candles (raw array)",
        "security": [
          {}
        ],
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "interval",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/aggregated/routing": {
      "get": {
        "operationId": "getRouting",
        "summary": "Routing recommendation",
        "security": [
          {}
        ],
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "side",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "BUY",
                "SELL"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/trades/{symbol}": {
      "get": {
        "operationId": "getTrades",
        "summary": "Recent trades",
        "security": [
          {}
        ],
        "parameters": [
          {
            "name": "symbol",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/positions": {
      "get": {
        "operationId": "getPositions",
        "summary": "Open positions",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/balances": {
      "get": {
        "operationId": "getBalances",
        "summary": "Balances",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/orders": {
      "get": {
        "operationId": "getOrders",
        "summary": "Open orders",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "operationId": "placeOrder",
        "summary": "Place a smart-routed perp order",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlaceOrder"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/orders/{venue}/{orderId}": {
      "delete": {
        "operationId": "cancelOrder",
        "summary": "Cancel an order",
        "parameters": [
          {
            "name": "venue",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "orderId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/positions/open": {
      "post": {
        "operationId": "openPosition",
        "summary": "Open a position",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/positions/close": {
      "post": {
        "operationId": "closePosition",
        "summary": "Close a position",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/pair/open": {
      "post": {
        "operationId": "openPair",
        "summary": "Open a long/short pair trade",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OpenPair"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/pair/{id}/close": {
      "post": {
        "operationId": "closePair",
        "summary": "Close a pair position",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/swap/quote": {
      "post": {
        "operationId": "swapQuote",
        "summary": "Quote a cross-chain swap",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SwapQuote"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/swap/prepare": {
      "post": {
        "operationId": "swapPrepare",
        "summary": "Prepare an unsigned swap",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/swap/execute": {
      "post": {
        "operationId": "swapExecute",
        "summary": "Execute a swap headlessly",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/agent/keys": {
      "post": {
        "operationId": "createKey",
        "summary": "Mint an agent key (owner JWT)",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "get": {
        "operationId": "listKeys",
        "summary": "List agent keys (owner JWT)",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}