Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated getTransactions and added getPendingTransactions #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,34 @@ Example:
bitx.getOrder('BXHW6PFRRXKFSB4', function(err, result) {});
```

### getTransactions(asset, [options, ]callback)
GET https://api.mybitx.com/api/1/transactions
### getTransactions(account_id, [options, ]callback)
GET https://api.mybitx.com/api/1/accounts/:id/transactions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same style of placeholder for variables as the rest of the docs i.e. {accountId}.


You can find your account_id by calling the Balances API.

Default options:
```javascript
{
offset: 0,
limit: 10
min_row: 1,
max_row: 100
}
```

Example:

```javascript
bitx.getTransactions('XBT', {offset: 5, limit: 20}, function(err, transactions) {});
bitx.getTransactions('319232323', {min_row: 5, max_row: 20}, function(err, transactions) {});
```

### getPendingTransactions(account_id, callback)
GET https://api.mybitx.com/api/1/accounts/:id/pending

You can find your account_id by calling the Balances API.

Example:

```javascript
bitx.getPendingTransactions('319232323', function(err, pendingTransactions) {});
```

### getWithdrawals(callback)
Expand Down
13 changes: 8 additions & 5 deletions lib/BitX.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,20 @@ BitX.prototype.createFundingAddress = function (asset, callback) {
this._request('POST', 'funding_address', {asset: asset}, callback)
}

BitX.prototype.getTransactions = function (asset, options, callback) {
BitX.prototype.getTransactions = function (account_id, options, callback) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you name the account id parameter using camel case so that it's consistent with the rest of the code like:

function BitX (keyId, keySecret, options) {

And please update the docs to match.

if (typeof options === 'function') {
callback = options
options = null
}
var defaults = {
asset: asset,
offset: 0,
limit: 10
min_row: 1,
max_row: 100
}
this._request('GET', 'transactions', extend(defaults, options), callback)
this._request('GET', 'accounts/' + account_id + '/transactions', extend(defaults, options), callback)
}

BitX.prototype.getPendingTransactions = function (account_id, callback) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above applies here.

this._request('GET', 'accounts/' + account_id + '/pending', null, callback)
}

BitX.prototype.getWithdrawals = function (callback) {
Expand Down
12 changes: 6 additions & 6 deletions test/IntegrationTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,11 @@ tap.test('getTransactions should return the transactions', function (t) {

server.on('request', function (req, res) {
t.equal(req.method, 'GET')
t.equal(req.url, '/api/1/transactions?asset=XBT&offset=0&limit=10')
t.equal(req.url, '/api/1/accounts/1224342323/transactions?min_row=1&max_row=100')
res.end(JSON.stringify(expectedTransactions))
})

bitx.getTransactions('XBT', function (err, transactions) {
bitx.getTransactions('1224342323', function (err, transactions) {
t.ifErr(err)
t.deepEqual(transactions, expectedTransactions)
t.end()
Expand Down Expand Up @@ -625,15 +625,15 @@ tap.test('getTransactions should send options and return the transactions', func

server.on('request', function (req, res) {
t.equal(req.method, 'GET')
t.equal(req.url, '/api/1/transactions?asset=XBT&offset=5&limit=5')
t.equal(req.url, '/api/1/accounts/1224342323/transactions?min_row=5&max_row=5')
res.end(JSON.stringify(expectedTransactions))
})

var options = {
offset: 5,
limit: 5
min_row: 5,
max_row: 5
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use different values for the min and max so that this test will fail if the logic gets accidentaly inverted at some point.

}
bitx.getTransactions('XBT', options, function (err, transactions) {
bitx.getTransactions('1224342323', options, function (err, transactions) {
t.ifErr(err)
t.deepEqual(transactions, expectedTransactions)
t.end()
Expand Down