diff --git a/README.md b/README.md index c748480..05ff911 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/src/auth.ts b/src/auth.ts index 21d3806..289efa0 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -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 & { @@ -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; @@ -161,6 +174,7 @@ export interface OrderStatus extends BaseOrder { type: OrderType; options: [OrderEexecutionOptions] | []; reason?: string; + trades?: PastTrade[]; was_forced: boolean; stop_price?: string; } @@ -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; @@ -588,6 +607,13 @@ export class AuthenticatedClient extends PublicClient { return this.post(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 { + const request = `/v1/payments/addbank`; + const body = { request, ...bank }; + return this.post(request, {}, body); + } + /** Get details about the specific account requested such as users, country codes, etc. */ public getAccountDetails(account?: AccountName): Promise { const request = "/v1/account"; diff --git a/src/public.ts b/src/public.ts index 7f245fc..57b111d 100644 --- a/src/public.ts +++ b/src/public.ts @@ -180,23 +180,17 @@ export class PublicClient extends FetchClient { }); } - /** - * Get all available symbols for trading. - */ + /** Get all available symbols for trading. */ public getSymbols(): Promise { return this.get("v1/symbols"); } - /** - * Get extra details about the symbol. - */ + /** Get extra details about the symbol. */ public getSymbol({ symbol }: { symbol: string }): Promise { return this.get(`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; public getTicker(options?: { symbol?: string; v?: "v1" }): Promise; public getTicker({ diff --git a/test/auth.spec.ts b/test/auth.spec.ts index f5d4caf..47115c2 100644 --- a/test/auth.spec.ts +++ b/test/auth.spec.ts @@ -27,6 +27,7 @@ import { NewAddress, Withdrawal, InternalTransferResponse, + AddBankResponse, AccountInfo, GUSDWithdrawal, Heartbeat, @@ -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"; @@ -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";