An API wrapper for the YOLOdice API
Sample usage:
npm install yolodice-api --save
const YOLOdice = require('yolodice-api');
let client = new YOLOdice('YOUR_API_PRIVATE_KEY');
client.on('loggedIn', (user) => {
console.log(`Logged in as (${user.id})${user.name}`);
});
client.on('error', (err) => {
console.dir(err);
});
process.on('SIGINT', () => {
client.quit();
});
>node app
Logged in as (12345)YourName
Nearly all the methods that take a callback (with the exception of getBalance()
) return the entire server response as the first and only argument to the callback function. These objects follow the JSON-RPC 2.0 spec, which means they all have an id
property and have a result
property on success and an error
property on failure. To access the info, you should in most cases check to see if the response has a result
property and parse the data from there.
Unsupported methods (none at the time of this writing) can be called by using YOLOdice.send(obj, callback)
where obj
is the object to send and callback is the method to call with the response when the server responds. Example:
client.send({
method: 'some_unsupported_method',
params: {
param_a: 1,
param_b: 2
}
}, aCallbackFunction(res) {
if(res.result) {
console.log('Got response');
}
});
The class does most of the legwork for you here, it will automatically add an id
property to the object before it sends it to the server and use it to track when the server responds, and it will then call the callback with the response.
Please note this is an early version of this library and many methods have not been tested extensively or at all. Please use at your own risk.
Kind: global class
Extends: EventEmitter
- YOLOdice ⇐
EventEmitter
- new YOLOdice()
- instance
- .send(req, [callback])
- .sign(msg) ⇒
string
- .quit()
- .readSiteData([callback])
- .readUser(id, [callback])
- .readUserData(id, [callback])
- .getBalance([callback])
- .readUserCoinData(id, [callback])
- .listUserCoinDatas(id, [callback])
- .resetSessionCounters([coin], [callback])
- .createBet(attrs, [includeDatas], [callback])
- .readBet(id, [callback])
- .listBets([userId], [options], [callback])
- .readSeed(id, [callback])
- .readCurrentSeed(userId, [callback])
- .listSeeds([options], [callback])
- .createSeed(attrs, [callback])
- .patchSeed(id, attrs, [callback])
- .readConfig([callback])
- .readDepositAddress(coin, [callback])
- .listDepositAddresses(coin, callback)
- .readDeposit(id, [callback])
- .listDeposits([options], [callback])
- .readWithdrawingConfig([callback])
- .readWithdrawal(id, [callback])
- .listWithdrawals([options], [callback])
- .readWithdrawalConfig([callback])
- .createWithdrawal(attrs, [callback])
- .patchWithdrawal(id, attrs, [callback])
- .cancelWithdrawal(id, [callback])
- .readInvestment(id, [callback])
- .listInvestments([status], [callback])
- .createInvestment(attrs, coin, leverage, [callback])
- .patchInvestment(id, attrs, [callback])
- .ping([callback])
- "error"
- "sign"
- "loggedIn"
- static
- inner
- ~responseHandler :
function
- ~responseHandler :
A class that handles connections to the YOLOdice API.
Kind: static class of YOLOdice
Creates an instance of YOLOdice.
Param | Type | Description |
---|---|---|
key | string |
A WIF format Bitcoin private key used to sign the login request |
[options] | Object |
An optional object to change some aspects of the server |
[options.host] | string |
The host to connect to (defaults to api.yolodice.com) |
[options.port] | number |
The port to connect to (defaults to 4444) |
Records the request sent in this.requests and sends the data. Can also be used to send unsupported/new methods.
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
req | Object |
The request to send |
[callback] | responseHandler |
An optional callback to call when a response is received The callback is passed the entire response object |
Signs a message with the client's private key
Kind: instance method of YOLOdice
Returns: string
- The signature
Emits: sign
Param | Type | Description |
---|---|---|
msg | string |
The message to sign |
Gracefully closes the connection and terminates the process
Kind: instance method of YOLOdice
Requests site data and calls callback with the data
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[callback] | responseHandler |
The callback function |
Returns user data including id, name, date created and roles
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The user id to look up |
[callback] | responseHandler |
The callback function |
Returns more extensive user data
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The user id to look up |
[callback] | responseHandler |
The callback function |
An abstraction for listUserCoinDatas on yourself
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[callback] | responseHandler |
The callback |
Returns some coin-specific user data
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | string |
A string composed of the user id and the coin |
[callback] | responseHandler |
The callback |
Returns an array of coin datas for the given user
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The user id |
[callback] | responseHandler |
The callback |
Resets session counters, optionally only for a specific coin
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[coin] | string |
The coin to reset |
[callback] | responseHandler |
The callback |
Creates a bet. Requires the play permission
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
attrs | Object |
Bet attributes |
attrs.coin | string |
The coin to bet with (e.g. 'btc' or 'ltc') |
attrs.amount | number |
The amount of the bet IN SATOSHIS |
attrs.target | number |
The target of the bet, in the range [1, 989900] |
attrs.range | string |
Either 'hi' or 'lo' |
[includeDatas] | boolean |
If true, the response will include site and user data |
[callback] | responseHandler |
The callback function |
Reads the data from a single bet
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The bet id to look up |
[callback] | responseHandler |
The callback function |
An array of hashes each containing a single bet
Kind: instance method of YOLOdice
Param | Type | Default | Description |
---|---|---|---|
[userId] | number |
The id of the user | |
[options] | Object |
The options to restrict data | |
[options.user_id] | number |
The user ID to restrict bets to | |
[options.order] | string |
"desc" |
Either 'asc' or 'desc' to sort in ascending or descending order. Default descending |
[options.id_marker] | number |
If order='asc', only bets > idMarker are returned. If order='desc', only bets < idMarker | |
[options.limit] | number |
100 |
Limit the number of objects returned. Default 100, max 1000 |
[callback] | responseHandler |
The callback function |
Reads the attributes of a seed
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The id of the seed |
[callback] | responseHandler |
The callback function |
Reads the current seed for the specified user
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
userId | number |
The user to get the seed for |
[callback] | responseHandler |
The callback function |
Lists the seeds that meet the given criteria
Kind: instance method of YOLOdice
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
Options to restrict results | |
[options.user_id] | number |
User ID to restrict seeds to | |
[options.order] | string |
"desc" |
Order, either 'asc' or 'desc' (see listBets) |
[options.id_marker] | string |
id marker (see listBets) | |
[options.limit] | number |
100 |
Limit number of results. Default 100, max 1000 |
[callback] | responseHandler |
The callback function |
Creates a new seed for the user
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
attrs | Object |
The attributes of the new seed |
attrs.client_seed | string |
User provided part of the seed |
[callback] | responseHandler |
The callback function |
Updates and returns the current seed
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The id of the seed to patch |
attrs | Object |
The attributes to change |
attrs.client_seed | string |
The client seed. Must be 6-128 chars and [a-zA-Z0-9 -_] |
[callback] | responseHandler |
The callback function |
<a name="YOLOdice+readConfig>
Gets some data about the site, such as coins and withdraw fees
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[callback] | responseHandler |
The callback function |
Reads the current deposit address for the authenticated user and coin
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
coin | string |
The coin to use |
[callback] | responseHandler |
The callback function |
Lists all user deposit addresses for the given coin
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
coin | string |
The coin to use |
[callback] | responseHandler |
The callback function |
Returns the information for a single deposit
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The id of the deposit |
[callback] | responseHandler |
The callback function |
Lists deposits
Kind: instance method of YOLOdice
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
Options for restricting results | |
[options.order] | string |
"desc" |
Order, either 'asc' or 'desc' (see listBets) |
[options.id_marker] | string |
id marker (see listBets) | |
[options.limit] | number |
100 |
Limit number of results. Default 100, max 1000 |
[callback] | responseHandler |
The callback function |
Contains info about withdrawing
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[callback] | responseHandler |
The callback function |
Reads withdrawal specified by id
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The withdrawal id |
[callback] | responseHandler |
The callback function |
Lists withdrawals for the logged in user
Kind: instance method of YOLOdice
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
Options for restricting results | |
[options.order] | string |
"desc" |
Order, either 'asc' or 'desc' (see listBets) |
[options.id_marker] | string |
id marker (see listBets) | |
[options.limit] | number |
100 |
Limit number of results. Default 100, max 1000 |
[callback] | responseHandler |
The callback function |
Contains info about withdrawing
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[callback] | responseHandler |
The callback function |
Creates a withdrawal. Returns the withdrawal (identical format to readWithdrawal)
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
attrs | Object |
The withdrawal attributes |
attrs.coin | string |
The coin to withdraw |
attrs.to_address | string |
The address to send the coins to |
attrs.amount | number |
The amount to withdrawal IN SATOSHIS |
attrs.withdrawal_type | string |
'instant' or 'batch' |
attrs.allow_pending | boolean |
If there are not enough funds in hot wallet, setting this to true allows the withdrawal to be put into a pending state awaing hot wallet refill |
[callback] | responseHandler |
The callback function |
Can only be used to cancel pending withdrawals
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The id of the withdrawal to cancel |
attrs | Object |
Attributes of the patch |
attrs.status | string |
Can only be 'canceled' |
[callback] | responseHandler |
The callback function |
Wrapper method for patchWithdrawal to cancel withdrawals
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The id of the withdrawal to cancel |
[callback] | responseHandler |
The callback function |
Reads the investment for the given id
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The id of the investment |
[callback] | responseHandler |
The callback function |
Lists investments for the logged in user
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[status] | string |
If status is set to 'open' then will only list open investments |
[callback] | responseHandler |
The callback function |
Creates an investment
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
attrs | Object |
The investment attributes |
coin | string |
The coin to invest |
attrs.base | number |
The initial value of the investment IN SATOSHIS |
leverage | number |
The leverage of the investment, from 1 to 10 |
[callback] | responseHandler |
The callback function |
Patches (closes) an investment
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
id | number |
The id of the investment |
attrs | Object |
The investment patch attributes |
attrs.status | string |
Only 'canceled' value is supported (to cancel the investment) |
[callback] | responseHandler |
The callback function |
Pings the server
Kind: instance method of YOLOdice
Param | Type | Description |
---|---|---|
[callback] | responseHandler |
The callback function |
Error
Kind: event emitted by YOLOdice
Fires when the instance signs a message with it's Bitcoin key
Kind: event emitted by YOLOdice
Fires when the user is successfully logged in
Kind: event emitted by YOLOdice
Callback called when a response is received from the server
Kind: inner typedef of YOLOdice
Param | Type | Description |
---|---|---|
response | Object |
The response received from the server |