import { describe, expect, test } from '@jest/globals'; import 'dotenv/config'; import { ActionFetchOptions, AlpacaExchange } from '../src/index'; import { createLogger, transports, format } from "winston"; const timeout = 10000; const logger = createLogger({ transports: [new transports.Console()], format: format.combine( format.colorize(), format.timestamp(), format.printf(({ timestamp, level, message, service }) => { return `[${timestamp}] ${service} ${level}: ${message}`; }) ), defaultMeta: { service: "AlpacaTest", }, }); describe('Alpaca Tests', () => { test('portfolio fetch', async () => { expect(process.env.ALPACA_API_KEY).toBeDefined(); expect(process.env.ALPACA_SECRET_KEY).toBeDefined(); const exchange = new AlpacaExchange(process.env.ALPACA_API_KEY!, process.env.ALPACA_SECRET_KEY!, true); await expect(exchange.portfolioProvider.fetchPortfolio()).resolves.toBeDefined(); }, timeout); test('quote fetch', async () => { expect(process.env.ALPACA_API_KEY).toBeDefined(); expect(process.env.ALPACA_SECRET_KEY).toBeDefined(); const exchange = new AlpacaExchange(process.env.ALPACA_API_KEY!, process.env.ALPACA_SECRET_KEY!, true); await expect(exchange.quoteProvider.fetchQuote("AAPL")).resolves.toBeDefined(); }, timeout); test('action fetch', async () => { expect(process.env.ALPACA_API_KEY).toBeDefined(); expect(process.env.ALPACA_SECRET_KEY).toBeDefined(); const exchange = new AlpacaExchange(process.env.ALPACA_API_KEY!, process.env.ALPACA_SECRET_KEY!, true); const response = await exchange.actionProvider.fetchActions(new ActionFetchOptions()); logger.info(JSON.stringify(response)); await expect(exchange.actionProvider.fetchActions(new ActionFetchOptions())).resolves.toBeDefined(); }, timeout); });