Official Python SDK for ORTEX financial data. Access short interest, cost to borrow, options chains, fundamentals, and stock scores via pip install ortex. Pandas DataFrame support included.
What is the ORTEX Python SDK?
The official Python SDK provides programmatic access to ORTEX financial market data. Access the same institutional-grade short interest, options analytics, and stock scores used by professional traders — directly in your Python applications, Jupyter notebooks, and automated trading systems.
Installation
pip install ortex Authentication
Get your API key at app.ortex.com/apis
import ortex
# Option 1: Set API key directly
ortex.set_api_key("your-api-key")
# Option 2: Use environment variable
# export ORTEX_API_KEY="your-api-key"
# The SDK will automatically use this
# Option 3: Pass to each function
response = ortex.get_short_interest("NYSE", "AMC", api_key="your-api-key") Quick Start
import ortex
ortex.set_api_key("your-api-key")
# Get short interest data
response = ortex.get_short_interest("NYSE", "AMC")
df = response.df # Access data as DataFrame
# Check your credit usage
print(f"Credits used: {response.credits_used}")
print(f"Credits left: {response.credits_left}")
# Get historical short interest
response = ortex.get_short_interest("NYSE", "AMC", "2024-01-01", "2024-12-31")
# Get stock prices
response = ortex.get_price("NASDAQ", "AAPL", "2024-01-01", "2024-12-31")
df = response.df Response Object
All functions return an OrtexResponse object:
response = ortex.get_short_interest("NYSE", "AMC")
# Access data as DataFrame
df = response.df
# Access raw row data
rows = response.rows
# Credit tracking
print(f"Credits used: {response.credits_used}")
print(f"Credits left: {response.credits_left}")
# Pagination info
print(f"Total results: {response.length}")
print(f"Has next page: {response.has_next_page}")
# Iterate through all pages
for page in response.iter_all_pages():
process(page.df)
# Get all data at once (fetches all pages)
full_df = response.to_dataframe_all() Available Functions
Short Interest
# Short interest data for a stock
response = ortex.get_short_interest("NYSE", "AMC")
response = ortex.get_short_interest("NYSE", "AMC", "2024-01-01", "2024-12-31")
# Short interest for an index (S&P 500, NASDAQ 100, etc.)
response = ortex.get_index_short_interest("US-S 500")
# Share availability for shorting
response = ortex.get_short_availability("NYSE", "AMC")
# Cost to borrow (all loans or new loans)
response = ortex.get_cost_to_borrow("NYSE", "AMC")
response = ortex.get_cost_to_borrow("NYSE", "AMC", loan_type="new")
# Days to cover
response = ortex.get_days_to_cover("NYSE", "AMC") Stock Prices
# OHLCV price data
response = ortex.get_price("NASDAQ", "AAPL")
response = ortex.get_price("NASDAQ", "AAPL", "2024-01-01", "2024-12-31")
# Close price
response = ortex.get_close_price("NASDAQ", "AAPL") Shares & Float
# Free float shares (from_date is required)
response = ortex.get_free_float("NYSE", "F", "2024-01-01")
# Shares outstanding
response = ortex.get_shares_outstanding("NYSE", "F", "2024-01-01") Fundamentals
# Income statement
response = ortex.get_income_statement("NYSE", "F", "2024Q3")
print(f"Company: {response.company}")
print(f"Period: {response.period}")
df = response.df
# Balance sheet
response = ortex.get_balance_sheet("NYSE", "F", "2024Q3")
# Cash flow statement
response = ortex.get_cash_flow("NYSE", "F", "2024Q3")
# Financial ratios
response = ortex.get_financial_ratios("NYSE", "F", "2024Q3")
# Fundamentals summary
response = ortex.get_fundamentals_summary("NYSE", "F", "2024Q3")
# Valuation metrics
response = ortex.get_valuation("NYSE", "F", "2024Q3") EU Short Interest
# EU short positions (individual holders)
response = ortex.get_eu_short_positions("XETR", "SAP")
# EU short positions at a specific date
response = ortex.get_eu_short_positions("XETR", "SAP", "2024-12-01")
# EU short positions history
response = ortex.get_eu_short_positions_history("XETR", "SAP", "2024-01-01", "2024-12-31")
# Total EU short interest
response = ortex.get_eu_short_total("XETR", "SAP") Market Data
# Earnings calendar
response = ortex.get_earnings("2024-12-01", "2024-12-31")
# List of exchanges
response = ortex.get_exchanges()
response = ortex.get_exchanges("United States")
# Macro economic events
response = ortex.get_macro_events("US")
response = ortex.get_macro_events("US", "2024-12-01", "2024-12-15") Pagination
Control page size and iterate through large result sets:
# Set page size
response = ortex.get_short_interest("NYSE", "AMC", page_size=100)
# Iterate through all pages
all_data = []
for page in response.iter_all_pages():
all_data.extend(page.rows)
print(f"Fetched {len(page.rows)} rows, credits used: {page.credits_used}")
# Or get everything at once
full_df = response.to_dataframe_all() Error Handling
The SDK provides specific exception types:
import ortex
from ortex import (
APIError,
AuthenticationError,
RateLimitError,
NotFoundError,
ValidationError,
ServerError,
)
try:
response = ortex.get_short_interest("NYSE", "INVALID")
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after} seconds")
except NotFoundError:
print("Stock not found")
except ValidationError as e:
print(f"Invalid parameters: {e}")
except ServerError:
print("ORTEX server error")
except APIError as e:
print(f"API error: {e}") Rate Limiting
The SDK automatically handles rate limiting with exponential backoff:
- Automatically retries on 429 (rate limit) responses
- Uses exponential backoff (1s, 2s, 4s, 8s, up to 60s)
- Maximum 5 retry attempts by default
Configure retry behavior:
from ortex import OrtexClient
client = OrtexClient(
api_key="your-api-key",
timeout=60, # Request timeout in seconds
max_retries=10, # Maximum retry attempts
) Requirements
- Python 3.9+
- pandas >= 2.0.0
- requests >= 2.31.0
- tenacity >= 8.2.0
Resources
Frequently Asked Questions
How do I install the ORTEX Python SDK?
Run pip install ortex in your terminal. The SDK requires Python 3.9 or higher.
How do I get an API key for the Python SDK?
Visit app.ortex.com/apis to subscribe and receive your API key instantly.
Does the SDK return pandas DataFrames?
Yes. All responses include a .df property that returns your data as a pandas DataFrame, ready for analysis.
How does pagination work?
Use response.iter_all_pages() to iterate through large datasets, or response.to_dataframe_all() to fetch all pages into a single DataFrame.
Is the SDK rate-limited?
The SDK automatically handles rate limiting with exponential backoff. You can monitor your usage via response.credits_used and response.credits_left.