Skip to content

Commit

Permalink
fix getBalance(), remove `getTransaction(), add sub-accounts methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dutu committed Dec 2, 2022
1 parent be4c810 commit ce51c84
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 132 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### 2.1.0 (2022-12-01)
### 2.1.0 (2022-12-02)

* add account methods,
* add sub-account methods: `createAccount`, `updateAccountName`, `listAccountPendingTransactions`, `listAccountTransactions`, `listAccountBalances`, `getMove`, `move`, `listMoves`
* fix method `getBalance()` to take optional parameter `asset` as string or array
* remove method `getTransaction()`, which was deprecated
* update tests

### 2.0.1 (2022-07-14)

Expand Down
131 changes: 104 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A simple wrapper for the Luno API. The module supports promise and callbacks.

> This module is forked from https://github.com/bausmeier/node-bitx.
> Since the original repository seems not to be maintained anymore, starting with version v2.0.0 this fork has been detached from original repository. It is now stand alone. Contributions are not pull-requested to original repository.
> Since the original repository is not maintained anymore, starting with version v2.0.0 this fork has been detached from original repository. It is now stand alone. Contributions are not pull-requested to original repository.
## Usage
Add luno as a dependency:
Expand All @@ -13,7 +13,7 @@ $ npm install --save luno-api-node
```


### Luno([keyId, keySecret][options])
### Luno([keyId, keySecret][, options])
To access the private Luno API methods you must supply your key id and key secret as the first two arguments. If you are only accessing the public API endpoints you can leave these two arguments out.

The optional `options` argument can be used to override the default options. The default options are equivalent to:
Expand Down Expand Up @@ -51,10 +51,87 @@ For details about the API endpoints see https://www.luno.com/en/developers/api.
The arguments passed to the callback function for each method are:

1. An error or `null` if no error occurred.
1. An object containing the data returned by the Luno API.
2. An object containing the data returned by the Luno API.

The `callback` function is optional. If the `callback` is not provided, the methods return a promise.

### createAccount(currency, name[, callback])
POST https://api.luno.com/api/1/accounts

Example:

```javascript
luno.createAccount('XBT', 'Trading ACC', function (err, response) {})
```


### updateAccountName(currency, name[, callback])
PUT https://api.luno.com/api/1/accounts/{id}/name

Example:

```javascript
luno.updateAccountName(12345, 'Trading ACC', function (err, response) {})
```


### listAccountPendingTransactions(id[, callback])
GET https://api.luno.com/api/1/accounts/{id}/pending

Example:

```javascript
luno.listAccountPendingTransactions(12345, function (err, response) {})
```


### listAccountTransactions(id, min_row, max_row[, callback])
GET https://api.luno.com/api/1/accounts/{id}/transactions

Example:

```javascript
luno.listAccountTransactions(12345, 1, 1000, function (err, response) {})
```


### listAccountBalances([assets][, callback])
GET https://api.luno.com/api/1/balance

Example:

```javascript
luno.listAccountBalances(['XBT', 'ETH'], function (err, response) {})
```

### getMove([options][, callback])
GET https://api.luno.com/api/exchange/1/move

Example:

```javascript
luno.getMove({ id: 18563829047 }, function (err, response) {})
```

### move(amount, debit_account_id, credit_account_id [,options] [, callback])
POST https://api.luno.com/api/exchange/1/move

Example:

```javascript
luno.move('10000', 12345, 12346, { client_move_id: 'mv-53960812' }, function (err, response) {})
```

### listMoves([options][, callback])
GET https://api.luno.com/api/exchange/1/move/list_moves

Example:

```javascript
luno.listMoves({ before: 1530865703508, limit: 986 }, function (err, response) {})
```


### getTicker([options][, callback])
GET https://api.luno.com/api/1/ticker/XBTZAR

Expand All @@ -69,7 +146,7 @@ Default options:
Example:

```javascript
luno.getTicker(function(err, ticker) {});
luno.getTicker(function (err, ticker) {})
```

### getAllTickers([callback])
Expand All @@ -78,7 +155,7 @@ GET https://api.luno.com/api/1/tickers
Example:

```javascript
luno.getAllTickers(function(err, tickers) {});
luno.getAllTickers(function (err, tickers) {})
```

### getOrderBook([options][, callback])
Expand All @@ -95,7 +172,7 @@ Default options:
Example:

