@cranberry-money/shared-services 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/services/instruments/constants.d.ts +38 -0
  5. package/dist/services/instruments/constants.d.ts.map +1 -0
  6. package/dist/services/instruments/constants.js +36 -0
  7. package/dist/services/instruments/index.d.ts +5 -0
  8. package/dist/services/instruments/index.d.ts.map +1 -0
  9. package/dist/services/instruments/index.js +6 -0
  10. package/dist/services/instruments/service.d.ts +54 -0
  11. package/dist/services/instruments/service.d.ts.map +1 -0
  12. package/dist/services/instruments/service.js +106 -0
  13. package/dist/services/instruments/types.d.ts +83 -0
  14. package/dist/services/instruments/types.d.ts.map +1 -0
  15. package/dist/services/instruments/types.js +1 -0
  16. package/dist/services/instruments/utils.d.ts +50 -0
  17. package/dist/services/instruments/utils.d.ts.map +1 -0
  18. package/dist/services/instruments/utils.js +111 -0
  19. package/dist/services/portfolio_templates/constants.d.ts +8 -0
  20. package/dist/services/portfolio_templates/constants.d.ts.map +1 -0
  21. package/dist/services/portfolio_templates/constants.js +8 -0
  22. package/dist/services/portfolio_templates/index.d.ts +5 -0
  23. package/dist/services/portfolio_templates/index.d.ts.map +1 -0
  24. package/dist/services/portfolio_templates/index.js +5 -0
  25. package/dist/services/portfolio_templates/service.d.ts +6 -0
  26. package/dist/services/portfolio_templates/service.d.ts.map +1 -0
  27. package/dist/services/portfolio_templates/service.js +14 -0
  28. package/dist/services/portfolio_templates/types.d.ts +49 -0
  29. package/dist/services/portfolio_templates/types.d.ts.map +1 -0
  30. package/dist/services/portfolio_templates/types.js +1 -0
  31. package/dist/services/portfolio_templates/utils.d.ts +8 -0
  32. package/dist/services/portfolio_templates/utils.d.ts.map +1 -0
  33. package/dist/services/portfolio_templates/utils.js +13 -0
  34. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -15,7 +15,9 @@ export * from './services/PortfolioService';
15
15
  export * as AccountsService from './services/accounts';
16
16
  export * as AuthService from './services/auth';
17
17
  export * as CashAccountsService from './services/cash_accounts';
18
+ export * as InstrumentsService from './services/instruments';
18
19
  export * as PortfoliosService from './services/portfolios';
20
+ export * as PortfolioTemplatesService from './services/portfolio_templates';
19
21
  export * as UsersService from './services/users';
20
22
  export * as TradesService from './services/trades';
21
23
  export * as WithdrawalsService from './services/withdrawals';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAG3C,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAGrB,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAG5C,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,WAAW,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,iBAAiB,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,kBAAkB,MAAM,wBAAwB,CAAC;AAG7D,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAG3C,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAGrB,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAG5C,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,WAAW,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,kBAAkB,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,iBAAiB,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,yBAAyB,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,kBAAkB,MAAM,wBAAwB,CAAC;AAG7D,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -19,7 +19,9 @@ export * from './services/PortfolioService';
19
19
  export * as AccountsService from './services/accounts';
20
20
  export * as AuthService from './services/auth';
21
21
  export * as CashAccountsService from './services/cash_accounts';
22
+ export * as InstrumentsService from './services/instruments';
22
23
  export * as PortfoliosService from './services/portfolios';
24
+ export * as PortfolioTemplatesService from './services/portfolio_templates';
23
25
  export * as UsersService from './services/users';
24
26
  export * as TradesService from './services/trades';
25
27
  export * as WithdrawalsService from './services/withdrawals';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Instruments-related constants for the instruments domain
