You need access to Schwab API to get the OpenAPI spec.

  1. Login and go to https://developer.schwab.com/products/trader-api--individual/details/specifications/Market%20Data%20Production
  2. Open Dev Tools and go to Network tab (refresh the page if needed)
  3. Look for a request names Market%20Data%20Production

The response is a JSON object with the following structure:

{
    "id": "123",
    "apiName": "Market Data Production",
    "fileName": "TraderApi.json",
    "specification": "{\r\n  \"openapi\": \"3.0.3\" ...",
    "appKey": "key",
    "appSecret": "secret"
}

Parsing the JSON

import json

specification: "{\r\n  \"openapi\": \"3.0.3\" ...",
openapi_spec = json.loads(specification)

with open("schwab-openapi.json", "w") as f:
    json.dump(openapi_spec, f, indent=2)

Generating Pydantic Models

Install datamodel-code-generator

pip install datamodel-code-generator

Run the following command to generate Pydantic models:


```bash
datamodel-codegen  --input schwab-openapi.json --input-file-type openapi --output models.py --output-model-type pydantic_v2.BaseModel