diff --git a/src/alpaca/exchange.ts b/src/alpaca/exchange.ts index 2edca77..725161e 100644 --- a/src/alpaca/exchange.ts +++ b/src/alpaca/exchange.ts @@ -5,7 +5,13 @@ import { Exchange } from '../interface/exchange' import { PortfolioProvider } from '../interface/portfolio' import { QuoteProvider } from '../interface/quote' +/** + * Exchange implementation for Alpaca. + */ export class AlpacaExchange implements Exchange { + /** + * The Alpaca API client. + */ readonly alpaca: Alpaca; /** @@ -23,6 +29,13 @@ export class AlpacaExchange implements Exchange { */ readonly name: string; + /** + * Creates an instance of the Alpaca exchange. + * @constructor + * @param {string} keyId - The API key ID for the Alpaca exchange. + * @param {string} secretKey - The secret key for the Alpaca exchange. + * @param {boolean} paper - Whether to use the paper trading environment or not. + */ constructor(keyId: string, secretKey: string, paper: boolean) { this.alpaca = new Alpaca({ keyId: keyId, diff --git a/src/alpaca/portfolio.ts b/src/alpaca/portfolio.ts index f21102a..9472e56 100644 --- a/src/alpaca/portfolio.ts +++ b/src/alpaca/portfolio.ts @@ -1,6 +1,10 @@ import Alpaca from '@alpacahq/alpaca-trade-api' import { PortfolioProvider, Portfolio, Position } from '../interface/portfolio'; +/** + * The position object returned by Alpaca. + * @see https://alpaca.markets/docs/api-references/trading-api/positions/#properties + */ class AlpacaPosition { asset_id!: string; symbol!: string; @@ -22,9 +26,18 @@ class AlpacaPosition { asset_marginable!: string; } +/** + * Provides a portfolio using the Alpaca API client. + */ export class AlpacaPortfolioProvider implements PortfolioProvider { + /** + * The Alpaca API client. + */ readonly alpaca: Alpaca; + /** + * Fetches the portfolio. + */ readonly fetchPortfolio = (): Promise => { return (this.alpaca.getPositions() as Promise).then((positions) => { return new Portfolio(positions.map((position) => { @@ -39,6 +52,11 @@ export class AlpacaPortfolioProvider implements PortfolioProvider { }); } + /** + * Creates a new AlpacaPortfolioProvider instance. + * @constructor + * @param {Alpaca} alpaca - The Alpaca API client. + */ constructor(alpaca: Alpaca) { this.alpaca = alpaca; } diff --git a/src/alpaca/quote.ts b/src/alpaca/quote.ts index df8eab9..0b6e291 100644 --- a/src/alpaca/quote.ts +++ b/src/alpaca/quote.ts @@ -1,9 +1,20 @@ import Alpaca from '@alpacahq/alpaca-trade-api' import { QuoteProvider, Quote } from '../interface/quote'; +/** + * Provides quotes using the Alpaca API. + */ export class AlpacaQuoteProvider implements QuoteProvider { + /** + * The Alpaca API client. + */ readonly alpaca: Alpaca; + /** + * 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 => { return this.alpaca.getLatestQuote(symbol).then((quote) => { return new Quote( @@ -19,6 +30,11 @@ export class AlpacaQuoteProvider implements QuoteProvider { }) } + /** + * Creates a new AlpacaQuoteProvider instance. + * @constructor + * @param {Alpaca} alpaca - The Alpaca API client. + */ constructor(alpaca: Alpaca) { this.alpaca = alpaca; }