I see Alpaca has started rolling out paper trading for options. Does Alpaca provide a way to query options chains? If not, whats your goto solutions for getting greeks and so on?
Following. I see the community docs (Option chain (BETA)), but I don’t really see a way to establish which contracts to trade. For example, which contract’s delta is closest to .40.
It seems that trading won’t be quite so automated at this point.
cheers friend, unfortunately that doesnt return the greeks.
heres a quick script to query 0DTE in it tho;
import requests
import datetime
# Your API keys (replace with your actual keys)
api_key = 'foo'
api_secret = 'bar'
# Alpaca API URL for options snapshots
url = 'https://data.alpaca.markets/v1beta1/options/snapshots/SPY'
# Headers including your API keys for authentication
headers = {
'APCA-API-KEY-ID': api_key,
'APCA-API-SECRET-KEY': api_secret,
'accept': 'application/json'
}
# Function to fetch options data from Alpaca
def fetch_options_data(url, headers):
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Error fetching data: {response.status_code}")
return None
# Function to find ODTE options
def find_odte_options(data, today_date):
odte_options = {}
for identifier, details in data.get('snapshots', {}).items():
expiration_date = identifier[3:9] # Extract YYMMDD part
if expiration_date == today_date:
odte_options[identifier] = details
return odte_options
# Get today's date in YYMMDD format
today = datetime.datetime.now().strftime("%y%m%d") # You may replace this with "240221" for Feb 21, 2024
# Fetch the options data
data = fetch_options_data(url, headers)
# Check if data is not None
if data:
# Find ODTE options for today
odte_options_today = find_odte_options(data, today)
# Display or process the ODTE options
for identifier, details in odte_options_today.items():
print(f"Identifier: {identifier}, Details: {details}")
else:
print("Failed to fetch or process data.")