cf-bet.mp4
cf-bet is a sports betting application for Codeforces competitions. Users can select a type of bet, and the backend will perform a Monte-Carlo simulation of the competition. Probabilities and lines are generated from the simulation, determining the payout for a given bet.
- Three Types of Bets: Users can select two competitors to go head-to-head, a competitor to win the contest, or a competitor to achieve a specific placement.
- Login System: Users can register and log in to their accounts to track their previous bets and view statistics about their bets. They can also view these statistics on other users' profiles.
- Monte-Carlo Simulation: Simulates thousands of competition runs based on the competitors' ELO ratings, accounting for the randomness of competitors' performance.
Technologies used:
- TypeScript: For front-end development
- ASP.NET: For back-end development
- React: Front-end library
- NextUI: React UI Library
- Axios: Library for making API calls from the front-end
The frontend is a React application designed to provide an interactive user experience. It uses various libraries and tools to manage data retrieval, state management, and UI rendering. Data retrieval is handled by axios
, which allows for HTTP requests to the backend. An example sequence of user inputs is described below:
- The user accesses the site, which requests the current contests, bets, and rankings from the backend. This can be done without logging in.
- The user can then log in with their Codeforces handle, storing a JWT token in their HTTP cookies.
- When placing a bet, this JWT token is passed between the frontend and the server to authenticate the user.
- The user can bet on any upcoming contest, choosing one of three types of bets.
- The frontend updates when the contest ends, allowing the user to see if their bet was successful.
The server has two main functions: updating the database and calculating betting probabilities.
Updating the database: The database is updated every 5 minutes with new data from the Codeforces API (to avoid exceeding rate limits). This includes getting new contests, updating the results of finished contests, and fetching the competitors of a specific contest. The data is stored in MongoDB Atlas using schemas.
Calculating betting probabilities: The calculations for the probabilities of a given bet vary based on the type of bet:
- For a bet pitting two competitors against each other, the probability that the competitor with rating (
$R_a$ ) will beat a competitor with rating ($R_b$ ) is given by:
- For a bet predicting a user's placement, the probability is calculated using a Monte-Carlo simulation. The rationale behind using this simulation is twofold: calculating the probability of a random system of 250 competitors is non-trivial, and the deviation between a competitor's performance level and skill level is considered to be i.i.d. (Paper). The Monte-Carlo simulation generates 10,000 simulations by adding a value from a normally distributed model to their skill level and tracking the rankings of competitors.
The moneyline or American odds are then calculated with:
- Clone this repository.
- Install the required dependencies:
- In the root of the repository and
./backend
, runnpm install
.
- In the root of the repository and
- In the root of the repository and
./backend
, rename the.env.example
file to.env
. - Update the values in the new
.env
file with your API keys and port selection. - Run
npm run start
ornpm run dev
in the root of the repository and./backend
.
- The Monte-Carlo simulation does not perfectly reflect real-life competition. For example, the chances that tourist (currently number 1 on Codeforces) places first are higher than they should be. This is due to inflation (See here).
- Users may be unable to bet on certain competitors if they register at the last minute and betting has closed. There is no way to circumvent this; users can only bet on registered competitors for the contest.
- Unlike sports betting, users cannot place bets after the contest has started.
cf-bet is licensed under the MIT License. See LICENSE for more details.