{
  "openapi": "3.0.3",
  "info": {
    "title": "Servidex Dólar API",
    "version": "1.0.0",
    "description": "Tasas oficiales del BCV y referencia USDT (Binance P2P) en Venezuela. Gratis, sin clave, CORS abierto. Límite: 120 peticiones/min por IP.",
    "contact": {
      "name": "Servidex",
      "url": "https://servidex.org"
    }
  },
  "servers": [
    {
      "url": "https://dolar.servidex.org/api/v1"
    }
  ],
  "paths": {
    "/rates": {
      "get": {
        "summary": "Todas las tasas",
        "operationId": "getRates",
        "parameters": [
          {
            "name": "codes",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Códigos separados por coma. Ej. usd,eur"
          },
          {
            "name": "pretty",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = JSON con formato."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RatesResponse"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/rates/{code}": {
      "get": {
        "summary": "Una tasa",
        "operationId": "getRate",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "usd",
                "eur",
                "usdt",
                "cny",
                "try",
                "rub"
              ]
            }
          },
          {
            "name": "pretty",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = JSON con formato."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "base": {
                      "type": "string"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "rate": {
                      "$ref": "#/components/schemas/Rate"
                    },
                    "attribution": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/convert": {
      "get": {
        "summary": "Convertir montos",
        "operationId": "convert",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Código de moneda (no distingue mayúsculas).",
              "enum": [
                "ves",
                "usd",
                "eur",
                "usdt",
                "cny",
                "try",
                "rub"
              ]
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Código de moneda (no distingue mayúsculas).",
              "enum": [
                "ves",
                "usd",
                "eur",
                "usdt",
                "cny",
                "try",
                "rub"
              ]
            }
          },
          {
            "name": "amount",
            "in": "query",
            "schema": {
              "type": "number",
              "default": 1,
              "minimum": 0,
              "maximum": 1000000000000.0
            },
            "description": "Punto como separador decimal."
          },
          {
            "name": "pretty",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = JSON con formato."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number"
                    },
                    "rate": {
                      "type": "number"
                    },
                    "result": {
                      "type": "number"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "stale": {
                      "type": "boolean"
                    },
                    "sources": {
                      "type": "object"
                    },
                    "attribution": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/history": {
      "get": {
        "summary": "Historial diario",
        "operationId": "getHistory",
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "usd",
                "eur",
                "usdt",
                "cny",
                "try",
                "rub"
              ]
            }
          },
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30,
              "minimum": 1,
              "maximum": 365
            }
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv"
              ],
              "default": "json"
            }
          },
          {
            "name": "pretty",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = JSON con formato."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "base": {
                      "type": "string"
                    },
                    "days": {
                      "type": "integer"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "points": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string",
                            "format": "date"
                          },
                          "price": {
                            "type": "number"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/currencies": {
      "get": {
        "summary": "Monedas disponibles",
        "operationId": "getCurrencies",
        "parameters": [
          {
            "name": "pretty",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = JSON con formato."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/status": {
      "get": {
        "summary": "Estado del servicio",
        "operationId": "getStatus",
        "parameters": [
          {
            "name": "pretty",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = JSON con formato."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          },
          "503": {
            "description": "Servicio sin actualizar hace más de 3 horas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Rate": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "example": "USD"
          },
          "name": {
            "type": "string",
            "example": "Dólar estadounidense"
          },
          "symbol": {
            "type": "string",
            "example": "$"
          },
          "type": {
            "type": "string",
            "enum": [
              "official",
              "market"
            ]
          },
          "source": {
            "type": "string",
            "enum": [
              "bcv",
              "binance_p2p"
            ]
          },
          "price": {
            "type": "number",
            "example": 876.7976,
            "description": "Bolívares por 1 unidad."
          },
          "previous": {
            "type": "number",
            "nullable": true
          },
          "change": {
            "type": "number",
            "nullable": true
          },
          "change_pct": {
            "type": "number",
            "nullable": true
          },
          "as_of": {
            "type": "string",
            "format": "date"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "stale": {
            "type": "boolean"
          }
        }
      },
      "RatesResponse": {
        "type": "object",
        "properties": {
          "base": {
            "type": "string",
            "example": "VES"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "valid_date": {
            "type": "string",
            "format": "date",
            "nullable": true
          },
          "stale": {
            "type": "boolean"
          },
          "spread": {
            "type": "object",
            "nullable": true,
            "properties": {
              "usdt_vs_usd_pct": {
                "type": "number"
              }
            }
          },
          "rates": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Rate"
            }
          },
          "attribution": {
            "type": "string"
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded",
              "down"
            ]
          },
          "api_version": {
            "type": "string"
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "age_minutes": {
            "type": "integer"
          },
          "stale": {
            "type": "boolean"
          },
          "sources": {
            "type": "object"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "example": "invalid_currency"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
