Skip to content

Commit ce51c84

Browse files
committed
fix getBalance(), remove `getTransaction(), add sub-accounts methods
1 parent be4c810 commit ce51c84

File tree

7 files changed

+129
-132
lines changed

7 files changed

+129
-132
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
### 2.1.0 (2022-12-01)
1+
### 2.1.0 (2022-12-02)
22

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

58
### 2.0.1 (2022-07-14)
69

README.md

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A simple wrapper for the Luno API. The module supports promise and callbacks.
44

55
> This module is forked from https://github.com/bausmeier/node-bitx.
6-
> 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.
6+
> 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.
77
88
## Usage
99
Add luno as a dependency:
@@ -13,7 +13,7 @@ $ npm install --save luno-api-node
1313
```
1414

1515

16-
### Luno([keyId, keySecret][options])
16+
### Luno([keyId, keySecret][, options])
1717
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.
1818

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

5353
1. An error or `null` if no error occurred.
54-
1. An object containing the data returned by the Luno API.
54+
2. An object containing the data returned by the Luno API.
5555

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

58+
### createAccount(currency, name[, callback])
59+
POST https://api.luno.com/api/1/accounts
60+
61+
Example:
62+
63+
```javascript
64+
luno.createAccount('XBT', 'Trading ACC', function (err, response) {})
65+
```
66+
67+
68+
### updateAccountName(currency, name[, callback])
69+
PUT https://api.luno.com/api/1/accounts/{id}/name
70+
71+
Example:
72+
73+
```javascript
74+
luno.updateAccountName(12345, 'Trading ACC', function (err, response) {})
75+
```
76+
77+
78+
### listAccountPendingTransactions(id[, callback])
79+
GET https://api.luno.com/api/1/accounts/{id}/pending
80+
81+
Example:
82+
83+
```javascript
84+
luno.listAccountPendingTransactions(12345, function (err, response) {})
85+
```
86+
87+
88+
### listAccountTransactions(id, min_row, max_row[, callback])
89+
GET https://api.luno.com/api/1/accounts/{id}/transactions
90+
91+
Example:
92+
93+
```javascript
94+
luno.listAccountTransactions(12345, 1, 1000, function (err, response) {})
95+
```
96+
97+
98+
### listAccountBalances([assets][, callback])
99+
GET https://api.luno.com/api/1/balance
100+
101+
Example:
102+
103+
```javascript
104+
luno.listAccountBalances(['XBT', 'ETH'], function (err, response) {})
105+
```
106+
107+
### getMove([options][, callback])
108+
GET https://api.luno.com/api/exchange/1/move
109+
110+
Example:
111+
112+
```javascript
113+
luno.getMove({ id: 18563829047 }, function (err, response) {})
114+
```
115+
116+
### move(amount, debit_account_id, credit_account_id [,options] [, callback])
117+
POST https://api.luno.com/api/exchange/1/move
118+
119+
Example:
120+
121+
```javascript
122+
luno.move('10000', 12345, 12346, { client_move_id: 'mv-53960812' }, function (err, response) {})
123+
```
124+
125+
### listMoves([options][, callback])
126+
GET https://api.luno.com/api/exchange/1/move/list_moves
127+
128+
Example:
129+
130+
```javascript
131+
luno.listMoves({ before: 1530865703508, limit: 986 }, function (err, response) {})
132+
```
133+
134+
58135
### getTicker([options][, callback])
59136
GET https://api.luno.com/api/1/ticker/XBTZAR
60137

@@ -69,7 +146,7 @@ Default options:
69146
Example:
70147

71148
```javascript
72-
luno.getTicker(function(err, ticker) {});
149+
luno.getTicker(function (err, ticker) {})
73150
```
74151

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

80157
```javascript
81-
luno.getAllTickers(function(err, tickers) {});
158+
luno.getAllTickers(function (err, tickers) {})
82159
```
83160

84161
### getOrderBook([options][, callback])
@@ -95,7 +172,7 @@ Default options:
95172
Example:
96173

97174
```javascript
98-
luno.getOrderBook(function(err, orderBook) {});
175+
luno.getOrderBook(function (err, orderBook) {})
99176
```
100177

101178
### getTrades([options][, callback])
@@ -112,7 +189,7 @@ Default options:
112189
Example:
113190

114191
```javascript
115-
luno.getTrades(function(err, trades) {});
192+
luno.getTrades(function (err, trades) {})
116193
```
117194

118195
### getTradeList([options][, callback])
@@ -129,7 +206,7 @@ Default options:
129206
Example:
130207

131208
```javascript
132-
luno.getTradeList({sort_desc: true, limit: 10}, function(err, tradeList) {});
209+
luno.getTradeList({ sort_desc: true, limit: 10 }, function (err, tradeList) {})
133210
```
134211

135212
### getOrderList([options][, callback])
@@ -147,7 +224,7 @@ Default options:
147224
Example:
148225

149226
```javascript
150-
luno.getOrderList({state: 'PENDING'}, function(err, orderList) {});
227+
luno.getOrderList({ state: 'PENDING' }, function (err, orderList) {})
151228
```
152229

153230
### getOrderListV2([options][, callback])
@@ -165,7 +242,7 @@ Default options:
165242
Example:
166243

167244
```javascript
168-
luno.getOrderListV2({ closed: true }, function(err, orderList) {});
245+
luno.getOrderListV2({ closed: true }, function (err, orderList) {})
169246
```
170247

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

176253
```javascript
177-
luno.getOrderListV3({id: 'BXMC2CJ7HNB88U4' }, function(err, orderList) {});
254+
luno.getOrderListV3({ id: 'BXMC2CJ7HNB88U4' }, function (err, orderList) {})
178255
```
179256

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

