@sudowealth/schwab-api
Version:
TypeScript client for Charles Schwab API with OAuth support, market data, trading functionality, and complete type safety
66 lines (65 loc) • 2.97 kB
TypeScript
export * from './schema';
export * from './endpoints';
import { type EndpointFunction } from '../../core/endpoint-types';
import { type getQuoteBySymbolIdMeta, type getQuotesMeta } from './endpoints';
export type GetQuotesFunction = EndpointFunction<typeof getQuotesMeta>;
export declare const getQuotes: GetQuotesFunction;
export type GetQuoteBySymbolIdFunction = EndpointFunction<typeof getQuoteBySymbolIdMeta>;
export declare const getQuoteBySymbolId: GetQuoteBySymbolIdFunction;
/**
* Extracts and aggregates quote errors from a GetQuotesResponseBody
*
* When using the quotes endpoints, it's possible to get a successful HTTP 200 response
* that contains a mix of valid quotes and per-symbol errors. This function helps identify
* and extract those symbol-level errors for easier processing.
*
* @param responseBody - The response body from getQuotes or getQuoteBySymbolId
* @returns An object with information about the errors, including:
* - hasErrors: Boolean indicating if any symbols had errors
* - errorCount: Total number of symbols with errors
* - symbolErrors: Map of symbol to error information
* - invalidSymbols: List of symbols marked as invalid
* - invalidCusips: List of CUSIPs marked as invalid
* - invalidSSIDs: List of SSIDs marked as invalid
*/
export declare function extractQuoteErrors(responseBody: Record<string, any>): {
hasErrors: boolean;
errorCount: number;
symbolErrors: Record<string, any>;
invalidSymbols: string[];
invalidCusips: string[];
invalidSSIDs: number[];
};
/**
* Checks if a specific symbol has an error in the quotes response
*
* @param responseBody - The response body from getQuotes or getQuoteBySymbolId
* @param symbol - The symbol to check for errors
* @returns True if the symbol has an error, false if it has valid quote data or isn't in the response
*/
export declare function hasSymbolError(responseBody: Record<string, any>, symbol: string): boolean;
/**
* Extracts the quote data for a single symbol from the getQuoteBySymbolId response
*
* Since the Schwab API returns the quote data wrapped in an object with the symbol as the key
* (e.g., { "TSLA": { assetType: "EQUITY", ... } }), this utility function makes it easier
* to extract the actual quote data.
*
* @param responseBody - The response body from getQuoteBySymbolId
* @param symbol - The symbol to extract (if not provided, will use the first key in the response)
* @returns The quote data for the symbol, or null if not found or has an error
*
* @example
* ```typescript
* const response = await client.marketData.quotes.getQuoteBySymbolId({
* pathParams: { symbol_id: 'TSLA' },
* queryParams: { fields: ['all'] }
* });
*
* const quote = extractSingleQuote(response, 'TSLA');
* if (quote) {
* console.log(`${quote.symbol}: $${quote.quote?.lastPrice}`);
* }
* ```
*/
export declare function extractSingleQuote(responseBody: Record<string, any>, symbol?: string): any;