File size: 2,073 Bytes
b190b45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**

 * Unit Tests for Trading Strategies

 */

import { analyzeWithStrategy, HYBRID_STRATEGIES } from './trading-strategies.js';

describe('Trading Strategies', () => {
  const mockMarketData = {
    price: 50000,
    volume: 1000000,
    high24h: 52000,
    low24h: 48000,
  };

  test('should analyze with trend-rsi-macd strategy', () => {
    const result = analyzeWithStrategy('BTC', 'trend-rsi-macd', mockMarketData);
    
    expect(result).toHaveProperty('strategy');
    expect(result).toHaveProperty('signal');
    expect(result).toHaveProperty('confidence');
    expect(result).toHaveProperty('indicators');
    expect(result).toHaveProperty('levels');
    expect(result).toHaveProperty('riskReward');
    expect(['buy', 'sell', 'hold']).toContain(result.signal);
  });

  test('should calculate support and resistance levels', () => {
    const result = analyzeWithStrategy('BTC', 'trend-rsi-macd', mockMarketData);
    
    expect(result.levels).toHaveProperty('resistance');
    expect(result.levels).toHaveProperty('support');
    expect(result.levels.resistance.length).toBeGreaterThan(0);
    expect(result.levels.support.length).toBeGreaterThan(0);
  });

  test('should calculate take profit levels', () => {
    const result = analyzeWithStrategy('BTC', 'trend-rsi-macd', mockMarketData);
    
    if (result.signal !== 'hold') {
      expect(result.takeProfitLevels).toBeDefined();
      expect(result.takeProfitLevels.length).toBeGreaterThan(0);
      expect(result.stopLoss).toBeDefined();
    }
  });

  test('should handle all strategy types', () => {
    Object.keys(HYBRID_STRATEGIES).forEach(strategyKey => {
      const result = analyzeWithStrategy('BTC', strategyKey, mockMarketData);
      expect(result).toBeDefined();
      expect(result.strategy).toBe(HYBRID_STRATEGIES[strategyKey].name);
    });
  });

  test('should throw error for unknown strategy', () => {
    expect(() => {
      analyzeWithStrategy('BTC', 'unknown-strategy', mockMarketData);
    }).toThrow();
  });
});