@discomedia/utils 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/index-frontend.cjs +7798 -0
- package/dist/index-frontend.cjs.map +1 -0
- package/dist/index-frontend.mjs +7792 -0
- package/dist/index-frontend.mjs.map +1 -0
- package/dist/index.cjs +17747 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +17741 -0
- package/dist/index.mjs.map +1 -0
- package/dist/test.js +6783 -0
- package/dist/test.js.map +1 -0
- package/dist/types/alpaca-market-data-api.d.ts +384 -0
- package/dist/types/alpaca-market-data-api.d.ts.map +1 -0
- package/dist/types/alpaca-trading-api.d.ts +318 -0
- package/dist/types/alpaca-trading-api.d.ts.map +1 -0
- package/dist/types/format-tools.d.ts +46 -0
- package/dist/types/format-tools.d.ts.map +1 -0
- package/dist/types/index-frontend.d.ts +18 -0
- package/dist/types/index-frontend.d.ts.map +1 -0
- package/dist/types/index.d.ts +150 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/json-tools.d.ts +33 -0
- package/dist/types/json-tools.d.ts.map +1 -0
- package/dist/types/llm-config.d.ts +36 -0
- package/dist/types/llm-config.d.ts.map +1 -0
- package/dist/types/llm-deepseek.d.ts +12 -0
- package/dist/types/llm-deepseek.d.ts.map +1 -0
- package/dist/types/llm-images.d.ts +49 -0
- package/dist/types/llm-images.d.ts.map +1 -0
- package/dist/types/llm-openai.d.ts +64 -0
- package/dist/types/llm-openai.d.ts.map +1 -0
- package/dist/types/llm-utils.d.ts +16 -0
- package/dist/types/llm-utils.d.ts.map +1 -0
- package/dist/types/logging.d.ts +12 -0
- package/dist/types/logging.d.ts.map +1 -0
- package/dist/types/market-hours.d.ts +24 -0
- package/dist/types/market-hours.d.ts.map +1 -0
- package/dist/types/market-time.d.ts +184 -0
- package/dist/types/market-time.d.ts.map +1 -0
- package/dist/types/misc-utils.d.ts +49 -0
- package/dist/types/misc-utils.d.ts.map +1 -0
- package/dist/types/polygon-indices.d.ts +85 -0
- package/dist/types/polygon-indices.d.ts.map +1 -0
- package/dist/types/polygon.d.ts +126 -0
- package/dist/types/polygon.d.ts.map +1 -0
- package/dist/types/technical-analysis.d.ts +90 -0
- package/dist/types/technical-analysis.d.ts.map +1 -0
- package/dist/types/test.d.ts +2 -0
- package/dist/types/test.d.ts.map +1 -0
- package/dist/types/testing/frontend-test.d.ts +2 -0
- package/dist/types/testing/frontend-test.d.ts.map +1 -0
- package/dist/types/time-utils.d.ts +17 -0
- package/dist/types/time-utils.d.ts.map +1 -0
- package/dist/types/types/alpaca-types.d.ts +962 -0
- package/dist/types/types/alpaca-types.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +7 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/llm-types.d.ts +82 -0
- package/dist/types/types/llm-types.d.ts.map +1 -0
- package/dist/types/types/logging-types.d.ts +10 -0
- package/dist/types/types/logging-types.d.ts.map +1 -0
- package/dist/types/types/market-time-types.d.ts +59 -0
- package/dist/types/types/market-time-types.d.ts.map +1 -0
- package/dist/types/types/polygon-indices-types.d.ts +190 -0
- package/dist/types/types/polygon-indices-types.d.ts.map +1 -0
- package/dist/types/types/polygon-types.d.ts +204 -0
- package/dist/types/types/polygon-types.d.ts.map +1 -0
- package/dist/types/types/ta-types.d.ts +89 -0
- package/dist/types/types/ta-types.d.ts.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ImageGenerationOptions } from './types';
|
|
2
|
+
import { ImageModel, ImagesResponse } from 'openai/resources/images';
|
|
3
|
+
/**
|
|
4
|
+
* Enhanced ImagesResponse that includes cost calculation
|
|
5
|
+
*/
|
|
6
|
+
export interface ImageResponseWithUsage extends ImagesResponse {
|
|
7
|
+
usage?: ImagesResponse['usage'] & {
|
|
8
|
+
provider: string;
|
|
9
|
+
model: ImageModel;
|
|
10
|
+
cost: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Makes a call to the OpenAI Images API to generate images based on a text prompt.
|
|
15
|
+
*
|
|
16
|
+
* This function provides access to OpenAI's image generation capabilities with support for:
|
|
17
|
+
* - Different output formats (JPEG, PNG, WebP)
|
|
18
|
+
* - Various image sizes and quality settings
|
|
19
|
+
* - Multiple image generation in a single call
|
|
20
|
+
* - Base64 encoded image data return
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Basic image generation
|
|
24
|
+
* const response = await makeImagesCall('A beautiful sunset over mountains');
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Custom options
|
|
28
|
+
* const response = await makeImagesCall('A birthday cake', {
|
|
29
|
+
* size: '1024x1024',
|
|
30
|
+
* outputFormat: 'png',
|
|
31
|
+
* quality: 'high',
|
|
32
|
+
* count: 2
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* @param prompt - The text prompt describing the image to generate
|
|
36
|
+
* @param options - Configuration options for image generation. Includes:
|
|
37
|
+
* - size: Image dimensions (uses OpenAI's size options)
|
|
38
|
+
* - outputFormat: Image format ('jpeg', 'png', 'webp') - defaults to 'webp'
|
|
39
|
+
* - compression: Compression level (number) - defaults to 50
|
|
40
|
+
* - quality: Quality setting (uses OpenAI's quality options) - defaults to 'high'
|
|
41
|
+
* - count: Number of images to generate - defaults to 1
|
|
42
|
+
* - background: Background setting for transparency support
|
|
43
|
+
* - moderation: Content moderation level
|
|
44
|
+
* - apiKey: OpenAI API key (optional, falls back to environment variable)
|
|
45
|
+
* @returns Promise<ImageResponseWithUsage> - The image generation response with cost information
|
|
46
|
+
* @throws Error if the API call fails or invalid parameters are provided
|
|
47
|
+
*/
|
|
48
|
+
export declare function makeImagesCall(prompt: string, options?: ImageGenerationOptions): Promise<ImageResponseWithUsage>;
|
|
49
|
+
//# sourceMappingURL=llm-images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-images.d.ts","sourceRoot":"","sources":["../../src/llm-images.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAuB,UAAU,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG;QAChC,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,UAAU,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,sBAAsB,CAAC,CAmFjC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Tool } from 'openai/resources/responses/responses';
|
|
2
|
+
import { LLMResponse, LLMOptions, OpenAIModel } from './types';
|
|
3
|
+
import { ResponseCreateParamsNonStreaming } from 'openai/resources/responses/responses';
|
|
4
|
+
export declare const DEFAULT_OPTIONS: LLMOptions;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the given model supports the temperature parameter. Reasoning models (o1*, o3*, o4*) do not support temperature.
|
|
7
|
+
* @param model The model to check.
|
|
8
|
+
* @returns True if the model supports the temperature parameter, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function supportsTemperature(model: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the given model is a reasoning model. Reasoning models have different tool choice constraints.
|
|
13
|
+
* @param model The model to check.
|
|
14
|
+
* @returns True if the model is a reasoning model, false otherwise.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isReasoningModel(model: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Makes a call to OpenAI's Responses API for more advanced use cases with built-in tools.
|
|
19
|
+
*
|
|
20
|
+
* This function provides access to the Responses API which supports:
|
|
21
|
+
* - Built-in tools (web search, file search, computer use, code interpreter, image generation)
|
|
22
|
+
* - Background processing
|
|
23
|
+
* - Conversation state management
|
|
24
|
+
* - Reasoning support for o-series models
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Basic text response
|
|
28
|
+
* const response = await makeResponsesAPICall('What is the weather like?');
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // With web search tool
|
|
32
|
+
* const response = await makeResponsesAPICall('Latest news about AI', {
|
|
33
|
+
* tools: [{ type: 'web_search_preview' }]
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* @param input - The input content. Can be:
|
|
37
|
+
* - A string for simple text prompts
|
|
38
|
+
* - An array of input items for complex/multi-modal content
|
|
39
|
+
* @param options - Configuration options for the Responses API
|
|
40
|
+
* @returns Promise<LLMResponse<T>> - The response in the same format as makeLLMCall
|
|
41
|
+
* @throws Error if the API call fails
|
|
42
|
+
*/
|
|
43
|
+
export declare const makeResponsesAPICall: <T = any>(input: string | ResponseCreateParamsNonStreaming["input"], options?: Omit<ResponseCreateParamsNonStreaming, "input" | "model"> & {
|
|
44
|
+
apiKey?: string;
|
|
45
|
+
model?: string;
|
|
46
|
+
}) => Promise<LLMResponse<T>>;
|
|
47
|
+
/**
|
|
48
|
+
* Makes a call to the OpenAI Responses API for advanced use cases with built-in tools.
|
|
49
|
+
*
|
|
50
|
+
* @param input The text prompt to send to the model (e.g., "What's in this image?")
|
|
51
|
+
* @param options The options for the Responses API call, including optional image data.
|
|
52
|
+
* @return A promise that resolves to the response from the Responses API.
|
|
53
|
+
*/
|
|
54
|
+
export declare function makeLLMCall<T = any>(input: string, options?: {
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
model?: OpenAIModel;
|
|
57
|
+
responseFormat?: 'text' | 'json';
|
|
58
|
+
tools?: Tool[];
|
|
59
|
+
useCodeInterpreter?: boolean;
|
|
60
|
+
useWebSearch?: boolean;
|
|
61
|
+
imageBase64?: string;
|
|
62
|
+
imageDetail?: 'low' | 'high' | 'auto';
|
|
63
|
+
}): Promise<LLMResponse<T>>;
|
|
64
|
+
//# sourceMappingURL=llm-openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-openai.d.ts","sourceRoot":"","sources":["../../src/llm-openai.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAiB,MAAM,sCAAsC,CAAC;AAK3E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAwB,MAAM,SAAS,CAAC;AACrF,OAAO,EACL,gCAAgC,EAOjC,MAAM,sCAAsC,CAAC;AAE9C,eAAO,MAAM,eAAe,EAAE,UAG7B,CAAC;AAkBF;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAI1D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,oBAAoB,GAAU,CAAC,GAAG,GAAG,EAChD,OAAO,MAAM,GAAG,gCAAgC,CAAC,OAAO,CAAC,EACzD,UAAS,IAAI,CAAC,gCAAgC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX,KACL,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CA0HxB,CAAC;AAGF;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,GAAG,EACvC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;CAClC,GACL,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CA6EzB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OpenAIResponseFormat } from './types';
|
|
2
|
+
export declare function normalizeModelName(model: string): string;
|
|
3
|
+
export declare const CODE_BLOCK_TYPES: string[];
|
|
4
|
+
/**
|
|
5
|
+
* Tries to parse JSON from the given content string according to the specified
|
|
6
|
+
* response format. If the response format is 'json' or a JSON schema object, it
|
|
7
|
+
* will attempt to parse the content using multiple strategies. If any of the
|
|
8
|
+
* strategies succeed, it will return the parsed JSON object. If all of them fail,
|
|
9
|
+
* it will throw an error.
|
|
10
|
+
*
|
|
11
|
+
* @param content The content string to parse
|
|
12
|
+
* @param responseFormat The desired format of the response
|
|
13
|
+
* @returns The parsed JSON object or null if it fails
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseResponse<T>(content: string, responseFormat: OpenAIResponseFormat): Promise<T | null>;
|
|
16
|
+
//# sourceMappingURL=llm-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-utils.d.ts","sourceRoot":"","sources":["../../src/llm-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAG/C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,eAAO,MAAM,gBAAgB,UAAsF,CAAC;AAElH;;;;;;;;;;GAUG;AACL,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,oBAAoB,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CA+E/G"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LogOptions } from './types/logging-types';
|
|
2
|
+
/**
|
|
3
|
+
* Logs a message to the console.
|
|
4
|
+
* @param message The message to log.
|
|
5
|
+
* @param options Optional options.
|
|
6
|
+
* @param options.source The source of the message.
|
|
7
|
+
* @param options.type The type of message to log.
|
|
8
|
+
* @param options.symbol The trading symbol associated with this log.
|
|
9
|
+
* @param options.account The account associated with this log.
|
|
10
|
+
*/
|
|
11
|
+
export declare function log(message: string, options?: LogOptions): void;
|
|
12
|
+
//# sourceMappingURL=logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,UAA4C,GAAG,IAAI,CAoBhG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface HolidayDetails {
|
|
2
|
+
date: string;
|
|
3
|
+
}
|
|
4
|
+
export interface MarketHolidaysForYear {
|
|
5
|
+
[holidayName: string]: HolidayDetails;
|
|
6
|
+
}
|
|
7
|
+
export interface MarketHolidays {
|
|
8
|
+
[year: number]: MarketHolidaysForYear;
|
|
9
|
+
}
|
|
10
|
+
export interface EarlyCloseDetails {
|
|
11
|
+
date: string;
|
|
12
|
+
time: string;
|
|
13
|
+
optionsTime: string;
|
|
14
|
+
notes: string;
|
|
15
|
+
}
|
|
16
|
+
export interface EarlyClosesForYear {
|
|
17
|
+
[date: string]: EarlyCloseDetails;
|
|
18
|
+
}
|
|
19
|
+
export interface MarketEarlyCloses {
|
|
20
|
+
[year: number]: EarlyClosesForYear;
|
|
21
|
+
}
|
|
22
|
+
export declare const marketHolidays: MarketHolidays;
|
|
23
|
+
export declare const marketEarlyCloses: MarketEarlyCloses;
|
|
24
|
+
//# sourceMappingURL=market-hours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"market-hours.d.ts","sourceRoot":"","sources":["../../src/market-hours.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC;CACvC;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAAC;CACvC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;CACnC;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC;CACpC;AAED,eAAO,MAAM,cAAc,EAAE,cAsC5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,iBAsE/B,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { IntradayReporting, PeriodDates, MarketTimeParams, MarketOpenCloseResult, MarketStatus, MarketTimesConfig } from './types/market-time-types';
|
|
2
|
+
/**
|
|
3
|
+
* Market times for NYSE
|
|
4
|
+
* Regular market hours are 9:30am-4:00pm
|
|
5
|
+
* Early market hours are 9:30am-10:00am (first 30 minutes)
|
|
6
|
+
* Extended market hours are 4:00am to 9:30am and 4:00pm-8:00pm
|
|
7
|
+
* On days before some holidays, the market closes early at 1:00pm
|
|
8
|
+
* Early extended market hours are 1:00pm-5:00pm on early close days
|
|
9
|
+
*/
|
|
10
|
+
export declare const MARKET_TIMES: MarketTimesConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Utility class for handling market time-related operations
|
|
13
|
+
*/
|
|
14
|
+
export declare class MarketTimeUtil {
|
|
15
|
+
private timezone;
|
|
16
|
+
private intradayReporting;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new MarketTimeUtil instance
|
|
19
|
+
* @param {string} [timezone='America/New_York'] - The timezone to use for market time calculations
|
|
20
|
+
* @param {IntradayReporting} [intradayReporting='market_hours'] - The intraday reporting mode
|
|
21
|
+
*/
|
|
22
|
+
constructor(timezone?: string, intradayReporting?: IntradayReporting);
|
|
23
|
+
/**
|
|
24
|
+
* Validates the provided timezone
|
|
25
|
+
* @private
|
|
26
|
+
* @param {string} timezone - The timezone to validate
|
|
27
|
+
* @throws {Error} If the timezone is invalid
|
|
28
|
+
*/
|
|
29
|
+
private validateTimezone;
|
|
30
|
+
private formatDate;
|
|
31
|
+
private isWeekend;
|
|
32
|
+
private isHoliday;
|
|
33
|
+
isEarlyCloseDay(date: Date): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get the early close time for a given date
|
|
36
|
+
* @param date - The date to get the early close time for
|
|
37
|
+
* @returns The early close time in minutes from midnight, or null if there is no early close
|
|
38
|
+
*/
|
|
39
|
+
getEarlyCloseTime(date: Date): number | null;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a given date is a market day
|
|
42
|
+
* @param date - The date to check
|
|
43
|
+
* @returns true if the date is a market day, false otherwise
|
|
44
|
+
*/
|
|
45
|
+
isMarketDay(date: Date): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a given date is within market hours
|
|
48
|
+
* @param date - The date to check
|
|
49
|
+
* @returns true if the date is within market hours, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
isWithinMarketHours(date: Date): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a given date is before market hours
|
|
54
|
+
* @param date - The date to check
|
|
55
|
+
* @returns true if the date is before market hours, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
private isBeforeMarketHours;
|
|
58
|
+
/**
|
|
59
|
+
* Get the last trading date, i.e. the last date that was a market day
|
|
60
|
+
* @param currentDate - The current date
|
|
61
|
+
* @returns The last trading date
|
|
62
|
+
*/
|
|
63
|
+
getLastTradingDate(currentDate?: Date): Date;
|
|
64
|
+
private getLastMarketDay;
|
|
65
|
+
getLastFullTradingDate(currentDate?: Date): Date;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the next market day from a reference date
|
|
68
|
+
* @param {Object} [options] - Options object
|
|
69
|
+
* @param {Date} [options.referenceDate] - The reference date (defaults to current date)
|
|
70
|
+
* @returns {Object} The next market day information
|
|
71
|
+
* @property {Date} date - The date object (start of day in NY time)
|
|
72
|
+
* @property {string} yyyymmdd - The date in YYYY-MM-DD format
|
|
73
|
+
* @property {string} dateISOString - Full ISO date string
|
|
74
|
+
*/
|
|
75
|
+
getNextMarketDay(date: Date): Date;
|
|
76
|
+
private getDayBoundaries;
|
|
77
|
+
private calculatePeriodStartDate;
|
|
78
|
+
getMarketTimePeriod({ period, end, intraday_reporting, outputFormat, }: MarketTimeParams): PeriodDates;
|
|
79
|
+
getMarketOpenClose(options?: {
|
|
80
|
+
date?: Date;
|
|
81
|
+
}): MarketOpenCloseResult;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new MarketTimeUtil instance
|
|
85
|
+
* @param {string} [timezone] - The timezone to use for market time calculations
|
|
86
|
+
* @param {IntradayReporting} [intraday_reporting] - The intraday reporting mode
|
|
87
|
+
* @returns {MarketTimeUtil} A new MarketTimeUtil instance
|
|
88
|
+
*/
|
|
89
|
+
export declare function createMarketTimeUtil(timezone?: string, intraday_reporting?: IntradayReporting): MarketTimeUtil;
|
|
90
|
+
/**
|
|
91
|
+
* Gets start and end timestamps for a given market time period
|
|
92
|
+
* @param {MarketTimeParams} [params] - The market time parameters
|
|
93
|
+
* @returns {PeriodDates} The start and end timestamps
|
|
94
|
+
*/
|
|
95
|
+
export declare function getStartAndEndTimestamps(params?: MarketTimeParams): PeriodDates;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the market open/close times for a given date
|
|
98
|
+
* @param {Object} [options] - Options object
|
|
99
|
+
* @param {Date} [options.date] - The date to check (defaults to current date)
|
|
100
|
+
* @returns {MarketOpenCloseResult} The market open/close times
|
|
101
|
+
*/
|
|
102
|
+
export declare function getMarketOpenClose(options?: {
|
|
103
|
+
date?: Date;
|
|
104
|
+
}): MarketOpenCloseResult;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the start and end dates for a given market time period
|
|
107
|
+
* @param {MarketTimeParams} [params] - The market time parameters
|
|
108
|
+
* @returns {Object} The start and end dates
|
|
109
|
+
* @property {Date} start - The start date
|
|
110
|
+
* @property {Date} end - The end date
|
|
111
|
+
*/
|
|
112
|
+
export declare function getStartAndEndDates(params?: MarketTimeParams): {
|
|
113
|
+
start: Date;
|
|
114
|
+
end: Date;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Gets the last trading date in YYYY-MM-DD format
|
|
118
|
+
* @returns {string} The last trading date in YYYY-MM-DD format
|
|
119
|
+
*/
|
|
120
|
+
export declare function getLastTradingDateYYYYMMDD(): string;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the last full trading date
|
|
123
|
+
* @param {Date} [currentDate] - The current date (defaults to now)
|
|
124
|
+
* @returns {Object} The last full trading date
|
|
125
|
+
* @property {Date} date - The date object
|
|
126
|
+
* @property {string} YYYYMMDD - The date in YYYY-MM-DD format
|
|
127
|
+
*/
|
|
128
|
+
export declare function getLastFullTradingDate(currentDate?: Date): {
|
|
129
|
+
date: Date;
|
|
130
|
+
YYYYMMDD: string;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Gets the next market day from a reference date
|
|
134
|
+
* @param {Object} [options] - Options object
|
|
135
|
+
* @param {Date} [options.referenceDate] - The reference date (defaults to current date)
|
|
136
|
+
* @returns {Object} The next market day information
|
|
137
|
+
* @property {Date} date - The date object (start of day in NY time)
|
|
138
|
+
* @property {string} yyyymmdd - The date in YYYY-MM-DD format
|
|
139
|
+
* @property {string} dateISOString - Full ISO date string
|
|
140
|
+
*/
|
|
141
|
+
export declare function getNextMarketDay({ referenceDate }?: {
|
|
142
|
+
referenceDate?: Date;
|
|
143
|
+
}): {
|
|
144
|
+
date: Date;
|
|
145
|
+
yyyymmdd: string;
|
|
146
|
+
dateISOString: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Gets the current time in Eastern Time
|
|
150
|
+
* @returns {Date} The current time in Eastern Time
|
|
151
|
+
*/
|
|
152
|
+
export declare const currentTimeET: () => Date;
|
|
153
|
+
/**
|
|
154
|
+
* Gets a date in New York timezone, rezoned using date-fns-tz
|
|
155
|
+
* @param {number|string|Date} time - The time to convert
|
|
156
|
+
* @returns {Date} The date in New York timezone
|
|
157
|
+
*/
|
|
158
|
+
export declare function getDateInNY(time: number | string | {
|
|
159
|
+
year: number;
|
|
160
|
+
month: number;
|
|
161
|
+
day: number;
|
|
162
|
+
}): Date;
|
|
163
|
+
/**
|
|
164
|
+
* Gets the trading date in YYYY-MM-DD format for New York timezone, for grouping of data
|
|
165
|
+
* @param {string|number|Date} time - The time to convert (string, unix timestamp in ms, or Date object)
|
|
166
|
+
* @returns {string} The trading date in YYYY-MM-DD format
|
|
167
|
+
*/
|
|
168
|
+
export declare function getTradingDate(time: string | number | Date): string;
|
|
169
|
+
/**
|
|
170
|
+
* Returns the New York timezone offset based on whether daylight savings is active
|
|
171
|
+
* @param dateString - The date string to check
|
|
172
|
+
* @returns "-04:00" during daylight savings (EDT) or "-05:00" during standard time (EST)
|
|
173
|
+
*/
|
|
174
|
+
export declare const getNYTimeZone: (date?: Date) => "-04:00" | "-05:00";
|
|
175
|
+
/**
|
|
176
|
+
* Gets the current market status
|
|
177
|
+
* @param {Object} [options] - Options object
|
|
178
|
+
* @param {Date} [options.date] - The date to check (defaults to current date)
|
|
179
|
+
* @returns {MarketStatus} The current market status
|
|
180
|
+
*/
|
|
181
|
+
export declare function getMarketStatus(options?: {
|
|
182
|
+
date?: Date;
|
|
183
|
+
}): MarketStatus;
|
|
184
|
+
//# sourceMappingURL=market-time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"market-time.d.ts","sourceRoot":"","sources":["../../src/market-time.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare const LOG_TYPES: readonly ["info", "warn", "error", "debug", "trace"];
|
|
2
|
+
type LogType = (typeof LOG_TYPES)[number];
|
|
3
|
+
/**
|
|
4
|
+
* Debug logging utility that respects environment debug flags.
|
|
5
|
+
* Logs messages to the console based on the specified log level.
|
|
6
|
+
*
|
|
7
|
+
* @param message - The message to log.
|
|
8
|
+
* @param data - Optional data to log alongside the message. This can be any type of data.
|
|
9
|
+
* @param type - Log level. One of: 'info' | 'warn' | 'error' | 'debug' | 'trace'. Defaults to 'info'.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* logIfDebug("User login failed", { userId: 123 }, "error");
|
|
13
|
+
* logIfDebug("Cache miss", undefined, "warn");
|
|
14
|
+
* logIfDebug("Processing request", { requestId: "abc" }, "debug");
|
|
15
|
+
*/
|
|
16
|
+
export declare const logIfDebug: (message: string, data?: unknown, type?: LogType) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Hides (masks) the value of any query parameter that is "apiKey" (case-insensitive),
|
|
19
|
+
* replacing the middle part with **** and keeping only the first 2 and last 2 characters.
|
|
20
|
+
*
|
|
21
|
+
* @param url - The URL containing the query parameters.
|
|
22
|
+
* @returns The URL with the masked API key.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* hideApiKeyFromurl("https://xxx.com/s/23/fdsa/?apiKey=12341239856677");
|
|
26
|
+
* // Returns "https://xxx.com/s/23/fdsa/?apiKey=12****77"
|
|
27
|
+
*/
|
|
28
|
+
export declare function hideApiKeyFromurl(url: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Fetches a resource with intelligent retry logic for handling transient errors.
|
|
31
|
+
* Features enhanced error logging, rate limit detection, and adaptive backoff.
|
|
32
|
+
*
|
|
33
|
+
* @param url - The URL to fetch.
|
|
34
|
+
* @param options - Optional fetch options.
|
|
35
|
+
* @param retries - The number of retry attempts. Defaults to 3.
|
|
36
|
+
* @param initialBackoff - The initial backoff time in milliseconds. Defaults to 1000.
|
|
37
|
+
* @returns A promise that resolves to the response.
|
|
38
|
+
*
|
|
39
|
+
* @throws Will throw an error if the fetch fails after the specified number of retries.
|
|
40
|
+
*/
|
|
41
|
+
export declare function fetchWithRetry(url: string, options?: RequestInit, retries?: number, initialBackoff?: number): Promise<Response>;
|
|
42
|
+
/**
|
|
43
|
+
* Validates a Polygon.io API key by making a test request.
|
|
44
|
+
* @param apiKey - The API key to validate.
|
|
45
|
+
* @returns Promise that resolves to true if valid, false otherwise.
|
|
46
|
+
*/
|
|
47
|
+
export declare function validatePolygonApiKey(apiKey: string): Promise<boolean>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=misc-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc-utils.d.ts","sourceRoot":"","sources":["../../src/misc-utils.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,SAAS,sDAAuD,CAAC;AAEvE,KAAK,OAAO,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,OAAO,OAAO,EAAE,OAAM,OAAgB,SAqBjF,CAAC;AAqBF;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAiBrD;AAyCD;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,OAAO,GAAE,MAAU,EACnB,cAAc,GAAE,MAAa,GAC5B,OAAO,CAAC,QAAQ,CAAC,CA2FnB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAe5E"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polygon Indices API Implementation
|
|
3
|
+
*
|
|
4
|
+
* This module provides functions to interact with the Polygon.io Indices API.
|
|
5
|
+
*/
|
|
6
|
+
import { PolygonIndicesAggregatesParams, PolygonIndicesAggregatesResponse, PolygonIndicesPrevCloseResponse, PolygonIndicesDailyOpenCloseResponse, PolygonIndicesSnapshotParams, PolygonIndicesSnapshotResponse } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Fetches aggregate bars for an index over a given date range in custom time window sizes.
|
|
9
|
+
*
|
|
10
|
+
* @param {PolygonIndicesAggregatesParams} params - Parameters for the aggregates request
|
|
11
|
+
* @param {Object} [options] - Optional parameters
|
|
12
|
+
* @param {string} [options.apiKey] - API key to use for the request
|
|
13
|
+
* @returns {Promise<PolygonIndicesAggregatesResponse>} The aggregates response
|
|
14
|
+
*/
|
|
15
|
+
export declare const fetchIndicesAggregates: (params: PolygonIndicesAggregatesParams, options?: {
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
}) => Promise<PolygonIndicesAggregatesResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the previous day's open, high, low, and close (OHLC) for the specified index.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} indicesTicker - The ticker symbol of the index
|
|
22
|
+
* @param {Object} [options] - Optional parameters
|
|
23
|
+
* @param {string} [options.apiKey] - API key to use for the request
|
|
24
|
+
* @returns {Promise<PolygonIndicesPrevCloseResponse>} The previous close response
|
|
25
|
+
*/
|
|
26
|
+
export declare const fetchIndicesPreviousClose: (indicesTicker: string, options?: {
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
}) => Promise<PolygonIndicesPrevCloseResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the open, close and afterhours values of an index symbol on a certain date.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} indicesTicker - The ticker symbol of the index
|
|
33
|
+
* @param {string} date - The date in YYYY-MM-DD format
|
|
34
|
+
* @param {Object} [options] - Optional parameters
|
|
35
|
+
* @param {string} [options.apiKey] - API key to use for the request
|
|
36
|
+
* @returns {Promise<PolygonIndicesDailyOpenCloseResponse>} The daily open/close response
|
|
37
|
+
*/
|
|
38
|
+
export declare const fetchIndicesDailyOpenClose: (indicesTicker: string, date: string, options?: {
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
}) => Promise<PolygonIndicesDailyOpenCloseResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets a snapshot of indices data for specified tickers.
|
|
43
|
+
*
|
|
44
|
+
* @param {PolygonIndicesSnapshotParams} [params] - Parameters for the snapshot request
|
|
45
|
+
* @param {Object} [options] - Optional parameters
|
|
46
|
+
* @param {string} [options.apiKey] - API key to use for the request
|
|
47
|
+
* @returns {Promise<PolygonIndicesSnapshotResponse>} The indices snapshot response
|
|
48
|
+
*/
|
|
49
|
+
export declare const fetchIndicesSnapshot: (params?: PolygonIndicesSnapshotParams, options?: {
|
|
50
|
+
apiKey?: string;
|
|
51
|
+
}) => Promise<PolygonIndicesSnapshotResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets snapshots for assets of all types, including indices.
|
|
54
|
+
*
|
|
55
|
+
* @param {string[]} tickers - Array of tickers to fetch snapshots for
|
|
56
|
+
* @param {Object} [options] - Optional parameters
|
|
57
|
+
* @param {string} [options.apiKey] - API key to use for the request
|
|
58
|
+
* @param {string} [options.type] - Filter by asset type
|
|
59
|
+
* @param {string} [options.order] - Order results
|
|
60
|
+
* @param {number} [options.limit] - Limit the number of results
|
|
61
|
+
* @param {string} [options.sort] - Sort field
|
|
62
|
+
* @returns {Promise<any>} The universal snapshot response
|
|
63
|
+
*/
|
|
64
|
+
export declare const fetchUniversalSnapshot: (tickers: string[], options?: {
|
|
65
|
+
apiKey?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
order?: string;
|
|
68
|
+
limit?: number;
|
|
69
|
+
sort?: string;
|
|
70
|
+
}) => Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Converts Polygon Indices bar data to a more standardized format
|
|
73
|
+
*
|
|
74
|
+
* @param {PolygonIndicesAggregatesResponse} data - The raw aggregates response
|
|
75
|
+
* @returns {Array<{date: string, open: number, high: number, low: number, close: number, timestamp: number}>} Formatted bar data
|
|
76
|
+
*/
|
|
77
|
+
export declare const formatIndicesBarData: (data: PolygonIndicesAggregatesResponse) => Array<{
|
|
78
|
+
date: string;
|
|
79
|
+
open: number;
|
|
80
|
+
high: number;
|
|
81
|
+
low: number;
|
|
82
|
+
close: number;
|
|
83
|
+
timestamp: number;
|
|
84
|
+
}>;
|
|
85
|
+
//# sourceMappingURL=polygon-indices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygon-indices.d.ts","sourceRoot":"","sources":["../../src/polygon-indices.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAChC,+BAA+B,EAC/B,oCAAoC,EACpC,4BAA4B,EAC5B,8BAA8B,EAE/B,MAAM,SAAS,CAAC;AAyBjB;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,8BAA8B,EACtC,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,gCAAgC,CAuC1C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACpC,eAAe,MAAM,EACrB,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,+BAA+B,CAyBzC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACrC,eAAe,MAAM,EACrB,MAAM,MAAM,EACZ,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,oCAAoC,CAyB9C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,4BAA4B,EACrC,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,8BAA8B,CAyCxC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EAAE,EACjB,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,KACA,OAAO,CAAC,GAAG,CA6Cb,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,gCAAgC,KACrC,KAAK,CAAC;IACP,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAYA,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**********************************************************************************
|
|
2
|
+
* Polygon.io calls
|
|
3
|
+
**********************************************************************************/
|
|
4
|
+
import { PolygonQuote, PolygonPriceData, PolygonGroupedDailyResponse, PolygonTickerInfo, PolygonDailyOpenClose, PolygonTradesResponse } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Fetches general information about a stock ticker.
|
|
7
|
+
* @param {string} symbol - The stock ticker symbol to fetch information for.
|
|
8
|
+
* @param {Object} [options] - Optional parameters.
|
|
9
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
10
|
+
* @returns {Promise<PolygonTickerInfo | null>} The ticker information or null if not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare const fetchTickerInfo: (symbol: string, options?: {
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
}) => Promise<PolygonTickerInfo | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetches the last trade for a given stock ticker.
|
|
17
|
+
* @param {string} symbol - The stock ticker symbol to fetch the last trade for.
|
|
18
|
+
* @param {Object} [options] - Optional parameters.
|
|
19
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
20
|
+
* @returns {Promise<PolygonQuote>} The last trade information.
|
|
21
|
+
*/
|
|
22
|
+
export declare const fetchLastTrade: (symbol: string, options?: {
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
}) => Promise<PolygonQuote>;
|
|
25
|
+
/**
|
|
26
|
+
* Fetches price data for a given stock ticker.
|
|
27
|
+
* @param {Object} params - The parameters for fetching price data.
|
|
28
|
+
* @param {string} params.ticker - The stock ticker symbol.
|
|
29
|
+
* @param {number} params.start - The start timestamp for fetching price data.
|
|
30
|
+
* @param {number} [params.end] - The end timestamp for fetching price data.
|
|
31
|
+
* @param {number} params.multiplier - The multiplier for the price data.
|
|
32
|
+
* @param {string} params.timespan - The timespan for the price data.
|
|
33
|
+
* @param {number} [params.limit] - The maximum number of price data points to fetch.
|
|
34
|
+
* @param {Object} [options] - Optional parameters.
|
|
35
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
36
|
+
* @returns {Promise<PolygonPriceData[]>} The fetched price data.
|
|
37
|
+
*/
|
|
38
|
+
export declare const fetchPrices: (params: {
|
|
39
|
+
ticker: string;
|
|
40
|
+
start: number;
|
|
41
|
+
end?: number;
|
|
42
|
+
multiplier: number;
|
|
43
|
+
timespan: string;
|
|
44
|
+
limit?: number;
|
|
45
|
+
}, options?: {
|
|
46
|
+
apiKey?: string;
|
|
47
|
+
}) => Promise<PolygonPriceData[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Analyzes the price data for a given stock.
|
|
50
|
+
* @param {PolygonPriceData[]} priceData - The price data to analyze.
|
|
51
|
+
* @returns {string} The analysis report.
|
|
52
|
+
*/
|
|
53
|
+
export declare function analysePolygonPriceData(priceData: PolygonPriceData[]): string;
|
|
54
|
+
/**
|
|
55
|
+
* Fetches grouped daily price data for a specific date.
|
|
56
|
+
* @param {string} date - The date to fetch grouped daily data for.
|
|
57
|
+
* @param {Object} [options] - Optional parameters.
|
|
58
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
59
|
+
* @param {boolean} [options.adjusted] - Whether to adjust the data.
|
|
60
|
+
* @param {boolean} [options.includeOTC] - Whether to include OTC data.
|
|
61
|
+
* @returns {Promise<PolygonGroupedDailyResponse>} The grouped daily response.
|
|
62
|
+
*/
|
|
63
|
+
export declare const fetchGroupedDaily: (date: string, options?: {
|
|
64
|
+
apiKey?: string;
|
|
65
|
+
adjusted?: boolean;
|
|
66
|
+
includeOTC?: boolean;
|
|
67
|
+
}) => Promise<PolygonGroupedDailyResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Formats the price data into a readable string.
|
|
70
|
+
* @param {PolygonPriceData[]} priceData - The price data to format.
|
|
71
|
+
* @returns {string} The formatted price data.
|
|
72
|
+
*/
|
|
73
|
+
export declare function formatPriceData(priceData: PolygonPriceData[]): string;
|
|
74
|
+
export declare const fetchDailyOpenClose: (
|
|
75
|
+
/**
|
|
76
|
+
* Fetches the daily open and close data for a given stock ticker.
|
|
77
|
+
* @param {string} symbol - The stock ticker symbol to fetch data for.
|
|
78
|
+
* @param {Date} [date=new Date()] - The date to fetch data for.
|
|
79
|
+
* @param {Object} [options] - Optional parameters.
|
|
80
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
81
|
+
* @param {boolean} [options.adjusted] - Whether to adjust the data.
|
|
82
|
+
* @returns {Promise<PolygonDailyOpenClose>} The daily open and close data.
|
|
83
|
+
*/
|
|
84
|
+
symbol: string, date?: Date, options?: {
|
|
85
|
+
apiKey?: string;
|
|
86
|
+
adjusted?: boolean;
|
|
87
|
+
}) => Promise<PolygonDailyOpenClose>;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the previous close price for a given stock ticker.
|
|
90
|
+
* @param {string} symbol - The stock ticker symbol to fetch the previous close for.
|
|
91
|
+
* @param {Date} [referenceDate] - The reference date to use for fetching the previous close.
|
|
92
|
+
* @returns {Promise<{ close: number; date: Date }>} The previous close price and date.
|
|
93
|
+
*/
|
|
94
|
+
export declare function getPreviousClose(symbol: string, referenceDate?: Date, options?: {
|
|
95
|
+
apiKey?: string;
|
|
96
|
+
}): Promise<{
|
|
97
|
+
close: number;
|
|
98
|
+
date: Date;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* Fetches trade data for a given stock ticker.
|
|
102
|
+
* @param {string} symbol - The stock ticker symbol to fetch trades for.
|
|
103
|
+
* @param {Object} [options] - Optional parameters.
|
|
104
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
105
|
+
* @param {string | number} [options.timestamp] - The timestamp for fetching trades.
|
|
106
|
+
* @param {string | number} [options.timestampgt] - Greater than timestamp for fetching trades.
|
|
107
|
+
* @param {string | number} [options.timestampgte] - Greater than or equal to timestamp for fetching trades.
|
|
108
|
+
* @param {string | number} [options.timestamplt] - Less than timestamp for fetching trades.
|
|
109
|
+
* @param {string | number} [options.timestamplte] - Less than or equal to timestamp for fetching trades.
|
|
110
|
+
* @param {'asc' | 'desc'} [options.order] - The order of the trades.
|
|
111
|
+
* @param {number} [options.limit] - The maximum number of trades to fetch.
|
|
112
|
+
* @param {string} [options.sort] - The sort order for the trades.
|
|
113
|
+
* @returns {Promise<PolygonTradesResponse>} The fetched trades response.
|
|
114
|
+
*/
|
|
115
|
+
export declare const fetchTrades: (symbol: string, options?: {
|
|
116
|
+
apiKey?: string;
|
|
117
|
+
timestamp?: string | number;
|
|
118
|
+
timestampgt?: string | number;
|
|
119
|
+
timestampgte?: string | number;
|
|
120
|
+
timestamplt?: string | number;
|
|
121
|
+
timestamplte?: string | number;
|
|
122
|
+
order?: "asc" | "desc";
|
|
123
|
+
limit?: number;
|
|
124
|
+
sort?: string;
|
|
125
|
+
}) => Promise<PolygonTradesResponse>;
|
|
126
|
+
//# sourceMappingURL=polygon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../src/polygon.ts"],"names":[],"mappings":"AAAA;;oFAEoF;AAGpF,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,2BAA2B,EAE3B,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAYjB;;;;;;GAMG;AAEH,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAoFlC,CAAC;AAGF;;;;;;GAMG;AAEH,eAAO,MAAM,cAAc,GAAU,QAAQ,MAAM,EAAE,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAAG,OAAO,CAAC,YAAY,CAkDxG,CAAC;AAGF;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,WAAW,GACtB,QAAQ;IACN,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EACD,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,gBAAgB,EAAE,CAiF5B,CAAC;AAEF;;;;GAIG;AAEH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAsC7E;AAID;;;;;;;;GAQG;AAEH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,KACA,OAAO,CAAC,2BAA2B,CA6DrC,CAAC;AAEF;;;;GAIG;AAEH,wBAAgB,eAAe,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAkBrE;AAED,eAAO,MAAM,mBAAmB;AAC9B;;;;;;;;GAQG;AAEH,QAAQ,MAAM,EACd,OAAM,IAAiB,EACvB,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,KACA,OAAO,CAAC,qBAAqB,CAsB/B,CAAC;AAIF;;;;;GAKG;AAEH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,IAAI,EACpB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAUxC;AAED;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,KACA,OAAO,CAAC,qBAAqB,CAuD/B,CAAC"}
|