Fantasy operations

Perform different actions related to Fantasy games

Fantasy operations are responsible for communicating with various of APIs.

Depending on the language set in your SDK configuration, the names in the model responses will be returned in the corresponding language, if supported.

If a particular name is not translated, the language falls back to English.

The namespace is of course called fantasy. All methods return promises. The general design of the namespace follows this pattern:

📘

General call:

sdk.fantasy
  .someMethod()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

The responses are comprised of different objects you can find here.

General operations

Get config

Method: getConfig()

This method returns fantasy configuration.

📘

Example call:

sdk.fantasy
  .getConfig()
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   enabled: true,
   clientId: "productiontesting1",
   addPointsToProfileTotal: false,
   coefficients: {
      assists: 6,
      shots: 2,
      offsides: -1,
      tackles: 2,
      saves: 0,
      minutesEqualOrOver60: 2,
      minutesUnder60: 1,
      yellowCards: -2,
      redCards: -5,
      goalsGoalkeeper: 10,
      goalsDefender: 10,
      goalsMidfielder: 10,
      goalsForwards: 10,
      penaltyGoals: 10,
      ownGoals: -5,
      cleanSheetsGoalkeeper: 4,
      cleanSheetsDefender: 4,
      cleanSheetsMidfielder: 1,
      cleanSheetsForwards: 0,
      shotsOn: 4,
      foulsCommitted: -1,
      penaltyCommitted: -5,
      penaltyWon: 4,
      penaltyMissed: -2,
      concededGoals: -1,
      caughtBall: 0
   },
   players: {
      total: 11,
      minGoalkeepers: 1,
      maxGoalkeepers: 1,
      minDefenders: 3,
      maxDefenders: 5,
      minMidfielders: 3,
      maxMidfielders: 5,
      minStrikers: 1,
      maxStrikers: 3
   },
   competitionsWhitelist: [
      "fb:c:1",
      "fb:c:3",
      "fb:c:4",
      "fb:c:5",
      "fb:c:6",
      "fb:c:7",
      "fb:c:8",
      "fb:c:9",
      "fb:c:11",
      "fb:c:12",
      "fb:c:13",
      "fb:c:14",
      "fb:c:15",
      "fb:c:16",
      "fb:c:17",
      "fb:c:18",
      "fb:c:19",
      "fb:c:20",
      "fb:c:21",
      "fb:c:22",
      "fb:c:27",
      "fb:c:28",
      "fb:c:30",
      "fb:c:34",
      "fb:c:37",
      "fb:c:119"
   ]
}

Player related methods

Get players points

Method: getPlayersPoints(templateId, playersPosition?, disableCache?)

Method returns points and ranks of all players who have participated in template's matches.

No authentication required.

Argument options for playersPosition (case insensitive):

  • keeper
  • defender
  • midfielder
  • forward

The response from API is cached for 1 hour. With disableCache argument you can avoid cached response.

📘

Example call:

sdk.fantasy
  .getPlayersPoints("Q1q0XdYBXVN5cIRSzpqap", "forward", true)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   meta: {
      filters: {
         templateId: "Q1q0XdYBXVN5cIRSzpqap"
      }
   },
   data: [
      {
         playerId: "fb:p:18506",
         playerModel: PlayerBasicModel,
         points: 39,
         rank: 1
      }
   ]
}

Get player statistics

Method: getPlayerStatistics(templateId, playerId, disableCache?)

Method returns statistics for concrete player in concrete template.

No authentication required.

The response from API is cached for 1 hour. With disableCache argument you can avoid cached response.

📘

Example call:

sdk.fantasy
  .getPlayerStatistics("Q1q0XdYBXVN5cIRSzpqap", "fb:p:18506", true)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

[
   {
      key: "minutesPlayed",
      label: "Minutes Played",
      value: 299
   },
   {
      key: "cleanSheets",
      label: "Clean Sheets",
      value: 1
   },
   {
      key: "concededGoals",
      label: "Goals Conceded",
      value: 0
   },
   {
      key: "saves",
      label: "Saves",
      value: 0
   },
   {
      key: "penaltySaved",
      label: "Penalties Saved",
      value: 0
   },
   {
      key: "penaltyCommitted",
      label: "Penalties Committed",
      value: 0
   },
   {
      key: "yellowCards",
      label: "Yellow Cards",
      value: 1
   },
   {
      key: "redCards",
      label: "Red Cards",
      value: 0
   },
   {
      key: "assists",
      label: "Assists",
      value: 0
   },
   {
      key: "foulsCommitted",
      label: "Fouls Committed",
      value: 2
   },
   {
      key: "ownGoals",
      label: "Own Goals",
      value: 0
   },
   {
      key: "goals",
      label: "Goals",
      value: 7
   },
   {
      key: "tackles",
      label: "Tackles",
      value: 0
   },
   {
      key: "shotsOn",
      label: "Shots On Target",
      value: 10
   }
]

Get player detailed statistics

Method: getPlayerDetailedStatistics(templateId, playerId, disableCache?)

Method returns statistics and points for the specified player in all matches where he has partcipated and are part of the template.

No authentication required.

The response from API is cached for 1 hour. With disableCache argument you can avoid cached response.

📘

Example call:

