{
  "openapi": "3.0.0",
  "info": {
    "title": "NIN Terminal API",
    "version": "1.0.0",
    "description": "API documentation for NIN Terminal"
  },
  "servers": [
    {
      "url": "https://nin-terminal.vercel.app"
    }
  ],
  "paths": {
    "/api/backtest": {
      "post": {
        "tags": [
          "Plugins"
        ],
        "summary": "Run a backtest simulation with different trading strategies",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "symbol",
                  "startDate",
                  "endDate",
                  "initialCapital",
                  "strategy"
                ],
                "properties": {
                  "symbol": {
                    "type": "string",
                    "description": "Stock symbol (e.g., AAPL, TSLA)"
                  },
                  "startDate": {
                    "type": "string",
                    "format": "date",
                    "description": "Start date in YYYY-MM-DD format"
                  },
                  "endDate": {
                    "type": "string",
                    "format": "date",
                    "description": "End date in YYYY-MM-DD format"
                  },
                  "initialCapital": {
                    "type": "number",
                    "description": "Initial investment amount"
                  },
                  "strategy": {
                    "type": "string",
                    "enum": [
                      "Buy and Hold",
                      "Moving Average Crossover",
                      "RSI Strategy",
                      "MACD Strategy",
                      "Bollinger Bands Strategy"
                    ],
                    "description": "Trading strategy to backtest"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Backtest simulation results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "metrics": {
                      "type": "object",
                      "properties": {
                        "ROI": {
                          "type": "number",
                          "description": "Return on Investment (%)"
                        },
                        "sharpeRatio": {
                          "type": "number",
                          "description": "Risk-adjusted return metric"
                        },
                        "maxDrawdown": {
                          "type": "number",
                          "description": "Maximum drawdown (%)"
                        }
                      }
                    },
                    "equityCurve": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string",
                            "format": "date"
                          },
                          "equity": {
                            "type": "number"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "404": {
            "description": "No historical data found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/events": {
      "get": {
        "tags": [
          "Plugins"
        ],
        "summary": "Get market events",
        "responses": {
          "200": {
            "description": "List of market events",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string"
                          },
                          "date": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "title": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/optionsbuilder": {
      "post": {
        "tags": [
          "Plugins"
        ],
        "summary": "Calculate options strategy payoff",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "basket",
                  "spotPrice"
                ],
                "properties": {
                  "spotPrice": {
                    "type": "number",
                    "description": "Current stock price"
                  },
                  "basket": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "symbol",
                        "expiry",
                        "strike",
                        "optionType",
                        "positionType",
                        "premium",
                        "quantity"
                      ],
                      "properties": {
                        "symbol": {
                          "type": "string",
                          "description": "Stock symbol"
                        },
                        "expiry": {
                          "type": "string",
                          "description": "Option expiry date"
                        },
                        "strike": {
                          "type": "number",
                          "description": "Strike price"
                        },
                        "optionType": {
                          "type": "string",
                          "enum": [
                            "CALL",
                            "PUT"
                          ],
                          "description": "Option type"
                        },
                        "positionType": {
                          "type": "string",
                          "enum": [
                            "BUY",
                            "SELL"
                          ],
                          "description": "Position type"
                        },
                        "premium": {
                          "type": "number",
                          "description": "Option premium"
                        },
                        "quantity": {
                          "type": "number",
                          "description": "Number of contracts"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Options strategy analysis",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payoffPoints": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "stockPrice": {
                            "type": "number"
                          },
                          "payoff": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "analysis": {
                      "type": "object",
                      "properties": {
                        "maxProfit": {
                          "type": "string",
                          "description": "Maximum profit (or \"Unlimited\")"
                        },
                        "maxLoss": {
                          "type": "string",
                          "description": "Maximum loss (or \"Unlimited\")"
                        },
                        "breakEvens": {
                          "type": "array",
                          "items": {
                            "type": "number"
                          },
                          "description": "Break-even points"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/api/optionschain": {
      "get": {
        "tags": [
          "Plugins"
        ],
        "summary": "Get options chain data",
        "responses": {
          "200": {
            "description": "Options chain data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "optionsChain": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "strike": {
                            "type": "number"
                          },
                          "expiry": {
                            "type": "string",
                            "format": "date"
                          },
                          "call": {
                            "type": "object",
                            "properties": {
                              "lastPrice": {
                                "type": "number"
                              },
                              "bid": {
                                "type": "number"
                              },
                              "ask": {
                                "type": "number"
                              },
                              "volume": {
                                "type": "number"
                              },
                              "openInterest": {
                                "type": "number"
                              },
                              "impliedVolatility": {
                                "type": "number"
                              },
                              "delta": {
                                "type": "number"
                              },
                              "gamma": {
                                "type": "number"
                              },
                              "theta": {
                                "type": "number"
                              },
                              "vega": {
                                "type": "number"
                              }
                            }
                          },
                          "put": {
                            "$ref": "#/components/schemas/OptionLeg"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/chart": {
      "get": {
        "summary": "Get stock chart data",
        "parameters": [
          {
            "in": "query",
            "name": "symbol",
            "schema": {
              "type": "string"
            },
            "description": "Stock symbol (e.g., SWIGGY.NS, PAYTM.NS)"
          }
        ],
        "responses": {
          "200": {
            "description": "Historical candle data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "time": {
                        "type": "string",
                        "format": "date"
                      },
                      "open": {
                        "type": "number"
                      },
                      "high": {
                        "type": "number"
                      },
                      "low": {
                        "type": "number"
                      },
                      "close": {
                        "type": "number"
                      },
                      "volume": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/openorders": {
      "get": {
        "summary": "Get open orders",
        "responses": {
          "200": {
            "description": "List of open orders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "time": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "side": {
                        "type": "string",
                        "enum": [
                          "BUY",
                          "SELL"
                        ]
                      },
                      "limitPrice": {
                        "type": "number"
                      },
                      "size": {
                        "type": "number"
                      },
                      "symbol": {
                        "type": "string"
                      },
                      "stopLoss": {
                        "type": "number"
                      },
                      "takeProfit": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/orderbook": {
      "get": {
        "summary": "Get order book data",
        "responses": {
          "200": {
            "description": "Current order book with bids and asks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "bids": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "price": {
                            "type": "number"
                          },
                          "size": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "asks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "price": {
                            "type": "number"
                          },
                          "size": {
                            "type": "number"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/trades": {
      "get": {
        "summary": "Get recent trades",
        "responses": {
          "200": {
            "description": "List of recent trades",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "time": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "side": {
                        "type": "string",
                        "enum": [
                          "BUY",
                          "SELL"
                        ]
                      },
                      "price": {
                        "type": "number"
                      },
                      "size": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/watchlist": {
      "get": {
        "summary": "Get watchlist items",
        "responses": {
          "200": {
            "description": "List of watchlist items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "symbol": {
                        "type": "string"
                      },
                      "lastPrice": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {},
  "tags": [
    {
      "name": "Plugins",
      "description": "Plugin-related endpoints including Backtest, Events, and Options Builder"
    }
  ]
}