Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f2e425e
chore: add ohlcv websocket
sahar-fehri May 5, 2026
42bfec7
chore: lint
sahar-fehri May 5, 2026
ab85cc5
chore: lint
sahar-fehri May 5, 2026
bd0d4d2
chore: changelog
sahar-fehri May 5, 2026
4a8a3cf
fix: re-organize code
sahar-fehri May 11, 2026
01237ea
fix: lint
sahar-fehri May 11, 2026
3569042
Merge branch 'main' into chore/add-ohlcv-websocket
sahar-fehri May 11, 2026
8324143
fix: fix messenger actions
sahar-fehri May 11, 2026
9f2e1de
fix: lint
sahar-fehri May 11, 2026
181ae75
fix: unit tests
sahar-fehri May 11, 2026
f3d53de
Merge branch 'main' into chore/add-ohlcv-websocket
sahar-fehri May 11, 2026
5b1b3c4
fix: lint
sahar-fehri May 11, 2026
1f601d6
fix: cleanup
sahar-fehri May 11, 2026
510d33d
fix: add debug logs
sahar-fehri May 11, 2026
c064480
fix: add grace period flush logic and log cleanup
sahar-fehri May 11, 2026
094d56f
fix: lint
sahar-fehri May 11, 2026
dbcc5ba
fix: handle rejection
sahar-fehri May 12, 2026
9676545
fix: do not resubscribe channels in grace period
sahar-fehri May 12, 2026
b806268
fix: add channel lock logic to handle concurrent sub/unsub
sahar-fehri May 12, 2026
c7e5841
fix: jsdoc
sahar-fehri May 12, 2026
bb01736
fix: add channel lock for performunsub
sahar-fehri May 12, 2026
6a86401
fix: fix unsub condition
sahar-fehri May 12, 2026
5b75ca1
fix: use mutex for ohlcv lock
sahar-fehri May 12, 2026
e365bff
Merge branch 'main' into chore/add-ohlcv-websocket
sahar-fehri May 12, 2026
f098394
fix: lint
sahar-fehri May 12, 2026
68f5cc7
fix: add mutex on concurrent resubscrible
sahar-fehri May 12, 2026
01e0180
fix: resubscribe after disconnect
sahar-fehri May 12, 2026
337abd9
fix: lint
sahar-fehri May 12, 2026
150787a
fix: fix refCount pump in subscribe
sahar-fehri May 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))

### Changed

- Bump `@metamask/accounts-controller` from `^38.1.0` to `^38.1.1` ([#8774](https://github.com/MetaMask/core/pull/8774))
Expand Down
1 change: 1 addition & 0 deletions packages/core-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@metamask/profile-sync-controller": "^28.0.2",
"@metamask/utils": "^11.9.0",
"@tanstack/query-core": "^5.62.16",
"async-mutex": "^0.5.0",
"uuid": "^8.3.2"
},
"devDependencies": {
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
Comment thread
Prithpal-Sooriya marked this conversation as resolved.
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
Comment thread
Prithpal-Sooriya marked this conversation as resolved.
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,40 @@
/**
* 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.
* @returns A promise that resolves once the subscription is established.
*/
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.
* @returns A promise that resolves once the unsubscription is processed.
*/
export type OHLCVServiceUnsubscribeAction = {
type: `OHLCVService:unsubscribe`;
handler: OHLCVService['unsubscribe'];
};

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