sdk.fantasy
  .getPlayerDetailedStatistics("Q1q0XdYBXVN5cIRSzpqap", "fb:p:18506", true)
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result

{
   meta: {
      filters: {
         templateId: "Q1q0XdYBXVN5cIRSzpqap",
         playerId: "fb:p:18506"
      }
   },
   data: [
      {
         matchId: "fb:m:251944",
         matchModel: MatchBasicModel,
         points: {
            total: 39,
            minutesPlayed: 2,
            yellowCards: 0,
            redCards: 0,
            goals: 20,
            penaltyGoals: 0,
            ownGoals: 0,
            assists: 0,
            cleanSheets: 0,
            shots: 10,
            shotsOn: 8,
            offsides: 0,
            foulsCommitted: -1,
            penaltyCommitted: 0,
            penaltyWon: 0,
            penaltyMissed: 0,
            tackles: 0,
            concededGoals: 0,
            caughtBall: 0,
            saves: 0
         },
         stats: {
            minutesPlayed: 87,
            yellowCards: 0,
            redCards: 0,
            goals: 2,
            penaltyGoals: 0,
            penaltyCommitted: 0,
            penaltyWon: null,
            penaltyMissed: 0,
            penaltySaved: null,
            penaltyReceived: null,
            ownGoals: 0,
            assists: 0,
            cleanSheets: 0,
            shots: 5,
            shotsOn: 2,
            shotsBlocked: null,
            offsides: 0,
            foulsCommitted: 1,
            foulsWon: null,
            tackles: null,
            tacklesBlocks: null,
            tacklesInterceptions: null,
            concededGoals: null,
            caughtBall: null,
            saves: null,
            passes: null,
            crosses: null,
            interceptions: null,
            keyPasses: null,
            passesAccuracy: null,
            duels: null,
            duelsWon: null,
            dribblesAttempts: null,
            dribblesSuccess: null,
            dribblesPast: null
         }
      }
   ]
}

User related operations

Play in fantasy game

Method: play(templateId, groupId, playerIds)

Submits the user's fantasy prediction for the specified template and group.

Params:

  • templateId: string. The fantasy template ID.
  • groupId: string. The Group ID of the template.
  • playerIds: string[]. An array of player IDs strings

📘

Example call:

sdk.fantasy
  .play("2vDjVTeEs3niCyGRqK9Lmp", "3", ["fb:p:18506"])
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result:

{
  id: "Y44CxUzkpHdypYxcVVlwIQiLNtD2_ff_2vDjVTeEs3niCyGRqK9Lmp_3",
  gameInstanceId: "2vDjVTeEs3niCyGRqK9Lmp_3",
  gameType: "FANTASY",
  wager: null,
  totalFixtures: 11,
  settledFixtures: 0,
  userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
  fixtures: [
        {
          matchId: "fb:m:251945",
          matchType: "FOOTBALL",
          matchModel: MatchBasicModel,
          result: {
            settledAt: null,
            resettledAt: null,
            status: "NOT_SETTLED",
            outcome: "NOT_VERIFIED",
            points: 0,
          },
          market: "PLAYER_PERFORMANCE",
          prediction: {
            value: null,
            playerId: "fb:p:18506",
            playerModel: PlayerBasicModel
          },
        },
      ],
      status: "ACTIVE",
      tiebreaker: null,
      points: 0,
      templateId: "2vDjVTeEs3niCyGRqK9Lmp",
      groupId: "3",
      createdAt: "2024-08-27T06:06:36Z",
      updatedAt: "2024-08-27T06:06:36Z",
}

Get user's own prediction

Method: getMyPrediction(templateId, groupId)

Returns the user's prediction for the specific template and group (round of fantasy game)

N.B. The method will return null when user hasn't placed any prediction yet.

📘

Example call:

sdk.fantasy
  .getMyPrediction("2vDjVTeEs3niCyGRqK9Lmp", "3")
  .then((response) => {
    // Handle response
  })
  .catch((error) => {
    // Handle error
  });

Example result:

{
  id: "Y44CxUzkpHdypYxcVVlwIQiLNtD2_ff_2vDjVTeEs3niCyGRqK9Lmp_3",
  gameInstanceId: "2vDjVTeEs3niCyGRqK9Lmp_3",
  gameType: "FANTASY",
  wager: null,
  totalFixtures: 11,
  settledFixtures: 0,
  userId: "Y44CxUzkpHdypYxcVVlwIQiLNtD2",
  fixtures: [
    {
      matchId: "4367496",
      matchType: "FOOTBALL",
      matchModel: MatchBasicModel,
      result: {
        settledAt: null,
        resettledAt: null,
        status: "NOT_SETTLED",
        outcome: "NOT_VERIFIED",
        points: 0,
      },
      market: "PLAYER_PERFORMANCE",
      prediction: {
        value: null,
        playerId: "263908",
        playerModel: PlayerBasicModel,
      },
    },
  ],
  status: "ACTIVE",
  tiebreaker: null,
  points: 0,
  templateId: "2vDjVTeEs3niCyGRqK9Lmp",
  groupId: "3",
  createdAt: "2024-08-27T06:06:36Z",
  updatedAt: "2024-08-27T06:06:36Z",
}