All files / src/services line-movement.service.ts

11.49% Statements 10/87
100% Branches 0/0
0% Functions 0/6
11.49% Lines 10/87

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134          1x     1x       1x                                 1x                               1x                                                           1x                                                     1x                                           1x           1x   1x  
/**
 * Line Movement Analytics Service
 * Provides API calls for line movement detection and analysis
 */
 
import api from './api';
import { LineMovement, MovementResponse, MovementFilters, MovementStats } from '../types/movements.types';
 
class LineMovementService {
  /**
   * Get recent steam moves and active movements in real-time
   */
  async getLiveMovements(
    limit: number = 20,
    hoursBack: number = 4,
    movementType: string = 'steam'
  ): Promise<{ movements: LineMovement[]; total: number }> {
    const response = await api.get<MovementResponse>('/analytics/movements/live', {
      params: { limit, hoursBack, movementType }
    });
    return {
      movements: response.data.data?.movements || [],
      total: response.data.data?.total || 0
    };
  }
 
  /**
   * Get movements for a specific game
   */
  async getGameMovements(
    gameId: string,
    limit: number = 50
  ): Promise<{ movements: LineMovement[]; game: any }> {
    const response = await api.get<MovementResponse>(`/analytics/movements/game/${gameId}`, {
      params: { limit }
    });
    return {
      movements: response.data.data?.movements || [],
      game: response.data.data?.game
    };
  }
 
  /**
   * Get historical movement data with statistics
   */
  async getMovementHistory(
    hoursBack: number = 24,
    movementType?: string
  ): Promise<{
    statistics: MovementStats;
    movements: LineMovement[];
    byDate: Record<string, LineMovement[]>;
  }> {
    const params: any = { hoursBack };
    if (movementType) {
      params.movementType = movementType;
    }
 
    const response = await api.get<MovementResponse>('/analytics/movements/history', {
      params
    });
 
    return {
      statistics: response.data.data?.statistics || {
        byType: { steam: 0, reverse: 0, gradual: 0, injury: 0, normal: 0 },
        byMarket: { h2h: 0, spreads: 0, totals: 0 }
      },
      movements: response.data.data?.movements || [],
      byDate: response.data.data?.byDate || {}
    };
  }
 
  /**
   * Get movements for a specific bookmaker
   */
  async getBookmakerMovements(
    bookmaker: string,
    hoursBack: number = 24,
    marketType?: string
  ): Promise<{
    impactStats: any;
    recentMovements: LineMovement[];
  }> {
    const params: any = { hoursBack };
    if (marketType) {
      params.marketType = marketType;
    }
 
    const response = await api.get<MovementResponse>(
      `/analytics/movements/bookmaker/${encodeURIComponent(bookmaker)}`,
      { params }
    );
 
    return {
      impactStats: response.data.data?.impactStats,
      recentMovements: response.data.data?.recentMovements || []
    };
  }
 
  /**
   * Get movement statistics
   */
  async getMovementStats(hoursBack: number = 24): Promise<{
    statistics: MovementStats;
    steamMovesCount: number;
    totalMovements: number;
  }> {
    const response = await api.get<MovementResponse>('/analytics/movements/stats', {
      params: { hoursBack }
    });
 
    return {
      statistics: response.data.data?.statistics || {
        byType: { steam: 0, reverse: 0, gradual: 0, injury: 0, normal: 0 },
        byMarket: { h2h: 0, spreads: 0, totals: 0 }
      },
      steamMovesCount: response.data.data?.steamMovesCount || 0,
      totalMovements: response.data.data?.totalMovements || 0
    };
  }
 
  /**
   * Get steam moves (most important for bettors)
   */
  async getSteamMoves(limit: number = 20): Promise<LineMovement[]> {
    const response = await api.get<MovementResponse>('/analytics/movements/live', {
      params: { limit, hoursBack: 24, movementType: 'steam' }
    });
    return response.data.data?.movements || [];
  }
}
 
export const lineMovementService = new LineMovementService();