{
 "openapi": "3.1.0",
 "info": {
  "title": "Options Profit Calculator API",
  "version": "1.0.0",
  "description": "Probability of profit, option finder, delayed quotes and option chains. Free tier: 100 requests/day, 10/minute per key (a finder search counts as 5, a calculation with graph data as 2). quote and expirations also work without a key (20/day per IP). Sign up for a free key at https://www.optionsprofitcalculator.com/api-signup.html. When you show results, please credit Options Profit Calculator (optionsprofitcalculator.com). Position results and finder results include calculatorUrl, a link that opens the position in the calculator."
 },
 "servers": [
  {
   "url": "https://www.optionsprofitcalculator.com/api/v1"
  }
 ],
 "security": [
  {
   "bearer": []
  },
  {
   "apiKey": []
  }
 ],
 "paths": {
  "/quote": {
   "get": {
    "summary": "Stock quote with IV30",
    "operationId": "getQuote",
    "security": [
     {},
     {
      "bearer": []
     },
     {
      "apiKey": []
     }
    ],
    "parameters": [
     {
      "name": "symbol",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "example": "AAPL"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Quote",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "const": true
          },
          "data": {
           "type": "object"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/expirations": {
   "get": {
    "summary": "Option expiry dates",
    "operationId": "getExpirations",
    "security": [
     {},
     {
      "bearer": []
     },
     {
      "apiKey": []
     }
    ],
    "parameters": [
     {
      "name": "symbol",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "example": "AAPL"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Expirations",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "const": true
          },
          "data": {
           "type": "object"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/chain": {
   "get": {
    "summary": "Option chain for one expiry",
    "operationId": "getChain",
    "parameters": [
     {
      "name": "symbol",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "example": "AAPL"
      }
     },
     {
      "name": "expiry",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Chain",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "const": true
          },
          "data": {
           "type": "object"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/pop": {
   "post": {
    "summary": "Probability of profit, breakevens, max profit and loss",
    "operationId": "probabilityOfProfit",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "legs"
        ],
        "properties": {
         "symbol": {
          "type": "string"
         },
         "underlyingPrice": {
          "type": "number"
         },
         "iv30": {
          "type": "number",
          "description": "Whole percent"
         },
         "legs": {
          "type": "array",
          "minItems": 1,
          "maxItems": 9,
          "items": {
           "type": "object",
           "required": [
            "type",
            "action"
           ],
           "properties": {
            "type": {
             "type": "string",
             "enum": [
              "call",
              "put",
              "stock"
             ]
            },
            "action": {
             "type": "string",
             "enum": [
              "buy",
              "sell"
             ]
            },
            "quantity": {
             "type": "integer",
             "minimum": 1,
             "default": 1,
             "description": "Contracts (100 shares each), or shares for a stock leg"
            },
            "strike": {
             "type": "number"
            },
            "expiry": {
             "type": "string",
             "format": "date"
            },
            "price": {
             "type": "number",
             "description": "Per share. Omitted: current mid price"
            },
            "iv": {
             "type": "number",
             "description": "Whole percent. Omitted: worked out from the price"
            }
           }
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Probability of profit and position summary",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "const": true
          },
          "data": {
           "type": "object"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/finder": {
   "get": {
    "summary": "Best options or spreads for a price target",
    "operationId": "findOptions",
    "parameters": [
     {
      "name": "symbol",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "example": "AAPL"
      }
     },
     {
      "name": "target",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "eq",
        "gt",
        "lt"
       ],
       "default": "eq"
      }
     },
     {
      "name": "price",
      "in": "query",
      "required": true,
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "date",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      }
     },
     {
      "name": "exactExpiry",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      }
     },
     {
      "name": "budget",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "strategies",
      "in": "query",
      "description": "Comma list",
      "schema": {
       "type": "string",
       "default": "option-purchase",
       "example": "option-purchase,debit-spread"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Up to 5 results",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "const": true
          },
          "data": {
           "type": "object"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/calculate": {
   "post": {
    "summary": "Probability of profit and position summary, plus P/L graph data (price x date grid)",
    "operationId": "calculatePosition",
    "description": "Same input and results as /pop, plus data.graph: today (the New York date that daysFromToday counts from), prices[], dates[{date, daysFromToday, atExpiry}] (New York market dates), profitLoss[dateIndex][priceIndex] in dollars for the whole position, expiry{date, profitLoss[]}, entryCost. Counts as 2 requests.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "legs"
        ],
        "properties": {
         "symbol": {
          "type": "string"
         },
         "underlyingPrice": {
          "type": "number"
         },
         "iv30": {
          "type": "number",
          "description": "Whole percent"
         },
         "legs": {
          "type": "array",
          "minItems": 1,
          "maxItems": 9,
          "items": {
           "type": "object",
           "required": [
            "type",
            "action"
           ],
           "properties": {
            "type": {
             "type": "string",
             "enum": [
              "call",
              "put",
              "stock"
             ]
            },
            "action": {
             "type": "string",
             "enum": [
              "buy",
              "sell"
             ]
            },
            "quantity": {
             "type": "integer",
             "minimum": 1,
             "default": 1,
             "description": "Contracts (100 shares each), or shares for a stock leg"
            },
            "strike": {
             "type": "number"
            },
            "expiry": {
             "type": "string",
             "format": "date"
            },
            "price": {
             "type": "number",
             "description": "Per share. Omitted: current mid price"
            },
            "iv": {
             "type": "number",
             "description": "Whole percent. Omitted: worked out from the price"
            }
           }
          }
         },
         "priceMin": {
          "type": "number",
          "description": "Lowest stock price on the graph (default: automatic)"
         },
         "priceMax": {
          "type": "number",
          "description": "Highest stock price on the graph (default: automatic)"
         },
         "ivChange": {
          "type": "number",
          "description": "Shift all implied volatilities by this percent, e.g. -10"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Probability of profit and position summary",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "const": true
          },
          "data": {
           "type": "object"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer"
   },
   "apiKey": {
    "type": "apiKey",
    "in": "header",
    "name": "X-API-Key"
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "success": {
      "type": "boolean",
      "const": false
     },
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string"
       },
       "message": {
        "type": "string"
       }
      }
     }
    }
   }
  }
 }
}
