Skip to content

Commit

Permalink
Merge pull request #103 from vansergen/payments
Browse files Browse the repository at this point in the history
Add the `getPaymentMethods` method
  • Loading branch information
vansergen committed May 15, 2022
2 parents 2c902f8 + 56dae99 commit 21dc47f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -394,6 +394,13 @@ const result = await client.addBank({
});
```

- [`getPaymentMethods`](https://docs.gemini.com/rest-api/#add-bank)

```typescript
const account = "primary";
const methods = await client.getPaymentMethods({ account });
```

- [`getAccountDetails`](https://docs.gemini.com/rest-api/#account-detail)

```typescript
Expand Down
32 changes: 32 additions & 0 deletions src/auth.ts
Expand Up @@ -334,6 +334,31 @@ export interface AddBankResponse {
referenceId: string;
}

export interface PaymentBalance {
/** Account type. Will always be `exchange`. */
type: "exchange";
/** Symbol for fiat balance. */
currency: "USD";
/** Total account balance for currency. */
amount: string;
/** Total amount available for trading */
available: string;
/** Total amount available for withdrawal */
availableForWithdrawal: string;
}

export interface PaymentBank {
/** Name of bank account */
bank: string;
/** Unique identifier for bank account */
bankId: string;
}

export interface PaymentMethods {
balances: PaymentBalance[];
banks: PaymentBank[];
}

export interface AccountInfo {
name: string;
account: string;
Expand Down Expand Up @@ -614,6 +639,13 @@ export class AuthenticatedClient extends PublicClient {
return this.post<AddBankResponse>(request, {}, body);
}

/** Get data on balances in the account and linked banks */
public getPaymentMethods(account?: AccountName): Promise<PaymentMethods> {
const request = `/v1/payments/methods`;
const body = { request, ...account };
return this.post<PaymentMethods>(request, {}, body);
}

/** Get details about the specific account requested such as users, country codes, etc. */
public getAccountDetails(account?: AccountName): Promise<AccountDetails> {
const request = "/v1/account";
Expand Down
32 changes: 32 additions & 0 deletions test/auth.spec.ts
Expand Up @@ -28,6 +28,7 @@ import {
Withdrawal,
InternalTransferResponse,
AddBankResponse,
PaymentMethods,
AccountInfo,
GUSDWithdrawal,
Heartbeat,
Expand Down Expand Up @@ -1503,6 +1504,37 @@ suite("AuthenticatedClient", () => {
deepStrictEqual(data, response);
});

test(".getPaymentMethods()", async () => {
const request = `/v1/payments/methods`;
const account = "primary";
const options = { request, account, nonce };
const response: PaymentMethods = {
balances: [
{
type: "exchange",
currency: "USD",
amount: "50893484.26",
available: "50889972.01",
availableForWithdrawal: "50889972.01",
},
],
banks: [
{
bank: "Jpmorgan Chase Bank Checking - 1111",
bankId: "97631a24-ca40-4277-b3d5-38c37673d029",
},
],
};
const payload = Buffer.from(JSON.stringify(options)).toString("base64");

nock(ApiUri, { reqheaders: { ...SignRequest({ key, secret, payload }) } })
.post(request)
.reply(200, response);

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

test(".getAccountDetails()", async () => {
const request = "/v1/account";
const account = "primary";
Expand Down
5 changes: 1 addition & 4 deletions test/public.spec.ts
Expand Up @@ -54,10 +54,7 @@ suite("PublicClient", () => {

test(".get() (reject non 2xx responses when no message is provided) ", async () => {
const uri = "/v1/symbols";
const response = {
result: "error",
reason: "RateLimit",
};
const response = { result: "error", reason: "RateLimit" };
nock(ApiUri).get(uri).delay(1).reply(429, response);

await rejects(client.get(uri), new Error(response.reason));
Expand Down

0 comments on commit 21dc47f

Please sign in to comment.