From 76cfbc80908c6bcd17ef9c3c9265800a75e89a00 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Tue, 3 Oct 2023 17:41:19 -0400 Subject: [PATCH 1/8] Started setting up basic exchange interface --- src/exchange.ts | 9 +++++++++ src/interface/account.ts | 3 +++ src/interface/portfolio.ts | 17 +++++++++++++++++ src/interface/quote.ts | 3 +++ 4 files changed, 32 insertions(+) create mode 100644 src/exchange.ts create mode 100644 src/interface/account.ts create mode 100644 src/interface/portfolio.ts create mode 100644 src/interface/quote.ts diff --git a/src/exchange.ts b/src/exchange.ts new file mode 100644 index 0000000..c53e963 --- /dev/null +++ b/src/exchange.ts @@ -0,0 +1,9 @@ +import { Account } from "./interface/account"; +import {Quote} from "./interface/quote" + +interface Exchange { + name: string; + + fetchAccounts: () => Account[]; + fetchQuote: (symbol: string) => Quote; +} \ No newline at end of file diff --git a/src/interface/account.ts b/src/interface/account.ts new file mode 100644 index 0000000..97e3ea6 --- /dev/null +++ b/src/interface/account.ts @@ -0,0 +1,3 @@ +export interface Account { + fetchPortfolio: () => Portfolio; +} \ No newline at end of file diff --git a/src/interface/portfolio.ts b/src/interface/portfolio.ts new file mode 100644 index 0000000..15706e9 --- /dev/null +++ b/src/interface/portfolio.ts @@ -0,0 +1,17 @@ +export interface Position { + readonly symbol: string; + + readonly quantity: number; + + readonly dateAcquired: Date; + + readonly pricePaid: number; + readonly price: number; + + readonly change: number; + readonly changePct: number; +} + +export interface Portfolio { + readonly positions: Position[]; +} \ No newline at end of file diff --git a/src/interface/quote.ts b/src/interface/quote.ts new file mode 100644 index 0000000..fd84a23 --- /dev/null +++ b/src/interface/quote.ts @@ -0,0 +1,3 @@ +export class Quote { + +} \ No newline at end of file -- 2.47.2 From b42d974c562410f512e0a17ce05db555685d59d3 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 6 Oct 2023 16:21:31 -0400 Subject: [PATCH 2/8] Setup basic portfolio interface --- src/exchange.ts | 9 --------- src/index.ts | 14 ++++++++++++-- src/interface/account.ts | 4 +++- src/interface/portfolio.ts | 38 ++++++++++++++++++++++++++------------ src/interface/quote.ts | 4 +++- 5 files changed, 44 insertions(+), 25 deletions(-) delete mode 100644 src/exchange.ts diff --git a/src/exchange.ts b/src/exchange.ts deleted file mode 100644 index c53e963..0000000 --- a/src/exchange.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Account } from "./interface/account"; -import {Quote} from "./interface/quote" - -interface Exchange { - name: string; - - fetchAccounts: () => Account[]; - fetchQuote: (symbol: string) => Quote; -} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 87a110b..195fd0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,14 @@ import { createLogger, transports, format } from "winston"; +import { Account } from "./interface/account"; +import { Quote } from "./interface/quote" + +export interface Exchange { + name: string; + + fetchAccounts: () => Account[]; + fetchQuote: (symbol: string) => Quote; +} + const logger = createLogger({ transports: [new transports.Console()], @@ -10,5 +20,5 @@ const logger = createLogger({ }) ), }); - -logger.info("Hello world!"); \ No newline at end of file + +logger.info("Hello world!"); diff --git a/src/interface/account.ts b/src/interface/account.ts index 97e3ea6..06d7357 100644 --- a/src/interface/account.ts +++ b/src/interface/account.ts @@ -1,3 +1,5 @@ +import { Portfolio } from "./portfolio"; + export interface Account { fetchPortfolio: () => Portfolio; -} \ No newline at end of file +} diff --git a/src/interface/portfolio.ts b/src/interface/portfolio.ts index 15706e9..3750f1d 100644 --- a/src/interface/portfolio.ts +++ b/src/interface/portfolio.ts @@ -1,17 +1,31 @@ -export interface Position { +export class Position { + readonly lastTrade: number; + readonly lastTradeTime: Date; + + readonly change: number; + readonly changePercent: number; + + readonly earningsPerShare: number; + + readonly marketCap: number; + readonly symbol: string; - readonly quantity: number; - - readonly dateAcquired: Date; - - readonly pricePaid: number; - readonly price: number; - - readonly change: number; - readonly changePct: number; + constructor(lastTrade: number, lastTradeTime: Date, change: number, changePercent: number, earningsPerShare: number, marketCap: number, symbol: string) { + this.lastTrade = lastTrade; + this.lastTradeTime = lastTradeTime; + this.change = change; + this.changePercent = changePercent; + this.earningsPerShare = earningsPerShare; + this.marketCap = marketCap; + this.symbol = symbol; + } } -export interface Portfolio { +export class Portfolio { readonly positions: Position[]; -} \ No newline at end of file + + constructor(positions: Position[]) { + this.positions = positions; + } +} diff --git a/src/interface/quote.ts b/src/interface/quote.ts index fd84a23..afbf7db 100644 --- a/src/interface/quote.ts +++ b/src/interface/quote.ts @@ -1,3 +1,5 @@ export class Quote { -} \ No newline at end of file +} + + -- 2.47.2 From d8ebcf99fb1fde58a34ae728b63247267d97b0f5 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 6 Oct 2023 16:25:54 -0400 Subject: [PATCH 3/8] Added Quote interface --- src/interface/quote.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/interface/quote.ts b/src/interface/quote.ts index afbf7db..1160da3 100644 --- a/src/interface/quote.ts +++ b/src/interface/quote.ts @@ -1,5 +1,22 @@ export class Quote { - + readonly companyName: string; + + readonly earningsPerShare: number; + readonly estimatedEarnings: number; + + readonly lastTrade: number; + + readonly symbol: string; + + constructor(companyName: string, earningsPerShare: number, estimatedEarnings: number, lastTrade: number, symbol: string) { + this.companyName = companyName; + this.earningsPerShare = earningsPerShare; + this.estimatedEarnings = estimatedEarnings; + this.lastTrade = lastTrade; + this.symbol = symbol; + } } - +export interface QuoteProvider { + readonly fetchQuote: (symbol: string) => Promise; +} -- 2.47.2 From 597a87ba55625be8053972c7af7f109b05ffa953 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 6 Oct 2023 16:26:28 -0400 Subject: [PATCH 4/8] Added portfolio provide interface. --- src/interface/account.ts | 5 ----- src/interface/portfolio.ts | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 src/interface/account.ts diff --git a/src/interface/account.ts b/src/interface/account.ts deleted file mode 100644 index 06d7357..0000000 --- a/src/interface/account.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Portfolio } from "./portfolio"; - -export interface Account { - fetchPortfolio: () => Portfolio; -} diff --git a/src/interface/portfolio.ts b/src/interface/portfolio.ts index 3750f1d..4f83d5a 100644 --- a/src/interface/portfolio.ts +++ b/src/interface/portfolio.ts @@ -29,3 +29,7 @@ export class Portfolio { this.positions = positions; } } + +export interface PortfolioProvider { + readonly fetchPortfolio: () => Promise; +} -- 2.47.2 From 445a6c76cc6ec1e33ba085b5309b0d55adcea948 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 6 Oct 2023 16:29:02 -0400 Subject: [PATCH 5/8] Added exchange interface. --- src/interface/exchange.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/interface/exchange.ts diff --git a/src/interface/exchange.ts b/src/interface/exchange.ts new file mode 100644 index 0000000..aba273c --- /dev/null +++ b/src/interface/exchange.ts @@ -0,0 +1,11 @@ +import { PortfolioProvider } from "./portfolio"; +import { QuoteProvider } from "./quote"; + +export interface Exchange { + readonly credentials: Credentials; + + readonly portfolioProvider: PortfolioProvider; + readonly quoteProvider: QuoteProvider; + + readonly name: string; +} \ No newline at end of file -- 2.47.2 From 71d9f9ae74270a4da0bf7b4138445414fa9445a9 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 6 Oct 2023 16:35:19 -0400 Subject: [PATCH 6/8] Remove credentials from abstract interface. --- src/interface/exchange.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/interface/exchange.ts b/src/interface/exchange.ts index aba273c..18f2a40 100644 --- a/src/interface/exchange.ts +++ b/src/interface/exchange.ts @@ -1,9 +1,7 @@ import { PortfolioProvider } from "./portfolio"; import { QuoteProvider } from "./quote"; -export interface Exchange { - readonly credentials: Credentials; - +export interface Exchange { readonly portfolioProvider: PortfolioProvider; readonly quoteProvider: QuoteProvider; -- 2.47.2 From bf3c140c467886b96ddfed93edeab0c430b901a6 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 6 Oct 2023 16:36:08 -0400 Subject: [PATCH 7/8] Move exchange into index.ts --- src/index.ts | 27 ++++++--------------------- src/interface/exchange.ts | 9 --------- 2 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 src/interface/exchange.ts diff --git a/src/index.ts b/src/index.ts index 195fd0e..aad8dbd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,24 +1,9 @@ -import { createLogger, transports, format } from "winston"; -import { Account } from "./interface/account"; -import { Quote } from "./interface/quote" +import { PortfolioProvider } from "./interface/portfolio"; +import { QuoteProvider } from "./interface/quote"; export interface Exchange { - name: string; + readonly portfolioProvider: PortfolioProvider; + readonly quoteProvider: QuoteProvider; - fetchAccounts: () => Account[]; - fetchQuote: (symbol: string) => Quote; -} - - -const logger = createLogger({ - transports: [new transports.Console()], - format: format.combine( - format.colorize(), - format.timestamp(), - format.printf(({ timestamp, level, message }) => { - return `[${timestamp}] ${level}: ${message}`; - }) - ), - }); - -logger.info("Hello world!"); + readonly name: string; +} \ No newline at end of file diff --git a/src/interface/exchange.ts b/src/interface/exchange.ts deleted file mode 100644 index 18f2a40..0000000 --- a/src/interface/exchange.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { PortfolioProvider } from "./portfolio"; -import { QuoteProvider } from "./quote"; - -export interface Exchange { - readonly portfolioProvider: PortfolioProvider; - readonly quoteProvider: QuoteProvider; - - readonly name: string; -} \ No newline at end of file -- 2.47.2 From 8635fea937230e6b07d3922f05b59d461a3d6fa4 Mon Sep 17 00:00:00 2001 From: Carter Bertolini Date: Fri, 6 Oct 2023 16:53:03 -0400 Subject: [PATCH 8/8] Documented the exchange interface. --- src/index.ts | 16 ++++++++- src/interface/portfolio.ts | 68 ++++++++++++++++++++++++++++++++++++-- src/interface/quote.ts | 45 ++++++++++++++++++++++++- 3 files changed, 125 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index aad8dbd..4a66d9b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,23 @@ import { PortfolioProvider } from "./interface/portfolio"; import { QuoteProvider } from "./interface/quote"; +/** + * Represents an exchange, which provides access to a portfolio provider and a quote provider. + */ export interface Exchange { + + /** + * The portfolio provider for the exchange. + */ readonly portfolioProvider: PortfolioProvider; + + /** + * The quote provider for the exchange. + */ readonly quoteProvider: QuoteProvider; + /** + * The name of the exchange. + */ readonly name: string; -} \ No newline at end of file +} diff --git a/src/interface/portfolio.ts b/src/interface/portfolio.ts index 4f83d5a..f65e153 100644 --- a/src/interface/portfolio.ts +++ b/src/interface/portfolio.ts @@ -1,17 +1,62 @@ +/** + * Represents a financial position in a portfolio. + */ export class Position { + /** + * The price of the last trade made for this position. + */ readonly lastTrade: number; + + /** + * The date and time of the last trade made for this position. + */ readonly lastTradeTime: Date; - + + /** + * The change in the position value. + */ readonly change: number; + + /** + * The percentage change in the position value. + */ readonly changePercent: number; + /** + * The earnings per share of the position. + */ readonly earningsPerShare: number; + /** + * The market capitalization of the position. + */ readonly marketCap: number; + /** + * The symbol of the position. + */ readonly symbol: string; - constructor(lastTrade: number, lastTradeTime: Date, change: number, changePercent: number, earningsPerShare: number, marketCap: number, symbol: string) { + /** + * Represents a position in a portfolio. + * @constructor + * @param {number} lastTrade - The price of the last trade made for this position. + * @param {Date} lastTradeTime - The date and time of the last trade made for this position. + * @param {number} change - The change in the position value. + * @param {number} changePercent - The percentage change in the position value. + * @param {number} earningsPerShare - The earnings per share of the position. + * @param {number} marketCap - The market capitalization of the position. + * @param {string} symbol - The symbol of the position. + */ + constructor( + lastTrade: number, + lastTradeTime: Date, + change: number, + changePercent: number, + earningsPerShare: number, + marketCap: number, + symbol: string + ) { this.lastTrade = lastTrade; this.lastTradeTime = lastTradeTime; this.change = change; @@ -22,14 +67,33 @@ export class Position { } } +/** + * Represents a portfolio of financial positions. + */ export class Portfolio { + /** + * An array of positions held in the portfolio. + */ readonly positions: Position[]; + /** + * Creates a new Portfolio instance. + * @constructor + * @param {Position[]} positions - An array of Position objects representing the positions in the portfolio. + */ constructor(positions: Position[]) { this.positions = positions; } } +/** + * A provider for fetching a portfolio. + */ export interface PortfolioProvider { + + /** + * Fetches the portfolio. + * @returns A promise that resolves with the fetched portfolio. + */ readonly fetchPortfolio: () => Promise; } diff --git a/src/interface/quote.ts b/src/interface/quote.ts index 1160da3..62b32e0 100644 --- a/src/interface/quote.ts +++ b/src/interface/quote.ts @@ -1,14 +1,48 @@ +/** + * Represents a stock quote. + */ export class Quote { + /** + * The name of the company associated with this quote. + */ readonly companyName: string; + /** + * The earnings per share of a company. + */ readonly earningsPerShare: number; + + /** + * The estimated earnings for a stock. + */ readonly estimatedEarnings: number; + /** + * The price of the last trade for the security. + */ readonly lastTrade: number; + /** + * The symbol of the financial instrument being quoted. + */ readonly symbol: string; - constructor(companyName: string, earningsPerShare: number, estimatedEarnings: number, lastTrade: number, symbol: string) { + /** + * Represents a quote for a particular stock. + * @constructor + * @param {string} companyName - The name of the company associated with the stock. + * @param {number} earningsPerShare - The earnings per share for the stock. + * @param {number} estimatedEarnings - The estimated earnings for the stock. + * @param {number} lastTrade - The last trade price for the stock. + * @param {string} symbol - The symbol for the stock. + */ + constructor( + companyName: string, + earningsPerShare: number, + estimatedEarnings: number, + lastTrade: number, + symbol: string + ) { this.companyName = companyName; this.earningsPerShare = earningsPerShare; this.estimatedEarnings = estimatedEarnings; @@ -17,6 +51,15 @@ export class Quote { } } +/** + * A provider for fetching stock quotes. + */ export interface QuoteProvider { + + /** + * Fetches a quote for the given stock symbol. + * @param symbol The stock symbol to fetch the quote for. + * @returns A Promise that resolves to a Quote object. + */ readonly fetchQuote: (symbol: string) => Promise; } -- 2.47.2