Stamp Alpaca Portfolio
This sample retrieves current US equity positions from Alpaca, converts them to portfolio weights, and creates a private vBase stamp for the exact CSV bytes stored in Amazon S3.
Implementation: samples/stamp_alpaca_portfolio.py
Prerequisites
Complete the quickstart, configure an S3 bucket where your AWS identity can write objects, and create Alpaca API credentials.
Install the optional broker dependency:
python -m pip install alpaca-pyAdd these values to .env:
VBASE_API_KEY=your-vbase-api-key
VBASE_COLLECTION_NAME=Alpaca Portfolio History
AWS_S3_BUCKET=your-s3-bucket
# AWS_DEFAULT_REGION=us-east-1
# AWS_ACCESS_KEY_ID=your-aws-access-key-id
# AWS_SECRET_ACCESS_KEY=your-aws-secret-access-key
# AWS_SESSION_TOKEN=your-session-token
ALPACA_API_KEY=your-alpaca-api-key
ALPACA_API_SECRET=your-alpaca-api-secret
ALPACA_PAPER=trueUse ALPACA_PAPER=false only when the credentials belong to a live account. Never commit real credentials.
Run the sample
The script:
Retrieves all current positions with Alpaca’s
TradingClient.Keeps US equity positions and normalizes their market values into weights.
Shows the portfolio and asks for confirmation.
Serializes the portfolio to deterministic CSV bytes and calculates their CID locally.
Writes the exact bytes to S3, creates a private stamp for their CID, and verifies the resulting receipt.
The S3 object key contains the collection CID and stamped data CID, so repeated snapshots do not overwrite one another.
See Alpaca’s official guides for working with positions and Python SDKs.
Last updated

