General
How to use
This documentation is divided into 4 sections:
  • General
  • Methods
  • Events
  • Endpoints
We've done our best to make the usage of our API as simple as possible. In the effort of creating an API with the fastest communication with client, we came up with a solution of using bi-directional communication using websocket and similar technologies. Sounds complicated? Don't worry, we've built a client library which handles everything for you.

Thanks to bi-directional communication your client will receive an event every time there's some new info the client should know. You can set custom event handlers (listeners) for those events. Available listeners can be found in Events section of this documentation.

API endpoints are callable endpoints to the BetBase API. This communication is as well going through socket for the best performance and speed. Available API endpoints with examples can be found in Endpoints section of this documentation.

In Methods section you'll find all methods you can use on BetBase object, once created. This includes the method used for calling api endpoints as well as the method used for setting event listeners.

For browsers which do not suppot websockets (around 5%) the long-polling and other solutions will be used. The behavior is same.
There are some methods, endpoints and events which require the socket to be authorized first. Those have an icon of on the right side.
Getting started
First of all you need to download our client lib and include it into your project:

BetbaseAPI-v1.js


	var betbase = new BetBaseAPI({
	  casino_id: 'xxxxxxxxxx'
	});	
  

This options are allowed:


	{
	  casino_id: 'xxxxxxxxxx',    // Required.
	  anonymous_login: true       // Optional (true/false). Default: true
	}
  

When anonymous_login is enabled, the unlogged visitor will be provided with an anonymous account once the site is loaded. The login event will be fired.

The fully functional example:


	var betbase = new BetBaseAPI({
	  casino_id: 'xxxxxxxxxx'   // replace with your casino identifier
	});
	
	betbase.ready(() => {
	  
	    // now the socket is READY.
	  
	    betbase.listen('login', (data) => {
	  
		      // now the socket is AUTHORIZED.
		
	    });
	  
	});	
  
Server-side
Although this documentation describes API for client-side calls, you can request any of its endpoints (and some more) from server-side using confidential api_key. API key can be found in casino administration.

The confidential requests are a POST requests to https://api.betbase.io/server.

Each POST request must contain:
  • auth: Authorization object
    • casino: Casino indentifier
    • api_key: Casino API key
    • user_id: User ID (optional)
  • endpoint: Endpoint
  • options: Options (optional)
user_id must be specified for endpoints which require authorization ().
Example POST data

	{
	  auth: {
	    casino: 'kHsSzmGBMa',
	    api_key: 'PShPanv1M0Co9MDQad6ff1acC4p3tk5fMyOXm6jp',
	    user_id: 4237
	  },
	  endpoint: 'hello',
	  options: {}
	}
  

Please refer to the Endpoints section of this documentation to see options and responses.

For server-side, there's a few more endpoints you can use. Click here to see them.
Methods
.ready()
Using this method, you can provide a function to execute when the socket is ready (the socket may be still unauthorized).

	.ready(function() {    
    
	  // socket is ready    
 
	});
  

There are some methods that can't be used until the socket is ready.
.listen()
This method will set an event listener.

	// replace 'event' with the event name
	
	.listen('event', (data) => {
	  
	  // data contains the optional event data
	
	});
  

You can find available events in Events section of this documentation.
.api()
This method will send an API request.

	// replace 'endpoint' with the endpoint name you're requesting
	
	var options = {};
	
	.api('endpoint', options, (response) => {
	  
	  // process the response
	
	});
  

You can find available endpoints in Endpoints section of this documentation.
options argument is optional, but can be required by some endpoints.
Some of the endpoints require the socket to be authorized first (those endpoints have the icon of on the right side)

This method can't be used until the socket is ready.
.login()
This method will open a pop-up window with login or re-login (if user is already logged in) form.

	.login();
  

This method can't be used until the socket is ready.
.fair()
This method will open a pop-up window with Provably Fair information.

	.fair();
  

This method can't be used until the socket is authorized.
.deposit()
This method will open a pop-up window with Deposit option.

	.deposit();
  

This method can't be used until the socket is authorized.
.withdraw()
This method will open a pop-up window with Withdraw option.

	.withdraw();
  

This method can't be used until the socket is authorized.
Events
Login
This event will fire when the user is logged in. This may happen when the site loads and whenever the visitor logs in for the first time or logs into different account.

	.listen('login', (data) => {
	  
	  // process data
	
	});
  
Example Data

	{
	    user: {
	        anonymous: false,
	        balance: 0.45128742,
	        user_id: 17,
	        username: "Player_MJGmqzzv"
	    }
	}
	

There are some methods, endpoints and events that can't be used until this event is received.
Balance change
This event will fire whenever the user's balance is changed.

	.listen('balance', (data) => {
	  
	  // process data
	
	});
  
Example Data

	{
	    new_balance: 0.37901000
	}
	

You won't be receiving this event until the socket is authorized.
New bet
This event will fire whenever someone makes a bet through this casino.

	.listen('new_bet', (data) => {
	  
	  // process data
	
	});
  
Example Data

	{
	  bet: {
	    betId: 367,
	    casino: "kHsSzmGBMa",
	    game: "roulette-old",
	    user: {
	      id: 45277,
	      username: "bestgamer001"
	    },
	    time: "2016-11-15T17:35:03.000Z",
	    wager: 2.47200600,
	    outcome: 31,
	    payout: 0,
	    multiplier: 0,
	    profit: 0.00000000,
	    fair: {
	      clientSeed: 204678681,
	      serverSeed: 934777182
	      serverSalt: "xbWHk93HFvsHotOeGjtrRR",
	    },
	    houseEdge: 0.02702702
	  }
	}
	
