Skip to content

RGBKey/yolodice-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOLOdice-api

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.

YOLOdice ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new YOLOdice()

A class that handles connections to the YOLOdice API.

YOLOdice.YOLOdice

Kind: static class of YOLOdice

new YOLOdice(key, [options])

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)

YOLOdice.send(req, [callback])

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

YOLOdice.sign(msg) ⇒ string

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

YOLOdice.quit()

Gracefully closes the connection and terminates the process

Kind: instance method of YOLOdice

YOLOdice.readSiteData([callback])

Requests site data and calls callback with the data

Kind: instance method of YOLOdice

Param Type Description
[callback] responseHandler The callback function

YOLOdice.readUser(id, [callback])

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

YOLOdice.readUserData(id, [callback])

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

YOLOdice.getBalance([callback])

An abstraction for listUserCoinDatas on yourself

Kind: instance method of YOLOdice

Param Type Description
[callback] responseHandler The callback

YOLOdice.readUserCoinData(id, [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

YOLOdice.listUserCoinDatas(id, [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

YOLOdice.resetSessionCounters([coin], [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

YOLOdice.createBet(attrs, [includeDatas], [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

YOLOdice.readBet(id, [callback])

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

YOLOdice.listBets([userId], [options], [callback])

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

YOLOdice.readSeed(id, [callback])

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

YOLOdice.readCurrentSeed(userId, [callback])

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

YOLOdice.listSeeds([options], [callback])

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

YOLOdice.createSeed(attrs, [callback])

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

YOLOdice.patchSeed(id, attrs, [callback])

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>

YOLOdice.readConfig([callback])

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

YOLOdice.readDepositAddress(coin, [callback])

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

YOLOdice.listDepositAddresses(coin, [callback])

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

YOLOdice.readDeposit(id, [callback])

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

YOLOdice.listDeposits([options], [callback])

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

YOLOdice.readWithdrawingConfig([callback])

Contains info about withdrawing

Kind: instance method of YOLOdice

Param Type Description
[callback] responseHandler The callback function

YOLOdice.readWithdrawal(id, [callback])

Reads withdrawal specified by id

Kind: instance method of YOLOdice

Param Type Description
id number The withdrawal id
[callback] responseHandler The callback function

YOLOdice.listWithdrawals([options], [callback])

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

YOLOdice.readWithdrawalConfig([callback])

Contains info about withdrawing

Kind: instance method of YOLOdice

Param Type Description
[callback] responseHandler The callback function

YOLOdice.createWithdrawal(attrs, [callback])

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

YOLOdice.patchWithdrawal(id, attrs, [callback])

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

YOLOdice.cancelWithdrawal(id, [callback])

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

YOLOdice.readInvestment(id, [callback])

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

YOLOdice.listInvestments([status], [callback])

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

YOLOdice.createInvestment(attrs, coin, leverage, [callback])

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

YOLOdice.patchInvestment(id, attrs, [callback])

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

YOLOdice.ping([callback])

Pings the server

Kind: instance method of YOLOdice

Param Type Description
[callback] responseHandler The callback function

"error"

Error

Kind: event emitted by YOLOdice

"sign"

Fires when the instance signs a message with it's Bitcoin key

Kind: event emitted by YOLOdice

"loggedIn"

Fires when the user is successfully logged in

Kind: event emitted by YOLOdice

YOLOdice~responseHandler : function

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published