Vikuna
Lightweight Python library for Alpaca paper trading, portfolio inspection, equity and options market data access, and DuckDB-backed bar caching. The package is structured so trading, account, market data, options, and storage can be used independently.
Features
- Place and manage Alpaca paper-trading orders
- Submit advanced equity orders including trailing stop, bracket, OCO, and OTO
- Read account snapshots and open positions
- Fetch historical bars and latest quotes
- Discover option contracts, read option quotes/bars, and place single-leg option orders
- Submit multi-leg option orders and inspect option chain snapshots with greeks
- Validate invalid order combinations before hitting the Alpaca API
- Cache bars locally in DuckDB for incremental sync workflows
- Work with typed dataclasses and Polars dataframes
Installation
Use the checked-in uv environment when possible:
uv sync --dev
Fallback:
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
Configuration
Create a local .env file from .env.example:
ALPACA_API_KEY=your_api_key_here
ALPACA_SECRET_KEY=your_secret_key_here
ALPACA_BASE_URL=https://paper-api.alpaca.markets
DB_PATH=./data/market_data.duckdb
Use paper-trading credentials for development.
Quick Start
from datetime import datetime, timedelta, timezone
from vikuna import (
AlpacaAccountClient,
AlpacaMarketData,
AlpacaOptionsClient,
MarketDatabase,
MultiLegOrderRequest,
OptionOrderLeg,
)
account_client = AlpacaAccountClient()
account = account_client.get_account()
print(account.portfolio_value)
market_data = AlpacaMarketData()
db = MarketDatabase()
end = datetime.now(timezone.utc)
start = end - timedelta(days=30)
bars = market_data.get_bars("AAPL", "1d", start, end)
db.save_bars(bars)
latest = db.get_latest_timestamp("AAPL", "1d")
print(latest)
db.close()
options = AlpacaOptionsClient()
contracts = options.list_contracts("AAPL", contract_type="call", limit=5)
print(contracts)
chain = options.get_chain_snapshot("AAPL", contract_type="call")
print(chain.select(["symbol", "bid_price", "ask_price", "delta", "theta"]))
db.save_option_bars(options.get_bars("AAPL240621C00190000", "1d", start, end))
db.save_option_snapshots(options.list_chain_snapshots("AAPL", contract_type="call"))
spread = MultiLegOrderRequest(
qty=1,
order_type="limit",
limit_price=1.25,
legs=[
OptionOrderLeg("AAPL240621C00190000", "buy", "buy_to_open"),
OptionOrderLeg("AAPL240621C00200000", "sell", "sell_to_open"),
],
)
# options.submit_multileg_order(spread)
API Overview
AlpacaTradingClient:buy,sell,cancel_order,cancel_all_orders,get_order,list_ordersAlpacaAccountClient:get_account,get_positions,get_position,close_position,close_all_positionsAlpacaMarketData:get_bars,get_latest_bar,get_quoteAlpacaOptionsClient:list_contracts,get_contract,get_bars,get_latest_quote,buy,sellAlpacaOptionsClient: alsosubmit_multileg_orderandget_chain_snapshotAlpacaOptionsClient: alsolist_chain_snapshotsfor typed snapshot objectsMarketDatabase:save_bars,load_bars,get_latest_timestamp,syncMarketDatabase: alsosave_option_bars,load_option_bars,get_latest_option_timestamp,sync_option_barsMarketDatabase: alsosave_option_snapshots,load_option_snapshots,sync_option_snapshots
Shared types exported by the package:
BarOrderPositionAccountOptionContractOptionOrderLegMultiLegOrderRequestOptionQuoteOptionSnapshotBAR_SCHEMA
Notes
- Options support is implemented against Alpaca’s current options trading and market data APIs.
- Futures are not implemented in this library yet because Alpaca does not expose a stable futures API surface here.
Development
Run the test suite:
.venv/bin/python -m pytest tests -q
Run the local smoke example:
python main.py
Metadata
Release files for vikuna 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vikuna-0.1.0.tar.gz | 17.5 kB | Without provenance | Details for vikuna-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vikuna-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for vikuna-0.1.0-py3-none-any.whl |
Total release size: 32.2 kB
Release files / vikuna-0.1.0.tar.gz
| Download URL | vikuna-0.1.0.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9537cc38a1c8c6c6ae98a76de0efc9cb9375218b79305fe84a2af3b2361edc00
|
|
BLAKE2b-256 checksum How to use checksums |
6abeef40668d0d2873eca33bff588ec516a192350fb0a89d0b71095f529360ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / vikuna-0.1.0-py3-none-any.whl
| Download URL | vikuna-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5246c8dc430b519be66fdc026ec42dc4524fd36b665c7af031c9862083b40d20
|
|
BLAKE2b-256 checksum How to use checksums |
382ca72d24d9f81a5b9bcaafdf234aa632655ba2c18b45b713e8752c81e31d2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for vikuna 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.