Australian odds in Google Sheets

Type a formula, get the Australian board in your sheet: game lines, player props and racing, with the best price on each side. No add-on to install. You copy one script into your own sheet, and your key stays in your Google account.

Set it up in five minutes

  1. Get a free key at /developer. The free plan has game lines; player props need the Starter plan ($29 a month) or above.
  2. In your Google Sheet, choose Extensions, then Apps Script.
  3. Delete what is in the editor, paste the script below, and click the save icon.
  4. Reload the sheet. A HaterPicks menu appears. Choose Set API key and paste your key. Google asks you to allow the script the first time. It warns that the app is unverified because it is your own script; that is expected.
  5. In any cell, type =HATERPICKS_ODDS("nba") and press Enter.

The formulas

  • =HATERPICKS_ODDS("nba")

    Every game line and prop on the board, with the best price on each side and the book that has it.

  • =HATERPICKS_ODDS("nba", "points", "murray")

    Only the points markets, and only rows matching a player, team or game.

  • =HATERPICKS_PROPS("afl", "disposals")

    Player props for one sport. Needs the Starter plan or above.

  • =HATERPICKS_RACING("today", "greyhound")

    Racing: one row per runner with the best win and place price. "next" gives tomorrow; the code is optional.

  • =HATERPICKS_ODDS("nba", "", "", "american")

    Prices as decimal (the default), "american" or "fractional".

The first argument is a sport code such as nba, afl, nrl, nbl, nfl or nhl. The full list is in the odds reference.

The script

Google Apps Script
/**
 * HaterPicks for Google Sheets.
 * Docs: https://www.haterpicks.app/haterpicks-api/sheets
 *
 * Formulas (the key is stored in your Google account; use the HaterPicks menu to set it):
 *   =HATERPICKS_ODDS("nba")                          game lines and props, best price per side
 *   =HATERPICKS_ODDS("nba", "points", "murray")      only a market and/or a player or team
 *   =HATERPICKS_PROPS("afl", "disposals")            player props (Starter plan and above)
 *   =HATERPICKS_RACING("today", "greyhound")         racing: best win and place price per runner
 * Add "american" or "fractional" as the next argument for other price formats.
 */
var HP_BASE_ = 'https://www.haterpicks.app/api/v1/';
var HP_MAX_ROWS_ = 3000;

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('HaterPicks')
    .addItem('Set API key', 'hpSetKey')
    .addItem('Remove API key', 'hpClearKey')
    .addToUi();
}

function hpSetKey() {
  var ui = SpreadsheetApp.getUi();
  var r = ui.prompt('HaterPicks API key', 'Paste your key (it starts with hp_live_). It is saved in your Google account, not in this sheet.', ui.ButtonSet.OK_CANCEL);
  if (r.getSelectedButton() === ui.Button.OK && r.getResponseText().trim()) {
    PropertiesService.getUserProperties().setProperty('HP_KEY', r.getResponseText().trim());
    ui.alert('Saved. Formulas refresh within a few minutes.');
  }
}

function hpClearKey() {
  PropertiesService.getUserProperties().deleteProperty('HP_KEY');
  SpreadsheetApp.getUi().alert('Removed.');
}

function hpKey_(override) {
  var k = override || PropertiesService.getUserProperties().getProperty('HP_KEY');
  if (!k) throw new Error('No API key yet. Use the HaterPicks menu, then Set API key. Get a free key at https://www.haterpicks.app/developer');
  return String(k).trim();
}

function hpToAmerican_(d) {
  return d >= 2 ? Math.round((d - 1) * 100) : -Math.round(100 / (d - 1));
}

function hpGcd_(a, b) {
  return b === 0 ? a : hpGcd_(b, a % b);
}

function hpToFractional_(d) {
  var x = d - 1;
  var dens = [1, 2, 3, 4, 5, 6, 8, 10, 11, 13, 20, 25, 40, 50, 100];
  for (var i = 0; i < dens.length; i++) {
    var q = dens[i];
    var p = Math.round(x * q);
    if (p > 0 && Math.abs(p / q - x) <= 0.005 * x) {
      var g = hpGcd_(p, q);
      return (p / g) + '/' + (q / g);
    }
  }
  var p2 = Math.round(x * 100);
  var g2 = hpGcd_(p2, 100);
  return (p2 / g2) + '/' + (100 / g2);
}

function hpShow_(price, format) {
  if (price === null || price === undefined || price === '' || !(price > 1)) return '';
  var f = String(format || 'decimal').toLowerCase();
  if (f === 'american') return hpToAmerican_(price);
  if (f === 'fractional') return hpToFractional_(price);
  return price;
}

function hpGet_(path, query, key) {
  var parts = [];
  for (var k in query) {
    if (query[k]) parts.push(encodeURIComponent(k) + '=' + encodeURIComponent(query[k]));
  }
  var url = HP_BASE_ + path + (parts.length ? '?' + parts.join('&') : '');
  var res = UrlFetchApp.fetch(url, { headers: { Authorization: 'Bearer ' + key }, muteHttpExceptions: true });
  var code = res.getResponseCode();
  var body = {};
  try { body = JSON.parse(res.getContentText()); } catch (e) { body = {}; }
  if (code === 401) throw new Error('That API key was not accepted. Use the HaterPicks menu, then Set API key.');
  if (code === 403) throw new Error(body.error || 'Your plan does not include this feed. See https://www.haterpicks.app/api');
  if (code === 429) throw new Error('Too many requests. Wait a minute and the formula will refresh.');
  if (code >= 400) throw new Error(body.error || ('HaterPicks API error ' + code));
  return body;
}

