From 8805dae9441e4fc954daff46ec80160a11d4394e Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Fri, 13 Sep 2024 15:39:13 +0100 Subject: [PATCH 1/5] chore(): extract order types --- src/AdvancedTradeClient.ts | 10 ++++------ src/types/request/advanced-trade-client.ts | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/AdvancedTradeClient.ts b/src/AdvancedTradeClient.ts index 2a1ab23..85f59dd 100644 --- a/src/AdvancedTradeClient.ts +++ b/src/AdvancedTradeClient.ts @@ -9,6 +9,7 @@ import { } from './lib/requestUtils.js'; import { AllocateAdvTradePortfolioRequest, + CloseAdvTradePositionRequest, GetAdvTradeFillsRequest, GetAdvTradeMarketTradesRequest, GetAdvTradeOrdersRequest, @@ -342,12 +343,9 @@ export class AdvancedTradeClient 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 { + closePosition( + params: CloseAdvTradePositionRequest, + ): Promise { this.validateOrderId(params as any, 'client_order_id'); return this.postPrivate(`/api/v3/brokerage/orders/close_position`, { body: params, 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 From 995599797dc18b26f6cd471ab7dac92b2a1e13a2 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Fri, 13 Sep 2024 16:09:09 +0100 Subject: [PATCH 2/5] chore(): rename client --- src/{AdvancedTradeClient.ts => CBAdvancedTradeClient.ts} | 0 src/WebsocketClient.ts | 2 +- src/index.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{AdvancedTradeClient.ts => CBAdvancedTradeClient.ts} (100%) diff --git a/src/AdvancedTradeClient.ts b/src/CBAdvancedTradeClient.ts similarity index 100% rename from src/AdvancedTradeClient.ts rename to src/CBAdvancedTradeClient.ts diff --git a/src/WebsocketClient.ts b/src/WebsocketClient.ts index 7116851..674b7de 100644 --- a/src/WebsocketClient.ts +++ b/src/WebsocketClient.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { AdvancedTradeClient } from './AdvancedTradeClient.js'; +import { AdvancedTradeClient } from './CBAdvancedTradeClient.js'; import { BaseWebsocketClient, EmittableEvent } from './lib/BaseWSClient.js'; import { neverGuard } from './lib/misc-util.js'; import { diff --git a/src/index.ts b/src/index.ts index 1ed6252..5bc5457 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export * from './AdvancedTradeClient.js'; +export * from './CBAdvancedTradeClient.js'; export * from './CoinbaseAppClient.js'; export * from './CoinbaseInternational.js'; export * from './CoinbasePrime.js'; From 643a31b5d5f32b81af3957e15cf6f9a7bc495a5f Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Fri, 13 Sep 2024 16:11:29 +0100 Subject: [PATCH 3/5] chore(): add order type --- src/lib/BaseRestClient.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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]) { From 8c60a03d6c5c86c6af7bb0ebc5c6ae4a0bd2ff0b Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Fri, 13 Sep 2024 16:24:09 +0100 Subject: [PATCH 4/5] chore(): remove redundant methods --- src/CBAdvancedTradeClient.ts | 11 ----------- src/CBAppClient.ts | 11 ----------- src/CBExchangeClient.ts | 11 ----------- src/CBInternationalClient.ts | 11 ----------- src/CBPrimeClient.ts | 11 ----------- 5 files changed, 55 deletions(-) diff --git a/src/CBAdvancedTradeClient.ts b/src/CBAdvancedTradeClient.ts index e851d32..8c77ce1 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 { @@ -72,16 +71,6 @@ export class CBAdvancedTradeClient extends BaseRestClient { return REST_CLIENT_TYPE_ENUM.advancedTrade; } - /** - * - * Misc Utility Methods - * - */ - - generateNewOrderID(): string { - return nanoid(32); - } - /** * * Account Endpoints 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 From d7cf0b62d88eb09edc5228581f8a4f11d9cb921f Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Fri, 13 Sep 2024 16:25:48 +0100 Subject: [PATCH 5/5] chore(): remove any cast --- src/CBAdvancedTradeClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CBAdvancedTradeClient.ts b/src/CBAdvancedTradeClient.ts index 8c77ce1..918f2b9 100644 --- a/src/CBAdvancedTradeClient.ts +++ b/src/CBAdvancedTradeClient.ts @@ -335,7 +335,7 @@ export class CBAdvancedTradeClient extends BaseRestClient { closePosition( params: CloseAdvTradePositionRequest, ): Promise { - this.validateOrderId(params as any, 'client_order_id'); + this.validateOrderId(params, 'client_order_id'); return this.postPrivate(`/api/v3/brokerage/orders/close_position`, { body: params, });