diff --git a/.eslintrc.js b/.eslintrc.js index cc54a78..f8e2339 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -69,7 +69,8 @@ module.exports = { "no-return-assign": "error", "no-script-url": "error", "no-sequences": "error", - "no-shadow": "error", + "no-shadow": "off", + "@typescript-eslint/no-shadow": ["error"], "no-throw-literal": "error", "no-undef-init": "error", "no-undefined": "error", diff --git a/src/alpaca/exchange.ts b/src/alpaca/exchange.ts index 70269f3..eceadd4 100644 --- a/src/alpaca/exchange.ts +++ b/src/alpaca/exchange.ts @@ -4,6 +4,7 @@ import { AlpacaQuoteProvider } from './quote'; import { Exchange } from '../interface/exchange'; import { PortfolioProvider } from '../interface/portfolio'; import { QuoteProvider } from '../interface/quote'; +import { ActionProvider } from '../interface/actions'; /** * Exchange implementation for Alpaca. @@ -24,6 +25,11 @@ export class AlpacaExchange implements Exchange { */ readonly quoteProvider: QuoteProvider; + /** + * The action provider for the exchange. + */ + readonly actionProvider: ActionProvider; + /** * The name of the exchange. */ @@ -45,6 +51,7 @@ export class AlpacaExchange implements Exchange { this.portfolioProvider = new AlpacaPortfolioProvider(this.alpaca); this.quoteProvider = new AlpacaQuoteProvider(this.alpaca); + this.actionProvider = null!; this.name = 'Alpaca'; } diff --git a/src/index.ts b/src/index.ts index 45a1724..c85fec1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,4 @@ -import { Exchange } from "./interface/exchange"; -import { Position, Portfolio, PortfolioProvider } from "./interface/portfolio"; -import { Quote, QuoteProvider } from "./interface/quote"; - -export { - Exchange, - Position, - Portfolio, - PortfolioProvider, - Quote, - QuoteProvider -}; +export * from './interface/exchange'; +export * from './interface/portfolio'; +export * from './interface/quote'; +export * from './interface/actions'; diff --git a/src/interface/actions.ts b/src/interface/actions.ts new file mode 100644 index 0000000..2fdad9c --- /dev/null +++ b/src/interface/actions.ts @@ -0,0 +1,127 @@ +/** + * Enum representing the possible sides of an action. + */ +export const enum ActionSide { + Buy, + Sell, +} + +/** + * Represents an action taken on a stock, such as a buy or sell order. + */ +export class Action { + /** + * The symbol of the asset being traded. + */ + readonly symbol: string; + + /** + * The quantity of the asset being traded. + */ + readonly quantity: number; + + /** + * The side of the action, either "buy" or "sell". + */ + readonly side: ActionSide; + + /** + * The price per share of the asset. + */ + readonly pricePerShare: number; + + /** + * Represents a user Action. + * @constructor + * @param {string} symbol - The symbol of the asset being traded. + * @param {number} quantity - The quantity of the asset being traded. + * @param {ActionSide} side - The side of the trade (buy or sell). + * @param {number} pricePerShare - The price per share of the asset being traded. + */ + constructor(symbol: string, quantity: number, side: ActionSide, pricePerShare: number) { + this.symbol = symbol; + this.quantity = quantity; + this.side = side; + this.pricePerShare = pricePerShare; + } +} + +/** + * Enum representing the type of date filter used in an action fetch. + * @enum {number} + */ +export const enum ActionDateType { + On, + After, + Before, +} + +/** + * Represents options for a date filter in an action fetch. + */ +export class ActionDateOptions { + /** + * The date to filter on. + */ + readonly date: Date; + + /** + * The type of date filter to use. + */ + readonly dateType: ActionDateType; + + /** + * Creates a new ActionDateOptions instance. + * @param date The date to filter on. + * @param dateType The type of date filter to use. + */ + constructor(date: Date, dateType: ActionDateType) { + this.date = date; + this.dateType = dateType; + } +} + +/** + * Represents the options for fetching actions. + */ +export class ActionFetchOptions { + /** + * The number of items to fetch per page. + */ + readonly pageSize?: number; + + /** + * The date options for filtering actions. + */ + readonly dateOptions?: ActionDateOptions; +} + +/** + * Represents the response of a fetch action request. + */ +export interface ActionFetchResponse { + + /** + * An array of `Action` objects. + */ + readonly actions: Action[]; + + /** + * A function that fetches the next page of actions, if available. + * Returns a promise that resolves to an `ActionFetchResponse` object. + */ + readonly fetchNextPage?: () => Promise; +} + +/** + * An interface representing an object that provides actions. + */ +export interface ActionProvider { + + /** + * Fetches actions based on the provided options. + * @param options - The options to use when fetching actions. + * @returns A promise that resolves to an object containing the fetched actions. + */ + readonly fetchActions: (options: ActionFetchOptions) => Promise; +} diff --git a/src/interface/exchange.ts b/src/interface/exchange.ts index cb659fb..a708b23 100644 --- a/src/interface/exchange.ts +++ b/src/interface/exchange.ts @@ -1,5 +1,6 @@ import { PortfolioProvider } from "./portfolio"; import { QuoteProvider } from "./quote"; +import { ActionProvider } from "./actions"; /** * Represents an exchange, which provides access to a portfolio provider and a quote provider. @@ -16,6 +17,11 @@ export interface Exchange { */ readonly quoteProvider: QuoteProvider; + /** + * The action provider for the exchange. + */ + readonly actionProvider: ActionProvider; + /** * The name of the exchange. */