Skip to content

Commit

Permalink
Merge pull request #30 from vansergen/getoffers
Browse files Browse the repository at this point in the history
Add getOpenLoanOffers method
  • Loading branch information
vansergen authored Jul 3, 2019
2 parents e4bb0f5 + 45b2304 commit 88676c1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;

export namespace WebsocketMessage {
Expand Down Expand Up @@ -622,6 +637,8 @@ declare module 'poloniex' {
createLoanOffer(options: OfferOptions): Promise<OfferResult>;

cancelLoanOffer(options: OrderFilter): Promise<CancelLoanResponse>;

getOpenLoanOffers(): Promise<LoanOffers>;
}

export class WebsocketClient extends EventEmitter {
Expand Down
10 changes: 10 additions & 0 deletions lib/authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions tests/authenticated.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});

0 comments on commit 88676c1

Please sign in to comment.