Skip to main content

3.6 Examples

Available examples:

The following examples use HTTPie as an example of a HTTP client performing synchronous requests, and wscat as an example of WebSocket consumer. Any HTTP compliant client or library in any programming language will work the same way (ws is another interesting WebSocket testing tool).

3.6.1 Login example

A successful login can be performed by:

$ http POST https://api.mollybet.com/v1/sessions/ username=john \ password=j0hnpass

Resulting in a request similar to:

POST /v1/sessions/ HTTP/1.1 Host: api.mollybet.comAccept: application/json Content-Type: application/json; charset=utf-8

{ "username": "john", "password": "j0hnpass" }

At which the API may return the following response, representing a successful login and reporting the session token to be used in the following requests:

HTTP/1.1 200 OK
Content-Type: application/json

{
"status": "ok",
"data": "28f818ee4699ea482d0363c2262f5f5d",
}

3.6.2 Synchronous request example

Once authentication is successful the client can use the other available method to place orders and to query the current position, using the returned session token in the Session HTTP header. For example, the following command returns the open betslips:

$ http GET https://api.mollybet.com/v1/betslips/ \ Session:28f818ee4699ea482d0363c2262f5f5d

Resulting in a request like:

GET /v1/betslips/ HTTP/1.1 Host: api.mollybet.comSession: 28f818ee4699ea482d0363c2262f5f5d

And resulting in the following response (if no betslip is open):

HTTP/1.1 200 OK
Content-Type: application/json

{
"status": "ok",
"data": []
}

3.6.3 Asynchronous connection

The same token obtained in the login must be used to create a WebSocket connection:

$ wscat --connect \ wss://api.mollybet.com/v1/stream/?token=28f818ee4699ea482d0363c2262f5f5d

which will immediately begin streaming:

< {
"ts": 1477094004.385003,
"data": [
["[xrate", {"rate": 1.223, "ccy": "USD"}],
["xrate", {"rate": 1.1193, "ccy": "EUR"}],
["xrate", {"rate": 9.489, "ccy": "HKD"}],
["balance", {"open_stake": ["GBP", 0.0], "balance": ["GBP", 0.0]}],
["event", {"sport": "fb", "event_id": "2016-10-26,245,234",
"home": "AC Chievo Verona", "away": "Bologna FC",
"competition_id": "19", "competition_name": "Italy Serie A",
"competition_country": "IT", "ir_status": "pre_event",
"start_time": "2016-10-26T18:45:00+00:00"}],

# a lot of other events...

["sync", {"token": "e55ab1d7edda4c31ac48283617d968df"}]
]
}

3.6.4 Receiving event offers

If you are interested in the available offers or in other events happening to a sport event you can send a message to the WebSocket you are receiving messages from:

> ["register_event", "fb", "2016-10-26,245,234"]

Doing so the WebSocket will add messages to the stream with information about the offers available on the event as soon as they change, changes in the event status (when the match kicks off, when the score changes), and so on:

< {
"ts": 1477326622.314035,
"data": [
["response", {"status": "ok", "data": null}]
]
}

< {
"ts": 1477326622.328543,
"data": [
["offer", {
"bookie": "sing2", "market": "regular|fb-r-future|16^^",
"selection": "2495514|r|70198|C|||",
"sport": "fb", "event_id": "2016-10-26,245,234",
"bet_type": "for,ah,a,-6", "in_running":false,
"price_list": [{"bookie": {"price":2.09, "min": null, "max": null}}],
}],
["offer", {
"bookie": "bf-it", "market": "1.127996398", "selection": "12,back,0,0.0",
"sport": "fb", "event_id": "2016-11-06,240,234",
"bet_type": "for,cs,3,2", "in_running":false,
"price_list":[
{"bookie": {"price": 21.0, "min": ["GBP", 1.80], "max": ["GBP", 3.87]}},
{"bookie": {"price":19.5, "min": ["GBP", 1.80], "max": ["GBP", 4.18]}}],
}]
]
}

< {
"ts": 1477326625.239232,
"data": [
["offer", {
"bookie": "sing2", "market": "regular|fb-r-future|16^^",
"selection": "2495514|r|70198|C|||",
"sport": "fb", "event_id": "2016-10-26,245,234",
"bet_type": "for,ah,a,-6", "in_running":false,
"price_list": [{"bookie": {"price":2.10, "min": null, "max": null}}],
}]
]
}

3.6.5 Working with a betslip

In order to place an order a MollyBet API user must open a betslip using the Open Betslip call. Updates about the betslip state will be received on the asynchronous channel. For example, in order to bet on the above event:

$ http POST https://api.mollybet.com/v1/betslips/ \ Session:28f818ee4699ea482d0363c2262f5f5d \ sport=fb event_id=2016-10-26,245,234 bet_type=for,h

The command will result both in a synchronous reply:

HTTP/1.1 200 OK
Content-Type: application/json

{
"status": "ok",
"data": {
"accounts": [
{"bet_type": "for,h", "bookie": "bf", "username": "_40a78ed8_"},
{"bet_type": "for,ah,h,-2", "bookie": "pin", "username": "_6d241fed_"},
],
"sport": "fb",
"bet_type": "for,h",
"betslip_type": "normal",
"betslip_id": "b2e936565fea4d778c38269ab1667f17",
"bookies_with_offers": ["ibc", "sing2"],
"close_reason": null,
"customer_ccy": "EUR",
"customer_username": "john",
"equivalent_bets": true,
"equivalent_bets_bookies": [],
"want_bookies": [],
"event_id": "2016-10-26,245,234",
"expiry_ts": 1477326778.358509,
"is_open": true,
"invalid_accounts": {},
"multiple_accounts": false
}
}

but also in a sequence of messages on the asynchronous stream, updating about the state of the betslip:

< {
"ts": 1477326723.482099,
"data": [
["betslip", { ... same data of the sync channel }]
]
}

< {
"ts": 1477326723.584029,
"data": [
["pmm", {
"betslip_id": "b2e936565fea4d778c38269ab1667f17",
"sport": "fb",
"event_id": "2016-10-26,245,234",
"bookie": "bf",
"username": "_40a78ed8_",
"bet_type": "for,h",
"status": {"code": "success"},
"price_list": [
{
"bookie": {"price": 2.16, "max": ["GBP", 5.4], "min": ["GBP", 2.0]},
"effective": {"price": 2.1368, "max": ["GBP", 5.4], "min": ["GBP", 2.0]}
},
{
"bookie": {"price": 2.12, "min": ["GBP", 2.0], "max": ["GBP", 278.57]},
"effective": {"price": 2.0976, "min": ["GBP", 2.0], "max": ["GBP", 278.57]}
}]
}]
]
}

< {
"ts": 1477326723.796697,
"data": [
["pmm", {
"betslip_id": "b2e936565fea4d778c38269ab1667f17",
"sport": "fb",
"event_id": "2016-10-26,245,234",
"bookie": "pin",
"username": "_3aa3dcac_",
"bet_type": "for,h",
"status": {"code": "success"},
"price_list": [
{
"bookie": {"max": ["EUR", 1838.4], "price": 2.09, "min": ["EUR", 45.96]},
"effective": {"max": ["GBP", 1640.11], "price": 2.09, "min": ["GBP", 41.00]}
}]
}]
]
}

< {
"ts": 1477326723.958774,
"data": [
["pmm",
...continuous stream of PMM updates until the betslip is closed
]
}

< {
"ts": 1477326733.137329,
"data": [
["betslip_closed", {
"close_reason": "explicit_close_request",
"betslip_id": "b2e936565fea4d778c38269ab1667f17"
}]
]
}