Skip to content

Commit

Permalink
Merge pull request #102 from vansergen/bank
Browse files Browse the repository at this point in the history
Add the `.addBank()` method
  • Loading branch information
vansergen committed May 15, 2022
2 parents 3c3538a + f445a41 commit 6529f98
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 10 deletions.
22 changes: 21 additions & 1 deletion README.md
Expand Up @@ -184,7 +184,12 @@ const response = await client.cancelAll({ account });
```typescript
const order_id = 44375901;
const account = "primary";
const order = await client.getOrderStatus({ order_id, account });
const include_trades = true;
const order = await client.getOrderStatus({
order_id,
account,
include_trades,
});
```

- [`getActiveOrders`](https://docs.gemini.com/rest-api/#get-active-orders)
Expand Down Expand Up @@ -374,6 +379,21 @@ const transfer = await client.internalTransfer({
});
```

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

```typescript
const accountnumber = "account-number-string";
const routing = "routing-number-string";
const type = "checking";
const name = "Satoshi Nakamoto Checking";
const result = await client.addBank({
accountnumber,
routing,
type,
name,
});
```

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

```typescript
Expand Down
26 changes: 26 additions & 0 deletions src/auth.ts
Expand Up @@ -36,6 +36,8 @@ export interface OrderOptions extends BasicOrderOptions {

export interface OrderID extends AccountName {
order_id: number;
client_order_id?: string;
include_trades?: boolean;
}

export type PastTradesFilter = SymbolFilter & {
Expand Down Expand Up @@ -103,6 +105,17 @@ export interface InternalTransferFilter {
amount: number;
}

export interface AddBankOptions extends AccountName {
/** Account number of bank account to be added */
accountnumber: string;
/** Routing number of bank account to be added */
routing: string;
/** Type of bank account to be added */
type: "checking" | "savings";
/** The name of the bank account as shown on your account statements */
name: string;
}

export interface AccountDetails {
account: {
accountName: string;
Expand Down Expand Up @@ -161,6 +174,7 @@ export interface OrderStatus extends BaseOrder {
type: OrderType;
options: [OrderEexecutionOptions] | [];
reason?: string;
trades?: PastTrade[];
was_forced: boolean;
stop_price?: string;
}
Expand Down Expand Up @@ -315,6 +329,11 @@ export interface InternalTransferResponse {
uuid: string;
}

export interface AddBankResponse {
/** Reference ID for the new bank addition request. Once received, send in a wire from the requested bank account to verify it and enable withdrawals to that account. */
referenceId: string;
}

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

/** The add bank API allows for banking information to be sent in via API. However, for the bank to be verified, you must still send in a wire for any amount from the bank account. */
public addBank(bank: AddBankOptions): Promise<AddBankResponse> {
const request = `/v1/payments/addbank`;
const body = { request, ...bank };
return this.post<AddBankResponse>(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
12 changes: 3 additions & 9 deletions src/public.ts
Expand Up @@ -180,23 +180,17 @@ export class PublicClient extends FetchClient<unknown> {
});
}

/**
* Get all available symbols for trading.
*/
/** Get all available symbols for trading. */
public getSymbols(): Promise<string[]> {
return this.get<string[]>("v1/symbols");
}

/**
* Get extra details about the symbol.
*/
/** Get extra details about the symbol. */
public getSymbol({ symbol }: { symbol: string }): Promise<ISymbol> {
return this.get<ISymbol>(`v1/symbols/details/${symbol}`);
}

/**
* Get information about recent trading activity for the symbol.
*/
/** Get information about recent trading activity for the symbol. */
public getTicker(options: { symbol?: string; v: "v2" }): Promise<TickerV2>;
public getTicker(options?: { symbol?: string; v?: "v1" }): Promise<TickerV1>;
public getTicker({
Expand Down
87 changes: 87 additions & 0 deletions test/auth.spec.ts
Expand Up @@ -27,6 +27,7 @@ import {
NewAddress,
Withdrawal,
InternalTransferResponse,
AddBankResponse,
AccountInfo,
GUSDWithdrawal,
Heartbeat,
Expand Down Expand Up @@ -468,6 +469,60 @@ suite("AuthenticatedClient", () => {
deepStrictEqual(data, response);
});

test(".getOrderStatus() (include trades)", async () => {
const request = "/v1/order/status";
const account = "primary";
const order_id = 17379712927;
const include_trades = true;
const options = { request, order_id, account, include_trades, nonce };
const response: OrderStatus = {
avg_execution_price: "22728.94",
exchange: "gemini",
executed_amount: "0.0219983861",
id: "17379712927",
is_cancelled: false,
is_hidden: false,
is_live: false,
options: [],
order_id: "17379712927",
remaining_amount: "0",
side: "buy",
symbol: "btcusd",
timestamp: "1608229172",
timestampms: 1608229172627,
trades: [
{
aggressor: true,
amount: "0.0219983861",
exchange: "gemini",
fee_amount: "0.00",
fee_currency: "USD",
is_auction_fill: false,
order_id: "17379712927",
price: "22728.94",
tid: 17379712930,
timestamp: 1608229172,
timestampms: 1608229172627,
type: "Buy",
},
],
type: "market buy",
was_forced: false,
};
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.getOrderStatus({
order_id,
account,
include_trades,
});
deepStrictEqual(data, response);
});

test(".getActiveOrders()", async () => {
const request = "/v1/orders";
const account = "primary";
Expand Down Expand Up @@ -1416,6 +1471,38 @@ suite("AuthenticatedClient", () => {
deepStrictEqual(data, response);
});

test(".addBank()", async () => {
const request = `/v1/payments/addbank`;
const accountnumber = "account-number-string";
const routing = "routing-number-string";
const type = "checking";
const name = "Satoshi Nakamoto Checking";
const options = {
request,
accountnumber,
routing,
type,
name,
nonce,
};
const response: AddBankResponse = {
referenceId: "BankAccountRefId(18428)",
};
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.addBank({
accountnumber,
routing,
type,
name,
});
deepStrictEqual(data, response);
});

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

0 comments on commit 6529f98

Please sign in to comment.