Official Python SDK for ORTEX Financial Data API
Project description
ORTEX Python SDK
Official Python SDK for the ORTEX Financial Data API. Access comprehensive financial data including short interest, stock prices, options, fundamentals, stock scores, and more.
Features
- Short Interest Data - Shares on loan, utilization, cost to borrow, days to cover
- Official Short Interest - FINRA-reported short interest for US, Canada, Australia, Hong Kong
- Stock Prices - OHLCV data with historical support
- Stock Data - Free float, shares outstanding, stock splits
- Stock Scores - Quality, value, momentum, growth scores with custom weights
- Options Data - Option chains, expiries, greeks, implied volatility, put/call ratios
- Fundamentals - Income statements, balance sheets, cash flow, ratios
- EU Short Interest - European regulatory short positions
- US Government Trades - Congressional stock trading disclosures
- Market Data - Earnings calendar, macro events, exchanges
- Pagination Support - Automatic pagination with
iter_all_pages() - Credit Tracking - Monitor API credit usage with
credits_usedandcredits_left
Installation
pip install ortex
Quick Start
Get Your API Key
Get your API key at app.ortex.com/apis
Set Up Authentication
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")
Basic Usage
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
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 that provides:
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()
Pagination
Control page size and iterate through results:
# 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()
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")
# Official (FINRA-reported) short interest for US, CA, AU, HK
response = ortex.get_official_short_interest("AAPL", "US", "2024-01-01")
response = ortex.get_official_short_interest("AAPL", "US", "2024-01-01", "2024-06-30")
Index Short Data
# Index-level short interest data
response = ortex.get_index_short_interest("US-S 500")
response = ortex.get_index_short_availability("US-S 500")
response = ortex.get_index_cost_to_borrow("US-S 500")
response = ortex.get_index_days_to_cover("US-S 500")
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 (alias for get_price)
response = ortex.get_close_price("NASDAQ", "AAPL")
Stock Data
# 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")
# Stock splits history
response = ortex.get_stock_splits("NASDAQ", "AAPL")
response = ortex.get_stock_splits("NASDAQ", "AAPL", from_date="2020-01-01")
Stock Scores
# Get stock scores with default weights (quality, value, momentum, growth, total)
response = ortex.get_stock_scores("NASDAQ", "AAPL")
response = ortex.get_stock_scores("NASDAQ", "AAPL", from_date="2025-01-01")
df = response.df
# Get stock scores with custom weights
weights = {"quality": 50, "growth": 50, "momentum": 65, "dtc": 100, "fcf_assets": 100}
response = ortex.get_stock_scores_custom("NASDAQ", "AAPL", weights)
Options
# List available option expiry dates
response = ortex.get_options_expiries("NASDAQ", "AAPL")
# Get full option chain for a specific expiry
response = ortex.get_options_chain("NASDAQ", "AAPL", "2025-03-21")
# Get option details (greeks, implied vol, open interest, etc.)
response = ortex.get_options_details("NASDAQ", "AAPL", "implied_vol")
response = ortex.get_options_details("NASDAQ", "AAPL", "delta")
# Available parameters: oi, volume, last_price, last_size, ask_price, ask_size,
# bid_price, bid_size, implied_vol, delta, gamma, theta, vega, rho,
# put_call_oi_ratio, put_call_volume_ratio
# Get put/call ratio sentiment
response = ortex.get_options_sentiment("NASDAQ", "AAPL")
response = ortex.get_options_sentiment("NASDAQ", "AAPL", days_fwd=30)
Fundamentals
# Income statement
response = ortex.get_income_statement("NYSE", "F", "2024Q3")
print(f"Company: {response.company}")
print(f"Period: {response.period}")
df = response.df # Financial data as DataFrame
# 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")
US Government Trades
# Get all recent congressional trades
response = ortex.get_us_government_trades()
# Filter by ticker
response = ortex.get_us_government_trades(ticker="AAPL")
# Filter by party, chamber, transaction type
response = ortex.get_us_government_trades(party="democrat", chamber="senate")
response = ortex.get_us_government_trades(transaction_type="buy")
# Filter by date range and filer
response = ortex.get_us_government_trades(
from_date="2024-01-01",
to_date="2024-12-31",
filer_name="John Doe",
)
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")
Using the Client Directly
For more control, use the OrtexClient class:
from ortex import OrtexClient
# Create client
client = OrtexClient(api_key="your-api-key")
# Make requests (returns raw JSON)
data = client.get("NYSE/AMC/short_interest")
# Make requests with OrtexResponse wrapper
response = client.fetch("NYSE/AMC/short_interest")
df = response.df
# POST requests (e.g., stock scores with custom weights)
response = client.fetch_post(
"stock/NASDAQ/AAPL/stock_scores",
json={"weights": {"quality": 50, "growth": 50}},
)
# Use as context manager
with OrtexClient(api_key="your-api-key") as client:
response = client.fetch("stock/NASDAQ/AAPL/closing_prices")
Date Handling
The SDK accepts dates in multiple formats:
from datetime import date, datetime
# String format (YYYY-MM-DD)
response = ortex.get_short_interest("NYSE", "AMC", "2024-01-01", "2024-12-31")
# Python date objects
response = ortex.get_short_interest("NYSE", "AMC", date(2024, 1, 1), date(2024, 12, 31))
# Python datetime objects
response = ortex.get_short_interest("NYSE", "AMC", datetime(2024, 1, 1), datetime(2024, 12, 31))
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
)
Documentation
- Full API Documentation: docs.ortex.com
- Get API Key: app.ortex.com/apis
- Support: support@ortex.com
Requirements
- Python 3.9+
- pandas >= 2.0.0
- requests >= 2.31.0
- tenacity >= 8.2.0
License
MIT License - ORTEX Technologies LTD
Version
1.0.5
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ortex-1.0.5.tar.gz.
File metadata
- Download URL: ortex-1.0.5.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18080f55e51b39abc8a0ba2a876244582369634563a97fd5577bf3857ce023ed
|
|
| MD5 |
d1f2c01bf941f299b6b80412444acace
|
|
| BLAKE2b-256 |
71f6dd50588dc08d13513c29c84bc827baf075009911b79da4b8af92f3365706
|
Provenance
The following attestation bundles were made for ortex-1.0.5.tar.gz:
Publisher:
ci.yml on ortex-financial/ortex-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ortex-1.0.5.tar.gz -
Subject digest:
18080f55e51b39abc8a0ba2a876244582369634563a97fd5577bf3857ce023ed - Sigstore transparency entry: 910329539
- Sigstore integration time:
-
Permalink:
ortex-financial/ortex-python-sdk@fac6f7fe853efd962ee27ccb5a8cc80bdc600f8f -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/ortex-financial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@fac6f7fe853efd962ee27ccb5a8cc80bdc600f8f -
Trigger Event:
push
-
Statement type:
File details
Details for the file ortex-1.0.5-py3-none-any.whl.
File metadata
- Download URL: ortex-1.0.5-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f66959ebcf729744c3055c488460007124191e389892272170247e18be8bb538
|
|
| MD5 |
d0c239a358c2501e8bc96e0ecddb3461
|
|
| BLAKE2b-256 |
3a77a6b7ac330352fc8b88840fa09c0365be0c45068b5420face8a11d6d9f065
|
Provenance
The following attestation bundles were made for ortex-1.0.5-py3-none-any.whl:
Publisher:
ci.yml on ortex-financial/ortex-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ortex-1.0.5-py3-none-any.whl -
Subject digest:
f66959ebcf729744c3055c488460007124191e389892272170247e18be8bb538 - Sigstore transparency entry: 910329544
- Sigstore integration time:
-
Permalink:
ortex-financial/ortex-python-sdk@fac6f7fe853efd962ee27ccb5a8cc80bdc600f8f -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/ortex-financial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@fac6f7fe853efd962ee27ccb5a8cc80bdc600f8f -
Trigger Event:
push
-
Statement type: