cleaning around api response types

This commit is contained in:
tiagosiebler
2022-05-11 23:58:53 +01:00
parent a89cb5148e
commit 326caac96a
6 changed files with 172 additions and 122 deletions

View File

@@ -1,6 +1,5 @@
import { AxiosRequestConfig } from 'axios';
import {
GenericAPIResponse,
getRestBaseUrl,
RestClientOptions,
REST_CLIENT_TYPE_ENUM,
@@ -133,7 +132,7 @@ export class InverseClient extends BaseRestClient {
*
*/
getApiKeyInfo(): GenericAPIResponse {
getApiKeyInfo(): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/account/api-key');
}
@@ -143,21 +142,27 @@ export class InverseClient extends BaseRestClient {
*
*/
getWalletBalance(params?: Partial<CoinParam>): GenericAPIResponse {
getWalletBalance(
params?: Partial<CoinParam>
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/balance', params);
}
getWalletFundRecords(params?: WalletFundRecordsReq): GenericAPIResponse {
getWalletFundRecords(
params?: WalletFundRecordsReq
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params?: WithdrawRecordsReq): GenericAPIResponse {
getWithdrawRecords(
params?: WithdrawRecordsReq
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}
getAssetExchangeRecords(
params?: AssetExchangeRecordsReq
): GenericAPIResponse {
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/exchange-order/list', params);
}
@@ -199,7 +204,7 @@ export class InverseClient extends BaseRestClient {
sl_trigger_by?: 'LastPrice' | 'MarkPrice' | 'IndexPrice';
close_on_trigger?: boolean;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/create', orderRequest);
}
@@ -209,7 +214,7 @@ export class InverseClient extends BaseRestClient {
direction?: string;
limit?: number;
cursor?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/order/list', params);
}
@@ -217,11 +222,13 @@ export class InverseClient extends BaseRestClient {
symbol: string;
order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/cancel', params);
}
cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse {
cancelAllActiveOrders(
params: SymbolParam
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/cancelAll', params);
}
@@ -235,7 +242,7 @@ export class InverseClient extends BaseRestClient {
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/replace', params);
}
@@ -243,7 +250,7 @@ export class InverseClient extends BaseRestClient {
order_id?: string;
order_link_id?: string;
symbol: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/order', params);
}
@@ -263,7 +270,7 @@ export class InverseClient extends BaseRestClient {
trigger_by?: string;
close_on_trigger?: boolean;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/create', params);
}
@@ -274,7 +281,7 @@ export class InverseClient extends BaseRestClient {
direction?: string;
limit?: number;
cursor?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/stop-order/list', params);
}
@@ -282,11 +289,13 @@ export class InverseClient extends BaseRestClient {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/cancel', params);
}
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
cancelAllConditionalOrders(
params: SymbolParam
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/cancelAll', params);
}
@@ -297,7 +306,7 @@ export class InverseClient extends BaseRestClient {
p_r_qty?: number;
p_r_price?: string;
p_r_trigger_price?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/replace', params);
}
@@ -305,7 +314,7 @@ export class InverseClient extends BaseRestClient {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/stop-order', params);
}
@@ -313,14 +322,16 @@ export class InverseClient extends BaseRestClient {
* Position
*/
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
getPosition(
params?: Partial<SymbolParam>
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/position/list', params);
}
changePositionMargin(params: {
symbol: string;
margin: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('position/change-position-margin', params);
}
@@ -332,7 +343,7 @@ export class InverseClient extends BaseRestClient {
tp_trigger_by?: string;
sl_trigger_by?: string;
new_trailing_active?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/position/trading-stop', params);
}
@@ -340,7 +351,7 @@ export class InverseClient extends BaseRestClient {
symbol: string;
leverage: number;
leverage_only?: boolean;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/position/leverage/save', params);
}
@@ -351,7 +362,7 @@ export class InverseClient extends BaseRestClient {
page?: number;
limit?: number;
order?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/execution/list', params);
}
@@ -362,14 +373,14 @@ export class InverseClient extends BaseRestClient {
exec_type?: string;
page?: number;
limit?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/trade/closed-pnl/list', params);
}
setSlTpPositionMode(params: {
symbol: string;
tp_sl_mode: 'Full' | 'Partial';
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/tpsl/switch-mode', params);
}
@@ -378,7 +389,7 @@ export class InverseClient extends BaseRestClient {
is_isolated: boolean;
buy_leverage: number;
sell_leverage: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/position/switch-isolated', params);
}
@@ -386,14 +397,14 @@ export class InverseClient extends BaseRestClient {
* Risk Limit
*/
getRiskLimitList(): GenericAPIResponse {
getRiskLimitList(): Promise<APIResponseWithTime<any>> {
return this.getPrivate('open-api/wallet/risk-limit/list');
}
setRiskLimit(params: {
symbol: string;
risk_id: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('open-api/wallet/risk-limit', params);
}
@@ -401,15 +412,15 @@ export class InverseClient extends BaseRestClient {
* Funding
*/
getLastFundingRate(params: SymbolParam): GenericAPIResponse {
getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.get('v2/public/funding/prev-funding-rate', params);
}
getMyLastFundingFee(params: SymbolParam): GenericAPIResponse {
getMyLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/funding/prev-funding', params);
}
getPredictedFunding(params: SymbolParam): GenericAPIResponse {
getPredictedFunding(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/funding/predicted-funding', params);
}
@@ -417,7 +428,7 @@ export class InverseClient extends BaseRestClient {
* LCP Info
*/
getLcpInfo(params: SymbolParam): GenericAPIResponse {
getLcpInfo(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/account/lcp', params);
}
}

View File

@@ -1,6 +1,5 @@
import { AxiosRequestConfig } from 'axios';
import {
GenericAPIResponse,
getRestBaseUrl,
RestClientOptions,
REST_CLIENT_TYPE_ENUM,
@@ -136,7 +135,7 @@ export class InverseFuturesClient extends BaseRestClient {
*
*/
getApiKeyInfo(): GenericAPIResponse {
getApiKeyInfo(): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/account/api-key');
}
@@ -146,21 +145,27 @@ export class InverseFuturesClient extends BaseRestClient {
*
*/
getWalletBalance(params?: Partial<CoinParam>): GenericAPIResponse {
getWalletBalance(
params?: Partial<CoinParam>
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/balance', params);
}
getWalletFundRecords(params?: WalletFundRecordsReq): GenericAPIResponse {
getWalletFundRecords(
params?: WalletFundRecordsReq
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params?: WithdrawRecordsReq): GenericAPIResponse {
getWithdrawRecords(
params?: WithdrawRecordsReq
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}
getAssetExchangeRecords(
params?: AssetExchangeRecordsReq
): GenericAPIResponse {
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/exchange-order/list', params);
}
@@ -174,7 +179,7 @@ export class InverseFuturesClient extends BaseRestClient {
return this.get('v2/public/time');
}
getApiAnnouncements(): GenericAPIResponse {
getApiAnnouncements(): Promise<APIResponseWithTime<any>> {
return this.get('v2/public/announcement');
}
@@ -200,7 +205,7 @@ export class InverseFuturesClient extends BaseRestClient {
reduce_only?: boolean;
close_on_trigger?: boolean;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/order/create', orderRequest);
}
@@ -210,7 +215,7 @@ export class InverseFuturesClient extends BaseRestClient {
direction?: string;
limit?: number;
cursor?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('futures/private/order/list', params);
}
@@ -218,11 +223,13 @@ export class InverseFuturesClient extends BaseRestClient {
symbol: string;
order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/order/cancel', params);
}
cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse {
cancelAllActiveOrders(
params: SymbolParam
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/order/cancelAll', params);
}
@@ -232,7 +239,7 @@ export class InverseFuturesClient extends BaseRestClient {
symbol: string;
p_r_qty?: string;
p_r_price?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/order/replace', params);
}
@@ -240,7 +247,7 @@ export class InverseFuturesClient extends BaseRestClient {
order_id?: string;
order_link_id?: string;
symbol: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('futures/private/order', params);
}
@@ -260,7 +267,7 @@ export class InverseFuturesClient extends BaseRestClient {
trigger_by?: string;
close_on_trigger?: boolean;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/stop-order/create', params);
}
@@ -270,7 +277,7 @@ export class InverseFuturesClient extends BaseRestClient {
direction?: string;
limit?: number;
cursor?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('futures/private/stop-order/list', params);
}
@@ -278,11 +285,13 @@ export class InverseFuturesClient extends BaseRestClient {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/stop-order/cancel', params);
}
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
cancelAllConditionalOrders(
params: SymbolParam
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/stop-order/cancelAll', params);
}
@@ -293,7 +302,7 @@ export class InverseFuturesClient extends BaseRestClient {
p_r_qty?: number;
p_r_price?: string;
p_r_trigger_price?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/stop-order/replace', params);
}
@@ -301,7 +310,7 @@ export class InverseFuturesClient extends BaseRestClient {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('futures/private/stop-order', params);
}
@@ -312,14 +321,16 @@ export class InverseFuturesClient extends BaseRestClient {
/**
* Get position list
*/
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
getPosition(
params?: Partial<SymbolParam>
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('futures/private/position/list', params);
}
changePositionMargin(params: {
symbol: string;
margin: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate(
'futures/private/position/change-position-margin',
params
@@ -334,7 +345,7 @@ export class InverseFuturesClient extends BaseRestClient {
tp_trigger_by?: string;
sl_trigger_by?: string;
new_trailing_active?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/position/trading-stop', params);
}
@@ -342,7 +353,7 @@ export class InverseFuturesClient extends BaseRestClient {
symbol: string;
buy_leverage: number;
sell_leverage: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/position/leverage/save', params);
}
@@ -352,7 +363,7 @@ export class InverseFuturesClient extends BaseRestClient {
setPositionMode(params: {
symbol: string;
mode: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/position/switch-mode', params);
}
@@ -364,7 +375,7 @@ export class InverseFuturesClient extends BaseRestClient {
is_isolated: boolean;
buy_leverage: number;
sell_leverage: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('futures/private/position/switch-isolated', params);
}
@@ -375,7 +386,7 @@ export class InverseFuturesClient extends BaseRestClient {
page?: number;
limit?: number;
order?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('futures/private/execution/list', params);
}
@@ -386,7 +397,7 @@ export class InverseFuturesClient extends BaseRestClient {
exec_type?: string;
page?: number;
limit?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('futures/private/trade/closed-pnl/list', params);
}
@@ -397,14 +408,14 @@ export class InverseFuturesClient extends BaseRestClient {
/**
* Risk Limit
*/
getRiskLimitList(): GenericAPIResponse {
getRiskLimitList(): Promise<APIResponseWithTime<any>> {
return this.getPrivate('open-api/wallet/risk-limit/list');
}
setRiskLimit(params: {
symbol: string;
risk_id: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('open-api/wallet/risk-limit', params);
}
@@ -412,15 +423,15 @@ export class InverseFuturesClient extends BaseRestClient {
* Funding
*/
getLastFundingRate(params: SymbolParam): GenericAPIResponse {
getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.get('v2/public/funding/prev-funding-rate', params);
}
getMyLastFundingFee(params: SymbolParam): GenericAPIResponse {
getMyLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/funding/prev-funding', params);
}
getPredictedFunding(params: SymbolParam): GenericAPIResponse {
getPredictedFunding(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/funding/predicted-funding', params);
}
@@ -428,7 +439,7 @@ export class InverseFuturesClient extends BaseRestClient {
* LCP Info
*/
getLcpInfo(params: SymbolParam): GenericAPIResponse {
getLcpInfo(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/account/lcp', params);
}
}

View File

@@ -1,6 +1,5 @@
import { AxiosRequestConfig } from 'axios';
import {
GenericAPIResponse,
getRestBaseUrl,
RestClientOptions,
REST_CLIENT_TYPE_ENUM,
@@ -139,7 +138,7 @@ export class LinearClient extends BaseRestClient {
*
*/
getApiKeyInfo(): GenericAPIResponse {
getApiKeyInfo(): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/account/api-key');
}
@@ -149,21 +148,27 @@ export class LinearClient extends BaseRestClient {
*
*/
getWalletBalance(params?: Partial<CoinParam>): GenericAPIResponse {
getWalletBalance(
params?: Partial<CoinParam>
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/balance', params);
}
getWalletFundRecords(params?: WalletFundRecordsReq): GenericAPIResponse {
getWalletFundRecords(
params?: WalletFundRecordsReq
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params?: WithdrawRecordsReq): GenericAPIResponse {
getWithdrawRecords(
params?: WithdrawRecordsReq
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}
getAssetExchangeRecords(
params?: AssetExchangeRecordsReq
): GenericAPIResponse {
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/exchange-order/list', params);
}
@@ -177,7 +182,7 @@ export class LinearClient extends BaseRestClient {
return this.get('v2/public/time');
}
getApiAnnouncements(): GenericAPIResponse {
getApiAnnouncements(): Promise<APIResponseWithTime<any>> {
return this.get('v2/public/announcement');
}
@@ -202,7 +207,7 @@ export class LinearClient extends BaseRestClient {
close_on_trigger: boolean;
order_link_id?: string;
position_idx?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/order/create', params);
}
@@ -214,7 +219,7 @@ export class LinearClient extends BaseRestClient {
page?: number;
limit?: number;
order_status?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/order/list', params);
}
@@ -222,11 +227,13 @@ export class LinearClient extends BaseRestClient {
symbol: string;
order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/order/cancel', params);
}
cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse {
cancelAllActiveOrders(
params: SymbolParam
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/order/cancel-all', params);
}
@@ -240,7 +247,7 @@ export class LinearClient extends BaseRestClient {
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/order/replace', params);
}
@@ -248,7 +255,7 @@ export class LinearClient extends BaseRestClient {
order_id?: string;
order_link_id?: string;
symbol: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/order/search', params);
}
@@ -273,7 +280,7 @@ export class LinearClient extends BaseRestClient {
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/stop-order/create', params);
}
@@ -285,7 +292,7 @@ export class LinearClient extends BaseRestClient {
order?: string;
page?: number;
limit?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/stop-order/list', params);
}
@@ -293,11 +300,13 @@ export class LinearClient extends BaseRestClient {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/stop-order/cancel', params);
}
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
cancelAllConditionalOrders(
params: SymbolParam
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/stop-order/cancel-all', params);
}
@@ -312,7 +321,7 @@ export class LinearClient extends BaseRestClient {
stop_loss?: number;
tp_trigger_by?: string;
sl_trigger_by?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/stop-order/replace', params);
}
@@ -320,7 +329,7 @@ export class LinearClient extends BaseRestClient {
symbol: string;
stop_order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/stop-order/search', params);
}
@@ -328,7 +337,9 @@ export class LinearClient extends BaseRestClient {
* Position
*/
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
getPosition(
params?: Partial<SymbolParam>
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/position/list', params);
}
@@ -336,7 +347,7 @@ export class LinearClient extends BaseRestClient {
symbol: string;
side: string;
auto_add_margin: boolean;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate(
'private/linear/position/set-auto-add-margin',
params
@@ -348,7 +359,7 @@ export class LinearClient extends BaseRestClient {
is_isolated: boolean;
buy_leverage: number;
sell_leverage: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/switch-isolated', params);
}
@@ -358,7 +369,7 @@ export class LinearClient extends BaseRestClient {
setPositionMode(params: {
symbol: string;
mode: typeof linearPositionModeEnum[keyof typeof linearPositionModeEnum];
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/switch-mode', params);
}
@@ -369,7 +380,7 @@ export class LinearClient extends BaseRestClient {
setPositionTpSlMode(params: {
symbol: string;
tp_sl_mode: typeof positionTpSlModeEnum[keyof typeof positionTpSlModeEnum];
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/tpsl/switch-mode', params);
}
@@ -377,7 +388,7 @@ export class LinearClient extends BaseRestClient {
symbol: string;
side: string;
margin: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/add-margin', params);
}
@@ -385,7 +396,7 @@ export class LinearClient extends BaseRestClient {
symbol: string;
buy_leverage: number;
sell_leverage: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/set-leverage', params);
}
@@ -399,7 +410,7 @@ export class LinearClient extends BaseRestClient {
sl_trigger_by?: string;
sl_size?: number;
tp_size?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/trading-stop', params);
}
@@ -410,7 +421,7 @@ export class LinearClient extends BaseRestClient {
exec_type?: string;
page?: number;
limit?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/trade/execution/list', params);
}
@@ -421,7 +432,7 @@ export class LinearClient extends BaseRestClient {
exec_type?: string;
page?: number;
limit?: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/trade/closed-pnl/list', params);
}
@@ -429,7 +440,7 @@ export class LinearClient extends BaseRestClient {
* Risk Limit
*/
getRiskLimitList(params: SymbolParam): GenericAPIResponse {
getRiskLimitList(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('public/linear/risk-limit', params);
}
@@ -437,7 +448,7 @@ export class LinearClient extends BaseRestClient {
symbol: string;
side: string;
risk_id: number;
}): GenericAPIResponse {
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate('private/linear/position/set-risk', params);
}
@@ -445,11 +456,13 @@ export class LinearClient extends BaseRestClient {
* Funding
*/
getPredictedFundingFee(params: SymbolParam): GenericAPIResponse {
getPredictedFundingFee(
params: SymbolParam
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/funding/predicted-funding', params);
}
getLastFundingFee(params: SymbolParam): GenericAPIResponse {
getLastFundingFee(params: SymbolParam): Promise<APIResponseWithTime<any>> {
return this.getPrivate('private/linear/funding/prev-funding', params);
}
}

View File

@@ -120,15 +120,15 @@ export class SpotClient extends BaseRestClient {
* Account Data Endpoints
*/
submitOrder(params: NewSpotOrder) {
submitOrder(params: NewSpotOrder): Promise<APIResponse<any>> {
return this.postPrivate('/spot/v1/order', params);
}
getOrder(params: SpotOrderQueryById) {
getOrder(params: SpotOrderQueryById): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/order', params);
}
cancelOrder(params: SpotOrderQueryById) {
cancelOrder(params: SpotOrderQueryById): Promise<APIResponse<any>> {
return this.deletePrivate('/spot/v1/order', params);
}
@@ -136,7 +136,7 @@ export class SpotClient extends BaseRestClient {
symbol: string;
side?: OrderSide;
orderTypes: OrderTypeSpot[];
}) {
}): Promise<APIResponse<any>> {
const orderTypes = params.orderTypes
? params.orderTypes.join(',')
: undefined;
@@ -146,7 +146,11 @@ export class SpotClient extends BaseRestClient {
});
}
getOpenOrders(symbol?: string, orderId?: string, limit?: number) {
getOpenOrders(
symbol?: string,
orderId?: string,
limit?: number
): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/open-orders', {
symbol,
orderId,
@@ -154,7 +158,11 @@ export class SpotClient extends BaseRestClient {
});
}
getPastOrders(symbol?: string, orderId?: string, limit?: number) {
getPastOrders(
symbol?: string,
orderId?: string,
limit?: number
): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/history-orders', {
symbol,
orderId,
@@ -162,7 +170,12 @@ export class SpotClient extends BaseRestClient {
});
}
getMyTrades(symbol?: string, limit?: number, fromId?: number, toId?: number) {
getMyTrades(
symbol?: string,
limit?: number,
fromId?: number,
toId?: number
): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/myTrades', {
symbol,
limit,
@@ -175,7 +188,7 @@ export class SpotClient extends BaseRestClient {
* Wallet Data Endpoints
*/
getBalances() {
getBalances(): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/account');
}
}

View File

@@ -1,19 +1,23 @@
import axios, {
AxiosError,
AxiosRequestConfig,
AxiosResponse,
Method,
} from 'axios';
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
import { APIResponse, APIResponseWithTime } from '../types/shared';
import { signMessage } from './node-support';
import {
RestClientOptions,
GenericAPIResponse,
serializeParams,
RestClientType,
REST_CLIENT_TYPE_ENUM,
} from './requestUtils';
// axios.interceptors.request.use((request) => {
// console.log(new Date(), 'Starting Request', JSON.stringify(request, null, 2));
// return request;
// });
// axios.interceptors.response.use((response) => {
// console.log(new Date(), 'Response:', JSON.stringify(response, null, 2));
// return response;
// });
interface SignedRequestContext {
timestamp: number;
@@ -95,23 +99,23 @@ export default abstract class BaseRestClient {
return this.clientType === REST_CLIENT_TYPE_ENUM.spot;
}
get(endpoint: string, params?: any): GenericAPIResponse {
get(endpoint: string, params?: any) {
return this._call('GET', endpoint, params, true);
}
post(endpoint: string, params?: any): GenericAPIResponse {
post(endpoint: string, params?: any) {
return this._call('POST', endpoint, params, true);
}
getPrivate(endpoint: string, params?: any): GenericAPIResponse {
getPrivate(endpoint: string, params?: any) {
return this._call('GET', endpoint, params, false);
}
postPrivate(endpoint: string, params?: any): GenericAPIResponse {
postPrivate(endpoint: string, params?: any) {
return this._call('POST', endpoint, params, false);
}
deletePrivate(endpoint: string, params?: any): GenericAPIResponse {
deletePrivate(endpoint: string, params?: any) {
return this._call('DELETE', endpoint, params, false);
}
@@ -142,7 +146,7 @@ export default abstract class BaseRestClient {
endpoint: string,
params?: any,
isPublicApi?: boolean
): GenericAPIResponse {
): Promise<any> {
const options = {
...this.globalRequestOptions,
url: [this.baseUrl, endpoint].join(endpoint.startsWith('/') ? '' : '/'),
@@ -247,7 +251,7 @@ export default abstract class BaseRestClient {
/**
* Trigger time sync and store promise
*/
private syncTime(): GenericAPIResponse {
private syncTime(): Promise<any> {
if (this.options.disable_time_sync === true) {
return Promise.resolve(false);
}

View File

@@ -19,8 +19,6 @@ export interface RestClientOptions {
parse_exceptions?: boolean;
}
export type GenericAPIResponse<T = any> = Promise<T>;
export function serializeParams(
params: object = {},
strict_validation = false