Copy in Pool

Overview

The Copy In Pool mode is an extension of the CopyStake product. In this mode, users copy the streamer's bets by contributing funds to a shared pool. The size of their win or loss is proportional to their share of the pool. All actions are processed via the streamer's balance on the operator's side.

This document defines the API contract required for operators to integrate the Copy In Pool functionality.

API Access:

  • all requests from CopyStake to Operator contain X-API-KEY with value issued by Operator;

  • all requests from Operator to CopyStake contain X-API-KEY with value issued by CopyStake;

Signature:

  • all requests from CopyStake must be signed by CopyStake and verified by Operator;

  • all requests from Operator must be signed by Operator and verified by CopyStake;

  • secretKey for signing the payload in both cases is issued by CopyStake

  • the signature will be placed in the X-REQUEST-SIGNATURE header of each request and uses Base64(HmacSHA512(SecretKey, MD5(request body)))

  • dealing with X-REQUEST-SIGNATURE

Example of how to generate a signature for SecretKey = secret

node Welcome to Node.js v16.13.0. Type ".help" for more information. var crypto = require('crypto'); undefined var hasher = crypto.createHash('md5'); undefined var hashed = hasher.update('{"id":"103193","action":"CREDIT","amount":4.123,"currency":"USD","exchangeRate":0.00203250655485,"tokenAmount":2500,"operatorId":123,"operatorUserId":"333"}') undefined var hash = hashed.digest('hex'); undefined var hmac = crypto.createHmac('sha512', 'secret'); undefined hmac.update(hash); Hmac { _options: undefined, [Symbol(kHandle)]: Hmac {}, [Symbol(kState)]: { [Symbol(kFinalized)]: false } } var sign = hmac.digest('base64'); undefined console.log('signature: ' + sign); signature: IifPVbfXptagZ6qSXH9vYrQiqSP4sKIC+hV+39z2K+FlLzRoEboPGTTymjmeuAhN1i0ICDyyrrufYspgAJmxHQ==

Callback URL:

  • callback_url - provided by Operator, e.g. callback_url=https://integration.operator.com/api/v1/copystake

IMPORTANT:

Operators need to whitelist the Trueplay IPs to receive callbacks about the status of transactions. Otherwise, Trueplay will return errors for deposit/withdrawal tokens requests.

IPs for whitelisting

18.193.249.95

18.184.86.250

18.196.113.251

Validation rules:

Operator side:

  • to prevent fraud and loss of funds by the follower, Operator should ensure control over the withdrawal of funds from the streamer’s balance on the operator’s site to streamer’s personal account (out of operator’s site);

CopyStake side:

  • to ensure the correct execution of operations, CopyStake should perform transfer operations only for users identified in the CopyStake system as streamers

Transfer operation

OPERATOR

  • type = DEPOSIT only under the condition of a successfully executed BET transaction on the follower’s account, i.e., the action when the follower joined the pool;

  • type = WITHDRAWAL under the condition that the follower decided to leave the pool (or the stream ended, or other scenarios). This operation must be completed with a WIN transaction on the follower’s account.

Performing deposit/withdraw operations concerning the streamer’s balance. This method can be invoked:

POST

{callback_url}/transfer

Headers

Content-Type: application/json
X-API-KEY: value issued by Operator
X-REQUEST-SIGNATURE: value generated based on the request payload (secret key issued by CopyStake)

Request

Field

Type

Require

Description

userId

String

mandatory

user identifier in the operator system

currency

String

optional

currency ISO 4217

  • field is present, return the account balance information in the specified currency

  • field is absent, return the account balance information with which the game was launched (not a balance inside the game)

  • field is absent and there is no active game session - throw ERR_OPEN_SESSION_NOT_FOUND

Response success

Field

Type

Require

Description

balance

Double

mandatory

  • rounding to 8 decimal places

  • current available user’s balance

currency

String

mandatory

currency ISO 4217

Response error

HTTP 400 Bad Request

Field

Type

Require

Description

errorCode

