Resolve "Use interfaces instead of classes where possible" #32

Merged
clbertolini merged 4 commits from 15-use-interfaces-instead-of-classes-where-possible into main 2023-11-10 22:24:06 +00:00
5 changed files with 46 additions and 25 deletions
Showing only changes of commit 986a0ab569 - Show all commits

View File

@ -1,6 +1,10 @@
import Alpaca from '@alpacahq/alpaca-trade-api';
import { ActionSide, ActionFetchOptions, ActionFetchResponse, ActionDateType } from '../interface/actions';
/**
* The activity object returned by Alpaca.
* @see https://docs.alpaca.markets/reference/getaccountactivitiesbyactivitytype
*/
interface AlpacaActivity {
id: string;
activity_type: string;

View File

@ -1,5 +1,5 @@
import Alpaca from '@alpacahq/alpaca-trade-api';
import { PortfolioProvider, Portfolio, Position } from '../interface/portfolio';
import { PortfolioProvider, Portfolio } from '../interface/portfolio';
/**
* The position object returned by Alpaca.
@ -48,7 +48,7 @@ export class AlpacaPortfolioProvider implements PortfolioProvider {
marketValue: parseFloat(position.market_value),
costBasis: parseFloat(position.cost_basis),
pricePerShare: parseFloat(position.avg_entry_price)
}
};
})
};
});

View File

@ -17,14 +17,14 @@ export class AlpacaQuoteProvider implements QuoteProvider {
*/
readonly fetchQuote = (symbol: string): Promise<Quote> => {
return this.alpaca.getLatestQuote(symbol).then((quote) => {
return new Quote(
quote.Symbol,
quote.AskPrice,
quote.AskSize,
quote.BidPrice,
quote.BidSize,
new Date(Date.parse(quote.Timestamp))
);
return {
symbol: quote.Symbol,
askPrice: quote.AskPrice,
askSize: quote.AskSize,
bidPrice: quote.BidPrice,
bidSize: quote.BidSize,
timestamp: new Date(Date.parse(quote.Timestamp))
};
}).catch((err) => {
return err;
});

View File

@ -2,6 +2,7 @@
* Represents a financial position in a portfolio.
*/
export interface Position {
/**
* The symbol name of the asset
*/
@ -32,6 +33,7 @@ export interface Position {
* Represents a portfolio of financial positions.
*/
export interface Portfolio {
/**
* An array of positions held in the portfolio.
*/

View File

@ -1,22 +1,37 @@
/**
* Represents a stock quote.
*/
export class Quote {
readonly symbol: string;
readonly askPrice: number;
readonly askSize: number;
readonly bidPrice: number;
readonly bidSize: number;
readonly timeStamp: Date;
export interface Quote {
constructor(symbol: string, askPrice: number, askSize: number, bidPrice: number, bidSize: number, timeStamp: Date) {
this.symbol = symbol;
this.askPrice = askPrice;
this.askSize = askSize;
this.bidPrice = bidPrice;
this.bidSize = bidSize;
this.timeStamp = timeStamp;
}
/**
* The symbol of the asset
*/
readonly symbol: string;
/**
* The ask price of the asset
*/
readonly askPrice: number;
/**
* The ask size of the asset
*/
readonly askSize: number;
/**
* The bid price of the asset
*/
readonly bidPrice: number;
/**
* The bid size of the asset
*/
readonly bidSize: number;
/**
* The timestamp of the quote
*/
readonly timeStamp: Date;
}
/**