// Sheets recalculates formulas often; keep each answer for two minutes so a sheet does not burn calls.
function hpCached_(name, args, produce) {
  var cache = CacheService.getUserCache();
  var raw = name + '|' + JSON.stringify(args);
  var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, raw);
  var ck = 'hp:' + digest.map(function (b) { return ('0' + (b & 255).toString(16)).slice(-2); }).join('');
  var hit = cache.get(ck);
  if (hit) {
    var rows = JSON.parse(hit);
    rows.forEach(function (r) { if (r[0] && typeof r[0] === 'object' && r[0].d) r[0] = new Date(r[0].d); });
    return rows;
  }
  var out = produce();
  var stored = JSON.stringify(out.map(function (r) { return r.map(function (c) { return c instanceof Date ? { d: c.toISOString() } : c; }); }));
  if (stored.length < 95000) cache.put(ck, stored, 120);
  return out;
}

function hpHas_(text, needle) {
  return !needle || String(text || '').toLowerCase().indexOf(String(needle).toLowerCase()) !== -1;
}

function hpBest_(prices, sideKeys, format) {
  var best = { price: 0, book: '' };
  for (var book in prices) {
    for (var i = 0; i < sideKeys.length; i++) {
      var v = prices[book] && prices[book][sideKeys[i]];
      if (typeof v === 'number' && v > best.price) best = { price: v, book: book };
    }
  }
  return best;
}

function hpLines_(list, market, search, format, limit) {
  var header = ['Start', 'Game', 'Market', 'Player or team', 'Line', 'Best over or home', 'Book', 'Best under or away', 'Book'];
  var rows = [];
  for (var i = 0; i < list.length && rows.length < limit; i++) {
    var r = list[i];
    var name = r.player_or_team || r.player_name || '';
    if (!hpHas_(r.market, market) || !(hpHas_(name, search) || hpHas_(r.matchup, search))) continue;
    var a = hpBest_(r.prices || {}, ['over', 'home'], format);
    var b = hpBest_(r.prices || {}, ['under', 'away'], format);
    rows.push([r.game_start_iso ? new Date(r.game_start_iso) : '', r.matchup || '', r.market || '', name, r.line === undefined || r.line === null ? '' : r.line,
      hpShow_(a.price, format), a.book, hpShow_(b.price, format), b.book]);
  }
  return [header].concat(rows);
}

/** Game lines and props for one sport, the best price on each side. */
function HATERPICKS_ODDS(sport, market, search, format, apiKey) {
  if (!sport) throw new Error('Give a sport, for example =HATERPICKS_ODDS("nba")');
  return hpCached_('odds', [sport, market, search, format, apiKey || ''], function () {
    var body = hpGet_('odds', { sport: String(sport) }, hpKey_(apiKey));
    return hpLines_(body.data || [], market, search, format, HP_MAX_ROWS_);
  });
}

/** Player props for one sport (Starter plan and above). */
function HATERPICKS_PROPS(sport, market, search, format, apiKey) {
  if (!sport) throw new Error('Give a sport, for example =HATERPICKS_PROPS("afl")');
  return hpCached_('props', [sport, market, search, format, apiKey || ''], function () {
    var body = hpGet_('props', { sport: String(sport).toLowerCase() }, hpKey_(apiKey));
    var list = (body.data && body.data.markets) || [];
    return hpLines_(list, market, search, format, HP_MAX_ROWS_);
  });
}

/** Racing: every runner with the best win and place price. day is "today" or "next". */
function HATERPICKS_RACING(day, type, format, apiKey) {
  return hpCached_('racing', [day, type, format, apiKey || ''], function () {
    var body = hpGet_('racing', { day: day === 'next' ? 'next' : 'today' }, hpKey_(apiKey));
    var header = ['Start', 'Venue', 'Race', 'Runner no.', 'Runner', 'Best win', 'Book', 'Best place', 'Book', 'Scratched'];
    var rows = [];
    var races = body.data || [];
    for (var i = 0; i < races.length && rows.length < HP_MAX_ROWS_; i++) {
      var race = races[i];
      if (type && String(race.race_type || '').toLowerCase() !== String(type).toLowerCase()) continue;
      var runners = race.runners || [];
      for (var j = 0; j < runners.length; j++) {
        var ru = runners[j];
        var w = ru.best_win || {};
        var p = ru.best_place || {};
        rows.push([race.start_time ? new Date(race.start_time) : '', race.venue || '', race.race_no || '', ru.number, ru.name || '',
          hpShow_(w.price, format), w.book || '', hpShow_(p.price, format), p.book || '', ru.scratched ? 'yes' : '']);
      }
    }
    return [header].concat(rows);
  });
}

Good to know

  • Each formula refresh is one API call against your monthly allowance. The script keeps each answer for two minutes, so a sheet that recalculates does not use extra calls.
  • A formula returns up to 3,000 rows. Use the market and search arguments to narrow it.
  • Your key is saved in your Google account, not in the sheet, so sharing the sheet does not share the key. Each person who opens it sets their own.
  • An error such as "Your plan does not include this feed" appears in the cell itself and says what to change.
  • The same feeds are available to code. See the API reference.