Resolve "Add support for account action history" #30

Merged
clbertolini merged 7 commits from 13-add-support-for-account-action-history into main 2023-10-27 20:43:34 +00:00
5 changed files with 146 additions and 13 deletions

View File

@ -69,7 +69,8 @@ module.exports = {
"no-return-assign": "error", "no-return-assign": "error",
"no-script-url": "error", "no-script-url": "error",
"no-sequences": "error", "no-sequences": "error",
"no-shadow": "error", "no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
"no-throw-literal": "error", "no-throw-literal": "error",
"no-undef-init": "error", "no-undef-init": "error",
"no-undefined": "error", "no-undefined": "error",

View File

@ -4,6 +4,7 @@ import { AlpacaQuoteProvider } from './quote';
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';
import { ActionProvider } from '../interface/actions';
/** /**
* Exchange implementation for Alpaca. * Exchange implementation for Alpaca.
@ -24,6 +25,11 @@ export class AlpacaExchange implements Exchange {
*/ */
readonly quoteProvider: QuoteProvider; readonly quoteProvider: QuoteProvider;
/**
* The action provider for the exchange.
*/
readonly actionProvider: ActionProvider;
/** /**
* The name of the exchange. * The name of the exchange.
*/ */
@ -45,6 +51,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.name = 'Alpaca'; this.name = 'Alpaca';
} }

View File

@ -1,12 +1,4 @@
import { Exchange } from "./interface/exchange"; export * from './interface/exchange';
import { Position, Portfolio, PortfolioProvider } from "./interface/portfolio"; export * from './interface/portfolio';
import { Quote, QuoteProvider } from "./interface/quote"; export * from './interface/quote';
export * from './interface/actions';
export {
Exchange,
Position,
Portfolio,
PortfolioProvider,
Quote,
QuoteProvider
};

127
src/interface/actions.ts Normal file
View File

@ -0,0 +1,127 @@
/**
* Enum representing the possible sides of an action.
*/
export const enum ActionSide {
Buy,
Sell,
}
/**
* Represents an action taken on a stock, such as a buy or sell order.
*/
export class Action {
/**
* The symbol of the asset being traded.
*/
readonly symbol: string;
/**
* The quantity of the asset being traded.
*/
readonly quantity: number;
/**
* The side of the action, either "buy" or "sell".
*/
readonly side: ActionSide;
/**
* The price per share of the asset.
*/
readonly pricePerShare: number;
/**
* Represents a user Action.
* @constructor
* @param {string} symbol - The symbol of the asset being traded.
* @param {number} quantity - The quantity of the asset being traded.
* @param {ActionSide} side - The side of the trade (buy or sell).
* @param {number} pricePerShare - The price per share of the asset being traded.
*/
constructor(symbol: string, quantity: number, side: ActionSide, pricePerShare: number) {
this.symbol = symbol;
this.quantity = quantity;
this.side = side;
this.pricePerShare = pricePerShare;
}
}
/**
* Enum representing the type of date filter used in an action fetch.
* @enum {number}
*/
export const enum ActionDateType {
On,
After,
Before,
}
/**
* Represents options for a date filter in an action fetch.
*/
export class ActionDateOptions {
/**
* The date to filter on.
*/
readonly date: Date;
/**
* The type of date filter to use.
*/
readonly dateType: ActionDateType;
/**
* Creates a new ActionDateOptions instance.
* @param date The date to filter on.
* @param dateType The type of date filter to use.
*/
constructor(date: Date, dateType: ActionDateType) {
this.date = date;
this.dateType = dateType;
}
}
/**
* Represents the options for fetching actions.
*/
export class ActionFetchOptions {
/**
* The number of items to fetch per page.
*/
readonly pageSize?: number;
/**
* The date options for filtering actions.
*/
readonly dateOptions?: ActionDateOptions;
}
/**
* Represents the response of a fetch action request.
*/
export interface ActionFetchResponse {
/**
* An array of `Action` objects.
*/
readonly actions: Action[];
/**
* A function that fetches the next page of actions, if available.
* Returns a promise that resolves to an `ActionFetchResponse` object.
*/
readonly fetchNextPage?: () => Promise<ActionFetchResponse>;
}
/**
* An interface representing an object that provides actions.
*/
export interface ActionProvider {
/**
* Fetches actions based on the provided options.
* @param options - The options to use when fetching actions.
* @returns A promise that resolves to an object containing the fetched actions.
*/
readonly fetchActions: (options: ActionFetchOptions) => Promise<ActionFetchResponse>;
}

View File

@ -1,5 +1,6 @@
import { PortfolioProvider } from "./portfolio"; import { PortfolioProvider } from "./portfolio";
import { QuoteProvider } from "./quote"; import { QuoteProvider } from "./quote";
import { ActionProvider } from "./actions";
/** /**
* Represents an exchange, which provides access to a portfolio provider and a quote provider. * Represents an exchange, which provides access to a portfolio provider and a quote provider.
@ -16,6 +17,11 @@ export interface Exchange {
*/ */
readonly quoteProvider: QuoteProvider; readonly quoteProvider: QuoteProvider;
/**
* The action provider for the exchange.
*/
readonly actionProvider: ActionProvider;
/** /**
* The name of the exchange. * The name of the exchange.
*/ */