Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): extract order types #18

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions src/CBAdvancedTradeClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import { nanoid } from 'nanoid';

import { BaseRestClient } from './lib/BaseRestClient.js';
import {
Expand All @@ -9,6 +8,7 @@ import {
} from './lib/requestUtils.js';
import {
AllocateAdvTradePortfolioRequest,
CloseAdvTradePositionRequest,
GetAdvTradeFillsRequest,
GetAdvTradeMarketTradesRequest,
GetAdvTradeOrdersRequest,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<AdvTradeClosePositionResponse> {
this.validateOrderId(params as any, 'client_order_id');
closePosition(
params: CloseAdvTradePositionRequest,
): Promise<AdvTradeClosePositionResponse> {
this.validateOrderId(params, 'client_order_id');
return this.postPrivate(`/api/v3/brokerage/orders/close_position`, {
body: params,
});
Expand Down
11 changes: 0 additions & 11 deletions src/CBAppClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import { nanoid } from 'nanoid';

import { BaseRestClient } from './lib/BaseRestClient.js';
import {
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/CBExchangeClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import { nanoid } from 'nanoid';

import { BaseRestClient } from './lib/BaseRestClient.js';
import {
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/CBInternationalClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import { nanoid } from 'nanoid';

import { BaseRestClient } from './lib/BaseRestClient.js';
import {
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/CBPrimeClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import { nanoid } from 'nanoid';

import { BaseRestClient } from './lib/BaseRestClient.js';
import {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/lib/BaseRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]) {
Expand Down
15 changes: 14 additions & 1 deletion src/types/request/advanced-trade-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down