3
+ */
4
+ export declare const API_ENDPOINTS: {
5
+ readonly INSTRUMENTS: "/api/instruments/";
6
+ };
7
+ export declare const INSTRUMENT_TYPE_ETF = "etf";
8
+ export declare const INSTRUMENT_TYPE_FUND = "fund";
9
+ export declare const INSTRUMENT_TYPE_STOCK = "stock";
10
+ export type InstrumentType = typeof INSTRUMENT_TYPE_ETF | typeof INSTRUMENT_TYPE_FUND | typeof INSTRUMENT_TYPE_STOCK;
11
+ export declare const INSTRUMENT_TYPE_LABELS: {
12
+ readonly etf: "ETF";
13
+ readonly fund: "Fund";
14
+ readonly stock: "Stock";
15
+ };
16
+ export declare const INSTRUMENT_TYPE_OPTIONS: readonly [{
17
+ readonly value: "etf";
18
+ readonly label: "ETF";
19
+ }, {
20
+ readonly value: "fund";
21
+ readonly label: "Fund";
22
+ }, {
23
+ readonly value: "stock";
24
+ readonly label: "Stock";
25
+ }];
26
+ export declare const INSTRUMENT_STATUS_ACTIVE = "active";
27
+ export declare const INSTRUMENT_STATUS_INACTIVE = "inactive";
28
+ export declare const INSTRUMENT_STATUS_SUSPENDED = "suspended";
29
+ export type InstrumentStatus = typeof INSTRUMENT_STATUS_ACTIVE | typeof INSTRUMENT_STATUS_INACTIVE | typeof INSTRUMENT_STATUS_SUSPENDED;
30
+ export declare const TRADING_STATUS_TRADING = "trading";
31
+ export declare const TRADING_STATUS_HALTED = "halted";
32
+ export declare const TRADING_STATUS_SUSPENDED = "suspended";
33
+ export type TradingStatus = typeof TRADING_STATUS_TRADING | typeof TRADING_STATUS_HALTED | typeof TRADING_STATUS_SUSPENDED;
34
+ export declare const CURRENCY_USD = "USD";
35
+ export declare const CURRENCY_AUD = "AUD";
36
+ export declare const CURRENCY_EUR = "EUR";
37
+ export declare const CURRENCY_GBP = "GBP";
38
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/services/instruments/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,aAAa;;CAEhB,CAAC;AAGX,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AACzC,eAAO,MAAM,oBAAoB,SAAS,CAAC;AAC3C,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG,OAAO,mBAAmB,GAAG,OAAO,oBAAoB,GAAG,OAAO,qBAAqB,CAAC;AAGrH,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAC;AAGX,eAAO,MAAM,uBAAuB;;;;;;;;;EAI1B,CAAC;AAGX,eAAO,MAAM,wBAAwB,WAAW,CAAC;AACjD,eAAO,MAAM,0BAA0B,aAAa,CAAC;AACrD,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD,MAAM,MAAM,gBAAgB,GACxB,OAAO,wBAAwB,GAC/B,OAAO,0BAA0B,GACjC,OAAO,2BAA2B,CAAC;AAGvC,eAAO,MAAM,sBAAsB,YAAY,CAAC;AAChD,eAAO,MAAM,qBAAqB,WAAW,CAAC;AAC9C,eAAO,MAAM,wBAAwB,cAAc,CAAC;AAEpD,MAAM,MAAM,aAAa,GACrB,OAAO,sBAAsB,GAC7B,OAAO,qBAAqB,GAC5B,OAAO,wBAAwB,CAAC;AAGpC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,YAAY,QAAQ,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Instruments-related constants for the instruments domain
3
+ */
4
+ // API endpoints for instruments
5
+ export const API_ENDPOINTS = {
6
+ INSTRUMENTS: '/api/instruments/',
7
+ };
8
+ // Instrument type constants
9
+ export const INSTRUMENT_TYPE_ETF = 'etf';
10
+ export const INSTRUMENT_TYPE_FUND = 'fund';
11
+ export const INSTRUMENT_TYPE_STOCK = 'stock';
12
+ // Instrument type labels for display
13
+ export const INSTRUMENT_TYPE_LABELS = {
14
+ [INSTRUMENT_TYPE_ETF]: 'ETF',
15
+ [INSTRUMENT_TYPE_FUND]: 'Fund',
16
+ [INSTRUMENT_TYPE_STOCK]: 'Stock',
17
+ };
18
+ // Instrument type options for dropdowns/forms
19
+ export const INSTRUMENT_TYPE_OPTIONS = [
20
+ { value: INSTRUMENT_TYPE_ETF, label: 'ETF' },
21
+ { value: INSTRUMENT_TYPE_FUND, label: 'Fund' },
22
+ { value: INSTRUMENT_TYPE_STOCK, label: 'Stock' },
23
+ ];
24
+ // Instrument status constants
25
+ export const INSTRUMENT_STATUS_ACTIVE = 'active';
26
+ export const INSTRUMENT_STATUS_INACTIVE = 'inactive';
27
+ export const INSTRUMENT_STATUS_SUSPENDED = 'suspended';
28
+ // Trading status constants
29
+ export const TRADING_STATUS_TRADING = 'trading';
30
+ export const TRADING_STATUS_HALTED = 'halted';
31
+ export const TRADING_STATUS_SUSPENDED = 'suspended';
32
+ // Currency constants commonly used with instruments
33
+ export const CURRENCY_USD = 'USD';
34
+ export const CURRENCY_AUD = 'AUD';
35
+ export const CURRENCY_EUR = 'EUR';
36
+ export const CURRENCY_GBP = 'GBP';
@@ -0,0 +1,5 @@
1
+ export type { Instrument, InstrumentSnapshot, InstrumentReference, MarketData, InstrumentsQueryParams, PaginatedInstruments, InstrumentType, InstrumentStatus, TradingStatus, } from './types';
2
+ export { getInstruments, getInstrumentByUuid, getInstrumentSnapshots, getInstrumentSnapshotsFiltered, getBatchInstrumentSnapshots, searchInstruments, getInstrumentsByExchange, getETFs, getFunds, } from './service';
3
+ export { formatInstrumentPrice, getCurrencySymbol, getInstrumentType, formatInstrumentName, calculatePriceChange, formatPriceChange, isInstrumentTradeable, formatMarketCap, formatVolume, hasMarketData, } from './utils';
4
+ export { API_ENDPOINTS, INSTRUMENT_TYPE_ETF, INSTRUMENT_TYPE_FUND, INSTRUMENT_TYPE_STOCK, INSTRUMENT_TYPE_LABELS, INSTRUMENT_TYPE_OPTIONS, INSTRUMENT_STATUS_ACTIVE, INSTRUMENT_STATUS_INACTIVE, INSTRUMENT_STATUS_SUSPENDED, TRADING_STATUS_TRADING, TRADING_STATUS_HALTED, TRADING_STATUS_SUSPENDED, CURRENCY_USD, CURRENCY_AUD, CURRENCY_EUR, CURRENCY_GBP, } from './constants';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/instruments/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,8BAA8B,EAC9B,2BAA2B,EAC3B,iBAAiB,EACjB,wBAAwB,EACxB,OAAO,EACP,QAAQ,GACT,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ // Export service functions
2
+ export { getInstruments, getInstrumentByUuid, getInstrumentSnapshots, getInstrumentSnapshotsFiltered, getBatchInstrumentSnapshots, searchInstruments, getInstrumentsByExchange, getETFs, getFunds, } from './service';
3
+ // Export utility functions
4
+ export { formatInstrumentPrice, getCurrencySymbol, getInstrumentType, formatInstrumentName, calculatePriceChange, formatPriceChange, isInstrumentTradeable, formatMarketCap, formatVolume, hasMarketData, } from './utils';
5
+ // Export constants
6
+ export { API_ENDPOINTS, INSTRUMENT_TYPE_ETF, INSTRUMENT_TYPE_FUND, INSTRUMENT_TYPE_STOCK, INSTRUMENT_TYPE_LABELS, INSTRUMENT_TYPE_OPTIONS, INSTRUMENT_STATUS_ACTIVE, INSTRUMENT_STATUS_INACTIVE, INSTRUMENT_STATUS_SUSPENDED, TRADING_STATUS_TRADING, TRADING_STATUS_HALTED, TRADING_STATUS_SUSPENDED, CURRENCY_USD, CURRENCY_AUD, CURRENCY_EUR, CURRENCY_GBP, } from './constants';
@@ -0,0 +1,54 @@
1
+ import type { Instrument, InstrumentSnapshot, InstrumentsQueryParams, PaginatedInstruments } from './types';
2
+ /**
3
+ * Fetch list of instruments with optional filtering
4
+ */
5
+ export declare const getInstruments: (params?: InstrumentsQueryParams) => Promise<import("axios").AxiosResponse<PaginatedInstruments, any>>;
6
+ /**
7
+ * Get instrument details by UUID
8
+ */
9
+ export declare const getInstrumentByUuid: (uuid: string) => Promise<import("axios").AxiosResponse<Instrument, any>>;
10
+ /**
11
+ * Get instrument historical data/snapshots
12
+ */
13
+ export declare const getInstrumentSnapshots: (instrumentUuid: string) => Promise<import("axios").AxiosResponse<InstrumentSnapshot[], any>>;
14
+ /**
15
+ * Get instrument historical data/snapshots with date filtering
16
+ */
17
+ export declare const getInstrumentSnapshotsFiltered: (instrumentUuid: string, params?: {
18
+ start_date?: string;
19
+ end_date?: string;
20
+ min_price?: number;
21
+ max_price?: number;
22
+ }) => Promise<import("axios").AxiosResponse<InstrumentSnapshot[], any>>;
23
+ /**
24
+ * Batch fetch snapshots for multiple instruments with date filtering
25
+ * This optimizes API calls by using Promise.all with proper error handling
26
+ */
27
+ export declare const getBatchInstrumentSnapshots: (requests: Array<{
28
+ instrumentUuid: string;
29
+ start_date?: string;
30
+ end_date?: string;
31
+ min_price?: number;
32
+ max_price?: number;
33
+ }>) => Promise<Array<{
34
+ instrumentUuid: string;
35
+ data?: InstrumentSnapshot[];
36
+ error?: string;
37
+ }>>;
38
+ /**
39
+ * Search instruments by symbol or name
40
+ */
41
+ export declare const searchInstruments: (searchTerm: string, params?: Omit<InstrumentsQueryParams, "search">) => Promise<import("axios").AxiosResponse<PaginatedInstruments, any>>;
42
+ /**
43
+ * Get instruments by exchange
44
+ */
45
+ export declare const getInstrumentsByExchange: (exchangeUuid: string, params?: Omit<InstrumentsQueryParams, "exchange_uuid">) => Promise<import("axios").AxiosResponse<PaginatedInstruments, any>>;
46
+ /**
47
+ * Get ETFs only
48
+ */
49
+ export declare const getETFs: (params?: Omit<InstrumentsQueryParams, "is_etf">) => Promise<import("axios").AxiosResponse<PaginatedInstruments, any>>;
50
+ /**
51
+ * Get mutual funds only
52
+ */
53
+ export declare const getFunds: (params?: Omit<InstrumentsQueryParams, "is_fund">) => Promise<import("axios").AxiosResponse<PaginatedInstruments, any>>;
54
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/services/instruments/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAG5G;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,sBAAsB,sEAwB7D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,4DAE/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,gBAAgB,MAAM,sEAE5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,GACzC,gBAAgB,MAAM,EACtB,SAAS;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,sEAKF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GACtC,UAAU,KAAK,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,KACD,OAAO,CACR,KAAK,CAAC;IACJ,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAmBH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,EAAE,SAAS,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,sEAKpG,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACnC,cAAc,MAAM,EACpB,SAAS,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAC,sEAMvD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,SAAS,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,sEAKtE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,SAAS,IAAI,CAAC,sBAAsB,EAAE,SAAS,CAAC,sEAKxE,CAAC"}
@@ -0,0 +1,106 @@
1
+ import { webApiClient } from '../../api/apiClient';
2
+ import { API_ENDPOINTS } from './constants';
3
+ /**
4
+ * Fetch list of instruments with optional filtering
5
+ */
6
+ export const getInstruments = (params) => {
7
+ // Transform parameters for the API
8
+ const transformedParams = { ...params };
9
+ // Handle boolean values
10
+ if (params?.is_etf !== undefined) {
11
+ transformedParams.is_etf = params.is_etf;
12
+ }
13
+ if (params?.is_fund !== undefined) {
14
+ transformedParams.is_fund = params.is_fund;
15
+ }
16
+ // Handle price parameters - convert to strings for API
17
+ const apiParams = { ...transformedParams };
18
+ if (params?.min_price !== undefined) {
19
+ apiParams.min_price = params.min_price.toString();
20
+ }
21
+ if (params?.max_price !== undefined) {
22
+ apiParams.max_price = params.max_price.toString();
23
+ }
24
+ return webApiClient.get(API_ENDPOINTS.INSTRUMENTS, {
25
+ params: apiParams,
26
+ });
27
+ };
28
+ /**
29
+ * Get instrument details by UUID
30
+ */
31
+ export const getInstrumentByUuid = (uuid) => {
32
+ return webApiClient.get(`${API_ENDPOINTS.INSTRUMENTS}${uuid}/`);
33
+ };
34
+ /**
35
+ * Get instrument historical data/snapshots
36
+ */
37
+ export const getInstrumentSnapshots = (instrumentUuid) => {
38
+ return webApiClient.get(`${API_ENDPOINTS.INSTRUMENTS}${instrumentUuid}/snapshots/`);
39
+ };
40
+ /**
41
+ * Get instrument historical data/snapshots with date filtering
42
+ */
43
+ export const getInstrumentSnapshotsFiltered = (instrumentUuid, params) => {
44
+ return webApiClient.get(`${API_ENDPOINTS.INSTRUMENTS}${instrumentUuid}/snapshots/`, {
45
+ params,
46
+ });
47
+ };
48
+ /**
49
+ * Batch fetch snapshots for multiple instruments with date filtering
50
+ * This optimizes API calls by using Promise.all with proper error handling
51
+ */
52
+ export const getBatchInstrumentSnapshots = async (requests) => {
53
+ const promises = requests.map(async ({ instrumentUuid, ...params }) => {
54
+ try {
55
+ const response = await getInstrumentSnapshotsFiltered(instrumentUuid, params);
56
+ return {
57
+ instrumentUuid,
58
+ data: response.data,
59
+ };
60
+ }
61
+ catch (error) {
62
+ console.error(`Failed to fetch snapshots for instrument ${instrumentUuid}:`, error);
63
+ return {
64
+ instrumentUuid,
65
+ error: error instanceof Error ? error.message : 'Failed to fetch data',
66
+ };
67
+ }
68
+ });
69
+ return Promise.all(promises);
70
+ };
71
+ /**
72
+ * Search instruments by symbol or name
73
+ */
74
+ export const searchInstruments = (searchTerm, params) => {
75
+ return getInstruments({
76
+ ...params,
77
+ search: searchTerm,
78
+ });
79
+ };
80
+ /**
81
+ * Get instruments by exchange
82
+ */
83
+ export const getInstrumentsByExchange = (exchangeUuid, params) => {
84
+ return getInstruments({
85
+ ...params,
86
+ exchange_uuid: exchangeUuid,
87
+ });
88
+ };
89
+ /**
90
+ * Get ETFs only
91
+ */
92
+ export const getETFs = (params) => {
93
+ return getInstruments({
94
+ ...params,
95
+ is_etf: true,
96
+ });
97
+ };
98
+ /**
99
+ * Get mutual funds only
100
+ */
101
+ export const getFunds = (params) => {
102
+ return getInstruments({
103
+ ...params,
104
+ is_fund: true,
105
+ });
106
+ };
@@ -0,0 +1,83 @@
1
+ import type { PaginatedResponse, PaginationParams, OrderingParams } from '../../api/types';
2
+ /**
3
+ * Core instrument entity
4
+ */
5
+ export interface Instrument {
6
+ uuid: string;
7
+ exchange: string;
8
+ exchangeName: string;
9
+ country: string;
10
+ countryName: string;
11
+ industry: string;
12
+ industryName: string;
13
+ sector: string;
14
+ sectorName: string;
15
+ symbol: string;
16
+ name: string;
17
+ currentPrice: string;
18
+ currency: string | null;
19
+ isEtf: boolean;
20
+ isFund: boolean;
21
+ isActive: boolean;
22
+ isActivelyTrading: boolean;
23
+ }
24
+ /**
25
+ * Market data for instruments
26
+ */
27
+ export interface MarketData {
28
+ pe: string | null;
29
+ eps: string | null;
30
+ volume: number;
31
+ dayLow: string | null;
32
+ dayHigh: string | null;
33
+ yearLow: string | null;
34
+ yearHigh: string | null;
35
+ avgVolume: number | null;
36
+ marketCap: string | null;
37
+ openPrice: string | null;
38
+ priceAvg50: string | null;
39
+ priceAvg200: string | null;
40
+ previousClose: string | null;
41
+ sharesOutstanding: number | null;
42
+ }
43
+ /**
44
+ * Instrument snapshot with historical price data
45
+ */
46
+ export interface InstrumentSnapshot {
47
+ uuid: string;
48
+ price: string;
49
+ change: string;
50
+ changePercent: string;
51
+ marketData: MarketData;
52
+ sourceTimestamp: string;
53
+ }
54
+ /**
55
+ * Lightweight instrument reference used in some contexts
56
+ */
57
+ export interface InstrumentReference {
58
+ uuid: string;
59
+ symbol: string;
60
+ name: string;
61
+ }
62
+ /**
63
+ * Query parameters for filtering instruments
64
+ */
65
+ export interface InstrumentsQueryParams extends PaginationParams, OrderingParams {
66
+ uuid?: string;
67
+ symbol?: string;
68
+ name?: string;
69
+ exchange_uuid?: string;
70
+ exchange_short_name?: string;
71
+ portfolio_uuid?: string;
72
+ is_etf?: boolean;
73
+ is_fund?: boolean;
74
+ sector_uuid?: string;
75
+ industry_uuid?: string;
76
+ country_uuid?: string;
77
+ min_price?: number;
78
+ max_price?: number;
79
+ search?: string;
80
+ }
81
+ export type PaginatedInstruments = PaginatedResponse<Instrument>;
82
+ export type { InstrumentType, InstrumentStatus, TradingStatus, } from './constants';
83
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/instruments/types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import type { Instrument, InstrumentSnapshot, MarketData } from './types';
2
+ /**
3
+ * Format instrument price with currency symbol
4
+ */
5
+ export declare const formatInstrumentPrice: (price: string, currency?: string | null) => string;
6
+ /**
7
+ * Get currency symbol for display
8
+ */
9
+ export declare const getCurrencySymbol: (currency?: string | null) => string;
10
+ /**
11
+ * Determine instrument type based on flags
12
+ */
13
+ export declare const getInstrumentType: (instrument: Instrument) => string;
14
+ /**
15
+ * Format instrument display name with symbol
16
+ */
17
+ export declare const formatInstrumentName: (instrument: Instrument) => string;
18
+ /**
19
+ * Calculate price change from snapshot
20
+ */
21
+ export declare const calculatePriceChange: (snapshot: InstrumentSnapshot) => {
22
+ change: number;
23
+ changePercent: number;
24
+ isPositive: boolean;
25
+ };
26
+ /**
27
+ * Format price change with appropriate color class
28
+ */
29
+ export declare const formatPriceChange: (snapshot: InstrumentSnapshot) => {
30
+ changeText: string;
31
+ changePercentText: string;
32
+ colorClass: string;
33
+ };
34
+ /**
35
+ * Check if instrument is actively tradeable
36
+ */
37
+ export declare const isInstrumentTradeable: (instrument: Instrument) => boolean;
38
+ /**
39
+ * Format market cap value
40
+ */
41
+ export declare const formatMarketCap: (marketData: MarketData) => string;
42
+ /**
43
+ * Format trading volume
44
+ */
45
+ export declare const formatVolume: (volume: number) => string;
46
+ /**
47
+ * Check if market data is available
48
+ */
49
+ export declare const hasMarketData: (marketData: MarketData) => boolean;
50
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/instruments/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAS1E;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,EAAE,WAAW,MAAM,GAAG,IAAI,KAAG,MAM/E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,GAAG,IAAI,KAAG,MAa5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,YAAY,UAAU,KAAG,MAI1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,YAAY,UAAU,KAAG,MAE7D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAC/B,UAAU,kBAAkB,KAC3B;IACD,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;CAUrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,kBAAkB,KAC3B;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CAapB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,YAAY,UAAU,KAAG,OAE9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,UAAU,KAAG,MAUxD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,MAK7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,YAAY,UAAU,KAAG,OAEtD,CAAC"}
@@ -0,0 +1,111 @@
1
+ import { INSTRUMENT_TYPE_ETF, INSTRUMENT_TYPE_FUND, INSTRUMENT_TYPE_STOCK, CURRENCY_USD, CURRENCY_AUD, } from './constants';
2
+ /**
3
+ * Format instrument price with currency symbol
4
+ */
5
+ export const formatInstrumentPrice = (price, currency) => {
6
+ const numericPrice = parseFloat(price);
7
+ if (isNaN(numericPrice))
8
+ return price;
9
+ const currencySymbol = getCurrencySymbol(currency);
10
+ return `${currencySymbol}${numericPrice.toFixed(2)}`;
11
+ };
12
+ /**
13
+ * Get currency symbol for display
14
+ */
15
+ export const getCurrencySymbol = (currency) => {
16
+ switch (currency) {
17
+ case CURRENCY_USD:
18
+ return '$';
19
+ case CURRENCY_AUD:
20
+ return 'A$';
21
+ case 'EUR':
22
+ return '€';
23
+ case 'GBP':
24
+ return '£';
25
+ default:
26
+ return '$'; // Default to USD symbol
27
+ }
28
+ };
29
+ /**
30
+ * Determine instrument type based on flags
31
+ */
32
+ export const getInstrumentType = (instrument) => {
33
+ if (instrument.isEtf)
34
+ return INSTRUMENT_TYPE_ETF;
35
+ if (instrument.isFund)
36
+ return INSTRUMENT_TYPE_FUND;
37
+ return INSTRUMENT_TYPE_STOCK;
38
+ };
39
+ /**
40
+ * Format instrument display name with symbol
41
+ */
42
+ export const formatInstrumentName = (instrument) => {
43
+ return `${instrument.symbol} - ${instrument.name}`;
44
+ };
45
+ /**
46
+ * Calculate price change from snapshot
47
+ */
48
+ export const calculatePriceChange = (snapshot) => {
49
+ const change = parseFloat(snapshot.change);
50
+ const changePercent = parseFloat(snapshot.changePercent);
51
+ return {
52
+ change,
53
+ changePercent,
54
+ isPositive: change >= 0,
55
+ };
56
+ };
57
+ /**
58
+ * Format price change with appropriate color class
59
+ */
60
+ export const formatPriceChange = (snapshot) => {
61
+ const { change, changePercent, isPositive } = calculatePriceChange(snapshot);
62
+ const changeText = `${isPositive ? '+' : ''}${change.toFixed(2)}`;
63
+ const changePercentText = `${isPositive ? '+' : ''}${changePercent.toFixed(2)}%`;
64
+ const colorClass = isPositive ? 'text-positive' : 'text-negative';
65
+ return {
66
+ changeText,
67
+ changePercentText,
68
+ colorClass,
69
+ };
70
+ };
71
+ /**
72
+ * Check if instrument is actively tradeable
73
+ */
74
+ export const isInstrumentTradeable = (instrument) => {
75
+ return instrument.isActive && instrument.isActivelyTrading;
76
+ };
77
+ /**
78
+ * Format market cap value
79
+ */
80
+ export const formatMarketCap = (marketData) => {
81
+ if (!marketData.marketCap)
82
+ return 'N/A';
83
+ const marketCap = parseFloat(marketData.marketCap);
84
+ if (isNaN(marketCap))
85
+ return 'N/A';
86
+ if (marketCap >= 1e12)
87
+ return `$${(marketCap / 1e12).toFixed(1)}T`;
88
+ if (marketCap >= 1e9)
89
+ return `$${(marketCap / 1e9).toFixed(1)}B`;
90
+ if (marketCap >= 1e6)
91
+ return `$${(marketCap / 1e6).toFixed(1)}M`;
92
+ return `$${marketCap.toFixed(0)}`;
93
+ };
94
+ /**
95
+ * Format trading volume
96
+ */
97
+ export const formatVolume = (volume) => {
98
+ if (volume >= 1e9)
99
+ return `${(volume / 1e9).toFixed(1)}B`;
100
+ if (volume >= 1e6)
101
+ return `${(volume / 1e6).toFixed(1)}M`;
102
+ if (volume >= 1e3)
103
+ return `${(volume / 1e3).toFixed(1)}K`;
104
+ return volume.toString();
105
+ };
106
+ /**
107
+ * Check if market data is available
108
+ */
109
+ export const hasMarketData = (marketData) => {
110
+ return Boolean(marketData.openPrice || marketData.dayHigh || marketData.dayLow || marketData.volume);
111
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Portfolio templates API constants
3
+ */
4
+ export declare const API_ENDPOINTS: {
5
+ readonly PORTFOLIO_TEMPLATES: "/api/portfolio-templates/";
6
+ readonly PORTFOLIO_TEMPLATES_RECOMMENDED: "/api/portfolio-templates/recommended/";
7
+ };
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,aAAa;;;CAGhB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Portfolio templates API constants
3
+ */
4
+ // API Endpoints
5
+ export const API_ENDPOINTS = {
6
+ PORTFOLIO_TEMPLATES: '/api/portfolio-templates/',
7
+ PORTFOLIO_TEMPLATES_RECOMMENDED: '/api/portfolio-templates/recommended/',
8
+ };
@@ -0,0 +1,5 @@
1
+ export * from './constants';
2
+ export * from './types';
3
+ export * from './service';
4
+ export * from './utils';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Portfolio templates domain exports
2
+ export * from './constants';
3
+ export * from './types';
4
+ export * from './service';
5
+ export * from './utils';
@@ -0,0 +1,6 @@
1
+ import type { PortfolioTemplate, TargetAssetAllocation, ApplyTemplateResponse, PaginatedPortfolioTemplates } from './types';
2
+ export declare const getPortfolioTemplates: () => Promise<import("axios").AxiosResponse<PaginatedPortfolioTemplates, any>>;
3
+ export declare const getRecommendedPortfolioTemplate: () => Promise<import("axios").AxiosResponse<PortfolioTemplate, any>>;
4
+ export declare const getPortfolioTemplateAllocations: (templateUuid: string) => Promise<import("axios").AxiosResponse<TargetAssetAllocation[], any>>;
5
+ export declare const applyPortfolioTemplate: (templateUuid: string) => Promise<import("axios").AxiosResponse<ApplyTemplateResponse, any>>;
6
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,2BAA2B,EAC5B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,qBAAqB,gFAEjC,CAAC;AAEF,eAAO,MAAM,+BAA+B,sEAE3C,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAAI,cAAc,MAAM,yEAEnE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,cAAc,MAAM,uEAE1D,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { webApiClient } from '../../api/apiClient';
2
+ import { API_ENDPOINTS } from './constants';
3
+ export const getPortfolioTemplates = () => {
4
+ return webApiClient.get(API_ENDPOINTS.PORTFOLIO_TEMPLATES);
5
+ };
6
+ export const getRecommendedPortfolioTemplate = () => {
7
+ return webApiClient.get(API_ENDPOINTS.PORTFOLIO_TEMPLATES_RECOMMENDED);
8
+ };
9
+ export const getPortfolioTemplateAllocations = (templateUuid) => {
10
+ return webApiClient.get(`${API_ENDPOINTS.PORTFOLIO_TEMPLATES}${templateUuid}/allocations/`);
11
+ };
12
+ export const applyPortfolioTemplate = (templateUuid) => {
13
+ return webApiClient.post(`${API_ENDPOINTS.PORTFOLIO_TEMPLATES}${templateUuid}/apply/`, {});
14
+ };
@@ -0,0 +1,49 @@
1
+ import type { PaginatedResponse } from '../../api/types';
2
+ export interface Instrument {
3
+ uuid: string;
4
+ symbol: string;
5
+ name: string;
6
+ instrumentType: string;
7
+ sector?: string;
8
+ stockExchange?: string;
9
+ }
10
+ export interface Portfolio {
11
+ uuid: string;
12
+ name: string;
13
+ description: string;
14
+ isActive: boolean;
15
+ createdAt?: string;
16
+ updatedAt?: string;
17
+ }
18
+ export interface PortfolioTemplate {
19
+ uuid: string;
20
+ name: string;
21
+ description: string;
22
+ isActive: boolean;
23
+ riskLevel: string;
24
+ createdAt?: string;
25
+ updatedAt?: string;
26
+ }
27
+ export interface TargetAssetAllocation {
28
+ uuid: string;
29
+ instrument: Instrument;
30
+ percentage: string;
31
+ }
32
+ export interface AssetAllocation {
33
+ instrument: {
34
+ symbol: string;
35
+ name: string;
36
+ };
37
+ percentage: string;
38
+ }
39
+ /**
40
+ * Response when applying a portfolio template
41
+ */
42
+ export interface ApplyTemplateResponse {
43
+ success: boolean;
44
+ message: string;
45
+ portfolio: Portfolio;
46
+ allocations: AssetAllocation[];
47
+ }
48
+ export type PaginatedPortfolioTemplates = PaginatedResponse<PortfolioTemplate>;
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC;AAGD,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const calculateTotalAllocation: (allocations: {
2
+ percentage: string;
3
+ }[]) => number;
4
+ export declare const validateAllocationPercentages: (allocations: {
5
+ percentage: string;
6
+ }[]) => boolean;
7
+ export declare const formatRiskLevel: (riskLevel: string) => string;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/portfolio_templates/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,wBAAwB,GAAI,aAAa;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,KAAG,MAIhF,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,aAAa;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EAAE,KAAG,OAGrF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,KAAG,MAEnD,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Portfolio template utilities and helper functions
2
+ export const calculateTotalAllocation = (allocations) => {
3
+ return allocations.reduce((total, allocation) => {
4
+ return total + parseFloat(allocation.percentage || '0');
5
+ }, 0);
6
+ };
7
+ export const validateAllocationPercentages = (allocations) => {
8
+ const total = calculateTotalAllocation(allocations);
9
+ return Math.abs(total - 100) < 0.01; // Allow for small floating point differences
10
+ };
11
+ export const formatRiskLevel = (riskLevel) => {
12
+ return riskLevel.charAt(0).toUpperCase() + riskLevel.slice(1).toLowerCase();
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cranberry-money/shared-services",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Shared API services and client for MyPortfolio platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",