Skip to content

Commit

Permalink
Merge pull request #67 from vansergen/getnotionalbalances
Browse files Browse the repository at this point in the history
Getnotionalbalances
  • Loading branch information
vansergen committed Mar 21, 2020
2 parents cd869b7 + d5844e9 commit 33e4bb7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ const account = "primary";
const balances = await client.getAvailableBalances({ account });
```

- [`getNotionalBalances`](https://docs.gemini.com/rest-api/#get-notional-balances)

```typescript
const account = "primary";
const balances = await client.getNotionalBalances({ account });
```

- [`getTransfers`](https://docs.gemini.com/rest-api/#transfers)

```typescript
Expand Down
18 changes: 18 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ export type Balance = {
availableForWithdrawal: string;
};

export type NotionalBalance = {
currency: string;
amount: string;
amountNotional: string;
available: string;
availableNotional: string;
availableForWithdrawal: string;
availableForWithdrawalNotional: string;
};

export type Transfer = {
type: "Deposit" | "Withdrawal";
status: "Advanced" | "Complete";
Expand Down Expand Up @@ -453,6 +463,14 @@ export class AuthenticatedClient extends PublicClient {
return this.post({ body: { request: "/v1/balances", ...body } });
}

/**
* Get the available balances in the supported currencies as well as in notional USD.
*/
getNotionalBalances(body?: AccountName): Promise<NotionalBalance[]> {
const request = "/v1/notionalbalances/usd";
return this.post({ body: { request, ...body } });
}

/**
* Get deposits and withdrawals in the supported currencies.
*/
Expand Down
33 changes: 33 additions & 0 deletions test/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ConfirmClearingOptionsResponse,
Account,
Balance,
NotionalBalance,
Transfer,
DepositAddress,
NewAddress,
Expand Down Expand Up @@ -1036,6 +1037,38 @@ suite("AuthenticatedClient", () => {
assert.deepStrictEqual(data, response);
});

test(".getNotionalBalances()", async () => {
const request = "/v1/notionalbalances/usd";
const account = "primary";
const options = { request, account, nonce };
const response: NotionalBalance[] = [
{
currency: "USD",
amount: "2.911176035",
amountNotional: "2.911176035",
available: "2.911176035",
availableNotional: "2.911176035",
availableForWithdrawal: "2.91",
availableForWithdrawalNotional: "2.91"
},
{
currency: "ETH",
amount: "0.53",
amountNotional: "69.9759",
available: "0.523",
availableNotional: "69.05169",
availableForWithdrawal: "0.523",
availableForWithdrawalNotional: "69.05169"
}
];
nock(ApiUri, { reqheaders: { ...SignRequest({ key, secret, options }) } })
.post(request, {})
.reply(200, response);

const data = await client.getNotionalBalances({ account });
assert.deepStrictEqual(data, response);
});

test(".getTransfers()", async () => {
const request = "/v1/transfers";
const account = "primary";
Expand Down

0 comments on commit 33e4bb7

Please sign in to comment.