Resolve "Create universal interface for exchange data" #22
16
src/index.ts
16
src/index.ts
@ -1,9 +1,23 @@
|
|||||||
import { PortfolioProvider } from "./interface/portfolio";
|
import { PortfolioProvider } from "./interface/portfolio";
|
||||||
import { QuoteProvider } from "./interface/quote";
|
import { QuoteProvider } from "./interface/quote";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an exchange, which provides access to a portfolio provider and a quote provider.
|
||||||
|
*/
|
||||||
export interface Exchange {
|
export interface Exchange {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The portfolio provider for the exchange.
|
||||||
|
*/
|
||||||
readonly portfolioProvider: PortfolioProvider;
|
readonly portfolioProvider: PortfolioProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The quote provider for the exchange.
|
||||||
|
*/
|
||||||
readonly quoteProvider: QuoteProvider;
|
readonly quoteProvider: QuoteProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the exchange.
|
||||||
|
*/
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* Represents a financial position in a portfolio.
|
||||||
|
*/
|
||||||
export class Position {
|
export class Position {
|
||||||
|
/**
|
||||||
|
* The price of the last trade made for this position.
|
||||||
|
*/
|
||||||
readonly lastTrade: number;
|
readonly lastTrade: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date and time of the last trade made for this position.
|
||||||
|
*/
|
||||||
readonly lastTradeTime: Date;
|
readonly lastTradeTime: Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The change in the position value.
|
||||||
|
*/
|
||||||
readonly change: number;
|
readonly change: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The percentage change in the position value.
|
||||||
|
*/
|
||||||
readonly changePercent: number;
|
readonly changePercent: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The earnings per share of the position.
|
||||||
|
*/
|
||||||
readonly earningsPerShare: number;
|
readonly earningsPerShare: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The market capitalization of the position.
|
||||||
|
*/
|
||||||
readonly marketCap: number;
|
readonly marketCap: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The symbol of the position.
|
||||||
|
*/
|
||||||
readonly symbol: string;
|
readonly symbol: string;
|
||||||
|
|
||||||
constructor(lastTrade: number, lastTradeTime: Date, change: number, changePercent: number, earningsPerShare: number, marketCap: number, symbol: string) {
|
/**
|
||||||
|
* Represents a position in a portfolio.
|
||||||
|
* @constructor
|
||||||
|
* @param {number} lastTrade - The price of the last trade made for this position.
|
||||||
|
* @param {Date} lastTradeTime - The date and time of the last trade made for this position.
|
||||||
|
* @param {number} change - The change in the position value.
|
||||||
|
* @param {number} changePercent - The percentage change in the position value.
|
||||||
|
* @param {number} earningsPerShare - The earnings per share of the position.
|
||||||
|
* @param {number} marketCap - The market capitalization of the position.
|
||||||
|
* @param {string} symbol - The symbol of the position.
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
lastTrade: number,
|
||||||
|
lastTradeTime: Date,
|
||||||
|
change: number,
|
||||||
|
changePercent: number,
|
||||||
|
earningsPerShare: number,
|
||||||
|
marketCap: number,
|
||||||
|
symbol: string
|
||||||
|
) {
|
||||||
this.lastTrade = lastTrade;
|
this.lastTrade = lastTrade;
|
||||||
this.lastTradeTime = lastTradeTime;
|
this.lastTradeTime = lastTradeTime;
|
||||||
this.change = change;
|
this.change = change;
|
||||||
@ -22,14 +67,33 @@ export class Position {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a portfolio of financial positions.
|
||||||
|
*/
|
||||||
export class Portfolio {
|
export class Portfolio {
|
||||||
|
/**
|
||||||
|
* An array of positions held in the portfolio.
|
||||||
|
*/
|
||||||
readonly positions: Position[];
|
readonly positions: Position[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Portfolio instance.
|
||||||
|
* @constructor
|
||||||
|
* @param {Position[]} positions - An array of Position objects representing the positions in the portfolio.
|
||||||
|
*/
|
||||||
constructor(positions: Position[]) {
|
constructor(positions: Position[]) {
|
||||||
this.positions = positions;
|
this.positions = positions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A provider for fetching a portfolio.
|
||||||
|
*/
|
||||||
export interface PortfolioProvider {
|
export interface PortfolioProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the portfolio.
|
||||||
|
* @returns A promise that resolves with the fetched portfolio.
|
||||||
|
*/
|
||||||
readonly fetchPortfolio: () => Promise<Portfolio>;
|
readonly fetchPortfolio: () => Promise<Portfolio>;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* Represents a stock quote.
|
||||||
|
*/
|
||||||
export class Quote {
|
export class Quote {
|
||||||
|
/**
|
||||||
|
* The name of the company associated with this quote.
|
||||||
|
*/
|
||||||
readonly companyName: string;
|
readonly companyName: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The earnings per share of a company.
|
||||||
|
*/
|
||||||
readonly earningsPerShare: number;
|
readonly earningsPerShare: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The estimated earnings for a stock.
|
||||||
|
*/
|
||||||
readonly estimatedEarnings: number;
|
readonly estimatedEarnings: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The price of the last trade for the security.
|
||||||
|
*/
|
||||||
readonly lastTrade: number;
|
readonly lastTrade: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The symbol of the financial instrument being quoted.
|
||||||
|
*/
|
||||||
readonly symbol: string;
|
readonly symbol: string;
|
||||||
|
|
||||||
constructor(companyName: string, earningsPerShare: number, estimatedEarnings: number, lastTrade: number, symbol: string) {
|
/**
|
||||||
|
* Represents a quote for a particular stock.
|
||||||
|
* @constructor
|
||||||
|
* @param {string} companyName - The name of the company associated with the stock.
|
||||||
|
* @param {number} earningsPerShare - The earnings per share for the stock.
|
||||||
|
* @param {number} estimatedEarnings - The estimated earnings for the stock.
|
||||||
|
* @param {number} lastTrade - The last trade price for the stock.
|
||||||
|
* @param {string} symbol - The symbol for the stock.
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
companyName: string,
|
||||||
|
earningsPerShare: number,
|
||||||
|
estimatedEarnings: number,
|
||||||
|
lastTrade: number,
|
||||||
|
symbol: string
|
||||||
|
) {
|
||||||
this.companyName = companyName;
|
this.companyName = companyName;
|
||||||
this.earningsPerShare = earningsPerShare;
|
this.earningsPerShare = earningsPerShare;
|
||||||
this.estimatedEarnings = estimatedEarnings;
|
this.estimatedEarnings = estimatedEarnings;
|
||||||
@ -17,6 +51,15 @@ export class Quote {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A provider for fetching stock quotes.
|
||||||
|
*/
|
||||||
export interface QuoteProvider {
|
export interface QuoteProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches a quote for the given stock symbol.
|
||||||
|
* @param symbol The stock symbol to fetch the quote for.
|
||||||
|
* @returns A Promise that resolves to a Quote object.
|
||||||
|
*/
|
||||||
readonly fetchQuote: (symbol: string) => Promise<Quote>;
|
readonly fetchQuote: (symbol: string) => Promise<Quote>;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user