UNPKG

@cloudbet/market-helper

Version:

SDK to generate localized sport market information

485 lines (446 loc) 79.4 kB
# Cloudbet API Market Helper - [Installation](#install) - [Usage](#getting-started-with-the-cloudbet-api-market-helper) - [Markets](#available-markets) - [Sports](#available-sports) - [Demo](https://codesandbox.io/s/cloudbet-odds-api-example-we1vk?file=/src/App.js) ## Install --- ``` npm install @cloudbet/market-helper ``` or ``` yarn add @cloudbet/market-helper ``` ## Getting Started with the Cloudbet API Market Helper --- See working [example app](https://codesandbox.io/s/cloudbet-odds-api-example-we1vk?file=/src/App.js) on how to display the marktes and odds returned by the [odds API](https://docs.cloudbet.com/) using the Cloudbet market helper library. There are a few things to note when using the [Cloudbet Feed API](https://docs.cloudbet.com/). To reduce the payload size of each API response, certain static market information has been stripped from the data. To make full sense of each market you can use the `Cloudbet Feed API Market Helper`. It will help you to: - Distinguish lines - Recognize handicap and totals values - Create human readable market and outcome names - Distinguish between back and lay side (upcoming feature) - Access odds for a specific market ### Fetching and getting a market from an event `getMarket` Returns a list of markets for a specific `MarketType`. The different markets of the same type are usually divided by the time period for which they are relevant. E.g. for soccer, it might return 3 markets for fulltime, first half, and second half. ```js import { getMarket } from '@cloudbet/market-helper'; function async getMarkets(eventId, marketType){ const event = await fetch(`https://sports-api.cloudbet.com/pub/v2/odds/events/${eventId}`, { method: 'GET', headers: { // e.g eyJhbGciOiJSUzI1NiIsImtpZCI6ImxPVGE3LXV... 'X-API-KEY': CLOUDBET_API_KEY } }).then(response => response.json()); const [markets, err] = getMarket(event, marketType); if(err){ throw new Error(err) } return markets; } ``` ### Accessing outcomes by line Each market consists of one or more lines. Or 0 lines, if the market is currently not active. <!-- not sure if that is the actual behavior of the sdk --> Lines are sorted by tightness. That means the first line has the smallest difference between the outcome prices. Each line is an array of outcome objects. ```js import { MarketTypes} from '@cloudbet/market-helper' function async getSoccerMatchOddsForEvent(eventId){ const markets = await getMarkets(eventId, MarketType.soccer_match_odds); return markets.map(market => { // the translated market name const marketName = market.name; // the lines for the given market, an array of outcomes const lines = market.lines; lines.map(outcomes => { outcomes.map(outcome => { // Translated name of the outcome const outcomeName = outcome.name; // the back selection for that particular outcome const backSelection = outcome.back; // price of the selection const price = backSelection.price; // variables, such as handicap or over/under value const variables = backSelection.variables; }) }) }); } ``` ### Accesing handicap value for an outcome ```js function getHandicapValue(outcome) { const handicap = outcome.variables.handicap; return handicap; } ``` ### Accessing over under value for an outcome ```js function getOverUnderValue(outcome) { const total = outcome.variable.total; return total; } ``` ## Available Markets --- A market is identified via its MarketType: ```js import { MarketType } from "@cloudbet/market-helper"; const afFirstHalfWinner = MarketType.american_football_1x2_period_first_half; ``` The following markets are available on the MarketType object. <details> <summary> Expand all available markets </summary> | MarketType | Market Name | | ---------------------------------------------------- | ------------------------------------------------------------------------ | | american_football_1x2_period_first_half | 1st half - 1x2 | | american_football_double_chance | Double chance | | american_football_draw_no_bet | Draw no bet (incl. overtime) | | american_football_halftime_fulltime_result | Halftime/fulltime | | american_football_handicap | Handicap | | american_football_handicap_period_first_half | 1st half - handicap | | american_football_moneyline | Money Line | | american_football_odd_even | Odd/even | | american_football_quarter_1x2 | Quarter {{quarter}} - 1x2 | | american_football_quarter_handicap | Quarter {{quarter}} - handicap | | american_football_quarter_handicap_incl_ot | Quarter {{quarter}} - handicap (incl. overtime) | | american_football_quarter_total | Quarter {{quarter}} - total | | american_football_quarter_totals_incl_ot | Quarter {{quarter}} - total (incl. overtime) | | american_football_team_odd_even | {{team}} odd/even | | american_football_team_total_period_first_half | 1st half - {{team}} total | | american_football_team_totals | {{team}} Total | | american_football_totals | Totals | | american_football_totals_period_first_half | 1st half - total | | american_football_totals_period_second_half | 2nd half - total (incl. overtime) | | american_football_player_long_reception | {{player}} (Long Reception) | | american_football_player_completions | {{player}} (Completions) | | american_football_player_interceptions | {{player}} (Interceptions) | | american_football_player_kicking_points | {{player}} (Kicking Points) | | american_football_player_long_completion | {{player}} (Long Completion) | | american_football_player_pass_attempts | {{player}} (Pass Attempts) | | american_football_player_pass_yards | {{player}} (Pass Yds) | | american_football_player_receiving_yards | {{player}} (Receiving Yds) | | american_football_player_receptions | {{player}} (Receptions) | | american_football_player_rush_touchdown | {{player}} (Rush TD) | | american_football_player_rush_yards | {{player}} (Rush Yds) | | american_football_player_touchdown_passes | {{player}} (TD Passes) | | american_football_player_touchdown_receptions | {{player}} (TD Receptions) | | american_football_player_anytime_touchdown | {{player}} (Anytime Touchdown) | | american_football_player_first_touchdown_scorer | {{player}} (1st Touchdown Scorer) | | american_football_player_last_touchdown_scorer | {{player}} (Last Touchdown Scorer) | | aussie_rules_1st_half_1x2 | 1st half - 1x2 | | aussie_rules_1st_half_double_chance | 1st half - double chance | | aussie_rules_1st_half_draw_no_bet | 1st half - draw no bet | | aussie_rules_1st_half_handicap | 1st half - handicap | | aussie_rules_1st_half_odd_even | 1st half - odd/even | | aussie_rules_1st_half_team_total | 1st half - {{team}} total | | aussie_rules_1st_half_total | 1st half - total | | aussie_rules_double_chance | Double chance | | aussie_rules_draw_no_bet | Draw no bet | | aussie_rules_handicap | Handicap | | aussie_rules_match_odds | Match Odds | | aussie_rules_odd_even | Odd/even | | aussie_rules_quarter_1x2 | Quarter {{quarter}} - 1x2 | | aussie_rules_quarter_draw_no_bet | Quarter {{quarter}} - draw no bet | | aussie_rules_quarter_handicap | Quarter {{quarter}} - handicap | | aussie_rules_quarter_team_total | Quarter {{quarter}} - {{team}} total | | aussie_rules_quarter_total | Quarter {{quarter}} - total | | aussie_rules_team_total | {{team}} total | | aussie_rules_totals | Total | | aussie_rules_winner | Winner | | aussie_rules_winning_margin_period_ft | Winning margin | | aussie_rules_which_team_wins_the_rest_of_the_match_period_ft | Which team wins the rest of the match at {{score}} | | aussie_rules_point_range_period_1st_half | 1st half - point range | | aussie_rules_point_range_period_ft | Point range | | badminton_correct_score | Correct score | | badminton_exact_games | Exact games | | badminton_game_winner | Game {{game}} - winner | | badminton_handicap | Handicap | | badminton_totals | Total | | badminton_winner | Winner | | bandy_match_odds | Match Odds | | bandy_totals | Total | | baseball_handicap_innings_1_to_5 | Innings 1 to 5 - handicap | | baseball_moneyline | Money Line | | baseball_moneyline_innings_1_to_5 | Innings 1 to 5 - Moneyline | | baseball_odd_even | Odd/even (incl. extra innings) | | baseball_run_line | Run Line | | baseball_team_totals | {{team}} Total (incl. extra innings) | | baseball_totals | Totals | | baseball_totals_innings_1_to_5 | Innings 1 to 5 - total | | baseball_which_team_wins_the_rest_of_the_match | Which team wins the rest of the match at {{score}} (incl. extra innings) | | baseball_1x2_and_total_period_ot | 1x2 & total (incl. extra innings) | | baseball_both_teams_to_score_in_inning | Inning {{inning}} - Both teams to score | | baseball_handicap_in_inning | Inning {{inning}} - Handicap | | baseball_highest_scoring_inning | Highest scoring inning | | baseball_hit_on_pitch_pitchnr | Hit on pitch {{pitchnr}} | | baseball_home_run_on_pitch_pitchnr | Home run on pitch {{pitchnr}} | | baseball_inning_1x2 | Inning {{inning}} - 1x2 | | baseball_player_total_batter_runs_and_runs_batted_in_period_ot| {{player}} total batter runs + runs batted in (incl. extra innings) | | baseball_result_of_pitch | Result of pitch {{pitchnr}} | | baseball_result_of_player_at_bat | Result of {{player}} at bat {{appearancenr}} | | baseball_run_range_period_ot | Run range (incl. extra innings) | | baseball_run_runnr_period_ot | Run {{runnr}} (incl. extr innings) | | baseball_team_total_home_runs_period_ot | {{team}} total home runs (incl. extra innings) | | baseball_total_hits_in_inning | Inning {{inning}} - Total Hits | | baseball_total_hits_period_ot | Total hits (incl. extra innings) | | baseball_total_home_runs_period_ot | Total home runs (incl. extra innings) | | baseball_total_in_inning | Inning {{inning}} - Total Hits | | basketball_1st_half_1x2 | 1st half - 1x2 | | basketball_1st_half_draw_no_bet | 1st half - draw no bet | | basketball_1st_half_team_total | 1st half - {{team}} total | | basketball_1x2 | 1x2 (excl. OT) | | basketball_2nd_half_1x2 | 2nd half - 1x2 | | basketball_2nd_half_1x2_incl_ot | 2nd half - 1x2 (incl. overtime) | | basketball_2nd_half_1x2_incl_ot_v2 | 2nd half - 1x2 (incl. overtime) | | basketball_2nd_half_handicap | 2nd half - handicap | | basketball_2nd_half_total | 2nd half - total | | basketball_halftime_fulltime | Halftime/fulltime | | basketball_handicap | Spread | | basketball_handicap_period_2h_incl_ot | 2nd half - handicap (incl. overtime) | | basketball_handicap_period_first_half | 1st half - handicap | | basketball_handicap_period_second_half | 2nd half - handicap (excl. overtime) | | basketball_moneyline | Money Line | | basketball_odd_even | Odd/Even | | basketball_odd_even_period_first_half | 1st half - odd/even | | basketball_quarter_1x2 | Quarter {{quarter}} - 1x2 | | basketball_quarter_handicap | Quarter {{quarter}} - handicap | | basketball_quarter_totals | Quarter {{quarter}} totals | | basketball_team_totals | {{team}} Total | | basketball_total_period_first_half | 1st half - total | | basketball_total_period_second_half | 2nd half - total (incl. overtime) | | basketball_totals | Totals | | basketball_player_three_point_field_goals | 3 Point FG | | basketball_player_assists | Assists | | basketball_player_blocks | Blocks | | basketball_player_double_double | Double+Double | | basketball_player_points | Points | | basketball_player_points_rebounds_assists | Pts+Rebs+Asts | | basketball_player_rebounds | Rebounds | | basketball_player_steals_blocks | Steals+Blocks | | basketball_player_turnovers | Turnovers | | beach_soccer_match_odds | Match Odds | | beach_soccer_totals | Total | | beach_volleyball_handicap | Point handicap | | beach_volleyball_totals | Total points | | beach_volleyball_winner | Winner | | bowls_correct_score | Correct score | | bowls_handicap | Set handicap | | bowls_totals | Total sets | | bowls_winner | Winner | | boxing_1x2 | 1x2 | | boxing_totals | Total Rounds | | boxing_winner | To Win Fight | | boxing_winner_exact_rounds | Winner & exact rounds | | boxing_freetext | {{market_name}} | | call_of_duty_correct_score | Correct Score | | call_of_duty_handicap | Map Handicap | | call_of_duty_map_winner | Map {{map}} - Winner | | call_of_duty_map_winner_v2 | Map {{map}} - Winner | | call_of_duty_totals | Total maps | | call_of_duty_winner | Winner | | call_of_duty_freetext | {{market_name}} | | chess_handicap | Handicap | | chess_match_odds | Match Odds | | counter_strike_correct_score_in_maps | Correct score (in maps) | | counter_strike_map_1st_half_winner | Map {{map}} 1st half - winner | | counter_strike_map_1x2 | Map {{map}} - 1x2 | | counter_strike_map_handicap | Map handicap | | counter_strike_map_odd_even_rounds | Map {{map}} - odd/even rounds (incl. overtime) | | counter_strike_map_odd_even_rounds_v2 | Map {{map}} - odd/even rounds (incl. overtime) | | counter_strike_map_round_handicap | Map {{map}} - round handicap (incl. overtime) | | counter_strike_map_round_winner | Map {{map}} round {{round}} - winner | | counter_strike_map_team_total | Map {{map}} - {{team}} total | | counter_strike_map_total_rounds | Map {{map}} - total rounds (incl. overtime) | | counter_strike_map_winner | Map {{map}} - winner (incl. overtime) | | counter_strike_match_odds | Match Odds | | counter_strike_total_maps | Total maps | | counter_strike_winner | Winner | | counter_strike_freetext | {{market_name}} | | **Cricket** | | cricket_innings_total_v2 | Total Runs | | cricket_team_totals | {{team}} total | | cricket_total_sixes | Total sixes | | cricket_total_in_highest_scoring_over | {{team}} total in the highest scoring over | | cricket_any_player_to_score_milestone | Any player to score {{milestone}} | | cricket_top_batter_total | Top batter total | | cricket_team_total_from_0_over_to_x_over | Overs 0 to {{to_over}} - {{team}} total | | cricket_team_total_at_dismissal | {{team}} total at dismissal {{dismissal}} | | cricket_test_1x2 | 1x2 | | cricket_test_innings_team_total | {{innings}} innings - {{team}} total | | cricket_test_match_inning_over_total_runs_spread | Innings {{innings}} Over {{over}} - total runs spread | | cricket_test_match_innings_team_totals | Innings {{innings}} - {{team}} total | | cricket_test_match_innings_totals | Innings {{innings}} - total | | cricket_test_match_team_with_top_batter | Team with top batter | | cricket_test_match_innings_any_player_score_milestone| Innings {{innings}} - any player to score {{milestone}} | | cricket_test_match_innings_team_total_at_dismissal | Innings {{innings}} - {{team}} total at dismissal {{dismissal}} | | cricket_test_winner | Match Winner | | cricket_any_player_to_score_milestone_v2 | Innings {{innings}} - Any player to score {{milestone}} runs | | cricket_winner | Match Winner (incl. Superovers) | | cricket_day_session_total | Day {{day}} session {{session}} total | | cricket_innings_dismissal_batter_out | Innings {{innings}} - dismissal {{dismissal}} batter out | | cricket_innings_player_to_score_milestone | Innings {{innings}} - {{player}} to score {{milestone}} | | cricket_innings_player_total_fours | Innings {{innings}} - {{player}} total fours | | cricket_innings_team_total_fours | Innings {{innings}} - {{team}} total fours | | cricket_innings_team_total_sixes | Innings {{innings}} - {{team}} total sixes | | cricket_player_to_score_milestone | {{player}} to score {{milestone}} | | cricket_player_total_fours | {{player}} total fours | | cricket_player_total_player_performance | {{player}} total player performance | | cricket_team_total_fours | {{team}} total fours | | cricket_team_total_sixes | cricket.team_total_sixes | | darts_correct_score_in_sets | Correct score (in sets) | | darts_handicap_sets | Set handicap | | darts_odd_even_sets | Odd/Even Sets | | darts_total_sets | Total Sets | | darts_winner | Winner | | dota_2_correct_score_in_maps | Correct score (in maps) | | dota_2_map_handicap | Map handicap | | dota_2_map_winner | Map {{map}} - Winner | | dota_2_map_winner_v2 | Map {{map}} - Winner | | dota_2_map_most_kills | Map {{map}} - Most Kills | | dota_2_map_team_total_kills | Map {{map}} - {{team}} total kills | | dota_2_match_odds | Match Odds | | dota_2_total_maps | Total maps | | dota_2_winner | Winner | | dota_2_freetext | {{market_name}} | | esport_arena_of_valor_winner | Winner | | esport_arena_of_valor_correct_score | Correct Score | | esport_arena_of_valor_handicap | Handicap | | esport_arena_of_valor_map_winner | Map {{map}} - Winner | | esport_arena_of_valor_match_3_way | 3-way | | esport_fifa_asian_handicap | Asian Handicap | | esport_fifa_asian_handicap_period_first_half | 1st Half Asian Handicap | | esport_fifa_asian_handicap_period_second_half | 2nd Half Asian Handicap | | esport_fifa_both_teams_to_score | Both teams to score | | esport_fifa_correct_score | Correct Score | | esport_fifa_correct_score_period_1st_half | 1st half - Correct Score | | esport_fifa_correct_score_period_2nd_half | 2nd half - correct score | | esport_fifa_double_chance | Double chance | | esport_fifa_draw_no_bet | Draw no bet | | esport_fifa_exact_total_goals_period_first_half | 1st Half Exact Total Goals | | esport_fifa_exact_total_goals_period_second_half | 2nd Half Exact Total Goals | | esport_fifa_halftime_fulltime_result | Halftime / Fulltime | | esport_fifa_match_odds | Full Time Result | | esport_fifa_match_odds_period_extratime | Match Odds - Extra Time | | esport_fifa_match_odds_period_first_half | Half Time Result | | esport_fifa_match_odds_period_second_half | Match Odds - 2nd half | | esport_fifa_penalty_shootout_odd_even | Penalty shootout - odd/even | | esport_fifa_team_clean_sheet | {{team}} clean sheet | | esport_fifa_team_total_goals | {{team}} Total Goals | | esport_fifa_team_total_goals_period_first_half | {{team}} 1st Half Total Goals | | esport_fifa_team_total_goals_period_second_half | {{team}} 2nd Half Total Goals | | esport_fifa_total_goals | Total Goals | | esport_fifa_total_goals_period_extratime | Total Goals - Extra Time | | esport_fifa_total_goals_period_first_half | 1st Half Total Goals | | esport_fifa_total_goals_period_second_half | 2nd Half Total Goals | | esport_fifa_total_booking_points | 10-25 Total Booking Points | | esport_fifa_penalty_shootout_odd_even | Penalty shootout - odd/even | | esport_fifa_odd_even_penalty_shootout | Penalty shootout - odd/even | | esport_king_of_glory_winner | Winner | | esport_king_of_glory_map_handicap | Map Handicap | | esport_king_of_glory_map_winner | Map {{map}} - Winner | | esport_king_of_glory_total_maps | Total Maps | | esport_king_of_glory_map_kill_handicap | Map {{map}} - kill handicap | | esport_king_of_glory_map_total_kills | Map {{map}} - total kills | | esport_king_of_glory_map_team_total_kills | Map {{map}} - {{team}} total kills | | esport_king_of_glory_map_most_kills | Map {{map}} - Most Kills | | esport_king_of_glory_correct_score | Correct Score | | esport_king_of_glory_freetext | {{market_name}} | | esport_nba2k_1st_half_1x2 | 1st half - 1x2 | | esport_nba2k_1st_half_draw_no_bet | 1st half - draw no bet | | esport_nba2k_1st_half_team_total | 1st half - {{team}} total | | esport_nba2k_1x2 | 1x2 | | esport_nba2k_2nd_half_1x2 | 2nd half - 1x2 | | esport_nba2k_2nd_half_1x2_incl_ot | 2nd half - 1x2 (incl. overtime) | | esport_nba2k_2nd_half_1x2_incl_ot_v2 | 2nd half - 1x2 (incl. overtime) | | esport_nba2k_2nd_half_handicap | 2nd half - handicap | | esport_nba2k_2nd_half_total | 2nd half - total | | esport_nba2k_halftime_fulltime | Halftime/fulltime | | esport_nba2k_handicap | Spread | | esport_nba2k_handicap_period_first_half | 1st half - handicap | | esport_nba2k_handicap_period_second_half | 2nd half - handicap (incl. overtime) | | esport_nba2k_odd_even | Odd/Even | | esport_nba2k_quarter_1x2 | Quarter {{quarter}} - 1x2 | | esport_nba2k_quarter_handicap | Quarter {{quarter}} - handicap | | esport_nba2k_quarter_totals | Quarter {{quarter}} totals | | esport_nba2k_team_totals | {{team}} Total | | esport_nba2k_total_period_first_half | 1st half - total | | esport_nba2k_total_period_second_half | 2nd half - total (incl. overtime) | | esport_nba2k_totals | Totals | | esport_nba2k_winner_incl_overtime | Winner (incl. overtime) | | esport_valorant_correct_score | Correct Score | | esport_valorant_handicap | Handicap | | esport_valorant_totals | Total maps | | esport_valorant_winner | Winner | | esport_valorant_map_round_handicap | Map {{map}} - handicap (incl. overtime) | | esport_valorant_map_team_total_rounds | Map {{map}} - {{team}} total | | esport_valorant_map_total_rounds | Map {{map}} - Total (incl. overtime) | | esport_valorant_freetext | {{market_name}} | | esport_warcraft_correct_score | Correct Score | | esport_warcraft_handicap | Handicap | | esport_warcraft_totals | Totals | | esport_warcraft_winner | Winner | | esport_aoe_correct_score | Correct Score | | esport_aoe_handicap | Handicap | | esport_aoe_map_winner | Map {{map}} - Winner | | esport_aoe_total_maps | Total maps | | esport_aoe_winner | Winner | | esport_brawl_stars_correct_score | Correct Score | | esport_brawl_stars_handicap | Handicap | | esport_brawl_stars_map_winner | Map {{map}} - Winner | | esport_brawl_stars_total_maps | Total maps | | esport_brawl_stars_winner | Winner | | field_hockey_match_odds | Match Odds | | field_hockey_totals | Total | | floorball_match_odds | Match Odds | | floorball_totals | Total | | futsal_double_chance | Double chance | | futsal_draw_no_bet | Draw no bet | | futsal_handicap | Handicap | | futsal_match_odds | Match Odds | | futsal_odd_even | Odd/even | | futsal_totals | Total | | golf_winner | Match up | | **Greyhound** | | greyhound_win_v2 | Winner | | greyhound_place_v2 | Place ({{position}} TBP) | | greyhound_win_sp_v2 | Winner | | greyhounds_win | Winner | | greyhounds_place | Place ({{position}} TBP) | | greyhounds_win_sp | Winner (SP) | | handball_1st_half_total | Total - 1st half | | handball_double_chance | Double chance | | handball_draw_no_bet | Draw no bet | | handball_halftime_fulltime_result | Halftime / Fulltime | | handball_handicap | Handicap | | handball_match_odds | Match Odds | | handball_odd_even | Odd/even | | handball_team_total | {{team}} Total | | handball_totals | Total | | handball_winner | Winner (incl. overtime and penalties) | | hearthstone_winner | Winner | | horse_racing_win | Winner | | horse_racing.place | Place ({{position}} TBP) | | horse_racing.win_sp | Winner (SP) | | **Ice Hockey** | | ice_hockey_1x2 | 1x2 (Excl. Overtime) | | ice_hockey_1x2_both_teams_to_score | 1x2 & both teams to score (incl. overtime and penalties) | | ice_hockey_both_teams_to_score | Both teams to score | | ice_hockey_correct_score | Correct score | | ice_hockey_correct_score_incl_overtime_and_penalties | Correct score (incl. overtime and penalties) | | ice_hockey_double_chance | Double chance (Excl. Overtime) | | ice_hockey_exact_goals | Exact goals | | ice_hockey_exact_goals_period_ft_incl_et_and_penalty_shootout | Exact goals (incl. overtime and penalties) | | ice_hockey_handicap | Handicap (incl. overtime and penalties) | | ice_hockey_handicap_regular_time | Handicap | | ice_hockey_period_1x2 | Period {{period}} - 1x2 | | ice_hockey_period_correct_score | Period {{period}} - correct score | | ice_hockey_period_handicap | Period {{period}} - handicap | | ice_hockey_period_total | Period {{period}} - total | | ice_hockey_team_clean_sheet | {{team}} clean sheet | | ice_hockey_team_exact_goals | {{team}} exact goals (incl. overtime and penalties) | | ice_hockey_team_total | {{