improve types for request parameters

This commit is contained in:
tiagosiebler
2021-12-31 00:45:30 +00:00
parent 543ace9cde
commit 5cd4ab2c36
6 changed files with 172 additions and 208 deletions

View File

@@ -2,6 +2,7 @@ import { AxiosRequestConfig } from 'axios';
import { GenericAPIResponse, getRestBaseUrl, RestClientOptions } from './util/requestUtils';
import RequestWrapper from './util/requestWrapper';
import SharedEndpoints from './shared-endpoints';
import { SymbolFromLimitParam, SymbolIntervalFromLimitParam, SymbolParam } from './types/shared';
export class InverseClient extends SharedEndpoints {
protected requestWrapper: RequestWrapper;
@@ -40,67 +41,37 @@ export class InverseClient extends SharedEndpoints {
*
*/
getKline(params: {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
return this.requestWrapper.get('v2/public/kline/list', params);
}
/**
* @deprecated use getTickers() instead
*/
getLatestInformation(params?: {
symbol?: string;
}): GenericAPIResponse {
getLatestInformation(params?: Partial<SymbolParam>): GenericAPIResponse {
return this.getTickers(params);
}
/**
* @deprecated use getTrades() instead
*/
getPublicTradingRecords(params: {
symbol: string;
from?: number;
limit?: number;
}): GenericAPIResponse {
getPublicTradingRecords(params: SymbolFromLimitParam): GenericAPIResponse {
return this.getTrades(params);
}
getTrades(params: {
symbol: string;
from?: number;
limit?: number;
}): GenericAPIResponse {
getTrades(params: SymbolFromLimitParam): GenericAPIResponse {
return this.requestWrapper.get('v2/public/trading-records', params);
}
getMarkPriceKline(params: {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
return this.requestWrapper.get('v2/public/mark-price-kline', params);
}
getIndexPriceKline(params: {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
return this.requestWrapper.get('v2/public/index-price-kline', params);
}
getPremiumIndexKline(params: {
symbol: string;
interval: string;
from: number;
limit?: number;
}): GenericAPIResponse {
getPremiumIndexKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
return this.requestWrapper.get('v2/public/premium-index-kline', params);
}
@@ -150,9 +121,7 @@ export class InverseClient extends SharedEndpoints {
return this.requestWrapper.post('v2/private/order/cancel', params);
}
cancelAllActiveOrders(params: {
symbol: string;
}): GenericAPIResponse {
cancelAllActiveOrders(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.post('v2/private/order/cancelAll', params);
}
@@ -212,9 +181,7 @@ export class InverseClient extends SharedEndpoints {
return this.requestWrapper.post('v2/private/stop-order/cancel', params);
}
cancelAllConditionalOrders(params: {
symbol: string;
}): GenericAPIResponse {
cancelAllConditionalOrders(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.post('v2/private/stop-order/cancelAll', params);
}
@@ -248,9 +215,7 @@ export class InverseClient extends SharedEndpoints {
return this.requestWrapper.get('user/leverage');
}
getPosition(params?: {
symbol?: string;
}): GenericAPIResponse {
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
return this.requestWrapper.get('v2/private/position/list', params);
}
@@ -359,21 +324,15 @@ export class InverseClient extends SharedEndpoints {
* Funding
*/
getLastFundingRate(params: {
symbol: string;
}): GenericAPIResponse {
getLastFundingRate(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.get('v2/public/funding/prev-funding-rate', params);
}
getMyLastFundingFee(params: {
symbol: string;
}): GenericAPIResponse {
getMyLastFundingFee(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.get('v2/private/funding/prev-funding', params);
}
getPredictedFunding(params: {
symbol: string;
}): GenericAPIResponse {
getPredictedFunding(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.get('v2/private/funding/predicted-funding', params);
}
@@ -381,12 +340,10 @@ export class InverseClient extends SharedEndpoints {
* LCP Info
*/
getLcpInfo(params: {
symbol: string;
}): GenericAPIResponse {
getLcpInfo(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/lcp', params);
}
//API Key Info
getAPIKeyInfo(): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/api-key');