Resolve "Implement action fetching for Alpaca" #31
@ -37,7 +37,8 @@ export class AlpacaActionProvider {
|
||||
activity.side === "buy" ? ActionSide.Buy : ActionSide.Sell,
|
||||
parseFloat(activity.price)
|
||||
);
|
||||
})
|
||||
}),
|
||||
undefined
|
||||
);
|
||||
}).catch((err) => {
|
||||
return err;
|
||||
|
@ -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';
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user