Logout
This event will fire when user logs out or de-authorizes casino. This may happen any time.

	.listen('logout', () => {
	  
	  // Logged out.
	
	});
  
Endpoints
Hello
This endpoint does nothing useful but it's good for testing purposes.

	.api('hello', (response) => {    
    
	  console.log(response);    
 
	});
  
Response

	{
		  hello: "Hello [username] from [casino_name]"
	}
	
Place a bet
With each bet, you must specify:
  • Wager
  • Range
  • Margin (optional)
  • Payouts
  • Game title

range is an amount of numbers (zero included) from which the result will be chosen. If you specify 100 as a range, the result of this bet will be any number from 0 to 99. If you need to have 1 to 100 as a range, simply set margin to 1.

margin specifies the lowest result, e.g. if range is 100 and margin is 5, the result will be chosen from 5 to 104.

payouts are some set of chances (their sum must equal specified range), each specifying how much money to return to player if the result matches this chance. In the example below, if the result is 0, player gets nothing back. If the result is between 1 and 12 (inclusive), player gets 0.15 BTC (wager * 3). If the result is between 13 and 36 (inclusive), player gets nothing.

The below example is a bet of European roulette, where player betted 0.05 BTC on a first 12.

game is a string representing a name of your game so it can be filtered when listing bets or receiving events. This can be anything.

The house edge will be computed from payouts and must be between 0.5% and 30%

Maximum wager is computed_house_edge * BetBase_bankroll
Example Options

	var options: {
	  wager: 0.05,
	  range: 37,
	  margin: 0, // optional
	  payouts: [
	    { chance: 1, return: 0 },
	    { chance: 12, return: 0.15 },
	    { chance: 24, return: 0 }
	  ],
	  game: 'roulette2-new'
	};
  
Example Call

	.api('bet', options, (response) => {
	
	  console.log(response);
	
	});
  
Example Response

	{
	  bet: {
	    betId: 24,
	    casino: "kHsSzmGBMa",
	    game: "roulette2-new",
	    user: {
	      id: 45277,
	      username: "bestgamer001"
	    },
	    time: "2016-11-15T17:35:03.000Z",
	    wager: 2.47200600,
	    outcome: 31,
	    payout: 0,
	    multiplier: 0,
	    profit: 0.00000000,
	    fair: {
	      clientSeed: 204131681,
	      serverSeed: 615777182
	      serverSalt: "xbWHk93HFvsHotOeGjtrRR",
	    },
	    houseEdge: 0.02702702
	  }
	}
	

Multiply houseEdge by 100 to get percentage. In the example above, the house edge of this bet is arround 2.7%
List bets
Use this endpoint to list bets.
Example Options

	var options: {
	  count: 20,              // Optional (max: 100). Default: 100
	  game: 'roulette2-new',  // Optional (string).
	  user: 17                // Optional (int).
	};
  

If game is specified, the response will contain only bets with the same string specified in game option when placing a bet.
Example Call

	.api('bets', options, (response) => {    
    
	  console.log(response);    
 
	});
  
Example Response

	{
	  bets: [
	    {
	      betId: 24,
	      casino: "kHsSzmGBMa",
	      game: "roulette2-new",
	      user: {
	        id: 45277,
	        username: "bestgamer001"
	      },
	      time: "2016-11-15T17:35:03.000Z",
	      wager: 2.47200600,
	      outcome: 31,
	      payout: 0,
	      multiplier: 0,
	      profit: 0.00000000,
	      fair: {
	        clientSeed: 204131681,
	        serverSeed: 615777182
	        serverSalt: "xbWHk93HFvsHotOeGjtrRR",
	      },
	      houseEdge: 0.02702702
	    },
	    ...
	  ]
	}
	

Multiply houseEdge by 100 to get percentage. In the example above, the house edge of this bet is arround 2.7%
Get user info
Get information about the user.

	.api('user', (response) => {    
    
	  console.log(response);    
 
	});
  
Example Response

	{
	    user: {
	        anonymous: false,
	        balance: 0.45128742,
	        user_id: 17,
	        username: "Player_MJGmqzzv"
	    }
	}
	
Get casino info
Get information about the casino.

	.api('casino', (response) => {    
    
	  console.log(response);    
 
	});
  
Example Response

	{
	  casino: {
	    identifier: 'kHsSzmGBMa',
	    stats: {
	      bets_operated: 64857,
	      total_wagered: 354.08643278,
	      players: {
	        total: 2412,
	        active: 1896,
	        online: 104
	      }
	    }
	  }
	}
	

active players are players who have betted at least once.
Get bankroll
Get the current bankroll state.

	.api('bankroll', (response) => {    
    
	  console.log(response);    
 
	});
  
Example Response

	{
		  bankroll: "709.84051202"
	}
	
Log Out
Log out from the casino.

	.api('logout', (response) => {    
    
	  console.log(response);    
 
	});
  
Example Response

	{
	    success: true
	}
	
Confidential Endpoints


This server-side endpoints don't require user_id specified in auth object.
Tip User
Use this endpoint to move funds from casino balance to user

				{
				  auth: {...},
				  endpoint: 'tip_user',
				  options: {
				    user_id: 25,
				    amount: 0.00001
				  }
				}
			  
Example Response

				{
				  moved: {
				    amount: 0.00001000,
				    movedTo: 25
				  }
				}