Resolve "Use interfaces instead of classes where possible" #32
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
|
@ -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;
|
||||
});
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user