```javascript
luno.getOrderBook(function(err, orderBook) {});
luno.getOrderBook(function (err, orderBook) {})
```

### getTrades([options][, callback])
Expand All @@ -112,7 +189,7 @@ Default options:
Example:

```javascript
luno.getTrades(function(err, trades) {});
luno.getTrades(function (err, trades) {})
```

### getTradeList([options][, callback])
Expand All @@ -129,7 +206,7 @@ Default options:
Example:

```javascript
luno.getTradeList({sort_desc: true, limit: 10}, function(err, tradeList) {});
luno.getTradeList({ sort_desc: true, limit: 10 }, function (err, tradeList) {})
```

### getOrderList([options][, callback])
Expand All @@ -147,7 +224,7 @@ Default options:
Example:

```javascript
luno.getOrderList({state: 'PENDING'}, function(err, orderList) {});
luno.getOrderList({ state: 'PENDING' }, function (err, orderList) {})
```

### getOrderListV2([options][, callback])
Expand All @@ -165,7 +242,7 @@ Default options:
Example:

```javascript
luno.getOrderListV2({ closed: true }, function(err, orderList) {});
luno.getOrderListV2({ closed: true }, function (err, orderList) {})
```

### getOrderListV3(options[, callback])
Expand All @@ -174,7 +251,7 @@ GET https://api.luno.com/api/exchange/3/order
Example:

```javascript
luno.getOrderListV3({id: 'BXMC2CJ7HNB88U4' }, function(err, orderList) {});
luno.getOrderListV3({ id: 'BXMC2CJ7HNB88U4' }, function (err, orderList) {})
```

### getBalance([asset][, callback])
Expand All @@ -183,7 +260,7 @@ GET https://api.luno.com/api/1/balance
Example:

```javascript
luno.getBalance('ZAR', function(err, balance) {});
luno.getBalance('ZAR', function (err, balance) {})
```

### getFundingAddress(asset[, options][, callback])
Expand All @@ -200,7 +277,7 @@ Default options:
Example:

```javascript
luno.getFundingAddress('XBT', {address: 'B1tC0InExAMPL3fundIN6AdDreS5t0Use'}, function(err, fundingAddress) {});
luno.getFundingAddress('XBT', { address: 'B1tC0InExAMPL3fundIN6AdDreS5t0Use' }, function (err, fundingAddress) {})
```

### createFundingAddress(asset[, callback])
Expand All @@ -209,7 +286,7 @@ POST https://api.luno.com/api/1/funding_address
Example:

```javascript
luno.createFundingAddress('XBT', function(err, fundingAddress) {});
luno.createFundingAddress('XBT', function (err, fundingAddress) {})
```

### getFeeInfo([options][, callback])
Expand All @@ -226,7 +303,7 @@ Default options:
Example:

```javascript
luno.getFeeInfo({pair: 'XBTZAR'}, function(err, feeInfo) {});
luno.getFeeInfo({ pair: 'XBTZAR' }, function (err, feeInfo) {})
```

### postBuyOrder(volume, price[, options][, callback])
Expand All @@ -235,7 +312,7 @@ POST https://api.luno.com/api/1/postorder
Example:

```javascript
luno.postBuyOrder(9999.99, 0.01, function(err, order) {});
luno.postBuyOrder(9999.99, 0.01, function (err, order) {})
```

### postSellOrder(volume, price[, options][, callback])
Expand All @@ -244,7 +321,7 @@ POST https://api.luno.com/api/1/postorder
Example:

```javascript
luno.postSellOrder(0.01, 9999.99, function(err, order) {});
luno.postSellOrder(0.01, 9999.99, function (err, order) {})
```

### postMarketBuyOrder(volume[, options][, callback])
Expand All @@ -253,7 +330,7 @@ POST https://api.luno.com/api/1/marketorder
Example:

```javascript
luno.postMarketBuyOrder(0.01, function(err, order) {});
luno.postMarketBuyOrder(0.01, function (err, order) {})
```

### postMarketSellOrder(volume[, options][, callback])
Expand All @@ -262,7 +339,7 @@ POST https://api.luno.com/api/1/marketorder
Example:

```javascript
luno.postMarketSellOrder(0.01, function(err, order) {});
luno.postMarketSellOrder(0.01, function (err, order) {})
```

