From 2327dcc7ec20897b75e8cc22b308dd1ab6ff519b Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Fri, 9 Jun 2023 15:25:41 +0100 Subject: [PATCH] feat(#261): add missing tpsl req/response types --- src/contract-client.ts | 68 ++++++++++++++++++++-------------- src/types/request/contract.ts | 32 ++++++++++------ src/types/response/contract.ts | 34 +++++++++++------ src/types/response/v5-trade.ts | 7 ++++ 4 files changed, 91 insertions(+), 50 deletions(-) diff --git a/src/contract-client.ts b/src/contract-client.ts index e88690f..b5df43c 100644 --- a/src/contract-client.ts +++ b/src/contract-client.ts @@ -54,7 +54,7 @@ export class ContractClient extends BaseRestClient { getOrderBook( symbol: string, category?: string, - limit?: number + limit?: number, ): Promise> { return this.get('/derivatives/v3/public/order-book/L2', { category, @@ -71,14 +71,14 @@ export class ContractClient extends BaseRestClient { /** Get a symbol price/statistics ticker */ getSymbolTicker( category: UMCategory | '', - symbol?: string + symbol?: string, ): Promise>> { return this.get('/derivatives/v3/public/tickers', { category, symbol }); } /** Get trading rules per symbol/contract, incl price/amount/value/leverage filters */ getInstrumentInfo( - params: UMInstrumentInfoRequest + params: UMInstrumentInfoRequest, ): Promise> { return this.get('/derivatives/v3/public/instruments-info', params); } @@ -98,18 +98,18 @@ export class ContractClient extends BaseRestClient { * For example, if a request is sent at 12:00 UTC, the funding rate generated earlier that day at 08:00 UTC will be sent. */ getFundingRateHistory( - params: UMFundingRateHistoryRequest + params: UMFundingRateHistoryRequest, ): Promise> { return this.get( '/derivatives/v3/public/funding/history-funding-rate', - params + params, ); } /** Get Risk Limit */ getRiskLimit( category: UMCategory, - symbol: string + symbol: string, ): Promise> { return this.get('/derivatives/v3/public/risk-limit/list', { category, @@ -119,7 +119,7 @@ export class ContractClient extends BaseRestClient { /** Get option delivery price */ getOptionDeliveryPrice( - params: UMOptionDeliveryPriceRequest + params: UMOptionDeliveryPriceRequest, ): Promise> { return this.get('/derivatives/v3/public/delivery-price', params); } @@ -150,9 +150,14 @@ export class ContractClient extends BaseRestClient { return this.postPrivate('/contract/v3/private/order/create', params); } - /** Query order history. As order creation/cancellation is asynchronous, the data returned from the interface may be delayed. To access order information in real-time, call getActiveOrders() */ + /** + * Query order history. + * + * As order creation/cancellation is asynchronous, the data returned from the interface may be delayed. + * To access order information in real-time, call getActiveOrders(). + */ getHistoricOrders( - params: ContractHistoricOrdersRequest + params: ContractHistoricOrdersRequest, ): Promise>> { return this.getPrivate('/contract/v3/private/order/list', params); } @@ -169,18 +174,25 @@ export class ContractClient extends BaseRestClient { }); } - /** Replace order : Active order parameters (such as quantity, price) and stop order parameters cannot be modified in one request at the same time. Please request modification separately. */ + /** + * Replace order + * + * Active order parameters (such as quantity, price) and stop order parameters + * cannot be modified in one request at the same time. + * + * Please request modification separately. + */ modifyOrder(params: ContractModifyOrderRequest): Promise> { return this.postPrivate('/contract/v3/private/order/replace', params); } /** Query Open Order(s) (real-time) */ getActiveOrders( - params: ContractActiveOrdersRequest + params: ContractActiveOrdersRequest, ): Promise> { return this.getPrivate( '/contract/v3/private/order/unfilled-orders', - params + params, ); } @@ -197,31 +209,31 @@ export class ContractClient extends BaseRestClient { /** Set auto add margin, or Auto-Margin Replenishment. */ setAutoAddMargin( - params: ContractSetAutoAddMarginRequest + params: ContractSetAutoAddMarginRequest, ): Promise> { return this.postPrivate( '/contract/v3/private/position/set-auto-add-margin', - params + params, ); } /** Switch cross margin mode/isolated margin mode */ setMarginSwitch( - params: ContractSetMarginSwitchRequest + params: ContractSetMarginSwitchRequest, ): Promise> { return this.postPrivate( '/contract/v3/private/position/switch-isolated', - params + params, ); } /** Supports switching between One-Way Mode and Hedge Mode at the coin level. */ setPositionMode( - params: ContractSetPositionModeRequest + params: ContractSetPositionModeRequest, ): Promise> { return this.postPrivate( '/contract/v3/private/position/switch-mode', - params + params, ); } @@ -230,7 +242,7 @@ export class ContractClient extends BaseRestClient { */ setTPSLMode( symbol: string, - tpSlMode: 'Full' | 'Partial' + tpSlMode: 'Full' | 'Partial', ): Promise> { return this.postPrivate('/contract/v3/private/position/switch-tpsl-mode', { symbol, @@ -242,7 +254,7 @@ export class ContractClient extends BaseRestClient { setLeverage( symbol: string, buyLeverage: string, - sellLeverage: string + sellLeverage: string, ): Promise> { return this.postPrivate('/contract/v3/private/position/set-leverage', { symbol, @@ -258,7 +270,7 @@ export class ContractClient extends BaseRestClient { setTPSL(params: ContractSetTPSLRequest): Promise> { return this.postPrivate( '/contract/v3/private/position/trading-stop', - params + params, ); } @@ -267,7 +279,7 @@ export class ContractClient extends BaseRestClient { symbol: string, riskId: number, /** 0-one-way, 1-buy side, 2-sell side */ - positionIdx: 0 | 1 | 2 + positionIdx: 0 | 1 | 2, ): Promise> { return this.postPrivate('/contract/v3/private/position/set-risk-limit', { symbol, @@ -281,7 +293,7 @@ export class ContractClient extends BaseRestClient { * The results are ordered in descending order (the first item is the latest). Returns records up to 2 years old. */ getUserExecutionHistory( - params: ContractUserExecutionHistoryRequest + params: ContractUserExecutionHistoryRequest, ): Promise> { return this.getPrivate('/contract/v3/private/execution/list', params); } @@ -291,7 +303,7 @@ export class ContractClient extends BaseRestClient { * The results are ordered in descending order (the first item is the latest). */ getClosedProfitAndLoss( - params: ContractClosedPNLRequest + params: ContractClosedPNLRequest, ): Promise> { return this.getPrivate('/contract/v3/private/position/closed-pnl', params); } @@ -321,16 +333,18 @@ export class ContractClient extends BaseRestClient { /** * Get wallet fund records. - * This endpoint also shows exchanges from the Asset Exchange, where the types for the exchange are ExchangeOrderWithdraw and ExchangeOrderDeposit. + * This endpoint also shows exchanges from the Asset Exchange, + * where the types for the exchange are ExchangeOrderWithdraw and ExchangeOrderDeposit. + * * This endpoint returns incomplete information for transfers involving the derivatives wallet. * Use the account asset API for creating and querying internal transfers. */ getWalletFundRecords( - params?: ContractWalletFundRecordRequest + params?: ContractWalletFundRecordRequest, ): Promise> { return this.getPrivate( '/contract/v3/private/account/wallet/fund-records', - params + params, ); } diff --git a/src/types/request/contract.ts b/src/types/request/contract.ts index 3c8508e..80c3c85 100644 --- a/src/types/request/contract.ts +++ b/src/types/request/contract.ts @@ -5,21 +5,24 @@ import { USDCOrderFilter, USDCTimeInForce } from './usdc-shared'; export interface ContractOrderRequest { symbol: string; side: OrderSide; - positionIdx?: '0' | '1' | '2'; orderType: UMOrderType; qty: string; + timeInForce: USDCTimeInForce; price?: string; triggerDirection?: '1' | '2'; triggerPrice?: string; triggerBy?: string; - tpTriggerBy?: string; - slTriggerBy?: string; - timeInForce: USDCTimeInForce; + positionIdx?: '0' | '1' | '2'; orderLinkId?: string; takeProfit?: string; stopLoss?: string; + tpTriggerBy?: string; + slTriggerBy?: string; reduceOnly?: boolean; closeOnTrigger?: boolean; + tpslMode?: 'Partial' | 'Full'; + tpOrderType?: UMOrderType; + slOrderType?: UMOrderType; } export interface ContractHistoricOrdersRequest { @@ -39,17 +42,19 @@ export interface ContractCancelOrderRequest { } export interface ContractModifyOrderRequest { + symbol: string; orderId?: string; orderLinkId?: string; - symbol: string; - qty?: string; price?: string; + qty?: string; + triggerPrice?: string; takeProfit?: string; stopLoss?: string; tpTriggerBy?: string; slTriggerBy?: string; triggerBy?: string; - triggerPrice?: string; + tpLimitPrice?: string; + slLimitPrice?: string; } export interface ContractActiveOrdersRequest { @@ -91,12 +96,17 @@ export interface ContractSetTPSLRequest { symbol: string; takeProfit?: string; stopLoss?: string; - activePrice?: string; - trailingStop?: string; + tpslMode?: 'Full' | 'Partial'; + tpSize?: string; + slSize?: string; tpTriggerBy?: string; slTriggerBy?: string; - slSize?: string; - tpSize?: string; + trailingStop?: string; + activePrice?: string; + tpLimitPrice?: string; + slLimitPrice?: string; + tpOrderType?: UMOrderType; + slOrderType?: UMOrderType; /** 0-one-way, 1-buy side, 2-sell side */ positionIdx?: 0 | 1 | 2; } diff --git a/src/types/response/contract.ts b/src/types/response/contract.ts index 76cc5cf..1a77ddd 100644 --- a/src/types/response/contract.ts +++ b/src/types/response/contract.ts @@ -10,33 +10,43 @@ export interface ContractListResult { export interface ContractHistoricOrder { symbol: string; + orderId: string; + orderLinkId: string; side: string; orderType: string; price: string; + iv: string; qty: string; - reduceOnly: boolean; timeInForce: string; orderStatus: string; - leavesQty: string; - leavesValue: string; - cumExecQty: string; - cumExecValue: string; - cumExecFee: string; + positionIdx: number; lastPriceOnCreated: string; - rejectReason: string; - orderLinkId: string; createdTime: string; updatedTime: string; - orderId: string; + cancelType: string; + rejectReason: string; stopOrderType: string; + triggerDirection: number; + triggerBy: string; + triggerPrice: string; + cumExecValue: string; + cumExecFee: string; + cumExecQty: string; + leavesValue: string; + leavesQty: string; takeProfit: string; stopLoss: string; + tpslMode: string; + tpLimitPrice: string; + slLimitPrice: string; tpTriggerBy: string; slTriggerBy: string; - triggerPrice: string; + reduceOnly: boolean; closeOnTrigger: boolean; - triggerDirection: number; - positionIdx: number; + blockTradeId: string; + smpType: string; + smpGroup: number; + smpOrderId: string; } export interface ContractSymbolTicker { diff --git a/src/types/response/v5-trade.ts b/src/types/response/v5-trade.ts index f9f4edc..870578f 100644 --- a/src/types/response/v5-trade.ts +++ b/src/types/response/v5-trade.ts @@ -42,6 +42,9 @@ export interface AccountOrderV5 { triggerPrice?: string; takeProfit?: string; stopLoss?: string; + tpslMode: 'Full' | 'Partial' | ''; + tpLimitPrice: string; + slLimitPrice: string; tpTriggerBy?: OrderTriggerByV5; slTriggerBy?: OrderTriggerByV5; triggerDirection?: number; @@ -49,6 +52,10 @@ export interface AccountOrderV5 { lastPriceOnCreated?: string; reduceOnly?: boolean; closeOnTrigger?: boolean; + placeType: 'iv' | 'price' | ''; + smpType: string; + smpGroup: string; + smpOrderId: string; createdTime: string; updatedTime: string; }