Skip to content
31 changes: 21 additions & 10 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -862,34 +862,45 @@
"count": 1
}
},
"packages/core-backend/src/AccountActivityService.test.ts": {
"packages/core-backend/src/api/shared-types.ts": {
"no-restricted-syntax": {
"count": 2
"count": 1
}
},
"packages/core-backend/src/AccountActivityService.ts": {
"packages/core-backend/src/index.ts": {
"no-restricted-syntax": {
"count": 1
"count": 4
}
},
"packages/core-backend/src/BackendWebSocketService.test.ts": {
"packages/core-backend/src/ws/AccountActivityService.test.ts": {
"no-restricted-syntax": {
"count": 1
"count": 2
}
},
"packages/core-backend/src/BackendWebSocketService.ts": {
"packages/core-backend/src/ws/AccountActivityService.ts": {
"no-restricted-syntax": {
"count": 5
"count": 1
}
},
"packages/core-backend/src/api/shared-types.ts": {
"packages/core-backend/src/ws/BackendWebSocketService.test.ts": {
"no-restricted-syntax": {
"count": 1
}
},
"packages/core-backend/src/index.ts": {
"packages/core-backend/src/ws/BackendWebSocketService.ts": {
"no-restricted-syntax": {
"count": 5
}
},
"packages/core-backend/src/ws/ohlcv/OHLCVService.test.ts": {
"@typescript-eslint/naming-convention": {
"count": 2
},
"id-length": {
"count": 1
},
"no-restricted-syntax": {
"count": 1
}
},
"packages/delegation-controller/src/DelegationController.test.ts": {
Expand Down
8 changes: 8 additions & 0 deletions packages/core-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `OHLCVService` for real-time OHLCV (candlestick) data streaming via WebSocket ([#8695](https://github.com/MetaMask/core/pull/8695))
- Wraps `BackendWebSocketService` through the messenger pattern to provide subscribe/unsubscribe semantics for market-data OHLCV channels
- Includes reference counting, grace-period unsubscribe, idempotency checks, chain-status forwarding, and automatic resubscription on reconnect
- Export new types `OHLCVBar`, `OHLCVSubscriptionOptions`, `OHLCVSystemNotificationData`, `OHLCVServiceOptions`, `OHLCVServiceActions`, `OHLCVServiceAllowedActions`, `OHLCVServiceBarUpdatedEvent`, `OHLCVServiceChainStatusChangedEvent`, `OHLCVServiceSubscriptionErrorEvent`, `OHLCVServiceEvents`, `OHLCVServiceAllowedEvents`, and `OHLCVServiceMessenger` ([#8695](https://github.com/MetaMask/core/pull/8695))
- Export new constants `OHLCV_SERVICE_ALLOWED_ACTIONS` and `OHLCV_SERVICE_ALLOWED_EVENTS` for configuring the messenger ([#8695](https://github.com/MetaMask/core/pull/8695))

## [6.2.2]

### Changed
Expand Down
33 changes: 29 additions & 4 deletions packages/core-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export {
getCloseReason,
WebSocketState,
WebSocketEventType,
} from './BackendWebSocketService';
} from './ws/BackendWebSocketService';

export type {
BackendWebSocketServiceOptions,
Expand All @@ -24,7 +24,7 @@ export type {
BackendWebSocketServiceConnectionStateChangedEvent,
BackendWebSocketServiceEvents,
BackendWebSocketServiceMessenger,
} from './BackendWebSocketService';
} from './ws/BackendWebSocketService';

// ============================================================================
// ACCOUNT ACTIVITY SERVICE
Expand All @@ -34,7 +34,7 @@ export {
AccountActivityService,
ACCOUNT_ACTIVITY_SERVICE_ALLOWED_ACTIONS,
ACCOUNT_ACTIVITY_SERVICE_ALLOWED_EVENTS,
} from './AccountActivityService';
} from './ws/AccountActivityService';

export type {
SystemNotificationData,
Expand All @@ -49,7 +49,7 @@ export type {
AccountActivityServiceEvents,
AllowedEvents as AccountActivityServiceAllowedEvents,
AccountActivityServiceMessenger,
} from './AccountActivityService';
} from './ws/AccountActivityService';

// ============================================================================
// SHARED TYPES
Expand Down Expand Up @@ -80,6 +80,31 @@ export type {
ApiPlatformClientServiceMessenger,
} from './ApiPlatformClientService';

// ============================================================================
// OHLCV SERVICE
// ============================================================================

export {
OHLCVService,
OHLCV_SERVICE_ALLOWED_ACTIONS,
OHLCV_SERVICE_ALLOWED_EVENTS,
} from './ws/ohlcv';

export type {
OHLCVBar,
OHLCVSubscriptionOptions,
OHLCVSystemNotificationData,
OHLCVServiceOptions,
OHLCVServiceActions,
OHLCVServiceAllowedActions,
OHLCVServiceBarUpdatedEvent,
OHLCVServiceChainStatusChangedEvent,
OHLCVServiceSubscriptionErrorEvent,
OHLCVServiceEvents,
OHLCVServiceAllowedEvents,
OHLCVServiceMessenger,
} from './ws/ohlcv';

// ============================================================================
// API PLATFORM CLIENT
// ============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import type {
} from '@metamask/messenger';
import type { Hex } from '@metamask/utils';

import { flushPromises } from '../../../tests/helpers';
import { flushPromises } from '../../../../tests/helpers';
import type { Transaction, BalanceUpdate } from '../types';
import type { AccountActivityMessage } from '../types';
import { AccountActivityService } from './AccountActivityService';
import type {
AccountActivityServiceMessenger,
SubscriptionOptions,
} from './AccountActivityService';
import type { ServerNotificationMessage } from './BackendWebSocketService';
import { WebSocketState } from './BackendWebSocketService';
import type { Transaction, BalanceUpdate } from './types';
import type { AccountActivityMessage } from './types';

type AllAccountActivityServiceActions =
MessengerActions<AccountActivityServiceMessenger>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import type { TraceCallback } from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type { Messenger } from '@metamask/messenger';

import { projectLogger, createModuleLogger } from '../logger';
import type {
Transaction,
AccountActivityMessage,
BalanceUpdate,
} from '../types';
import type { AccountActivityServiceMethodActions } from './AccountActivityService-method-action-types';
import type {
WebSocketConnectionInfo,
Expand All @@ -21,12 +27,6 @@ import type {
} from './BackendWebSocketService';
import { WebSocketState } from './BackendWebSocketService';
import type { BackendWebSocketServiceMethodActions } from './BackendWebSocketService-method-action-types';
import { projectLogger, createModuleLogger } from './logger';
import type {
Transaction,
AccountActivityMessage,
BalanceUpdate,
} from './types';

// =============================================================================
// Types and Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
MockAnyNamespace,
} from '@metamask/messenger';

import { flushPromises } from '../../../tests/helpers';
import { flushPromises } from '../../../../tests/helpers';
import {
BackendWebSocketService,
getCloseReason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type { AuthenticationController } from '@metamask/profile-sync-controller
import { getErrorMessage } from '@metamask/utils';
import { v4 as uuidV4 } from 'uuid';

import { projectLogger, createModuleLogger } from '../logger';
import type { BackendWebSocketServiceMethodActions } from './BackendWebSocketService-method-action-types';
import { projectLogger, createModuleLogger } from './logger';

const SERVICE_NAME = 'BackendWebSocketService' as const;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* This file is auto generated.
* Do not edit manually.
*/

import type { OHLCVService } from './OHLCVService';

/**
* Subscribe to an OHLCV channel. If this is the first subscriber for the
* given asset/interval/currency combination a WebSocket subscription is
* created. Additional calls for the same combination only bump the reference
* count.
*
* @param options - The subscription parameters.
*/
export type OHLCVServiceSubscribeAction = {
type: `OHLCVService:subscribe`;
handler: OHLCVService['subscribe'];
};

/**
* Unsubscribe from an OHLCV channel. Decrements the reference count and,
* when it reaches zero, starts a grace-period timer before actually
* unsubscribing from the WebSocket to absorb rapid navigation patterns.
*
* @param options - The subscription parameters to unsubscribe from.
*/
export type OHLCVServiceUnsubscribeAction = {
type: `OHLCVService:unsubscribe`;
handler: OHLCVService['unsubscribe'];
};

/**
* Union of all OHLCVService action types.
*/
export type OHLCVServiceMethodActions =
| OHLCVServiceSubscribeAction
| OHLCVServiceUnsubscribeAction;
Loading
Loading