/** * Market Types * * Types for market data operations including trading pair metadata and OHLCV data. */ import type { BaseAPI } from "../api"; /** * Trading pair metadata */ export interface TradingPair { /** Unique identifier */ id: string; /** Trading pair symbol e.g. BTC/USDC */ symbol: string; /** Base token symbol */ base_token: string; /** Quote token symbol */ quote_token: string; /** Base asset ID (UUID) */ base_asset_id: string; /** Quote asset ID (UUID) */ quote_asset_id: string; /** Base token contract address */ base_token_contract: string; /** Quote token contract address */ quote_token_contract: string; /** Base token decimals */ base_decimals: number; /** Base token icon URL */ base_icon_url: string; /** Quote token decimals */ quote_decimals: number; /** Quote token icon URL */ quote_icon_url: string; /** Market type (e.g. SPOT) */ market_type: string; /** Whether the market is active */ is_active: boolean; /** Maker fee in basis points */ maker_fee_bps: number; /** Taker fee in basis points */ taker_fee_bps: number; /** Minimum order size */ min_order_size: string; /** Maximum order size */ max_order_size: string; /** Tick size for price increments */ tick_size: string; } /** * OHLCV candlestick data point (matches API response format) * * Note: Field naming follows backend API format where: * - T = Start timestamp (open_time from backend) * - t = End timestamp (close_time from backend) */ export interface Candlestick { /** Start timestamp for the candlestick period (Unix timestamp in milliseconds) */ T: number; /** End timestamp for the candlestick period (Unix timestamp in milliseconds) */ t: number; /** Opening price */ o: string; /** Highest price during the period */ h: string; /** Lowest price during the period */ l: string; /** Closing price */ c: string; /** Volume traded during the period */ v: string; /** Symbol */ s: string; /** Interval */ i: string; /** Number of trades */ n: number; } /** * Supported candlestick intervals */ export type Interval = "1m" | "5m" | "15m" | "1h" | "4h" | "1d"; /** * Candlestick subscription configuration */ export interface CandlestickSubscription { /** Trading pair ID (UUID) */ tradingPairId: string; /** Candlestick interval */ interval: Interval; } /** * Query parameters for fetching candlestick data * * All parameters are optional and can be used independently: * - Use `endTime` + `limit` for backward pagination (TradingView primary pattern) * - Use `startTime` + `limit` for forward pagination * - Use just `limit` for most recent bars * - Use `startTime` + `endTime` + `limit` for a specific range (capped at limit) */ export interface GetCandlesticksParams { /** Start time (Unix ms). Use with `limit` for forward pagination from this timestamp. */ startTime?: number; /** End time (Unix ms). Use with `limit` for backward pagination ending at this timestamp. */ endTime?: number; /** Maximum number of bars to return (max: 500, server defaults to 350 if omitted) */ limit?: number; } /** * Query parameters for fetching trading pairs */ export interface GetTradingPairsParams { /** Page number (starts from 1) */ page?: number; /** Number of items per page (max 100) */ page_size?: number; /** Filter by market type (SPOT, MARGIN) */ market_type?: string; /** Filter by base token symbol */ base_token?: string; /** Filter by quote token symbol */ quote_token?: string; /** Filter by active status */ is_active?: boolean; } /** * Response for listing trading pairs with pagination */ export interface GetTradingPairsResponse { trading_pairs: TradingPair[]; page: number; page_size: number; total: number; total_pages: number; } /** * Response for a single trading pair */ export interface GetTradingPairResponse { trading_pair: TradingPair; } /** * API response wrapper for single trading pair */ export interface GetCandlestickResponse { data: Candlestick[]; } /** * Market metadata with 24-hour statistics */ export interface MarketMetadata { /** Trading pair symbol (e.g., "BTC/USDC") */ symbol: string; /** Base token icon URL */ base_icon_url: string; /** Quote token icon URL */ quote_icon_url: string; /** Current price (8 decimal precision, null if no trades yet) */ last_price: string | null; /** Unix timestamp (ms) of latest price (null if no trades yet) */ last_price_timestamp: number | null; /** 24h high price (null if <24h data) */ high_24h: string | null; /** 24h low price (null if <24h data) */ low_24h: string | null; /** 24h volume in base asset (null if <24h data) */ volume_24h: string | null; /** Absolute price change in 24h (null if <24h data) */ price_change_24h: string | null; /** Percentage price change in 24h (2 decimals, null if <24h data) */ price_change_percent_24h: string | null; /** Unix timestamp (ms) when market started trading (null if not available) */ market_initialization_timestamp: number | null; } export interface RiskTier { notional_floor: string; notional_cap?: string; initial_margin_ratio: string; maintenance_margin_ratio: string; max_leverage: string; } export interface PerpMarketConfig { trading_pair_id: string; symbol: string; min_leverage: string; max_leverage: string; initial_margin_ratio: string; maintenance_margin_ratio: string; funding_interval_seconds: number; liquidation_fee_bps?: string; risk_tiers: RiskTier[]; updated_at: string; } export interface PerpMarketSummary { trading_pair_id: string; symbol: string; last_price: string; mark_price: string; index_price: string; high_24h?: string; low_24h?: string; volume_24h?: string; price_change_24h?: string; price_change_percent_24h?: string; open_interest: string; current_funding_rate?: string; estimated_next_funding_rate?: string; next_funding_time?: string; market_status: string; market_regime: string; updated_at: string; } export interface MarkPrice { trading_pair_id: string; mark_price: string; oracle_provider: string; oracle_epoch?: string; updated_at: string; regime: string; } export interface IndexComponent { provider: string; price: string; weight?: string; updated_at?: string; } export interface IndexPrice { trading_pair_id: string; index_price: string; components: IndexComponent[]; updated_at: string; } export interface FundingState { trading_pair_id: string; current_funding_rate: string; estimated_next_funding_rate?: string; next_funding_time: string; funding_interval_seconds: number; last_funding_time?: string; updated_at: string; } export interface FundingRecord { trading_pair_id: string; funding_rate: string; funding_time: string; cumulative_funding_per_unit?: string; } export interface ListFundingHistoryParams { start_time?: string; end_time?: string; page?: number; page_size?: number; } export interface ListFundingHistoryResponse { records: FundingRecord[]; total: number; page: number; page_size: number; } export interface OpenInterest { trading_pair_id: string; open_interest_base: string; open_interest_notional: string; updated_at: string; } /** * Market API interface. * Provides methods for fetching market metadata and trading pair information. */ export interface MarketAPI extends BaseAPI { /** * Fetch all available trading pairs supported by Monaco. * @param params - Optional query parameters for filtering and pagination * @returns Promise resolving to paginated response with trading pairs */ getPaginatedTradingPairs(params?: GetTradingPairsParams): Promise; /** * Fetch metadata for a single trading pair by its symbol (e.g. BTC-USDC). * @param symbol - Trading pair symbol * @returns Promise resolving to trading pair or undefined if not found */ getTradingPairBySymbol(symbol: string): Promise; /** * Fetch historical candlestick data for a trading pair. * * Supports TradingView-compliant query patterns: * - `endTime` + `limit`: Backward pagination (bars ending at timestamp) * - `startTime` + `limit`: Forward pagination (bars starting from timestamp) * - `limit` only: Most recent bars * - `startTime` + `endTime` + `limit`: Specific range (capped at limit) * * @param tradingPairId - Trading pair UUID * @param interval - Candlestick interval (1m, 5m, 15m, 1h, 4h, 1d) * @param params - Optional query parameters (startTime, endTime, limit). Server defaults to 350 bars if limit omitted. * @returns Promise resolving to array of candlesticks (oldest to newest) */ getCandlesticks(tradingPairId: string, interval: Interval, params?: GetCandlesticksParams): Promise; /** * Get comprehensive market metadata including 24h statistics. * @param tradingPairId - Trading pair UUID * @returns Promise resolving to market metadata with current price and 24h stats * @throws {Error} If pair not found or no data available */ getMarketMetadata(tradingPairId: string): Promise; getPerpMarketConfig(tradingPairId: string): Promise; getPerpMarketSummary(tradingPairId: string): Promise; getMarkPrice(tradingPairId: string): Promise; getIndexPrice(tradingPairId: string): Promise; getFundingState(tradingPairId: string): Promise; listFundingHistory(tradingPairId: string, params?: ListFundingHistoryParams): Promise; getOpenInterest(tradingPairId: string): Promise; }