migrate linear public methods + expand tests
This commit is contained in:
@@ -52,7 +52,7 @@ export class InverseClient extends BaseRestClient {
|
|||||||
key,
|
key,
|
||||||
secret,
|
secret,
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
getRestBaseUrl(useLivenet, restClientOptions),
|
||||||
restClientOptions,
|
{ ...restClientOptions, disable_time_sync: true },
|
||||||
requestOptions
|
requestOptions
|
||||||
);
|
);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class InverseFuturesClient extends BaseRestClient {
|
|||||||
key,
|
key,
|
||||||
secret,
|
secret,
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
getRestBaseUrl(useLivenet, restClientOptions),
|
||||||
restClientOptions,
|
{ ...restClientOptions, disable_time_sync: true },
|
||||||
requestOptions
|
requestOptions
|
||||||
);
|
);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
import RequestWrapper from './util/requestWrapper';
|
import RequestWrapper from './util/requestWrapper';
|
||||||
import {
|
import {
|
||||||
APIResponse,
|
APIResponse,
|
||||||
|
APIResponseWithTime,
|
||||||
AssetExchangeRecordsReq,
|
AssetExchangeRecordsReq,
|
||||||
CoinParam,
|
CoinParam,
|
||||||
SymbolInfo,
|
SymbolInfo,
|
||||||
@@ -14,7 +15,6 @@ import {
|
|||||||
SymbolLimitParam,
|
SymbolLimitParam,
|
||||||
SymbolParam,
|
SymbolParam,
|
||||||
SymbolPeriodLimitParam,
|
SymbolPeriodLimitParam,
|
||||||
TimeResult,
|
|
||||||
WalletFundRecordsReq,
|
WalletFundRecordsReq,
|
||||||
WithdrawRecordsReq,
|
WithdrawRecordsReq,
|
||||||
} from './types/shared';
|
} from './types/shared';
|
||||||
@@ -53,7 +53,7 @@ export class LinearClient extends BaseRestClient {
|
|||||||
key,
|
key,
|
||||||
secret,
|
secret,
|
||||||
getRestBaseUrl(useLivenet, restClientOptions),
|
getRestBaseUrl(useLivenet, restClientOptions),
|
||||||
restClientOptions,
|
{ ...restClientOptions, disable_time_sync: true },
|
||||||
requestOptions
|
requestOptions
|
||||||
);
|
);
|
||||||
return this;
|
return this;
|
||||||
@@ -61,7 +61,7 @@ export class LinearClient extends BaseRestClient {
|
|||||||
|
|
||||||
async fetchServerTime(): Promise<number> {
|
async fetchServerTime(): Promise<number> {
|
||||||
const timeRes = await this.getServerTime();
|
const timeRes = await this.getServerTime();
|
||||||
return timeRes.time_now;
|
return Number(timeRes.time_now);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,36 +70,82 @@ export class LinearClient extends BaseRestClient {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
getOrderBook(params: SymbolParam): GenericAPIResponse {
|
getOrderBook(params: SymbolParam): Promise<APIResponseWithTime<any[]>> {
|
||||||
return this.requestWrapper.get('v2/public/orderBook/L2', params);
|
return this.requestWrapper.get('v2/public/orderBook/L2', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getKline(
|
||||||
|
params: SymbolIntervalFromLimitParam
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
|
return this.requestWrapper.get('public/linear/kline', params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get latest information for symbol
|
* Get latest information for symbol
|
||||||
*/
|
*/
|
||||||
getTickers(params?: Partial<SymbolParam>): GenericAPIResponse {
|
getTickers(
|
||||||
|
params?: Partial<SymbolParam>
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
return this.requestWrapper.get('v2/public/tickers', params);
|
return this.requestWrapper.get('v2/public/tickers', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTrades(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>> {
|
||||||
|
return this.requestWrapper.get(
|
||||||
|
'public/linear/recent-trading-records',
|
||||||
|
params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
getSymbols(): Promise<APIResponse<SymbolInfo[]>> {
|
getSymbols(): Promise<APIResponse<SymbolInfo[]>> {
|
||||||
return this.requestWrapper.get('v2/public/symbols');
|
return this.requestWrapper.get('v2/public/symbols');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastFundingRate(params: SymbolParam): Promise<APIResponseWithTime<any[]>> {
|
||||||
|
return this.requestWrapper.get(
|
||||||
|
'public/linear/funding/prev-funding-rate',
|
||||||
|
params
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getMarkPriceKline(
|
||||||
|
params: SymbolIntervalFromLimitParam
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
|
return this.requestWrapper.get('public/linear/mark-price-kline', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
getIndexPriceKline(
|
||||||
|
params: SymbolIntervalFromLimitParam
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
|
return this.requestWrapper.get('public/linear/index-price-kline', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPremiumIndexKline(
|
||||||
|
params: SymbolIntervalFromLimitParam
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
|
return this.requestWrapper.get('public/linear/premium-index-kline', params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Market Data : Advanced
|
* Market Data : Advanced
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
getOpenInterest(params: SymbolPeriodLimitParam): GenericAPIResponse {
|
getOpenInterest(
|
||||||
|
params: SymbolPeriodLimitParam
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
return this.requestWrapper.get('v2/public/open-interest', params);
|
return this.requestWrapper.get('v2/public/open-interest', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLatestBigDeal(params: SymbolLimitParam): GenericAPIResponse {
|
getLatestBigDeal(
|
||||||
|
params: SymbolLimitParam
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
return this.requestWrapper.get('v2/public/big-deal', params);
|
return this.requestWrapper.get('v2/public/big-deal', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLongShortRatio(params: SymbolPeriodLimitParam): GenericAPIResponse {
|
getLongShortRatio(
|
||||||
|
params: SymbolPeriodLimitParam
|
||||||
|
): Promise<APIResponseWithTime<any[]>> {
|
||||||
return this.requestWrapper.get('v2/public/account-ratio', params);
|
return this.requestWrapper.get('v2/public/account-ratio', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +189,7 @@ export class LinearClient extends BaseRestClient {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
getServerTime(): GenericAPIResponse<TimeResult> {
|
getServerTime(): Promise<APIResponseWithTime<{}>> {
|
||||||
return this.requestWrapper.get('v2/public/time');
|
return this.requestWrapper.get('v2/public/time');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,44 +197,6 @@ export class LinearClient extends BaseRestClient {
|
|||||||
return this.requestWrapper.get('v2/public/announcement');
|
return this.requestWrapper.get('v2/public/announcement');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Market Data Endpoints
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
|
|
||||||
return this.requestWrapper.get('public/linear/kline', params);
|
|
||||||
}
|
|
||||||
|
|
||||||
getTrades(params: SymbolLimitParam): GenericAPIResponse {
|
|
||||||
return this.requestWrapper.get(
|
|
||||||
'public/linear/recent-trading-records',
|
|
||||||
params
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
getLastFundingRate(params: SymbolParam): GenericAPIResponse {
|
|
||||||
return this.requestWrapper.get(
|
|
||||||
'public/linear/funding/prev-funding-rate',
|
|
||||||
params
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
|
|
||||||
return this.requestWrapper.get('public/linear/mark-price-kline', params);
|
|
||||||
}
|
|
||||||
|
|
||||||
getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse {
|
|
||||||
return this.requestWrapper.get('public/linear/index-price-kline', params);
|
|
||||||
}
|
|
||||||
|
|
||||||
getPremiumIndexKline(
|
|
||||||
params: SymbolIntervalFromLimitParam
|
|
||||||
): GenericAPIResponse {
|
|
||||||
return this.requestWrapper.get('public/linear/premium-index-kline', params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Account Data Endpoints
|
* Account Data Endpoints
|
||||||
|
|||||||
@@ -1,66 +1,92 @@
|
|||||||
import { LinearClient } from "../../src/linear-client";
|
import { LinearClient } from '../../src/linear-client';
|
||||||
import { notAuthenticatedError, successResponseList, successResponseObject } from "../response.util";
|
import {
|
||||||
|
notAuthenticatedError,
|
||||||
|
successResponseList,
|
||||||
|
successResponseObject,
|
||||||
|
} from '../response.util';
|
||||||
|
|
||||||
describe('Public Linear REST API Endpoints', () => {
|
describe('Public Linear REST API Endpoints', () => {
|
||||||
const useLivenet = true;
|
const useLivenet = true;
|
||||||
const api = new LinearClient(undefined, undefined, useLivenet, { disable_time_sync: true });
|
const api = new LinearClient(undefined, undefined, useLivenet, {
|
||||||
|
disable_time_sync: true,
|
||||||
|
});
|
||||||
|
|
||||||
const symbol = 'BTCUSDT';
|
const symbol = 'BTCUSDT';
|
||||||
const interval = '15';
|
const interval = '15';
|
||||||
const timestampOneHourAgo = (new Date().getTime() / 1000) - (1000 * 60 * 60);
|
const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60;
|
||||||
const from = Number(timestampOneHourAgo.toFixed(0));
|
const from = Number(timestampOneHourAgo.toFixed(0));
|
||||||
|
|
||||||
describe('Linear only endpoints', () => {
|
describe('Linear only endpoints', () => {
|
||||||
it('should throw for unauthenticated private calls', async () => {
|
it('should throw for unauthenticated private calls', async () => {
|
||||||
expect(() => api.getPosition()).rejects.toMatchObject(notAuthenticatedError());
|
expect(() => api.getPosition()).rejects.toMatchObject(
|
||||||
});
|
notAuthenticatedError()
|
||||||
|
);
|
||||||
it('getKline()', async () => {
|
expect(() => api.getApiKeyInfo()).rejects.toMatchObject(
|
||||||
expect(
|
notAuthenticatedError()
|
||||||
await api.getKline({ symbol, interval, from })
|
);
|
||||||
).toMatchObject(successResponseList());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getTrades()', async () => {
|
|
||||||
expect(await api.getTrades({ symbol })).toMatchObject(successResponseList());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getIndexPriceKline()', async () => {
|
|
||||||
expect(await api.getIndexPriceKline({ symbol, interval, from })).toMatchObject(successResponseList());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getPremiumIndexKline()', async () => {
|
|
||||||
expect(await api.getPremiumIndexKline({ symbol, interval, from })).toMatchObject(successResponseList());
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getLastFundingRate()', async () => {
|
|
||||||
expect(await api.getLastFundingRate({ symbol })).toMatchObject(successResponseObject());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Shared endpoints', () => {
|
|
||||||
it('should throw for unauthenticated private calls', async () => {
|
|
||||||
expect(() => api.getApiKeyInfo()).rejects.toMatchObject(notAuthenticatedError());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getOrderBook()', async () => {
|
it('getOrderBook()', async () => {
|
||||||
expect(await api.getOrderBook({ symbol })).toMatchObject(successResponseList());
|
expect(await api.getOrderBook({ symbol })).toMatchObject(
|
||||||
|
successResponseList()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getKline()', async () => {
|
||||||
|
expect(await api.getKline({ symbol, interval, from })).toMatchObject(
|
||||||
|
successResponseList()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getTickers()', async () => {
|
it('getTickers()', async () => {
|
||||||
expect(await api.getTickers()).toMatchObject(successResponseList());
|
expect(await api.getTickers()).toMatchObject(successResponseList());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTrades()', async () => {
|
||||||
|
expect(await api.getTrades({ symbol })).toMatchObject(
|
||||||
|
successResponseList()
|
||||||
|
);
|
||||||
|
});
|
||||||
it('getSymbols()', async () => {
|
it('getSymbols()', async () => {
|
||||||
expect(await api.getSymbols()).toMatchObject(successResponseList());
|
expect(await api.getSymbols()).toMatchObject(successResponseList());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getMarkPriceKline()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getMarkPriceKline({ symbol, interval, from })
|
||||||
|
).toMatchObject(successResponseList());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getIndexPriceKline()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getIndexPriceKline({ symbol, interval, from })
|
||||||
|
).toMatchObject(successResponseList());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getPremiumIndexKline()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.getPremiumIndexKline({ symbol, interval, from })
|
||||||
|
).toMatchObject(successResponseList());
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getLastFundingRate()', async () => {
|
||||||
|
expect(await api.getLastFundingRate({ symbol })).toMatchObject(
|
||||||
|
successResponseObject()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('getServerTime()', async () => {
|
it('getServerTime()', async () => {
|
||||||
expect(await api.getServerTime()).toMatchObject(successResponseObject());
|
expect(await api.getServerTime()).toMatchObject(successResponseObject());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('fetchServertime() returns number', async () => {
|
||||||
|
expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number));
|
||||||
|
});
|
||||||
|
|
||||||
it('getApiAnnouncements()', async () => {
|
it('getApiAnnouncements()', async () => {
|
||||||
expect(await api.getApiAnnouncements()).toMatchObject(successResponseList());
|
expect(await api.getApiAnnouncements()).toMatchObject(
|
||||||
|
successResponseList()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user