diff --git a/README.md b/README.md index 9e530eb..4eb4549 100644 --- a/README.md +++ b/README.md @@ -380,6 +380,12 @@ const orderNumber = 1002013188; const offer = await AuthenticatedClient.cancelLoanOffer({ orderNumber }); ``` +- [`getOpenLoanOffers`](https://docs.poloniex.com/?shell#returnopenloanoffers) + +```javascript +const offers = await AuthenticatedClient.getOpenLoanOffers(); +``` + - `post` ```javascript diff --git a/index.d.ts b/index.d.ts index 39365dc..41e13e0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -419,6 +419,21 @@ declare module 'poloniex' { amount?: string; }; + export type LoanOffer = { + id: number; + rate: string; + amount: string; + duration: number; + autoRenew: 0 | 1; + date: string; + }; + + export type LoanOffers = + | { + [currency: string]: LoanOffer[]; + } + | LoanOffer[]; + export type WsRawMessage = Array; export namespace WebsocketMessage { @@ -622,6 +637,8 @@ declare module 'poloniex' { createLoanOffer(options: OfferOptions): Promise; cancelLoanOffer(options: OrderFilter): Promise; + + getOpenLoanOffers(): Promise; } export class WebsocketClient extends EventEmitter { diff --git a/lib/authenticated.js b/lib/authenticated.js index 1880437..9d14282 100644 --- a/lib/authenticated.js +++ b/lib/authenticated.js @@ -554,6 +554,16 @@ class AuthenticatedClient extends PublicClient { return this.post({ command: 'cancelLoanOffer', orderNumber }); } + /** + * @example + * const offers = AuthenticatedClient.getOpenLoanOffers(); + * @see {@link https://docs.poloniex.com/?shell#returnopenloanoffers|returnOpenLoanOffers} + * @description Get your open loan offers for each currency. + */ + getOpenLoanOffers() { + return this.post({ command: 'returnOpenLoanOffers' }); + } + /** * @private * @example diff --git a/tests/authenticated.spec.js b/tests/authenticated.spec.js index a911855..8556e1b 100644 --- a/tests/authenticated.spec.js +++ b/tests/authenticated.spec.js @@ -983,4 +983,34 @@ suite('AuthenticatedClient', () => { }) .catch(error => assert.fail(error)); }); + + test('.getOpenLoanOffers()', done => { + const response = { + BTC: [ + { + id: 1002015083, + rate: '0.01500000', + amount: '0.10000000', + duration: 2, + autoRenew: 0, + date: '2018-10-26 20:26:46', + }, + ], + }; + const nonce = 154264078495300; + authClient.nonce = () => nonce; + + nock(EXCHANGE_API_URL) + .post('/tradingApi', { command: 'returnOpenLoanOffers', nonce }) + .times(1) + .reply(200, response); + + authClient + .getOpenLoanOffers() + .then(data => { + assert.deepEqual(data, response); + done(); + }) + .catch(error => assert.fail(error)); + }); });