feat(#261): add missing tpsl req/response types

This commit is contained in:
tiagosiebler
2023-06-09 15:25:41 +01:00
parent 9013bf749d
commit 2327dcc7ec
4 changed files with 91 additions and 50 deletions

View File

@@ -54,7 +54,7 @@ export class ContractClient extends BaseRestClient {
getOrderBook(
symbol: string,
category?: string,
limit?: number
limit?: number,
): Promise<APIResponseV3<any>> {
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<APIResponseV3<ContractListResult<ContractSymbolTicker>>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
return this.get(
'/derivatives/v3/public/funding/history-funding-rate',
params
params,
);
}
/** Get Risk Limit */
getRiskLimit(
category: UMCategory,
symbol: string
symbol: string,
): Promise<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<PaginatedResult<ContractHistoricOrder>>> {
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<APIResponseV3<any>> {
return this.postPrivate('/contract/v3/private/order/replace', params);
}
/** Query Open Order(s) (real-time) */
getActiveOrders(
params: ContractActiveOrdersRequest
params: ContractActiveOrdersRequest,
): Promise<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
return this.postPrivate('/contract/v3/private/position/set-leverage', {
symbol,
@@ -258,7 +270,7 @@ export class ContractClient extends BaseRestClient {
setTPSL(params: ContractSetTPSLRequest): Promise<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
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<APIResponseV3<any>> {
return this.getPrivate(
'/contract/v3/private/account/wallet/fund-records',
params
params,
);
}

View File

@@ -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;
}

View File

@@ -10,33 +10,43 @@ export interface ContractListResult<TList = any> {
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 {

View File

@@ -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;
}