### stopOrder(orderId[, callback])
Expand All @@ -271,7 +348,7 @@ POST https://api.luno.com/api/1/stoporder
Example:

```javascript
luno.stopOrder('BXMC2CJ7HNB88U4', function(err, result) {});
luno.stopOrder('BXMC2CJ7HNB88U4', function (err, result) {})
```

### getOrder(orderId[, callback])
Expand All @@ -280,7 +357,7 @@ GET https://api.luno.com/api/1/orders/{orderId}
Example:

```javascript
luno.getOrder('BXHW6PFRRXKFSB4', function(err, result) {});
luno.getOrder('BXHW6PFRRXKFSB4', function (err, result) {})
```

### getOrderV2(orderId[, callback])
Expand All @@ -289,7 +366,7 @@ GET https://api.luno.com/api/exchange/2/orders/{orderId}
Example:

```javascript
luno.getOrder('BXHW6PFRRXKFSB4', function(err, result) {});
luno.getOrder('BXHW6PFRRXKFSB4', function (err, result) {})
```

### getTransactions(asset[, options][, callback])
Expand All @@ -306,7 +383,7 @@ Default options:
Example:

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

### getWithdrawals([callback])
Expand All @@ -315,7 +392,7 @@ GET https://api.luno.com/api/1/withdrawals
Example:

```javascript
luno.getWithdrawals(function(err, withdrawals) {});
luno.getWithdrawals(function (err, withdrawals) {})
```

### getWithdrawal(withdrawalId[, callback])
Expand All @@ -324,7 +401,7 @@ GET https://api.luno.com/api/1/withdrawals/{withdrawalId}
Example:

```javascript
luno.getWithdrawal('1212', function(err, withdrawal) {});
luno.getWithdrawal('1212', function (err, withdrawal) {})
```

### requestWithdrawal(type, amount[, callback])
Expand All @@ -333,7 +410,7 @@ POST https://api.luno.com/api/1/withdrawals
Example:

```javascript
luno.requestWithdrawal('ZAR_EFT', 1000, function(err, withdrawal) {});
luno.requestWithdrawal('ZAR_EFT', 1000, function (err, withdrawal) {})
```

### cancelWithdrawal(withdrawalId[, callback])
Expand All @@ -342,7 +419,7 @@ DELETE https://api.luno.com/api/1/withdrawals/{withdrawalId}
Example:

```javascript
luno.cancelWithdrawal('1212', function(err, withdrawal) {});
luno.cancelWithdrawal('1212', function (err, withdrawal) {})
```

## Contributing
Expand Down
24 changes: 14 additions & 10 deletions lib/luno.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,17 @@ Luno.prototype.postSellOrder = function (volume, price, options, callback) {
Luno.prototype.postMarketOrder = function (type, volume, options, callback) {
let [params, cb] = defaults({
type,
base_volume: volume,
pair: this.pair,
}, options, callback)

if (type === 'SELL') {
params.base_volume = volume
}

if (type === 'BUY') {
params.counter_volume = volume
}

return this._request('POST', '/api/1/marketorder', params, cb)
}

Expand Down Expand Up @@ -366,6 +373,7 @@ Luno.prototype.getOrderV3 = function (options, callback) {

Luno.prototype.getBalance = function (asset, callback) {
let params = null
let cb = callback
if (typeof asset === 'string') {
params = { assets: [asset] }
}
Expand All @@ -374,7 +382,11 @@ Luno.prototype.getBalance = function (asset, callback) {
params = { assets: asset }
}

return this._request('GET', `/api/1/balance`, params, callback)
if (typeof asset === 'function') {
cb = asset
}

return this._request('GET', `/api/1/balance`, params, cb)
}

Luno.prototype.getFundingAddress = function (asset, options, callback) {
Expand All @@ -389,14 +401,6 @@ Luno.prototype.createFundingAddress = function (asset, callback) {
return this._request('POST', '/api/1/funding_address', { asset }, callback)
}

Luno.prototype.getTransactions = function (asset, options, callback) {
let [params, cb] = defaults({
asset,
}, options, callback)

return this._request('GET', '/api/1/transactions', params, cb)
}

Luno.prototype.getWithdrawals = function (callback) {
return this._request('GET', '/api/1/withdrawals/', null, callback)
}
Expand Down
Loading

0 comments on commit ce51c84

Please sign in to comment.