Reference Data API¶
Functions for accessing symbol metadata, exchange information, and market discovery.
Symbol Information¶
get_symbol_info()¶
Get detailed metadata about a trading symbol.
import qldata as qd
info = qd.get_symbol_info("BTCUSDT", source="binance", category="spot")
print(f"Symbol: {info.symbol}")
print(f"Base/Quote: {info.base_asset}/{info.quote_asset}")
print(f"Status: {info.status}")
print(f"Is Active: {info.is_active}")
Get complete symbol metadata and trading specifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol | str | Trading pair symbol (e.g., "BTCUSDT") | required |
source | str | Exchange ("binance", "bybit") | required |
category | str | None | Market category (spot, usdm, linear, etc.) | None |
Returns:
| Type | Description |
|---|---|
SymbolInfo | SymbolInfo with complete trading specifications |
Examples:
SymbolInfo Model¶
The returned SymbolInfo object contains:
SymbolInfo dataclass ¶
SymbolInfo(
symbol: str,
base_asset: str,
quote_asset: str,
status: str = "TRADING",
filters: SymbolFilters = SymbolFilters(),
trading_hours: TradingHours = TradingHours(),
contract_type: str | None = None,
delivery_date: str | None = None,
margin_asset: str | None = None,
maker_fee: Decimal | None = None,
taker_fee: Decimal | None = None,
fee_tier: str | None = None,
source: str | None = None,
last_updated: str | None = None,
)
Complete symbol metadata and trading specifications.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol | str | Trading pair symbol |
base_asset | str | Base currency (e.g., "BTC" in "BTCUSDT") |
quote_asset | str | Quote currency (e.g., "USDT" in "BTCUSDT") |
status | str | Trading status ("TRADING", "HALT", "BREAK", etc.) |
filters | SymbolFilters | Price/quantity filters |
trading_hours | TradingHours | Market hours |
contract_type | str | None | For futures ("PERPETUAL", "CURRENT_QUARTER", etc.) |
delivery_date | str | None | For futures contracts |
margin_asset | str | None | Asset used for margin |
fee_tier | str | None | Fee tier or maker/taker fees |
source | str | None | Data source |
filters class-attribute instance-attribute ¶
validate_price ¶
Check if price meets filter requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
price | Decimal | Price to validate | required |
Returns:
| Type | Description |
|---|---|
bool | True if valid, False otherwise |
validate_quantity ¶
Check if quantity meets filter requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantity | Decimal | Quantity to validate | required |
Returns:
| Type | Description |
|---|---|
bool | True if valid, False otherwise |
Trading Filters¶
The filters attribute contains trading constraints:
info = qd.get_symbol_info("BTCUSDT", source="binance", category="spot")
print(f"Tick Size: {info.filters.tick_size}") # Price increment
print(f"Step Size: {info.filters.step_size}") # Quantity increment
print(f"Min Quantity: {info.filters.min_quantity}") # Minimum order size
print(f"Min Notional: {info.filters.min_notional}") # Minimum order value
| Field | Type | Description |
|---|---|---|
tick_size | Decimal | Minimum price increment |
step_size | Decimal | Minimum quantity increment |
min_quantity | Decimal | Minimum order quantity |
max_quantity | Decimal | Maximum order quantity |
min_notional | Decimal | Minimum order value (price × quantity) |
Price/Quantity Validation¶
Validate prices and quantities against exchange rules:
from decimal import Decimal
info = qd.get_symbol_info("BTCUSDT", source="binance", category="spot")
# Validate a price
price = Decimal("50000.123")
if info.validate_price(price):
print(f"Price {price} is valid")
else:
print(f"Price {price} is invalid (tick size: {info.filters.tick_size})")
# Validate a quantity
qty = Decimal("0.00123")
if info.validate_quantity(qty):
print(f"Quantity {qty} is valid")
else:
print(f"Quantity {qty} is invalid (step size: {info.filters.step_size})")
Exchange Information¶
get_exchange_info()¶
Get exchange-level metadata.
import qldata as qd
exchange = qd.get_exchange_info(source="binance")
print(f"Exchange: {exchange.exchange}")
print(f"Timezone: {exchange.timezone}")
print(f"Status: {exchange.status}")
print(f"Total Symbols: {exchange.symbol_count}")
Get exchange-wide information and available symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source | str | Exchange ("binance", "bybit") | required |
category | str | None | Market category (optional) | None |
Returns:
| Type | Description |
|---|---|
ExchangeInfo | ExchangeInfo with exchange metadata |
Examples:
Symbol Discovery¶
list_symbols()¶
List available trading symbols with optional filtering.
import qldata as qd
# All active USDT pairs
usdt_pairs = qd.list_symbols(
source="binance",
category="spot",
quote_asset="USDT",
active_only=True
)
print(f"Found {len(usdt_pairs)} USDT pairs")
print(f"First 10: {usdt_pairs[:10]}")
# All BTC pairs
btc_base = qd.list_symbols(
source="binance",
category="spot",
base_asset="BTC"
)
print(f"BTC pairs: {btc_base}")
# All perpetual contracts
perpetuals = qd.list_symbols(
source="binance",
category="usdm",
active_only=True
)
print(f"Found {len(perpetuals)} perpetual contracts")
List all available trading symbols on an exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source | str | Exchange ("binance", "bybit") | required |
category | str | None | Market category (optional) | None |
active_only | bool | Only return actively trading symbols | True |
base_asset | str | None | Filter by base asset (e.g., "BTC") | None |
quote_asset | str | None | Filter by quote asset (e.g., "USDT") | None |
Returns:
| Type | Description |
|---|---|
list[str] | List of symbol names |
Examples:
Funding Rates¶
current_funding_rate()¶
Get the current funding rate for perpetual contracts.
import qldata as qd
# Binance USDM perpetual
rate = qd.current_funding_rate("BTCUSDT", source="binance", category="usdm")
print(f"Current funding rate: {rate:.6f}")
print(f"Annualized: {rate * 3 * 365 * 100:.2f}%") # 8-hour funding = 3x daily
# Bybit linear perpetual
rate = qd.current_funding_rate("BTCUSDT", source="bybit", category="linear")
print(f"Bybit funding rate: {rate:.6f}")
Get current funding rate for a perpetual contract.
Convenience function for quick funding rate access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol | str | Trading pair symbol (e.g., "BTCUSDT") | required |
source | str | Exchange ("binance", "bybit") | 'binance' |
category | str | Futures category ("usdm", "coinm", "linear", "inverse") | 'usdm' |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary with funding rate information |
Examples:
Examples¶
Example 1: Symbol Metadata Report¶
import qldata as qd
def print_symbol_report(symbol: str, source: str, category: str):
"""Print detailed symbol information."""
info = qd.get_symbol_info(symbol, source=source, category=category)
print(f"\n{'='*50}")
print(f"Symbol Report: {info.symbol}")
print(f"{'='*50}")
print(f"\nBasic Info:")
print(f" Base Asset: {info.base_asset}")
print(f" Quote Asset: {info.quote_asset}")
print(f" Status: {info.status}")
print(f" Active: {info.is_active}")
print(f"\nMarket Type:")
print(f" Is Spot: {info.is_spot}")
print(f" Is Perpetual: {info.is_perpetual}")
if info.is_perpetual:
print(f" Contract Type: {info.contract_type}")
print(f" Margin Asset: {info.margin_asset}")
print(f"\nTrading Filters:")
print(f" Tick Size: {info.filters.tick_size}")
print(f" Step Size: {info.filters.step_size}")
print(f" Min Quantity: {info.filters.min_quantity}")
print(f" Min Notional: {info.filters.min_notional}")
# Generate reports
print_symbol_report("BTCUSDT", "binance", "spot")
print_symbol_report("BTCUSDT", "binance", "usdm")
print_symbol_report("BTCUSDT", "bybit", "linear")
Example 2: Find High-Volume Pairs¶
import qldata as qd
# Get all USDT pairs
symbols = qd.list_symbols(
source="binance",
category="spot",
quote_asset="USDT",
active_only=True
)
# Fetch 24h volume for each (simplified example)
print(f"Analyzing {len(symbols)} symbols...")
# In practice, you'd batch this
for symbol in symbols[:10]:
try:
info = qd.get_symbol_info(symbol, source="binance", category="spot")
print(f"{symbol}: {info.status}")
except Exception as e:
print(f"{symbol}: Error - {e}")
Example 3: Compare Exchange Listings¶
import qldata as qd
# Get symbols from both exchanges
binance_symbols = set(qd.list_symbols(
source="binance",
category="spot",
quote_asset="USDT",
active_only=True
))
bybit_symbols = set(qd.list_symbols(
source="bybit",
category="spot",
active_only=True
))
# Find common and unique
common = binance_symbols & bybit_symbols
only_binance = binance_symbols - bybit_symbols
only_bybit = bybit_symbols - binance_symbols
print(f"Common symbols: {len(common)}")
print(f"Binance only: {len(only_binance)}")
print(f"Bybit only: {len(only_bybit)}")
Example 4: Funding Rate Arbitrage Check¶
import qldata as qd
symbols = ["BTCUSDT", "ETHUSDT", "SOLUSDT", "BNBUSDT"]
print("Funding Rate Comparison")
print("-" * 50)
print(f"{'Symbol':<12} {'Binance':>12} {'Bybit':>12} {'Diff':>10}")
print("-" * 50)
for symbol in symbols:
try:
binance_rate = qd.current_funding_rate(symbol, source="binance", category="usdm")
bybit_rate = qd.current_funding_rate(symbol, source="bybit", category="linear")
diff = (binance_rate - bybit_rate) * 100
print(f"{symbol:<12} {binance_rate*100:>11.4f}% {bybit_rate*100:>11.4f}% {diff:>9.4f}%")
except Exception as e:
print(f"{symbol:<12} Error: {e}")
print("-" * 50)
See Also¶
- Historical Data - Fetch OHLCV data
- Models Reference - Data model details
- Binance Cookbook - Exchange-specific examples