diff --git a/src/CBAdvancedTradeClient.ts b/src/CBAdvancedTradeClient.ts index 701c53a..918f2b9 100644 --- a/src/CBAdvancedTradeClient.ts +++ b/src/CBAdvancedTradeClient.ts @@ -1,5 +1,4 @@ import { AxiosRequestConfig } from 'axios'; -import { nanoid } from 'nanoid'; import { BaseRestClient } from './lib/BaseRestClient.js'; import { @@ -9,6 +8,7 @@ import { } from './lib/requestUtils.js'; import { AllocateAdvTradePortfolioRequest, + CloseAdvTradePositionRequest, GetAdvTradeFillsRequest, GetAdvTradeMarketTradesRequest, GetAdvTradeOrdersRequest, @@ -71,16 +71,6 @@ export class CBAdvancedTradeClient extends BaseRestClient { return REST_CLIENT_TYPE_ENUM.advancedTrade; } - /** - * - * Misc Utility Methods - * - */ - - generateNewOrderID(): string { - return nanoid(32); - } - /** * * Account Endpoints @@ -342,13 +332,10 @@ export class CBAdvancedTradeClient extends BaseRestClient { * Places an order to close any open positions for a specified product_id. * */ - closePosition(params: { - // TODO: extract type - client_order_id: string; - product_id: string; - size?: string; - }): Promise { - this.validateOrderId(params as any, 'client_order_id'); + closePosition( + params: CloseAdvTradePositionRequest, + ): Promise { + this.validateOrderId(params, 'client_order_id'); return this.postPrivate(`/api/v3/brokerage/orders/close_position`, { body: params, }); diff --git a/src/CBAppClient.ts b/src/CBAppClient.ts index 6dd72a0..9207d63 100644 --- a/src/CBAppClient.ts +++ b/src/CBAppClient.ts @@ -1,5 +1,4 @@ import { AxiosRequestConfig } from 'axios'; -import { nanoid } from 'nanoid'; import { BaseRestClient } from './lib/BaseRestClient.js'; import { @@ -38,16 +37,6 @@ export class CBAppClient extends BaseRestClient { return REST_CLIENT_TYPE_ENUM.coinbaseApp; } - /** - * - * Misc Utility Methods - * - */ - - generateNewOrderID(): string { - return nanoid(32); - } - /** * * Account Endpoints diff --git a/src/CBExchangeClient.ts b/src/CBExchangeClient.ts index 0019ac2..336281d 100644 --- a/src/CBExchangeClient.ts +++ b/src/CBExchangeClient.ts @@ -1,5 +1,4 @@ import { AxiosRequestConfig } from 'axios'; -import { nanoid } from 'nanoid'; import { BaseRestClient } from './lib/BaseRestClient.js'; import { @@ -56,16 +55,6 @@ export class CBExchangeClient extends BaseRestClient { return REST_CLIENT_TYPE_ENUM.exchange; } - /** - * - * Misc Utility Methods - * - */ - - generateNewOrderID(): string { - return nanoid(32); - } - /** * * Accounts Endpoints diff --git a/src/CBInternationalClient.ts b/src/CBInternationalClient.ts index 48a6ac5..a2c4b98 100644 --- a/src/CBInternationalClient.ts +++ b/src/CBInternationalClient.ts @@ -1,5 +1,4 @@ import { AxiosRequestConfig } from 'axios'; -import { nanoid } from 'nanoid'; import { BaseRestClient } from './lib/BaseRestClient.js'; import { @@ -41,16 +40,6 @@ export class CBInternationalClient extends BaseRestClient { return REST_CLIENT_TYPE_ENUM.international; } - /** - * - * Misc Utility Methods - * - */ - - generateNewOrderID(): string { - return nanoid(32); - } - /** * * Assets Endpoints diff --git a/src/CBPrimeClient.ts b/src/CBPrimeClient.ts index 534c6a4..083c49a 100644 --- a/src/CBPrimeClient.ts +++ b/src/CBPrimeClient.ts @@ -1,5 +1,4 @@ import { AxiosRequestConfig } from 'axios'; -import { nanoid } from 'nanoid'; import { BaseRestClient } from './lib/BaseRestClient.js'; import { @@ -51,16 +50,6 @@ export class CBPrimeClient extends BaseRestClient { return REST_CLIENT_TYPE_ENUM.prime; } - /** - * - * Misc Utility Methods - * - */ - - generateNewOrderID(): string { - return nanoid(32); - } - /** * * Allocation Endpoints diff --git a/src/lib/BaseRestClient.ts b/src/lib/BaseRestClient.ts index a4c8cb2..3777c37 100644 --- a/src/lib/BaseRestClient.ts +++ b/src/lib/BaseRestClient.ts @@ -3,7 +3,10 @@ import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; import https from 'https'; import { nanoid } from 'nanoid'; -import { SubmitAdvTradeOrderRequest } from '../types/request/advanced-trade-client.js'; +import { + CloseAdvTradePositionRequest, + SubmitAdvTradeOrderRequest, +} from '../types/request/advanced-trade-client.js'; import { CustomOrderIdProperty } from '../types/shared.types.js'; import { signJWT } from './jwtNode.js'; import { neverGuard } from './misc-util.js'; @@ -268,7 +271,7 @@ export abstract class BaseRestClient { * Validate syntax meets requirements set by binance. Log warning if not. */ protected validateOrderId( - params: SubmitAdvTradeOrderRequest, + params: SubmitAdvTradeOrderRequest | CloseAdvTradePositionRequest, orderIdProperty: CustomOrderIdProperty, ): void { if (!params[orderIdProperty]) { diff --git a/src/types/request/advanced-trade-client.ts b/src/types/request/advanced-trade-client.ts index 01ff6ca..729b60b 100644 --- a/src/types/request/advanced-trade-client.ts +++ b/src/types/request/advanced-trade-client.ts @@ -63,7 +63,8 @@ export interface GetAdvTradeMarketTradesRequest { /** * Note: client_order_id is optional, because the SDK will automatically generate a value for you during the request. * - * If you are generating your own, make sure you either use the client.generateNewOrderId() method or make sure to prefix your value with "cbnode". The SDK will automatically do this, if the prefix is missing. + * If you are generating your own, make sure you either use the client.generateNewOrderId() method or make sure to prefix your value with "cbnode". + * The SDK will automatically add the prefix if the prefix is missing. */ export interface SubmitAdvTradeOrderRequest { client_order_id?: string; @@ -123,6 +124,18 @@ export interface PreviewAdvTradeOrderRequest { retail_portfolio_id?: string; } +/** + * Note: client_order_id is optional, because the SDK will automatically generate a value for you during the request. + * + * If you are generating your own, make sure you either use the client.generateNewOrderId() method or make sure to prefix your value with "cbnode". + * The SDK will automatically add the prefix if the prefix is missing. + */ +export interface CloseAdvTradePositionRequest { + client_order_id?: string; + product_id: string; + size?: string; +} + /** * * Portfolios Endpoints