diff --git a/src/alpaca/actions.ts b/src/alpaca/actions.ts index 1be98b9..d71cdb1 100644 --- a/src/alpaca/actions.ts +++ b/src/alpaca/actions.ts @@ -1,6 +1,10 @@ import Alpaca from '@alpacahq/alpaca-trade-api'; import { ActionSide, ActionFetchOptions, ActionFetchResponse, ActionDateType } from '../interface/actions'; +/** + * The activity object returned by Alpaca. + * @see https://docs.alpaca.markets/reference/getaccountactivitiesbyactivitytype + */ interface AlpacaActivity { id: string; activity_type: string; diff --git a/src/alpaca/portfolio.ts b/src/alpaca/portfolio.ts index 105d68a..03cf3fc 100644 --- a/src/alpaca/portfolio.ts +++ b/src/alpaca/portfolio.ts @@ -1,5 +1,5 @@ import Alpaca from '@alpacahq/alpaca-trade-api'; -import { PortfolioProvider, Portfolio, Position } from '../interface/portfolio'; +import { PortfolioProvider, Portfolio } from '../interface/portfolio'; /** * The position object returned by Alpaca. @@ -48,7 +48,7 @@ export class AlpacaPortfolioProvider implements PortfolioProvider { marketValue: parseFloat(position.market_value), costBasis: parseFloat(position.cost_basis), pricePerShare: parseFloat(position.avg_entry_price) - } + }; }) }; }); diff --git a/src/alpaca/quote.ts b/src/alpaca/quote.ts index 574a106..7b0e6bd 100644 --- a/src/alpaca/quote.ts +++ b/src/alpaca/quote.ts @@ -17,14 +17,14 @@ export class AlpacaQuoteProvider implements QuoteProvider { */ readonly fetchQuote = (symbol: string): Promise => { return this.alpaca.getLatestQuote(symbol).then((quote) => { - return new Quote( - quote.Symbol, - quote.AskPrice, - quote.AskSize, - quote.BidPrice, - quote.BidSize, - new Date(Date.parse(quote.Timestamp)) - ); + return { + symbol: quote.Symbol, + askPrice: quote.AskPrice, + askSize: quote.AskSize, + bidPrice: quote.BidPrice, + bidSize: quote.BidSize, + timestamp: new Date(Date.parse(quote.Timestamp)) + }; }).catch((err) => { return err; }); diff --git a/src/interface/portfolio.ts b/src/interface/portfolio.ts index 0d26058..e20e152 100644 --- a/src/interface/portfolio.ts +++ b/src/interface/portfolio.ts @@ -2,6 +2,7 @@ * Represents a financial position in a portfolio. */ export interface Position { + /** * The symbol name of the asset */ @@ -32,6 +33,7 @@ export interface Position { * Represents a portfolio of financial positions. */ export interface Portfolio { + /** * An array of positions held in the portfolio. */ diff --git a/src/interface/quote.ts b/src/interface/quote.ts index 4449bb8..2856632 100644 --- a/src/interface/quote.ts +++ b/src/interface/quote.ts @@ -1,22 +1,37 @@ /** * Represents a stock quote. */ -export class Quote { - readonly symbol: string; - readonly askPrice: number; - readonly askSize: number; - readonly bidPrice: number; - readonly bidSize: number; - readonly timeStamp: Date; +export interface Quote { - constructor(symbol: string, askPrice: number, askSize: number, bidPrice: number, bidSize: number, timeStamp: Date) { - this.symbol = symbol; - this.askPrice = askPrice; - this.askSize = askSize; - this.bidPrice = bidPrice; - this.bidSize = bidSize; - this.timeStamp = timeStamp; - } + /** + * The symbol of the asset + */ + readonly symbol: string; + + /** + * The ask price of the asset + */ + readonly askPrice: number; + + /** + * The ask size of the asset + */ + readonly askSize: number; + + /** + * The bid price of the asset + */ + readonly bidPrice: number; + + /** + * The bid size of the asset + */ + readonly bidSize: number; + + /** + * The timestamp of the quote + */ + readonly timeStamp: Date; } /**