Resolve "Implement action fetching for Alpaca" #31

Merged
clbertolini merged 12 commits from 14-implement-action-fetching-for-alpaca into main 2023-11-10 21:36:43 +00:00
3 changed files with 27 additions and 3 deletions
Showing only changes of commit 327ab308bf - Show all commits

View File

@ -37,7 +37,8 @@ export class AlpacaActionProvider {
activity.side === "buy" ? ActionSide.Buy : ActionSide.Sell,
parseFloat(activity.price)
);
})
}),
undefined
);
}).catch((err) => {
return err;

View File

@ -1,6 +1,7 @@
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';
@ -51,7 +52,7 @@ export class AlpacaExchange implements Exchange {
this.portfolioProvider = new AlpacaPortfolioProvider(this.alpaca);
this.quoteProvider = new AlpacaQuoteProvider(this.alpaca);
this.actionProvider = null!;
this.actionProvider = new AlpacaActionProvider(this.alpaca);
this.name = 'Alpaca';
}

View File

@ -1,6 +1,21 @@
import { describe, expect, test } from '@jest/globals';
import 'dotenv/config';
import { AlpacaExchange } from '../src/index';
import { ActionFetchOptions, AlpacaExchange } from '../src/index';
import { createLogger, transports, format } from "winston";
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', () => {
@ -16,4 +31,11 @@ describe('Alpaca Tests', () => {
const exchange = new AlpacaExchange(process.env.ALPACA_API_KEY!, process.env.ALPACA_SECRET_KEY!, true);
expect(exchange.quoteProvider.fetchQuote("AAPL")).resolves.toBeDefined();
});
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);
expect(exchange.actionProvider.fetchActions(new ActionFetchOptions)).resolves.toBeDefined();
});
});