Setup basic Alpaca action fetch and test.
This commit is contained in:
parent
8437515904
commit
327ab308bf
@ -37,7 +37,8 @@ export class AlpacaActionProvider {
|
|||||||
activity.side === "buy" ? ActionSide.Buy : ActionSide.Sell,
|
activity.side === "buy" ? ActionSide.Buy : ActionSide.Sell,
|
||||||
parseFloat(activity.price)
|
parseFloat(activity.price)
|
||||||
);
|
);
|
||||||
})
|
}),
|
||||||
|
undefined
|
||||||
);
|
);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
return err;
|
return err;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import Alpaca from '@alpacahq/alpaca-trade-api';
|
import Alpaca from '@alpacahq/alpaca-trade-api';
|
||||||
import { AlpacaPortfolioProvider } from './portfolio';
|
import { AlpacaPortfolioProvider } from './portfolio';
|
||||||
import { AlpacaQuoteProvider } from './quote';
|
import { AlpacaQuoteProvider } from './quote';
|
||||||
|
import { AlpacaActionProvider } from './actions';
|
||||||
import { Exchange } from '../interface/exchange';
|
import { Exchange } from '../interface/exchange';
|
||||||
import { PortfolioProvider } from '../interface/portfolio';
|
import { PortfolioProvider } from '../interface/portfolio';
|
||||||
import { QuoteProvider } from '../interface/quote';
|
import { QuoteProvider } from '../interface/quote';
|
||||||
@ -51,7 +52,7 @@ export class AlpacaExchange implements Exchange {
|
|||||||
|
|
||||||
this.portfolioProvider = new AlpacaPortfolioProvider(this.alpaca);
|
this.portfolioProvider = new AlpacaPortfolioProvider(this.alpaca);
|
||||||
this.quoteProvider = new AlpacaQuoteProvider(this.alpaca);
|
this.quoteProvider = new AlpacaQuoteProvider(this.alpaca);
|
||||||
this.actionProvider = null!;
|
this.actionProvider = new AlpacaActionProvider(this.alpaca);
|
||||||
|
|
||||||
this.name = 'Alpaca';
|
this.name = 'Alpaca';
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,21 @@
|
|||||||
import { describe, expect, test } from '@jest/globals';
|
import { describe, expect, test } from '@jest/globals';
|
||||||
import 'dotenv/config';
|
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', () => {
|
describe('Alpaca Tests', () => {
|
||||||
test('portfolio fetch', () => {
|
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);
|
const exchange = new AlpacaExchange(process.env.ALPACA_API_KEY!, process.env.ALPACA_SECRET_KEY!, true);
|
||||||
expect(exchange.quoteProvider.fetchQuote("AAPL")).resolves.toBeDefined();
|
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