123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- "use strict";
- /**
- * Integration test for hedging session creation
- * Tests the complete flow of creating and managing hedging sessions
- */
- Object.defineProperty(exports, "__esModule", { value: true });
- const globals_1 = require("@jest/globals");
- const HedgingManager_1 = require("../../src/core/HedgingManager");
- const HedgingConfigManager_1 = require("../../src/core/HedgingConfigManager");
- (0, globals_1.describe)('Hedging Session Creation Integration', () => {
- let hedgingManager;
- let configManager;
- (0, globals_1.beforeAll)(async () => {
- // Initialize configuration manager
- configManager = new HedgingConfigManager_1.HedgingConfigManager({
- accounts: './config/accounts.json',
- hedging: './config/hedging-config.json',
- marketData: './config/market-data-config.json'
- });
- // Initialize hedging manager
- hedgingManager = new HedgingManager_1.HedgingManager({
- accounts: './config/accounts.json',
- hedging: './config/hedging-config.json',
- marketData: './config/market-data-config.json'
- });
- await hedgingManager.initialize();
- });
- (0, globals_1.afterAll)(async () => {
- if (hedgingManager) {
- await hedgingManager.shutdown();
- }
- });
- (0, globals_1.beforeEach)(() => {
- // Clean up any existing sessions before each test
- hedgingManager.cleanup();
- });
- (0, globals_1.describe)('Session Creation Flow', () => {
- (0, globals_1.it)('should create a new hedging session with valid parameters', async () => {
- const sessionRequest = {
- name: 'Integration Test Session',
- accountIds: ['account-1', 'account-2'],
- volumeTarget: 10000,
- strategy: {
- symbol: 'ETH/USD',
- volumeDistribution: 'equal',
- priceRange: {
- min: 0.001,
- max: 0.01
- },
- timing: {
- minInterval: 30,
- maxInterval: 120,
- orderSize: {
- min: 100,
- max: 500
- }
- },
- riskLimits: {
- maxPositionSize: 0.1,
- stopLossThreshold: 0.05,
- maxSlippage: 0.02
- },
- orderTypes: {
- primary: 'limit',
- fallback: 'market'
- }
- }
- };
- try {
- const session = await hedgingManager.createSession(sessionRequest);
- (0, globals_1.expect)(session).toBeDefined();
- (0, globals_1.expect)(session.id).toBeDefined();
- (0, globals_1.expect)(session.name).toBe(sessionRequest.name);
- (0, globals_1.expect)(session.status).toBe('pending');
- (0, globals_1.expect)(session.accounts).toEqual(sessionRequest.accountIds);
- (0, globals_1.expect)(session.strategy).toEqual(sessionRequest.strategy);
- (0, globals_1.expect)(session.volumeTarget).toBe(sessionRequest.volumeTarget);
- (0, globals_1.expect)(session.volumeGenerated).toBe(0);
- (0, globals_1.expect)(session.riskBreaches).toEqual([]);
- (0, globals_1.expect)(session.orders).toEqual([]);
- (0, globals_1.expect)(session.createdAt).toBeInstanceOf(Date);
- (0, globals_1.expect)(session.updatedAt).toBeInstanceOf(Date);
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- (0, globals_1.it)('should validate account availability before creating session', async () => {
- const sessionRequest = {
- name: 'Test Session with Invalid Account',
- accountIds: ['account-1', 'non-existent-account'],
- volumeTarget: 10000,
- strategy: {
- symbol: 'ETH/USD',
- volumeDistribution: 'equal',
- priceRange: { min: 0.001, max: 0.01 },
- timing: { minInterval: 30, maxInterval: 120, orderSize: { min: 100, max: 500 } },
- riskLimits: { maxPositionSize: 0.1, stopLossThreshold: 0.05, maxSlippage: 0.02 },
- orderTypes: { primary: 'limit', fallback: 'market' }
- }
- };
- try {
- await hedgingManager.createSession(sessionRequest);
- fail('Should have rejected session with invalid account');
- }
- catch (error) {
- (0, globals_1.expect)(error.message).toContain('account');
- }
- });
- (0, globals_1.it)('should validate account balance before creating session', async () => {
- const sessionRequest = {
- name: 'Test Session with Insufficient Balance',
- accountIds: ['account-1', 'account-2'],
- volumeTarget: 1000000, // Very high volume target
- strategy: {
- symbol: 'ETH/USD',
- volumeDistribution: 'equal',
- priceRange: { min: 0.001, max: 0.01 },
- timing: { minInterval: 30, maxInterval: 120, orderSize: { min: 100, max: 500 } },
- riskLimits: { maxPositionSize: 0.1, stopLossThreshold: 0.05, maxSlippage: 0.02 },
- orderTypes: { primary: 'limit', fallback: 'market' }
- }
- };
- try {
- await hedgingManager.createSession(sessionRequest);
- fail('Should have rejected session with insufficient balance');
- }
- catch (error) {
- (0, globals_1.expect)(error.message).toContain('balance');
- }
- });
- (0, globals_1.it)('should validate strategy parameters before creating session', async () => {
- const sessionRequest = {
- name: 'Test Session with Invalid Strategy',
- accountIds: ['account-1', 'account-2'],
- volumeTarget: 10000,
- strategy: {
- symbol: 'ETH/USD',
- volumeDistribution: 'equal',
- priceRange: {
- min: 0.01,
- max: 0.001 // Invalid: min > max
- },
- timing: { minInterval: 30, maxInterval: 120, orderSize: { min: 100, max: 500 } },
- riskLimits: { maxPositionSize: 0.1, stopLossThreshold: 0.05, maxSlippage: 0.02 },
- orderTypes: { primary: 'limit', fallback: 'market' }
- }
- };
- try {
- await hedgingManager.createSession(sessionRequest);
- fail('Should have rejected session with invalid strategy');
- }
- catch (error) {
- (0, globals_1.expect)(error.message).toContain('strategy');
- }
- });
- });
- (0, globals_1.describe)('Session Management', () => {
- let testSessionId;
- (0, globals_1.beforeEach)(async () => {
- const sessionRequest = {
- name: 'Test Management Session',
- accountIds: ['account-1', 'account-2'],
- volumeTarget: 10000,
- strategy: {
- symbol: 'ETH/USD',
- volumeDistribution: 'equal',
- priceRange: { min: 0.001, max: 0.01 },
- timing: { minInterval: 30, maxInterval: 120, orderSize: { min: 100, max: 500 } },
- riskLimits: { maxPositionSize: 0.1, stopLossThreshold: 0.05, maxSlippage: 0.02 },
- orderTypes: { primary: 'limit', fallback: 'market' }
- }
- };
- try {
- const session = await hedgingManager.createSession(sessionRequest);
- testSessionId = session.id;
- }
- catch (error) {
- // Session creation will fail initially
- testSessionId = 'mock-session-id';
- }
- });
- (0, globals_1.it)('should retrieve session by ID', async () => {
- try {
- const session = await hedgingManager.getSession(testSessionId);
- (0, globals_1.expect)(session).toBeDefined();
- (0, globals_1.expect)(session.id).toBe(testSessionId);
- (0, globals_1.expect)(session.name).toBe('Test Management Session');
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- (0, globals_1.it)('should list all sessions', async () => {
- try {
- const sessions = await hedgingManager.listSessions();
- (0, globals_1.expect)(Array.isArray(sessions)).toBe(true);
- (0, globals_1.expect)(sessions.length).toBeGreaterThanOrEqual(1);
- const testSession = sessions.find(s => s.id === testSessionId);
- (0, globals_1.expect)(testSession).toBeDefined();
- (0, globals_1.expect)(testSession.name).toBe('Test Management Session');
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- (0, globals_1.it)('should filter sessions by status', async () => {
- try {
- const pendingSessions = await hedgingManager.listSessions({ status: 'pending' });
- (0, globals_1.expect)(Array.isArray(pendingSessions)).toBe(true);
- pendingSessions.forEach(session => {
- (0, globals_1.expect)(session.status).toBe('pending');
- });
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- (0, globals_1.it)('should filter sessions by account ID', async () => {
- try {
- const accountSessions = await hedgingManager.listSessions({ accountId: 'account-1' });
- (0, globals_1.expect)(Array.isArray(accountSessions)).toBe(true);
- accountSessions.forEach(session => {
- (0, globals_1.expect)(session.accounts).toContain('account-1');
- });
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- });
- (0, globals_1.describe)('Session State Transitions', () => {
- let testSessionId;
- (0, globals_1.beforeEach)(async () => {
- const sessionRequest = {
- name: 'Test State Transition Session',
- accountIds: ['account-1', 'account-2'],
- volumeTarget: 10000,
- strategy: {
- symbol: 'ETH/USD',
- volumeDistribution: 'equal',
- priceRange: { min: 0.001, max: 0.01 },
- timing: { minInterval: 30, maxInterval: 120, orderSize: { min: 100, max: 500 } },
- riskLimits: { maxPositionSize: 0.1, stopLossThreshold: 0.05, maxSlippage: 0.02 },
- orderTypes: { primary: 'limit', fallback: 'market' }
- }
- };
- try {
- const session = await hedgingManager.createSession(sessionRequest);
- testSessionId = session.id;
- }
- catch (error) {
- testSessionId = 'mock-session-id';
- }
- });
- (0, globals_1.it)('should start a pending session', async () => {
- try {
- const session = await hedgingManager.startSession(testSessionId);
- (0, globals_1.expect)(session.status).toBe('active');
- (0, globals_1.expect)(session.startTime).toBeDefined();
- (0, globals_1.expect)(session.startTime).toBeInstanceOf(Date);
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- (0, globals_1.it)('should pause an active session', async () => {
- try {
- // First start the session
- await hedgingManager.startSession(testSessionId);
- // Then pause it
- const session = await hedgingManager.pauseSession(testSessionId);
- (0, globals_1.expect)(session.status).toBe('paused');
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- (0, globals_1.it)('should resume a paused session', async () => {
- try {
- // Start and pause the session
- await hedgingManager.startSession(testSessionId);
- await hedgingManager.pauseSession(testSessionId);
- // Then resume it
- const session = await hedgingManager.resumeSession(testSessionId);
- (0, globals_1.expect)(session.status).toBe('active');
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- (0, globals_1.it)('should stop an active session', async () => {
- try {
- // Start the session
- await hedgingManager.startSession(testSessionId);
- // Then stop it
- const session = await hedgingManager.stopSession(testSessionId);
- (0, globals_1.expect)(session.status).toBe('completed');
- (0, globals_1.expect)(session.endTime).toBeDefined();
- (0, globals_1.expect)(session.endTime).toBeInstanceOf(Date);
- }
- catch (error) {
- // This test should fail initially since HedgingManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingManager');
- }
- });
- });
- (0, globals_1.describe)('Error Handling', () => {
- (0, globals_1.it)('should handle non-existent session operations gracefully', async () => {
- const nonExistentSessionId = 'non-existent-session-id';
- try {
- await hedgingManager.getSession(nonExistentSessionId);
- fail('Should have thrown error for non-existent session');
- }
- catch (error) {
- (0, globals_1.expect)(error.message).toContain('not found');
- }
- });
- (0, globals_1.it)('should handle invalid session state transitions', async () => {
- const sessionRequest = {
- name: 'Test Invalid Transition Session',
- accountIds: ['account-1', 'account-2'],
- volumeTarget: 10000,
- strategy: {
- symbol: 'ETH/USD',
- volumeDistribution: 'equal',
- priceRange: { min: 0.001, max: 0.01 },
- timing: { minInterval: 30, maxInterval: 120, orderSize: { min: 100, max: 500 } },
- riskLimits: { maxPositionSize: 0.1, stopLossThreshold: 0.05, maxSlippage: 0.02 },
- orderTypes: { primary: 'limit', fallback: 'market' }
- }
- };
- try {
- const session = await hedgingManager.createSession(sessionRequest);
- // Try to pause a pending session (should fail)
- await hedgingManager.pauseSession(session.id);
- fail('Should have rejected pausing a pending session');
- }
- catch (error) {
- (0, globals_1.expect)(error.message).toContain('status');
- }
- });
- });
- (0, globals_1.describe)('Configuration Integration', () => {
- (0, globals_1.it)('should use default strategy from configuration', async () => {
- try {
- const defaultStrategy = await configManager.getDefaultStrategy();
- (0, globals_1.expect)(defaultStrategy).toBeDefined();
- (0, globals_1.expect)(defaultStrategy.symbol).toBeDefined();
- (0, globals_1.expect)(defaultStrategy.volumeDistribution).toBeDefined();
- (0, globals_1.expect)(defaultStrategy.priceRange).toBeDefined();
- (0, globals_1.expect)(defaultStrategy.timing).toBeDefined();
- (0, globals_1.expect)(defaultStrategy.riskLimits).toBeDefined();
- (0, globals_1.expect)(defaultStrategy.orderTypes).toBeDefined();
- }
- catch (error) {
- // This test should fail initially since HedgingConfigManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingConfigManager');
- }
- });
- (0, globals_1.it)('should validate configuration parameters', async () => {
- try {
- const config = await configManager.getConfig();
- (0, globals_1.expect)(config).toBeDefined();
- (0, globals_1.expect)(config.defaultStrategy).toBeDefined();
- (0, globals_1.expect)(config.monitoring).toBeDefined();
- (0, globals_1.expect)(config.sessionDefaults).toBeDefined();
- (0, globals_1.expect)(config.orderDefaults).toBeDefined();
- (0, globals_1.expect)(config.websocket).toBeDefined();
- }
- catch (error) {
- // This test should fail initially since HedgingConfigManager doesn't exist yet
- (0, globals_1.expect)(error.message).toContain('HedgingConfigManager');
- }
- });
- });
- });
- //# sourceMappingURL=test_hedging_session_creation.js.map
|