1.1.9 • Published 6 years ago

yolodice-api v1.1.9

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

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.

ParamTypeDescription
keystringA WIF format Bitcoin private key used to sign the login request
optionsObjectAn optional object to change some aspects of the server
options.hoststringThe host to connect to (defaults to api.yolodice.com)
options.portnumberThe 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

ParamTypeDescription
reqObjectThe request to send
callbackresponseHandlerAn 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

ParamTypeDescription
msgstringThe 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

ParamTypeDescription
callbackresponseHandlerThe callback function

YOLOdice.readUser(id, callback)

Returns user data including id, name, date created and roles

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe user id to look up
callbackresponseHandlerThe callback function

YOLOdice.readUserData(id, callback)

Returns more extensive user data

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe user id to look up
callbackresponseHandlerThe callback function

YOLOdice.getBalance(callback)

An abstraction for listUserCoinDatas on yourself

Kind: instance method of YOLOdice

ParamTypeDescription
callbackresponseHandlerThe callback

YOLOdice.readUserCoinData(id, callback)

Returns some coin-specific user data

Kind: instance method of YOLOdice

ParamTypeDescription
idstringA string composed of the user id and the coin
callbackresponseHandlerThe callback

YOLOdice.listUserCoinDatas(id, callback)

Returns an array of coin datas for the given user

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe user id
callbackresponseHandlerThe callback

YOLOdice.resetSessionCounters(coin, callback)

Resets session counters, optionally only for a specific coin

Kind: instance method of YOLOdice

ParamTypeDescription
coinstringThe coin to reset
callbackresponseHandlerThe callback

YOLOdice.createBet(attrs, includeDatas, callback)

Creates a bet. Requires the play permission

Kind: instance method of YOLOdice

ParamTypeDescription
attrsObjectBet attributes
attrs.coinstringThe coin to bet with (e.g. 'btc' or 'ltc')
attrs.amountnumberThe amount of the bet IN SATOSHIS
attrs.targetnumberThe target of the bet, in the range 1, 989900
attrs.rangestringEither 'hi' or 'lo'
includeDatasbooleanIf true, the response will include site and user data
callbackresponseHandlerThe callback function

YOLOdice.readBet(id, callback)

Reads the data from a single bet

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe bet id to look up
callbackresponseHandlerThe callback function

YOLOdice.listBets(userId, options, callback)

An array of hashes each containing a single bet

Kind: instance method of YOLOdice

ParamTypeDefaultDescription
userIdnumberThe id of the user
optionsObjectThe options to restrict data
options.user_idnumberThe user ID to restrict bets to
options.orderstring"desc"Either 'asc' or 'desc' to sort in ascending or descending order. Default descending
options.id_markernumberIf order='asc', only bets > idMarker are returned. If order='desc', only bets < idMarker
options.limitnumber100Limit the number of objects returned. Default 100, max 1000
callbackresponseHandlerThe callback function

YOLOdice.readSeed(id, callback)

Reads the attributes of a seed

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe id of the seed
callbackresponseHandlerThe callback function

YOLOdice.readCurrentSeed(userId, callback)

Reads the current seed for the specified user

Kind: instance method of YOLOdice

ParamTypeDescription
userIdnumberThe user to get the seed for
callbackresponseHandlerThe callback function

YOLOdice.listSeeds(options, callback)

Lists the seeds that meet the given criteria

Kind: instance method of YOLOdice

ParamTypeDefaultDescription
optionsObjectOptions to restrict results
options.user_idnumberUser ID to restrict seeds to
options.orderstring"desc"Order, either 'asc' or 'desc' (see listBets)
options.id_markerstringid marker (see listBets)
options.limitnumber100Limit number of results. Default 100, max 1000
callbackresponseHandlerThe callback function

YOLOdice.createSeed(attrs, callback)

Creates a new seed for the user

Kind: instance method of YOLOdice

ParamTypeDescription
attrsObjectThe attributes of the new seed
attrs.client_seedstringUser provided part of the seed
callbackresponseHandlerThe callback function

YOLOdice.patchSeed(id, attrs, callback)

Updates and returns the current seed

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe id of the seed to patch
attrsObjectThe attributes to change
attrs.client_seedstringThe client seed. Must be 6-128 chars and a-zA-Z0-9 -_
callbackresponseHandlerThe 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

