Alpaca Python Trading Coder
Objective
Generate high-quality Python code for Alpaca Trading API integrations with explicit typing for:
- input parameters
- request payload objects
- output response structures
Treat this skill as a programming reference. Do not treat it as permission to execute live trades.
Core Workflow
- Identify whether the task should use
alpaca-pyhigh-level SDK calls or direct REST calls. - Resolve typed inputs from request models and enums before writing business logic.
- Add one concrete Python example per API used in the target code.
- Validate output parsing against documented response model fields/types.
- Default examples to paper trading unless the user explicitly requests live environment code.
Reference Navigation
Read files on demand in this order:
references/00-sources-and-scope.mdUse to confirm source versions and coverage.references/01-python-sdk-tradingclient.mdUse forTradingClientandTradingStreammethod signatures, parameter types, and examples.references/02-python-sdk-request-models.mdUse for request object field-level typing and constructor shapes.references/03-python-sdk-response-models.mdUse for response object field-level typing and output structure expectations.references/04-python-sdk-enums.mdUse when a parameter type is an enum and allowed values must be explicit.references/05-rest-trading-api-reference.mdUse for complete endpoint-level REST coverage (including APIs not yet wrapped by high-level SDK methods).references/06-sdk-rest-mapping.mdUse to map SDK methods to REST paths and identify gaps requiring raw REST calls.references/openapi/trading-api.jsonUse as full raw OpenAPI snapshot when deep schema details are needed.
Implementation Rules
- Prefer
TradingClienthigh-level methods first. - Fall back to
TradingClient.get/post/put/patch/deleteorrequestsfor unmapped endpoints. - Keep code strongly typed with explicit request model and enum usage.
- Reflect response typing in return annotations and parsing code.
- Include defensive handling for empty responses, HTTP errors, and optional fields.
Regeneration
When references become stale, regenerate from latest OpenAPI + installed SDK:
python3 scripts/build_references.py
This refreshes all files in references/ and the OpenAPI snapshot.