import Alpaca from '@alpacahq/alpaca-trade-api'; import { AlpacaPortfolioProvider } from './portfolio'; import { AlpacaQuoteProvider } from './quote'; import { AlpacaActionProvider } from './actions'; import { Exchange } from '../interface/exchange'; import { PortfolioProvider } from '../interface/portfolio'; import { QuoteProvider } from '../interface/quote'; import { ActionProvider } from '../interface/actions'; /** * Exchange implementation for Alpaca. */ export class AlpacaExchange implements Exchange { /** * The Alpaca API client. */ readonly alpaca: Alpaca; /** * The portfolio provider for the exchange. */ readonly portfolioProvider: PortfolioProvider; /** * The quote provider for the exchange. */ readonly quoteProvider: QuoteProvider; /** * The action provider for the exchange. */ readonly actionProvider: ActionProvider; /** * The name of the 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, secretKey: secretKey, paper: paper }); this.portfolioProvider = new AlpacaPortfolioProvider(this.alpaca); this.quoteProvider = new AlpacaQuoteProvider(this.alpaca); this.actionProvider = new AlpacaActionProvider(this.alpaca); this.name = 'Alpaca'; } }