DEV Community

Sergey Gustun
Sergey Gustun

Posted on

How I create value bet scanner for Starcraft2

Hello everyone!

I am a free developer and I love esports very much.

And where there is a sport, there are bookmakers. I have long understood how bookmakers work and try to write a lot of software to identify interesting points in this area.

Relatively recently, I decided to create a small open source community where I will post my small developments, and at the same time, if you are interested, you could participate in this.

That's it https://github.com/BETTING-CODE

But let's get to the point of this article.

I wondered how often bookmakers make mistakes and overestimate a particular bet. The answer lay on the surface, very often, which means we could find such bids.

What is a discipline in esports is the most simple outcomes of events? Star StarCraft2!

For this discipline, the bookmaker does not give too many betting options, there are only two of them - either the first or second player will win.

Our first task will be to get the coefficients for each player. How do we do this?

"Puppeteer".

Like this.

const puppeteer = require('puppeteer');

async function get_money_line() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://gg22.bet/en/starcraft2', { waitUntil: 'networkidle2' });
    await browser.close();
}

Well, we opened the browser, opened the page we need with the bookmaker's odds and closed it.

What can we do with all the content on the page?
Yes, everything is the same as in a normal browser.

For example, get all the games that are currently displayed on the page.

const starcraft2matches = await page.evaluate(() => {
        let object = []
        let j = 0
        let names = document.querySelectorAll('.__app-LogoTitle-name.LogoTitle__name___2LTlu')
        let odds = document.querySelectorAll('.odd__ellipsis___3b4Yk')
        let date_time = document.querySelectorAll('.dateTime__date___147AU')

        function get_day(text) {
            if (text.indexOf('TODAY') !== -1) {
                let day = new Date()
                day = day.toLocaleDateString('en-EN', { month: 'short', day: 'numeric' })
                day = day.toUpperCase()
                return text.replace('TODAY', day)
            } else {
                return text
            }
        }

        for (let i = 0; i < names.length; i++) {
            if (i == 0)
                object[j] = []
            if (i % 2 == 0 && i != 0) {
                j++
                object[j] = []
                object[j].push({ time: get_day(date_time[j].innerText), name: names[i].innerText, odds: odds[i].innerText })
            } else {
                object[j].push({ time: get_day(date_time[j].innerText), name: names[i].innerText, odds: odds[i].innerText })
            }
        }

        return object
    })

As you may have noticed, working with a page is very similar to what we can do in dev tools.

This way we take all the matches from the page and create an array. How cool is that?

Now we have all the matches we need. But where can we get the possible winning percentages?

After all, the odds that we see at the bookmaker are nothing but percentages, try dividing the unit by the coefficient, what did you get?

Here we will come to the aid of a rather interesting site called aligulac, which is a huge database of matches in Starcraft2 if this site is also open source.

Let's learn how to get data from aligulac.

First, let's go here and get the API key http://aligulac.com/about/api/

Great, now let's add a few packages to our script.

const fs = require('fs')
const sc2 = require('./sc2moneyline')
const aligulac_api_key = 'your-api-key'
const node_fetch = require('node-fetch')

What is node-fetch? This is an implementation of the fetch function from the browser for NodeJS.

Let's now write a few functions for our aligulac.

async function search_players(name) {
    return node_fetch(`http://aligulac.com/search/json/?q=${name}&search_for=players`)
        .then(res => res.json())
}

async function get_info_player(id) {
    return node_fetch(`http://aligulac.com/api/v1/player/?id=${id}&apikey=${aligulac_api_key}`)
        .then(res => res.json())
}

async function get_predictmatch(id1, id2) {
    return node_fetch(`http://aligulac.com/api/v1/predictmatch/${id1},${id2}/?apikey=${aligulac_api_key}&bo=3`)
        .then(res => res.json())
}

Great, now we have with you, the bookmaker's line, all the information on the players and everything is ready to find value bets.

How do you find them at all?

The formula is quite simple, knowing how the players play with each other, we can estimate the percentage of victory of one player over another, we denote it as P, we also have the bookmaker's coefficient, we denote it as K, then our formula will look something like this.

K * P > 1

If > 1 then this is the overvalued bid.

Can you now generate an HTML page yourself?

I created a repository for this so that you can see how it works.
https://github.com/BETTING-CODE/starcraft2-value-bet-generator

I hope you are a little interested in this topic and will be able to understand such technologies as parsing and information collection.
Happy coding!

Alt Text

Discussion (2)

Collapse
afk_esports_bar profile image
Afk Esports Bar

Great tool! Can we implement in on our website about esports betting ?
afkesportsbar.com/

Collapse
b0risb profile image
b0risB

What else interesting did you do for betting? We have a project - sportlights.ru/, we are looking for a developer who understands sports betting...