String

mandatory

ERR_UNKNOWN General error status, for cases without a special error code

ERR_TRANSFER_FORBIDDEN Any conditions under which the user is prohibited for deposit/withdraw operations

ERR_INSUFFICIENT_BALANCE Insufficient streamer balance

ERR_INVALID_USER User does not exist

ERR_OPEN_SESSION_NOT_FOUND User session not found

errorMessage

String

optional

more detailed description of the errorRequest example

Request example
curl --location ’{callback_url}/streamer-balance’ \
--header ’Content-Type: application/json’ \
--header ’X-API-KEY: e58d1990-31b9-41f5-aa39-fd150643a8fe’ \
--header ’X-REQUEST-SIGNATURE: FbS2341Uu0mSUAGw4LwF7GVBa7GT7drJXCvHkI+ORHJQ07uxVKAi3pA/0vB8/shlzX16x234FD==’ \
--data ’{
    "userId": "29e946a1-e801-4e27-952d-1d6ebbd19525"
}’

Response example

200 OK
{
    "balance": 805.00000000,
    "currency": "USD",
}

Get balance (Copy In Pool mode)

This API method allows operators to retrieve the current balance of the streamer before join the pool.

POST

{callback_url}/streamer-balance

Headers

Content-Type: application/json
X-API-KEY: value issued by CopyStake

Request

Field

Type

Require

Description

language

String

optional

User's UI language code from the permitted set in the backoffice (ISO 639)

streamId

String

optional

User identifier for active stream. If present, followers are directed to the Broadcast page, skipping the Lobby

Response success

Field

Type

Require

Description

url

String

mandatory

CopyStake url with auth token

Response error HTTP

400 Bad Request

Field

Type

Require

Description

errorCode

String

mandatory

ERR_UNKNOWN General error status, for cases without a special error code.

ERR_COPYSTAKE_OFF CopyStake is disabled

errorMessage

String

optional

more detailed description of the error

Request example
Request
curl --location 'https://integration.trueplay.io/api/v1/copystake/init-demo' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: d922bd1c-e7ac-4c98-9b1a-baa724440b0e' \
--header 'X-REQUEST-SIGNATURE: XhNkfy6WCTdiewUu0mSUAGw4LwF7GVBa7GT7drJXCvHkI+ORHJQ07uxVKAi3pA/0vB8/shlzX16x+77DvqCGRw==' \
--data '{
    "language": "en",
    "streamId": "7b699688-f4ad-407d-baf5-c006ba8d50e2"
}'

Response example

200 OK
{
    "url": "https://copystake.trueplay.io?token=eyJhbGciOiJIUzUxMiJ9.eyJpZF9vcGVyYXRvciI6”
}

Game Pool state

Send information to the Operator that the streamer's balance is the Game Pool.

It could be OPEN before the first follower decides to join the pool or CLOSED when the last follower leaves the pool. Based on the information about state, Operator able to create internal rules to forbidden some operator actions (withdrawal of funds from the streamer’s balance on the operator’s site to streamer’s personal account, token exchanges and other that can impact on streamer’s balance)

POST

{callback_url}/game-pool

Headers

Content-Type: application/json
X-API-KEY: value issued by CopyStake

Request

Field

Type

Require

Description

userId

String

mandatory

User identifier in the operator system

state

String

mandatory

OPEN - first follower decides to join the pool

CLOSE - last follower leaves the pool

Request example
curl --location ’{callback_url}/game-pool’ \
--header ’Content-Type: application/json’ \
--header ’X-API-KEY: e58d1990-31b9-41f5-aa39-fd150643a8fe’ \
--header ’X-REQUEST-SIGNATURE: FbS2341Uu0mSUAGw4LwF7GVBa7GT7drJXCvHkI+ORHJQ07uxVKAi3pA/0vB8/shlzX16x234FD==’ \
--data ’{
    "userId": "29e946a1-e801-4e27-952d-1d6ebbd19525",
    "state": "OPEN"
}’
200 OK

Last updated