ParamTypeDescription
callbackresponseHandlerThe callback function

YOLOdice.readDepositAddress(coin, callback)

Reads the current deposit address for the authenticated user and coin

Kind: instance method of YOLOdice

ParamTypeDescription
coinstringThe coin to use
callbackresponseHandlerThe callback function

YOLOdice.listDepositAddresses(coin, callback)

Lists all user deposit addresses for the given coin

Kind: instance method of YOLOdice

ParamTypeDescription
coinstringThe coin to use
callbackresponseHandlerThe callback function

YOLOdice.readDeposit(id, callback)

Returns the information for a single deposit

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe id of the deposit
callbackresponseHandlerThe callback function

YOLOdice.listDeposits(options, callback)

Lists deposits

Kind: instance method of YOLOdice

ParamTypeDefaultDescription
optionsObjectOptions for restricting results
options.orderstring"desc"Order, either 'asc' or 'desc' (see listBets)
options.id_markerstringid marker (see listBets)
options.limitnumber100Limit number of results. Default 100, max 1000
callbackresponseHandlerThe callback function

YOLOdice.readWithdrawingConfig(callback)

Contains info about withdrawing

Kind: instance method of YOLOdice

ParamTypeDescription
callbackresponseHandlerThe callback function

YOLOdice.readWithdrawal(id, callback)

Reads withdrawal specified by id

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe withdrawal id
callbackresponseHandlerThe callback function

YOLOdice.listWithdrawals(options, callback)

Lists withdrawals for the logged in user

Kind: instance method of YOLOdice

ParamTypeDefaultDescription
optionsObjectOptions for restricting results
options.orderstring"desc"Order, either 'asc' or 'desc' (see listBets)
options.id_markerstringid marker (see listBets)
options.limitnumber100Limit number of results. Default 100, max 1000
callbackresponseHandlerThe callback function

YOLOdice.readWithdrawalConfig(callback)

Contains info about withdrawing

Kind: instance method of YOLOdice

ParamTypeDescription
callbackresponseHandlerThe callback function

YOLOdice.createWithdrawal(attrs, callback)

Creates a withdrawal. Returns the withdrawal (identical format to readWithdrawal)

Kind: instance method of YOLOdice

ParamTypeDescription
attrsObjectThe withdrawal attributes
attrs.coinstringThe coin to withdraw
attrs.to_addressstringThe address to send the coins to
attrs.amountnumberThe amount to withdrawal IN SATOSHIS
attrs.withdrawal_typestring'instant' or 'batch'
attrs.allow_pendingbooleanIf 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
callbackresponseHandlerThe callback function

YOLOdice.patchWithdrawal(id, attrs, callback)

Can only be used to cancel pending withdrawals

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe id of the withdrawal to cancel
attrsObjectAttributes of the patch
attrs.statusstringCan only be 'canceled'
callbackresponseHandlerThe callback function

YOLOdice.cancelWithdrawal(id, callback)

Wrapper method for patchWithdrawal to cancel withdrawals

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe id of the withdrawal to cancel
callbackresponseHandlerThe callback function

YOLOdice.readInvestment(id, callback)

Reads the investment for the given id

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe id of the investment
callbackresponseHandlerThe callback function

YOLOdice.listInvestments(status, callback)

Lists investments for the logged in user

Kind: instance method of YOLOdice

ParamTypeDescription
statusstringIf status is set to 'open' then will only list open investments
callbackresponseHandlerThe callback function

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

Creates an investment

Kind: instance method of YOLOdice

ParamTypeDescription
attrsObjectThe investment attributes
coinstringThe coin to invest
attrs.basenumberThe initial value of the investment IN SATOSHIS
leveragenumberThe leverage of the investment, from 1 to 10
callbackresponseHandlerThe callback function

YOLOdice.patchInvestment(id, attrs, callback)

Patches (closes) an investment

Kind: instance method of YOLOdice

ParamTypeDescription
idnumberThe id of the investment
attrsObjectThe investment patch attributes
attrs.statusstringOnly 'canceled' value is supported (to cancel the investment)
callbackresponseHandlerThe callback function

YOLOdice.ping(callback)

Pings the server

Kind: instance method of YOLOdice

ParamTypeDescription
callbackresponseHandlerThe 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

ParamTypeDescription
responseObjectThe response received from the server
1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago