cc22174b78
- Implemented tests for fetching historical bars for AAPL with different timeframes (1D, 5Min, 1H). - Verified response structure and data integrity for each timeframe. - Ensured that the API returns valid data and appropriate status for the requests.
19 lines
602 B
TypeScript
19 lines
602 B
TypeScript
import Alpaca from "@alpacahq/alpaca-trade-api";
|
|
|
|
const alpaca = new Alpaca({
|
|
keyId: process.env.ALPACA_API_KEY!,
|
|
secretKey: process.env.ALPACA_SECRET_KEY!,
|
|
baseUrl: process.env.ALPACA_BASE_URL || "https://paper-api.alpaca.markets",
|
|
dataBaseUrl: process.env.ALPACA_DATA_URL || "https://data.alpaca.markets",
|
|
retryOnError: false,
|
|
});
|
|
|
|
export async function loader() {
|
|
try {
|
|
const orders = await alpaca.getOrders();
|
|
return Response.json({ orders });
|
|
} catch (error) {
|
|
console.error("Alpaca orders error:", error);
|
|
return Response.json({ orders: [] }, { status: 500 });
|
|
}
|
|
} |