Files
opendata/ts/stocks/interfaces/stockprice.ts

110 lines
2.9 KiB
TypeScript

import * as plugins from '../../plugins.js';
// Enhanced stock price interface with additional OHLCV data
export interface IStockPrice {
ticker: string;
price: number;
currency: string;
change: number;
changePercent: number;
previousClose: number;
timestamp: Date;
provider: string;
marketState: 'PRE' | 'REGULAR' | 'POST' | 'CLOSED';
exchange?: string;
exchangeName?: string;
// Phase 1 enhancements
volume?: number; // Trading volume
open?: number; // Opening price
high?: number; // Day high
low?: number; // Day low
adjusted?: boolean; // If price is split/dividend adjusted
dataType: 'eod' | 'intraday' | 'live'; // What kind of data this is
fetchedAt: Date; // When we fetched (vs data timestamp)
}
type CheckStockPrice = plugins.tsclass.typeFest.IsEqual<
IStockPrice,
plugins.tsclass.finance.IStockPrice
>;
export interface IStockPriceError {
ticker: string;
error: string;
provider: string;
timestamp: Date;
}
// Pagination support for large datasets
export interface IPaginatedResponse<T> {
data: T[];
pagination: {
currentPage: number;
totalPages: number;
totalRecords: number;
hasMore: boolean;
limit: number;
offset: number;
};
}
// Phase 1: Discriminated union types for different request types
export type TIntervalType = '1min' | '5min' | '10min' | '15min' | '30min' | '1hour';
export type TSortOrder = 'ASC' | 'DESC';
// Current price request (latest EOD or live)
export interface IStockCurrentRequest {
type: 'current';
ticker: string;
exchange?: string; // MIC code like 'XNAS', 'XNYS', 'XLON'
}
// Historical price request (date range)
export interface IStockHistoricalRequest {
type: 'historical';
ticker: string;
from: Date;
to: Date;
exchange?: string;
sort?: TSortOrder;
limit?: number; // Max results per page (default 1000)
offset?: number; // For pagination
}
// Intraday price request (real-time intervals)
export interface IStockIntradayRequest {
type: 'intraday';
ticker: string;
interval: TIntervalType;
exchange?: string;
limit?: number; // Number of bars to return
date?: Date; // Specific date for historical intraday
}
// Batch current prices request
export interface IStockBatchCurrentRequest {
type: 'batch';
tickers: string[];
exchange?: string;
}
// Union type for all stock data requests
export type IStockDataRequest =
| IStockCurrentRequest
| IStockHistoricalRequest
| IStockIntradayRequest
| IStockBatchCurrentRequest;
// Legacy interfaces (for backward compatibility during migration)
/** @deprecated Use IStockDataRequest with type: 'current' instead */
export interface IStockQuoteRequest {
ticker: string;
includeExtendedHours?: boolean;
}
/** @deprecated Use IStockDataRequest with type: 'batch' instead */
export interface IStockBatchQuoteRequest {
tickers: string[];
includeExtendedHours?: boolean;
}