{
  "openapi": "3.1.0",
  "info": {
    "title": "Vishwa x402 API",
    "version": "2.0.0",
    "description": "Vishwa is building agent-native banking infrastructure for autonomous capital, bringing pre-execution control to agent-driven payments and capital flows.",
    "x-guidance": ""
  },
  "servers": [
    {
      "url": "https://api.vishwalab.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/v1/services": {
      "get": {
        "summary": "Service list",
        "description": "Vishwa x402 Service List",
        "operationId": "serviceList",
        "parameters": [
          {
            "name": "text",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Echo string to include in response"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "message": { "type": "string" },
                    "data": {
                      "type": "object",
                      "properties": {
                        "timestamp": { "type": "number" },
                        "text": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required — include x-payment header to proceed" }
        }
      }
    },

    "/v1/prediction/events": {
      "get": {
        "summary": "List Events",
        "description": "List all active prediction market events with rich filtering",
        "operationId": "listEvents",
        "parameters": [
          {
            "name": "provider",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["polymarket", "kalshi"] },
            "description": "Market provider"
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["all", "crypto", "sports", "politics", "esports", "culture", "economics", "tech", "finance", "climate & science", "weather", "mentions"]
            },
            "description": "Event category filter"
          },
          {
            "name": "tag",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Single tag filter (e.g. '15m', '5m')"
          },
          {
            "name": "tags",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Comma-separated tags (e.g. '5m,15m')"
          },
          {
            "name": "subcategory",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Subcategory filter"
          },
          {
            "name": "sortBy",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["volume", "volume24hr", "beginAt"] },
            "description": "Sort field"
          },
          {
            "name": "sortDirection",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["asc", "desc"] },
            "description": "Sort direction"
          },
          {
            "name": "filter",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["new", "live", "trending", "upcoming"] },
            "description": "Status filter"
          },
          {
            "name": "includeMarkets",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Include markets in response"
          },
          {
            "name": "start",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination start offset"
          },
          {
            "name": "end",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination end offset"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/events/search": {
      "get": {
        "summary": "Search Events",
        "description": "Search prediction market events by keyword",
        "operationId": "searchEvents",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "required": true,
            "schema": { "type": "string", "minLength": 1, "maxLength": 200 },
            "description": "Search keyword (1-200 chars)"
          },
          {
            "name": "provider",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["polymarket", "kalshi"] },
            "description": "Market provider"
          },
          {
            "name": "includeMarkets",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Include markets in response"
          },
          {
            "name": "start",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination start offset"
          },
          {
            "name": "end",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination end offset"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/events/{eventId}": {
      "get": {
        "summary": "Get Event",
        "description": "Get a specific prediction market event by ID",
        "operationId": "getEvent",
        "parameters": [
          {
            "name": "eventId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Event ID"
          },
          {
            "name": "includeMarkets",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Include markets in response"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "eventId": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/events/{eventId}/markets": {
      "get": {
        "summary": "Get Event Markets",
        "description": "List all markets for a specific event",
        "operationId": "getEventMarkets",
        "parameters": [
          {
            "name": "eventId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Event ID"
          },
          {
            "name": "start",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination start offset"
          },
          {
            "name": "end",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination end offset"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "eventId": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/markets/{marketId}": {
      "get": {
        "summary": "Get Market",
        "description": "Get details of a single prediction market by ID",
        "operationId": "getMarket",
        "parameters": [
          {
            "name": "marketId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Market ID"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "marketId": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/orderbook/{marketId}": {
      "get": {
        "summary": "Get Orderbook",
        "description": "Get bid/ask depth data for a market",
        "operationId": "getOrderbook",
        "parameters": [
          {
            "name": "marketId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Market ID"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "marketId": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/trades": {
      "get": {
        "summary": "Get Trades",
        "description": "Get recent public trade events across all markets",
        "operationId": "getTrades",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": { "type": "integer", "minimum": 1 },
            "description": "Maximum number of trades to return"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/orders": {
      "get": {
        "summary": "List Orders",
        "description": "List on-chain orders with optional owner filter",
        "operationId": "listOrders",
        "parameters": [
          {
            "name": "ownerPubkey",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Filter by owner public key"
          },
          {
            "name": "start",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination start offset"
          },
          {
            "name": "end",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination end offset"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      },
      "post": {
        "summary": "Create Order",
        "description": "Create a prediction market order (buy or sell), returns signed transaction",
        "operationId": "createOrder",
        "parameters": [
          {
            "name": "payment-signature",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "x402 payment signature (required if 402 response received previously)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["isBuy"],
                "properties": {
                  "isBuy": { "type": "boolean", "description": "true for buy order, false for sell order" },
                  "ownerPubkey": { "type": "string", "description": "Owner's Solana public key" },
                  "payerPubkey": { "type": "string", "description": "Payer public key" },
                  "marketId": { "type": "string", "description": "Market ID (required for buy orders)" },
                  "positionPubkey": { "type": "string", "description": "Position pubkey (required for sell orders)" },
                  "isYes": { "type": "boolean", "description": "true for YES side, false for NO side" },
                  "contracts": { "type": "number", "description": "Number of contracts to trade" },
                  "maxBuyPriceUsd": { "type": "number", "description": "Max buy price in micro USD" },
                  "minSellPriceUsd": { "type": "number", "description": "Min sell price in micro USD" },
                  "depositAmount": { "type": "number", "description": "Deposit amount" },
                  "depositMint": { "type": "string", "description": "Deposit mint address" },
                  "orderType": { "type": "string", "enum": ["market", "limit"], "description": "Order type" }
                }
              }
            }
          }
        },
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "9.9" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Order created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      },
      "delete": {
        "summary": "Cancel Order",
        "description": "Cancel a pending order, returns a signed transaction",
        "operationId": "cancelOrder",
        "parameters": [
          {
            "name": "payment-signature",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "x402 payment signature"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["orderPubkey"],
                "properties": {
                  "orderPubkey": { "type": "string", "description": "Order public key to cancel" },
                  "ownerPubkey": { "type": "string", "description": "Owner's Solana public key" },
                  "payerPubkey": { "type": "string", "description": "Payer public key" }
                }
              }
            }
          }
        },
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Order cancelled successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "orderPubkey": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/orders/{orderPubkey}": {
      "get": {
        "summary": "Get Order",
        "description": "Get details of a single on-chain order",
        "operationId": "getOrder",
        "parameters": [
          {
            "name": "orderPubkey",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Order public key"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "orderPubkey": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/orders/status/{orderPubkey}": {
      "get": {
        "summary": "Get Order Status",
        "description": "Get the latest status of an order with full event history",
        "operationId": "getOrderStatus",
        "parameters": [
          {
            "name": "orderPubkey",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Order public key"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "orderPubkey": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/positions": {
      "get": {
        "summary": "List Positions",
        "description": "List on-chain positions with multi-dimensional filtering",
        "operationId": "listPositions",
        "parameters": [
          {
            "name": "ownerPubkey",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Filter by owner public key"
          },
          {
            "name": "marketPubkey",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Filter by market public key"
          },
          {
            "name": "marketId",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Filter by market ID"
          },
          {
            "name": "isYes",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["true", "false"] },
            "description": "Filter by position side"
          },
          {
            "name": "start",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination start offset"
          },
          {
            "name": "end",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination end offset"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/positions/{positionPubkey}": {
      "get": {
        "summary": "Get Position",
        "description": "Get details of a single on-chain position",
        "operationId": "getPosition",
        "parameters": [
          {
            "name": "positionPubkey",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Position public key"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "positionPubkey": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      },
      "delete": {
        "summary": "Close Position",
        "description": "Close a position (sell all contracts), returns signed transaction",
        "operationId": "closePosition",
        "parameters": [
          {
            "name": "payment-signature",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "x402 payment signature"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["positionPubkey"],
                "properties": {
                  "ownerPubkey": { "type": "string", "description": "Owner's Solana public key" },
                  "payerPubkey": { "type": "string", "description": "Payer public key" }
                }
              }
            }
          }
        },
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Position closed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object", "properties": { "positionPubkey": { "type": "string" } } }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/positions/{positionPubkey}/claim": {
      "post": {
        "summary": "Claim Position",
        "description": "Claim payout for a winning position, returns signed transaction",
        "operationId": "claimPosition",
        "parameters": [
          {
            "name": "positionPubkey",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "Position public key"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "ownerPubkey": { "type": "string", "description": "Owner's Solana public key" },
                  "payerPubkey": { "type": "string", "description": "Payer public key" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Claim submitted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          }
        }
      }
    },

    "/v1/prediction/execute": {
      "post": {
        "summary": "Execute Transaction",
        "description": "Co-sign and/or submit a signed transaction",
        "operationId": "executeTransaction",
        "parameters": [
          {
            "name": "payment-signature",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "x402 payment signature"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "signedTransaction": { "type": "string", "description": "Base64 encoded transaction, signed by the owner" },
                  "requestId": { "type": "string", "description": "Optional client correlation ID" }
                }
              }
            }
          }
        },
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Transaction executed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    },

    "/v1/prediction/history": {
      "get": {
        "summary": "Get History",
        "description": "Get paginated event history (orders, claims, positions)",
        "operationId": "getHistory",
        "parameters": [
          {
            "name": "ownerPubkey",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Filter by owner public key"
          },
          {
            "name": "id",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Filter by history event ID"
          },
          {
            "name": "positionPubkey",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Filter by position public key"
          },
          {
            "name": "start",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination start offset"
          },
          {
            "name": "end",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" },
            "description": "Pagination end offset"
          }
        ],
        "x-payment-info": {
          "price": { "mode": "fixed", "currency": "USD", "amount": "0.01" },
          "protocols": [{ "x402": {} }]
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "data": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment Required" }
        }
      }
    }
  }
}
