fix linear request type, fix linear request method, add private read tests

This commit is contained in:
tiagosiebler
2022-05-07 23:35:24 +01:00
parent 72ce693d24
commit 7840829454
2 changed files with 131 additions and 29 deletions

View File

@@ -150,7 +150,7 @@ export class LinearClient extends BaseRestClient {
*/
getApiKeyInfo(): GenericAPIResponse {
return this.requestWrapper.get('v2/private/account/api-key');
return this.getPrivate('v2/private/account/api-key');
}
/**
@@ -160,21 +160,21 @@ export class LinearClient extends BaseRestClient {
*/
getWalletBalance(params?: Partial<CoinParam>): GenericAPIResponse {
return this.requestWrapper.get('v2/private/wallet/balance', params);
return this.getPrivate('v2/private/wallet/balance', params);
}
getWalletFundRecords(params?: WalletFundRecordsReq): GenericAPIResponse {
return this.requestWrapper.get('v2/private/wallet/fund/records', params);
return this.getPrivate('v2/private/wallet/fund/records', params);
}
getWithdrawRecords(params: WithdrawRecordsReq): GenericAPIResponse {
return this.requestWrapper.get('v2/private/wallet/withdraw/list', params);
getWithdrawRecords(params?: WithdrawRecordsReq): GenericAPIResponse {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}
getAssetExchangeRecords(
params?: AssetExchangeRecordsReq
): GenericAPIResponse {
return this.requestWrapper.get('v2/private/exchange-order/list', params);
return this.getPrivate('v2/private/exchange-order/list', params);
}
/**
@@ -225,7 +225,7 @@ export class LinearClient extends BaseRestClient {
limit?: number;
order_status?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/order/list', params);
return this.getPrivate('private/linear/order/list', params);
}
cancelActiveOrder(params: {
@@ -259,7 +259,7 @@ export class LinearClient extends BaseRestClient {
order_link_id?: string;
symbol: string;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/order/search', params);
return this.getPrivate('private/linear/order/search', params);
}
/**
@@ -296,7 +296,7 @@ export class LinearClient extends BaseRestClient {
page?: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/stop-order/list', params);
return this.getPrivate('private/linear/stop-order/list', params);
}
cancelConditionalOrder(params: {
@@ -337,7 +337,7 @@ export class LinearClient extends BaseRestClient {
stop_order_id?: string;
order_link_id?: string;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/stop-order/search', params);
return this.getPrivate('private/linear/stop-order/search', params);
}
/**
@@ -345,7 +345,7 @@ export class LinearClient extends BaseRestClient {
*/
getPosition(params?: Partial<SymbolParam>): GenericAPIResponse {
return this.requestWrapper.get('private/linear/position/list', params);
return this.getPrivate('private/linear/position/list', params);
}
setAutoAddMargin(params?: {
@@ -450,10 +450,7 @@ export class LinearClient extends BaseRestClient {
page?: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get(
'private/linear/trade/execution/list',
params
);
return this.getPrivate('private/linear/trade/execution/list', params);
}
getClosedPnl(params: {
@@ -464,10 +461,7 @@ export class LinearClient extends BaseRestClient {
page?: number;
limit?: number;
}): GenericAPIResponse {
return this.requestWrapper.get(
'private/linear/trade/closed-pnl/list',
params
);
return this.getPrivate('private/linear/trade/closed-pnl/list', params);
}
/**
@@ -475,7 +469,7 @@ export class LinearClient extends BaseRestClient {
*/
getRiskLimitList(params: SymbolParam): GenericAPIResponse {
return this.get('public/linear/risk-limit', params);
return this.getPrivate('public/linear/risk-limit', params);
}
setRiskLimit(params: {
@@ -483,7 +477,7 @@ export class LinearClient extends BaseRestClient {
side: string;
risk_id: string;
}): GenericAPIResponse {
return this.requestWrapper.get('private/linear/position/set-risk', params);
return this.requestWrapper.post('private/linear/position/set-risk', params);
}
/**
@@ -491,16 +485,10 @@ export class LinearClient extends BaseRestClient {
*/
getPredictedFundingFee(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.get(
'private/linear/funding/predicted-funding',
params
);
return this.getPrivate('private/linear/funding/predicted-funding', params);
}
getLastFundingFee(params: SymbolParam): GenericAPIResponse {
return this.requestWrapper.get(
'private/linear/funding/prev-funding',
params
);
return this.getPrivate('private/linear/funding/prev-funding', params);
}
}

View File

@@ -0,0 +1,114 @@
import { LinearClient } from '../../src/linear-client';
import {
notAuthenticatedError,
successResponseList,
successResponseObject,
} from '../response.util';
describe('Public Linear REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_COM;
it('should have api credentials to test with', () => {
expect(API_KEY).toStrictEqual(expect.any(String));
expect(API_SECRET).toStrictEqual(expect.any(String));
});
const api = new LinearClient(API_KEY, API_SECRET, useLivenet, {
disable_time_sync: true,
});
const symbol = 'BTCUSDT';
const interval = '15';
const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60;
const from = Number(timestampOneHourAgo.toFixed(0));
describe('Linear only private GET endpoints', () => {
it('getApiKeyInfo()', async () => {
expect(await api.getApiKeyInfo()).toMatchObject(successResponseObject());
});
it('getWalletBalance()', async () => {
expect(await api.getWalletBalance()).toMatchObject(
successResponseObject()
);
});
it('getWalletFundRecords()', async () => {
expect(await api.getWalletFundRecords()).toMatchObject(
successResponseObject()
);
});
it('getWithdrawRecords()', async () => {
expect(await api.getWithdrawRecords()).toMatchObject(
successResponseObject()
);
});
it('getAssetExchangeRecords()', async () => {
expect(await api.getAssetExchangeRecords()).toMatchObject(
successResponseList()
);
});
it('getActiveOrderList()', async () => {
expect(await api.getActiveOrderList({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('queryActiveOrder()', async () => {
expect(await api.queryActiveOrder({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getConditionalOrder()', async () => {
expect(await api.getConditionalOrder({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('queryConditionalOrder()', async () => {
expect(await api.queryConditionalOrder({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getPosition()', async () => {
expect(await api.getPosition()).toMatchObject(successResponseObject());
});
it('getTradeRecords()', async () => {
expect(await api.getTradeRecords({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getClosedPnl()', async () => {
expect(await api.getClosedPnl({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
it('getRiskLimitList()', async () => {
expect(await api.getRiskLimitList({ symbol: symbol })).toMatchObject(
successResponseList()
);
});
it('getPredictedFundingFee()', async () => {
expect(
await api.getPredictedFundingFee({ symbol: symbol })
).toMatchObject(successResponseObject());
});
it('getLastFundingFee()', async () => {
expect(await api.getLastFundingFee({ symbol: symbol })).toMatchObject(
successResponseObject()
);
});
});
});