185262
```javascript
186-
luno.getBalance('ZAR', function(err, balance) {});
263+
luno.getBalance('ZAR', function (err, balance) {})
187264
```
188265

189266
### getFundingAddress(asset[, options][, callback])
@@ -200,7 +277,7 @@ Default options:
200277
Example:
201278

202279
```javascript
203-
luno.getFundingAddress('XBT', {address: 'B1tC0InExAMPL3fundIN6AdDreS5t0Use'}, function(err, fundingAddress) {});
280+
luno.getFundingAddress('XBT', { address: 'B1tC0InExAMPL3fundIN6AdDreS5t0Use' }, function (err, fundingAddress) {})
204281
```
205282

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

211288
```javascript
212-
luno.createFundingAddress('XBT', function(err, fundingAddress) {});
289+
luno.createFundingAddress('XBT', function (err, fundingAddress) {})
213290
```
214291

215292
### getFeeInfo([options][, callback])
@@ -226,7 +303,7 @@ Default options:
226303
Example:
227304

228305
```javascript
229-
luno.getFeeInfo({pair: 'XBTZAR'}, function(err, feeInfo) {});
306+
luno.getFeeInfo({ pair: 'XBTZAR' }, function (err, feeInfo) {})
230307
```
231308

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

237314
```javascript
238-
luno.postBuyOrder(9999.99, 0.01, function(err, order) {});
315+
luno.postBuyOrder(9999.99, 0.01, function (err, order) {})
239316
```
240317

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

246323
```javascript
247-
luno.postSellOrder(0.01, 9999.99, function(err, order) {});
324+
luno.postSellOrder(0.01, 9999.99, function (err, order) {})
248325
```
249326

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

255332
```javascript
256-
luno.postMarketBuyOrder(0.01, function(err, order) {});
333+
luno.postMarketBuyOrder(0.01, function (err, order) {})
257334
```
258335

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

264341
```javascript
265-
luno.postMarketSellOrder(0.01, function(err, order) {});
342+
luno.postMarketSellOrder(0.01, function (err, order) {})
266343
```
267344

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

273350
```javascript
274-
luno.stopOrder('BXMC2CJ7HNB88U4', function(err, result) {});
351+
luno.stopOrder('BXMC2CJ7HNB88U4', function (err, result) {})
275352
```
276353

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

282359
```javascript
283-
luno.getOrder('BXHW6PFRRXKFSB4', function(err, result) {});
360+
luno.getOrder('BXHW6PFRRXKFSB4', function (err, result) {})
284361
```
285362

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

291368
```javascript
292-
luno.getOrder('BXHW6PFRRXKFSB4', function(err, result) {});
369+
luno.getOrder('BXHW6PFRRXKFSB4', function (err, result) {})
293370
```
294371

295372
### getTransactions(asset[, options][, callback])
@@ -306,7 +383,7 @@ Default options:
306383
Example:
307384

308385
```javascript
309-
luno.getTransactions('XBT', {offset: 5, limit: 20}, function(err, transactions) {});
386+
luno.getTransactions('XBT', { offset: 5, limit: 20 }, function (err, transactions) {})
310387
```
311388

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

317394
```javascript
318-
luno.getWithdrawals(function(err, withdrawals) {});
395+
luno.getWithdrawals(function (err, withdrawals) {})
319396
```
320397

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

326403
```javascript
327-
luno.getWithdrawal('1212', function(err, withdrawal) {});
404+
luno.getWithdrawal('1212', function (err, withdrawal) {})
328405
```
329406

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

335412
```javascript
336-
luno.requestWithdrawal('ZAR_EFT', 1000, function(err, withdrawal) {});
413+
luno.requestWithdrawal('ZAR_EFT', 1000, function (err, withdrawal) {})
337414
```
338415

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

344421
```javascript
345-
luno.cancelWithdrawal('1212', function(err, withdrawal) {});
422+
luno.cancelWithdrawal('1212', function (err, withdrawal) {})
346423
```
347424

348425
## Contributing

lib/luno.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,17 @@ Luno.prototype.postSellOrder = function (volume, price, options, callback) {
335335
Luno.prototype.postMarketOrder = function (type, volume, options, callback) {
336336
let [params, cb] = defaults({
337337
type,
338-
base_volume: volume,
339338
pair: this.pair,
340339
}, options, callback)
341340

341+
if (type === 'SELL') {
342+
params.base_volume = volume
343+
}
344+
345+
if (type === 'BUY') {
346+
params.counter_volume = volume
347+
}
348+
342349
return this._request('POST', '/api/1/marketorder', params, cb)
343350
}
344351

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

367374
Luno.prototype.getBalance = function (asset, callback) {
368375
let params = null
376+
let cb = callback
369377
if (typeof asset === 'string') {
370378
params = { assets: [asset] }
371379
}
@@ -374,7 +382,11 @@ Luno.prototype.getBalance = function (asset, callback) {
374382
params = { assets: asset }
375383
}
376384

377-
return this._request('GET', `/api/1/balance`, params, callback)
385+
if (typeof asset === 'function') {
386+
cb = asset
387+
}
388+
389+
return this._request('GET', `/api/1/balance`, params, cb)
378390
}
379391

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

392-
Luno.prototype.getTransactions = function (asset, options, callback) {
393-
let [params, cb] = defaults({
394-
asset,
395-
}, options, callback)
396-
397-
return this._request('GET', '/api/1/transactions', params, cb)
398-
}
399-
400404
Luno.prototype.getWithdrawals = function (callback) {
401405
return this._request('GET', '/api/1/withdrawals/', null, callback)
402406
}

0 commit comments

Comments
 (0)