diff --git a/src/inverse-client.ts b/src/inverse-client.ts index 340e596..822400a 100644 --- a/src/inverse-client.ts +++ b/src/inverse-client.ts @@ -16,7 +16,6 @@ import { SymbolLimitParam, SymbolParam, SymbolPeriodLimitParam, - TimeResult, WalletFundRecordsReq, WithdrawRecordsReq, } from './types/shared'; @@ -121,15 +120,21 @@ export class InverseClient extends BaseRestClient { * */ - getOpenInterest(params: SymbolPeriodLimitParam): GenericAPIResponse { + getOpenInterest( + params: SymbolPeriodLimitParam + ): Promise> { return this.requestWrapper.get('v2/public/open-interest', params); } - getLatestBigDeal(params: SymbolLimitParam): GenericAPIResponse { + getLatestBigDeal( + params: SymbolLimitParam + ): Promise> { return this.requestWrapper.get('v2/public/big-deal', params); } - getLongShortRatio(params: SymbolPeriodLimitParam): GenericAPIResponse { + getLongShortRatio( + params: SymbolPeriodLimitParam + ): Promise> { return this.requestWrapper.get('v2/public/account-ratio', params); } diff --git a/src/inverse-futures-client.ts b/src/inverse-futures-client.ts index fc33195..cd6c073 100644 --- a/src/inverse-futures-client.ts +++ b/src/inverse-futures-client.ts @@ -7,6 +7,7 @@ import { import RequestWrapper from './util/requestWrapper'; import { APIResponse, + APIResponseWithTime, AssetExchangeRecordsReq, CoinParam, SymbolFromLimitParam, @@ -15,7 +16,6 @@ import { SymbolLimitParam, SymbolParam, SymbolPeriodLimitParam, - TimeResult, WalletFundRecordsReq, WithdrawRecordsReq, } from './types/shared'; @@ -60,7 +60,7 @@ export class InverseFuturesClient extends BaseRestClient { async fetchServerTime(): Promise { const res = await this.getServerTime(); - return res.time_now; + return Number(res.time_now); } /** @@ -69,36 +69,75 @@ export class InverseFuturesClient extends BaseRestClient { * */ - getOrderBook(params: SymbolParam): GenericAPIResponse { + getOrderBook(params: SymbolParam): Promise> { return this.requestWrapper.get('v2/public/orderBook/L2', params); } + getKline( + params: SymbolIntervalFromLimitParam + ): Promise> { + return this.requestWrapper.get('v2/public/kline/list', params); + } + /** * Get latest information for symbol */ - getTickers(params?: Partial): GenericAPIResponse { + getTickers( + params?: Partial + ): Promise> { return this.requestWrapper.get('v2/public/tickers', params); } - getSymbols(): Promise> { + /** + * Public trading records + */ + getTrades(params: SymbolLimitParam): Promise> { + return this.requestWrapper.get('v2/public/trading-records', params); + } + + getSymbols(): Promise> { return this.requestWrapper.get('v2/public/symbols'); } + getMarkPriceKline( + params: SymbolIntervalFromLimitParam + ): Promise> { + return this.requestWrapper.get('v2/public/mark-price-kline', params); + } + + getIndexPriceKline( + params: SymbolIntervalFromLimitParam + ): Promise> { + return this.requestWrapper.get('v2/public/index-price-kline', params); + } + + getPremiumIndexKline( + params: SymbolIntervalFromLimitParam + ): Promise> { + return this.requestWrapper.get('v2/public/premium-index-kline', params); + } + /** * * Market Data : Advanced * */ - getOpenInterest(params: SymbolPeriodLimitParam): GenericAPIResponse { + getOpenInterest( + params: SymbolPeriodLimitParam + ): Promise> { return this.requestWrapper.get('v2/public/open-interest', params); } - getLatestBigDeal(params: SymbolLimitParam): GenericAPIResponse { + getLatestBigDeal( + params: SymbolLimitParam + ): Promise> { return this.requestWrapper.get('v2/public/big-deal', params); } - getLongShortRatio(params: SymbolPeriodLimitParam): GenericAPIResponse { + getLongShortRatio( + params: SymbolPeriodLimitParam + ): Promise> { return this.requestWrapper.get('v2/public/account-ratio', params); } @@ -142,7 +181,7 @@ export class InverseFuturesClient extends BaseRestClient { * */ - getServerTime(): GenericAPIResponse { + getServerTime(): Promise> { return this.requestWrapper.get('v2/public/time'); } @@ -150,37 +189,6 @@ export class InverseFuturesClient extends BaseRestClient { return this.requestWrapper.get('v2/public/announcement'); } - /** - * - * Market Data Endpoints - * Note: These are currently the same as the inverse client - */ - - getKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse { - return this.requestWrapper.get('v2/public/kline/list', params); - } - - /** - * Public trading records - */ - getTrades(params: SymbolFromLimitParam): GenericAPIResponse { - return this.requestWrapper.get('v2/public/trading-records', params); - } - - getMarkPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse { - return this.requestWrapper.get('v2/public/mark-price-kline', params); - } - - getIndexPriceKline(params: SymbolIntervalFromLimitParam): GenericAPIResponse { - return this.requestWrapper.get('v2/public/index-price-kline', params); - } - - getPremiumIndexKline( - params: SymbolIntervalFromLimitParam - ): GenericAPIResponse { - return this.requestWrapper.get('v2/public/premium-index-kline', params); - } - /** * * Account Data Endpoints diff --git a/src/types/shared.ts b/src/types/shared.ts index 0d38a84..68baf69 100644 --- a/src/types/shared.ts +++ b/src/types/shared.ts @@ -122,7 +122,3 @@ export interface SymbolInfo { price_filter: PriceFilter; lot_size_filter: LotSizeFilter; } - -export interface TimeResult { - time_now: number; -} diff --git a/test/inverse-futures/public.test.ts b/test/inverse-futures/public.test.ts index 213701c..5a99aa4 100644 --- a/test/inverse-futures/public.test.ts +++ b/test/inverse-futures/public.test.ts @@ -1,66 +1,93 @@ -import { InverseFuturesClient } from "../../src/inverse-futures-client"; -import { notAuthenticatedError, successResponseList, successResponseObject } from "../response.util"; +import { InverseFuturesClient } from '../../src/inverse-futures-client'; +import { + notAuthenticatedError, + successResponseList, + successResponseObject, +} from '../response.util'; describe('Public Inverse Futures REST API Endpoints', () => { const useLivenet = true; - const api = new InverseFuturesClient(undefined, undefined, useLivenet, { disable_time_sync: true }); + const api = new InverseFuturesClient(undefined, undefined, useLivenet, { + disable_time_sync: true, + }); const symbol = 'BTCUSD'; 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)); describe('Inverse-Futures only endpoints', () => { it('should throw for unauthenticated private calls', async () => { - expect(() => api.getPosition()).rejects.toMatchObject(notAuthenticatedError()); - }); - - it('getKline()', async () => { - expect( - 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()); + expect(() => api.getPosition()).rejects.toMatchObject( + notAuthenticatedError() + ); + expect(() => api.getApiKeyInfo()).rejects.toMatchObject( + notAuthenticatedError() + ); }); 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 () => { expect(await api.getTickers()).toMatchObject(successResponseList()); }); + it('getTrades()', async () => { + expect(await api.getTrades({ symbol })).toMatchObject( + successResponseList() + ); + }); + it('getSymbols()', async () => { 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 () => { expect(await api.getServerTime()).toMatchObject(successResponseObject()); }); + it('fetchServertime() returns number', async () => { + expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number)); + }); + it('getApiAnnouncements()', async () => { - expect(await api.getApiAnnouncements()).toMatchObject(successResponseList()); + expect(await api.getApiAnnouncements()).toMatchObject( + successResponseList() + ); }); }); }); diff --git a/test/inverse/public.test.ts b/test/inverse/public.test.ts index 7ff235c..a61cebf 100644 --- a/test/inverse/public.test.ts +++ b/test/inverse/public.test.ts @@ -80,6 +80,10 @@ describe('Public Inverse REST API Endpoints', () => { expect(await api.getServerTime()).toMatchObject(successResponseObject()); }); + it('fetchServertime() returns number', async () => { + expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number)); + }); + it('getApiAnnouncements()', async () => { expect(await api.getApiAnnouncements()).toMatchObject( successResponseList()