clean extract linear req types

This commit is contained in:
tiagosiebler
2022-09-17 11:33:49 +01:00
parent 8ec07c2552
commit c02a2f0c75
4 changed files with 267 additions and 167 deletions

View File

@@ -4,7 +4,26 @@ import {
APIResponseWithTime, APIResponseWithTime,
AssetExchangeRecordsReq, AssetExchangeRecordsReq,
CoinParam, CoinParam,
LinearCancelConditionalOrderRequest,
LinearCancelOrderRequest,
LinearConditionalOrderRequest,
LinearGetClosedPnlRequest,
LinearGetConditionalOrderRequest,
LinearGetOrderRequest,
LinearGetOrdersRequest,
LinearGetTradeRecordsRequest,
LinearOrder, LinearOrder,
LinearQueryConditionalOrderRequest,
LinearReplaceConditionalOrderRequest,
LinearReplaceOrderRequest,
LinearSetAddReduceMarginRequest,
LinearSetAutoAddMarginRequest,
LinearSetMarginSwitchRequest,
LinearSetPositionModeRequest,
LinearSetPositionTpSlModeRequest,
LinearSetRiskLimitRequest,
LinearSetTradingStopRequest,
LinearSetUserLeverageRequest,
NewLinearOrder, NewLinearOrder,
PerpPosition, PerpPosition,
PerpPositionRoot, PerpPositionRoot,
@@ -178,23 +197,15 @@ export class LinearClient extends BaseRestClient {
return this.postPrivate('private/linear/order/create', params); return this.postPrivate('private/linear/order/create', params);
} }
getActiveOrderList(params: { getActiveOrderList(
order_id?: string; params: LinearGetOrdersRequest
order_link_id?: string; ): Promise<APIResponseWithTime<any>> {
symbol: string;
order?: string;
page?: number;
limit?: number;
order_status?: string;
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/order/list', params); return this.getPrivate('private/linear/order/list', params);
} }
cancelActiveOrder(params: { cancelActiveOrder(
symbol: string; params: LinearCancelOrderRequest
order_id?: string; ): Promise<APIResponseWithTime<any>> {
order_link_id?: string;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/order/cancel', params); return this.postPrivate('private/linear/order/cancel', params);
} }
@@ -204,25 +215,15 @@ export class LinearClient extends BaseRestClient {
return this.postPrivate('private/linear/order/cancel-all', params); return this.postPrivate('private/linear/order/cancel-all', params);
} }
replaceActiveOrder(params: { replaceActiveOrder(
order_id?: string; params: LinearReplaceOrderRequest
order_link_id?: string; ): Promise<APIResponseWithTime<any>> {
symbol: string;
p_r_qty?: number;
p_r_price?: number;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/order/replace', params); return this.postPrivate('private/linear/order/replace', params);
} }
queryActiveOrder(params: { queryActiveOrder(
order_id?: string; params: LinearGetOrderRequest
order_link_id?: string; ): Promise<APIResponseWithTime<any>> {
symbol: string;
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/order/search', params); return this.getPrivate('private/linear/order/search', params);
} }
@@ -230,44 +231,21 @@ export class LinearClient extends BaseRestClient {
* Conditional orders * Conditional orders
*/ */
placeConditionalOrder(params: { placeConditionalOrder(
side: string; params: LinearConditionalOrderRequest
symbol: string; ): Promise<APIResponseWithTime<any>> {
order_type: string;
qty: number;
price?: number;
base_price: number;
stop_px: number;
time_in_force: string;
trigger_by?: string;
close_on_trigger?: boolean;
order_link_id?: string;
reduce_only: boolean;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/stop-order/create', params); return this.postPrivate('private/linear/stop-order/create', params);
} }
getConditionalOrder(params: { getConditionalOrder(
stop_order_id?: string; params: LinearGetConditionalOrderRequest
order_link_id?: string; ): Promise<APIResponseWithTime<any>> {
symbol: string;
stop_order_status?: string;
order?: string;
page?: number;
limit?: number;
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/stop-order/list', params); return this.getPrivate('private/linear/stop-order/list', params);
} }
cancelConditionalOrder(params: { cancelConditionalOrder(
symbol: string; params: LinearCancelConditionalOrderRequest
stop_order_id?: string; ): Promise<APIResponseWithTime<any>> {
order_link_id?: string;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/stop-order/cancel', params); return this.postPrivate('private/linear/stop-order/cancel', params);
} }
@@ -277,26 +255,15 @@ export class LinearClient extends BaseRestClient {
return this.postPrivate('private/linear/stop-order/cancel-all', params); return this.postPrivate('private/linear/stop-order/cancel-all', params);
} }
replaceConditionalOrder(params: { replaceConditionalOrder(
stop_order_id?: string; params: LinearReplaceConditionalOrderRequest
order_link_id?: string; ): Promise<APIResponseWithTime<any>> {
symbol: string;
p_r_qty?: number;
p_r_price?: number;
p_r_trigger_price?: number;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/stop-order/replace', params); return this.postPrivate('private/linear/stop-order/replace', params);
} }
queryConditionalOrder(params: { queryConditionalOrder(
symbol: string; params: LinearQueryConditionalOrderRequest
stop_order_id?: string; ): Promise<APIResponseWithTime<any>> {
order_link_id?: string;
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/stop-order/search', params); return this.getPrivate('private/linear/stop-order/search', params);
} }
@@ -315,33 +282,27 @@ export class LinearClient extends BaseRestClient {
return this.getPrivate('private/linear/position/list', params); return this.getPrivate('private/linear/position/list', params);
} }
setAutoAddMargin(params?: { setAutoAddMargin(
symbol: string; params?: LinearSetAutoAddMarginRequest
side: string; ): Promise<APIResponseWithTime<any>> {
auto_add_margin: boolean;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate( return this.postPrivate(
'private/linear/position/set-auto-add-margin', 'private/linear/position/set-auto-add-margin',
params params
); );
} }
setMarginSwitch(params?: { setMarginSwitch(
symbol: string; params?: LinearSetMarginSwitchRequest
is_isolated: boolean; ): Promise<APIResponseWithTime<any>> {
buy_leverage: number;
sell_leverage: number;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/switch-isolated', params); return this.postPrivate('private/linear/position/switch-isolated', params);
} }
/** /**
* Switch between one-way vs hedge mode. Use `linearPositionModeEnum` for the mode parameter. * Switch between one-way vs hedge mode. Use `linearPositionModeEnum` for the mode parameter.
*/ */
setPositionMode(params: { setPositionMode(
symbol: string; params: LinearSetPositionModeRequest
mode: typeof linearPositionModeEnum[keyof typeof linearPositionModeEnum]; ): Promise<APIResponseWithTime<any>> {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/switch-mode', params); return this.postPrivate('private/linear/position/switch-mode', params);
} }
@@ -349,62 +310,39 @@ export class LinearClient extends BaseRestClient {
* Switch TP/SL mode between full or partial. When set to Partial, TP/SL orders may have a quantity less than the position size. * Switch TP/SL mode between full or partial. When set to Partial, TP/SL orders may have a quantity less than the position size.
* This is set with the setTradingStop() method. Use `positionTpSlModeEnum` for the tp_sl_mode parameter. * This is set with the setTradingStop() method. Use `positionTpSlModeEnum` for the tp_sl_mode parameter.
*/ */
setPositionTpSlMode(params: { setPositionTpSlMode(
symbol: string; params: LinearSetPositionTpSlModeRequest
tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum]; ): Promise<APIResponseWithTime<any>> {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/tpsl/switch-mode', params); return this.postPrivate('private/linear/tpsl/switch-mode', params);
} }
setAddReduceMargin(params?: { setAddReduceMargin(
symbol: string; params?: LinearSetAddReduceMarginRequest
side: string; ): Promise<APIResponseWithTime<any>> {
margin: number;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/add-margin', params); return this.postPrivate('private/linear/position/add-margin', params);
} }
setUserLeverage(params: { setUserLeverage(
symbol: string; params: LinearSetUserLeverageRequest
buy_leverage: number; ): Promise<APIResponseWithTime<any>> {
sell_leverage: number;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/set-leverage', params); return this.postPrivate('private/linear/position/set-leverage', params);
} }
setTradingStop(params: { setTradingStop(
symbol: string; params: LinearSetTradingStopRequest
side: string; ): Promise<APIResponseWithTime<any>> {
take_profit?: number;
stop_loss?: number;
trailing_stop?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
sl_size?: number;
tp_size?: number;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/trading-stop', params); return this.postPrivate('private/linear/position/trading-stop', params);
} }
getTradeRecords(params: { getTradeRecords(
symbol: string; params: LinearGetTradeRecordsRequest
start_time?: number; ): Promise<APIResponseWithTime<any>> {
end_time?: number;
exec_type?: string;
page?: number;
limit?: number;
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/trade/execution/list', params); return this.getPrivate('private/linear/trade/execution/list', params);
} }
getClosedPnl(params: { getClosedPnl(
symbol: string; params: LinearGetClosedPnlRequest
start_time?: number; ): Promise<APIResponseWithTime<any>> {
end_time?: number;
exec_type?: string;
page?: number;
limit?: number;
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/trade/closed-pnl/list', params); return this.getPrivate('private/linear/trade/closed-pnl/list', params);
} }
@@ -416,11 +354,9 @@ export class LinearClient extends BaseRestClient {
return this.getPrivate('public/linear/risk-limit', params); return this.getPrivate('public/linear/risk-limit', params);
} }
setRiskLimit(params: { setRiskLimit(
symbol: string; params: LinearSetRiskLimitRequest
side: string; ): Promise<APIResponseWithTime<any>> {
risk_id: number;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/set-risk', params); return this.postPrivate('private/linear/position/set-risk', params);
} }

View File

@@ -1,5 +1,6 @@
export * from './account-asset'; export * from './account-asset';
export * from './copy-trading'; export * from './copy-trading';
export * from './linear';
export * from './inverse'; export * from './inverse';
export * from './spot'; export * from './spot';
export * from './usdt-perp'; export * from './usdt-perp';

190
src/types/request/linear.ts Normal file
View File

@@ -0,0 +1,190 @@
import {
LinearPositionIdx,
linearPositionModeEnum,
positionTpSlModeEnum,
} from '../../constants/enum';
import { OrderSide } from '../shared';
export interface LinearGetOrdersRequest {
order_id?: string;
order_link_id?: string;
symbol: string;
order?: string;
page?: number;
limit?: number;
order_status?: string;
}
export interface LinearCancelOrderRequest {
symbol: string;
order_id?: string;
order_link_id?: string;
}
export interface LinearReplaceOrderRequest {
order_id?: string;
order_link_id?: string;
symbol: string;
p_r_qty?: number;
p_r_price?: number;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}
export interface LinearGetOrderRequest {
order_id?: string;
order_link_id?: string;
symbol: string;
}
export type LinearOrderType = 'Limit' | 'Market';
export type LinearTimeInForce =
| 'GoodTillCancel'
| 'ImmediateOrCancel'
| 'FillOrKill'
| 'PostOnly';
export interface NewLinearOrder {
side: OrderSide;
symbol: string;
order_type: LinearOrderType;
qty: number;
price?: number;
time_in_force: LinearTimeInForce;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
reduce_only: boolean;
close_on_trigger: boolean;
order_link_id?: string;
position_idx?: LinearPositionIdx;
}
export interface LinearConditionalOrderRequest {
side: string;
symbol: string;
order_type: string;
qty: number;
price?: number;
base_price: number;
stop_px: number;
time_in_force: string;
trigger_by?: string;
close_on_trigger?: boolean;
order_link_id?: string;
reduce_only: boolean;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}
export interface LinearGetConditionalOrderRequest {
stop_order_id?: string;
order_link_id?: string;
symbol: string;
stop_order_status?: string;
order?: string;
page?: number;
limit?: number;
}
export interface LinearCancelConditionalOrderRequest {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}
export interface LinearReplaceConditionalOrderRequest {
stop_order_id?: string;
order_link_id?: string;
symbol: string;
p_r_qty?: number;
p_r_price?: number;
p_r_trigger_price?: number;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}
export interface LinearQueryConditionalOrderRequest {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}
export interface LinearSetAutoAddMarginRequest {
symbol: string;
side: string;
auto_add_margin: boolean;
}
export interface LinearSetMarginSwitchRequest {
symbol: string;
is_isolated: boolean;
buy_leverage: number;
sell_leverage: number;
}
export interface LinearSetPositionModeRequest {
symbol: string;
mode: typeof linearPositionModeEnum[keyof typeof linearPositionModeEnum];
}
export interface LinearSetPositionTpSlModeRequest {
symbol: string;
tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum];
}
export interface LinearSetAddReduceMarginRequest {
symbol: string;
side: string;
margin: number;
}
export interface LinearSetUserLeverageRequest {
symbol: string;
buy_leverage: number;
sell_leverage: number;
}
export interface LinearSetTradingStopRequest {
symbol: string;
side: string;
take_profit?: number;
stop_loss?: number;
trailing_stop?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
sl_size?: number;
tp_size?: number;
}
export interface LinearGetTradeRecordsRequest {
symbol: string;
start_time?: number;
end_time?: number;
exec_type?: string;
page?: number;
limit?: number;
}
export interface LinearGetClosedPnlRequest {
symbol: string;
start_time?: number;
end_time?: number;
exec_type?: string;
page?: number;
limit?: number;
}
export interface LinearSetRiskLimitRequest {
symbol: string;
side: string;
risk_id: number;
}

View File

@@ -1,27 +0,0 @@
import { LinearPositionIdx } from '../../constants/enum';
import { OrderSide } from '../shared';
export type LinearOrderType = 'Limit' | 'Market';
export type LinearTimeInForce =
| 'GoodTillCancel'
| 'ImmediateOrCancel'
| 'FillOrKill'
| 'PostOnly';
export interface NewLinearOrder {
side: OrderSide;
symbol: string;
order_type: LinearOrderType;
qty: number;
price?: number;
time_in_force: LinearTimeInForce;
take_profit?: number;
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
reduce_only: boolean;
close_on_trigger: boolean;
order_link_id?: string;
position_idx?: LinearPositionIdx;
}