From 20a8920a30fb81565f5f4034d44bce099104b7a0 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 27 Oct 2023 16:07:43 -0400 Subject: [PATCH 1/7] Added interface for fetching user actions. --- src/interface/actions.ts | 49 +++++++++++++++++++++++++++++++++++++++ src/interface/exchange.ts | 6 +++++ 2 files changed, 55 insertions(+) create mode 100644 src/interface/actions.ts diff --git a/src/interface/actions.ts b/src/interface/actions.ts new file mode 100644 index 0000000..29571fd --- /dev/null +++ b/src/interface/actions.ts @@ -0,0 +1,49 @@ +export enum ActionSide { + Buy, + Sell, +} + +export class Action { + readonly symbol: string; + readonly quantity: number; + readonly side: ActionSide; + readonly pricePerShare: number; + + constructor(symbol: string, quantity: number, side: ActionSide, pricePerShare: number) { + this.symbol = symbol; + this.quantity = quantity; + this.side = side; + this.pricePerShare = pricePerShare; + } +} + +export enum ActionDateType { + On, + After, + Before, +} + +export class ActionDateOptions { + readonly date: Date; + readonly dateType: ActionDateType; + + constructor(date: Date, dateType: ActionDateType) { + this.date = date; + this.dateType = dateType; + } +} + +export class ActionFetchOptions { + readonly pageSize?: number; + readonly dateOptions?: ActionDateOptions; +} + +export interface ActionFetchResponse { + readonly actions: Action[]; + + readonly fetchNextPage?: () => Promise; +} + +export interface ActionProvider { + readonly fetchActions: (options: ActionFetchOptions) => Promise; +} \ No newline at end of file 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. */ From dd72d4a7179f04a2bb3db0b5016de887845a7310 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 27 Oct 2023 16:10:11 -0400 Subject: [PATCH 2/7] Documented the action interface. --- src/interface/actions.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/interface/actions.ts b/src/interface/actions.ts index 29571fd..34b39d0 100644 --- a/src/interface/actions.ts +++ b/src/interface/actions.ts @@ -1,14 +1,43 @@ +/** + * Enum representing the possible sides of an action. + */ export 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; + /** + * Creates an instance of an 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; @@ -44,6 +73,14 @@ export interface ActionFetchResponse { 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; } \ No newline at end of file From 39742da43e6be61a066671a09d58b81210613c98 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 27 Oct 2023 16:13:53 -0400 Subject: [PATCH 3/7] Finish action interface documentation. --- src/interface/actions.ts | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/interface/actions.ts b/src/interface/actions.ts index 34b39d0..f42530a 100644 --- a/src/interface/actions.ts +++ b/src/interface/actions.ts @@ -31,7 +31,7 @@ export class Action { readonly pricePerShare: number; /** - * Creates an instance of an Action. + * 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. @@ -46,30 +46,69 @@ export class Action { } } +/** + * Enum representing the type of date filter used in an action fetch. + * @enum {number} + */ export 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; } From c113bd4f5ced96986e998ba2685ad0ece8691303 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 27 Oct 2023 16:16:51 -0400 Subject: [PATCH 4/7] Add temporary undefined action provider to existing exchanges. --- src/alpaca/exchange.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/alpaca/exchange.ts b/src/alpaca/exchange.ts index 70269f3..2d701d0 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 = undefined!; this.name = 'Alpaca'; } From dcdb2bad1acdafa3e3eef044638d570cc56f790a Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 27 Oct 2023 16:21:52 -0400 Subject: [PATCH 5/7] Make enums action option enums const and fix linter issues. --- .eslintrc.js | 3 ++- src/alpaca/exchange.ts | 2 +- src/interface/actions.ts | 12 +++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) 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 2d701d0..eceadd4 100644 --- a/src/alpaca/exchange.ts +++ b/src/alpaca/exchange.ts @@ -51,7 +51,7 @@ export class AlpacaExchange implements Exchange { this.portfolioProvider = new AlpacaPortfolioProvider(this.alpaca); this.quoteProvider = new AlpacaQuoteProvider(this.alpaca); - this.actionProvider = undefined!; + this.actionProvider = null!; this.name = 'Alpaca'; } diff --git a/src/interface/actions.ts b/src/interface/actions.ts index f42530a..2fdad9c 100644 --- a/src/interface/actions.ts +++ b/src/interface/actions.ts @@ -1,7 +1,7 @@ /** * Enum representing the possible sides of an action. */ -export enum ActionSide { +export const enum ActionSide { Buy, Sell, } @@ -19,7 +19,7 @@ export class Action { * The quantity of the asset being traded. */ readonly quantity: number; - + /** * The side of the action, either "buy" or "sell". */ @@ -50,7 +50,7 @@ export class Action { * Enum representing the type of date filter used in an action fetch. * @enum {number} */ -export enum ActionDateType { +export const enum ActionDateType { On, After, Before, @@ -89,7 +89,7 @@ export class ActionFetchOptions { * The number of items to fetch per page. */ readonly pageSize?: number; - + /** * The date options for filtering actions. */ @@ -100,6 +100,7 @@ export class ActionFetchOptions { * Represents the response of a fetch action request. */ export interface ActionFetchResponse { + /** * An array of `Action` objects. */ @@ -116,10 +117,11 @@ export interface ActionFetchResponse { * 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; -} \ No newline at end of file +} From 52b100667d456616cfc58ed84d457c448b646f28 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 27 Oct 2023 16:31:21 -0400 Subject: [PATCH 6/7] Add action stuff to module exports. --- src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 45a1724..8aa0da9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { Exchange } from "./interface/exchange"; import { Position, Portfolio, PortfolioProvider } from "./interface/portfolio"; import { Quote, QuoteProvider } from "./interface/quote"; +import { Action, ActionDateOptions, ActionDateType, ActionFetchOptions, ActionFetchResponse, ActionProvider, ActionSide } from './interface/actions'; export { Exchange, @@ -8,5 +9,12 @@ export { Portfolio, PortfolioProvider, Quote, - QuoteProvider + QuoteProvider, + Action, + ActionDateOptions, + ActionDateType, + ActionFetchOptions, + ActionFetchResponse, + ActionProvider, + ActionSide, }; From 5f6acd99fbd38f008074a89e26da3b18cfb50fea Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 27 Oct 2023 16:35:34 -0400 Subject: [PATCH 7/7] Redo interface exports. --- src/index.ts | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8aa0da9..c85fec1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,20 +1,4 @@ -import { Exchange } from "./interface/exchange"; -import { Position, Portfolio, PortfolioProvider } from "./interface/portfolio"; -import { Quote, QuoteProvider } from "./interface/quote"; -import { Action, ActionDateOptions, ActionDateType, ActionFetchOptions, ActionFetchResponse, ActionProvider, ActionSide } from './interface/actions'; - -export { - Exchange, - Position, - Portfolio, - PortfolioProvider, - Quote, - QuoteProvider, - Action, - ActionDateOptions, - ActionDateType, - ActionFetchOptions, - ActionFetchResponse, - ActionProvider, - ActionSide, -}; +export * from './interface/exchange'; +export * from './interface/portfolio'; +export * from './interface/quote'; +export * from './interface/actions';