cleaned public inverse futures endpoints & expanded tests

This commit is contained in:
tiagosiebler
2022-05-05 21:46:58 +01:00
parent 603a07ec85
commit 784555cf9f
5 changed files with 123 additions and 83 deletions

View File

@@ -16,7 +16,6 @@ import {
SymbolLimitParam, SymbolLimitParam,
SymbolParam, SymbolParam,
SymbolPeriodLimitParam, SymbolPeriodLimitParam,
TimeResult,
WalletFundRecordsReq, WalletFundRecordsReq,
WithdrawRecordsReq, WithdrawRecordsReq,
} from './types/shared'; } from './types/shared';
@@ -121,15 +120,21 @@ export class InverseClient extends BaseRestClient {
* *
*/ */
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);
} }

View File

@@ -7,6 +7,7 @@ import {
import RequestWrapper from './util/requestWrapper'; import RequestWrapper from './util/requestWrapper';
import { import {
APIResponse, APIResponse,
APIResponseWithTime,
AssetExchangeRecordsReq, AssetExchangeRecordsReq,
CoinParam, CoinParam,
SymbolFromLimitParam, SymbolFromLimitParam,
@@ -15,7 +16,6 @@ import {
SymbolLimitParam, SymbolLimitParam,
SymbolParam, SymbolParam,
SymbolPeriodLimitParam, SymbolPeriodLimitParam,
TimeResult,
WalletFundRecordsReq, WalletFundRecordsReq,
WithdrawRecordsReq, WithdrawRecordsReq,
} from './types/shared'; } from './types/shared';
@@ -60,7 +60,7 @@ export class InverseFuturesClient extends BaseRestClient {
async fetchServerTime(): Promise<number> { async fetchServerTime(): Promise<number> {
const res = await this.getServerTime(); 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<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('v2/public/kline/list', 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);
} }
getSymbols(): Promise<APIResponse<SymbolInfo[]>> { /**
* Public trading records
*/
getTrades(params: SymbolLimitParam): Promise<APIResponseWithTime<any[]>> {
return this.requestWrapper.get('v2/public/trading-records', params);
}
getSymbols(): Promise<APIResponseWithTime<SymbolInfo[]>> {
return this.requestWrapper.get('v2/public/symbols'); return this.requestWrapper.get('v2/public/symbols');
} }
getMarkPriceKline(
params: SymbolIntervalFromLimitParam
): Promise<APIResponseWithTime<any[]>> {
return this.requestWrapper.get('v2/public/mark-price-kline', params);
}
getIndexPriceKline(
params: SymbolIntervalFromLimitParam
): Promise<APIResponseWithTime<any[]>> {
return this.requestWrapper.get('v2/public/index-price-kline', params);
}
getPremiumIndexKline(
params: SymbolIntervalFromLimitParam
): Promise<APIResponseWithTime<any[]>> {
return this.requestWrapper.get('v2/public/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);
} }
@@ -142,7 +181,7 @@ export class InverseFuturesClient extends BaseRestClient {
* *
*/ */
getServerTime(): GenericAPIResponse<TimeResult> { getServerTime(): Promise<APIResponseWithTime<{}>> {
return this.requestWrapper.get('v2/public/time'); return this.requestWrapper.get('v2/public/time');
} }
@@ -150,37 +189,6 @@ export class InverseFuturesClient extends BaseRestClient {
return this.requestWrapper.get('v2/public/announcement'); 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 * Account Data Endpoints

View File

@@ -122,7 +122,3 @@ export interface SymbolInfo {
price_filter: PriceFilter; price_filter: PriceFilter;
lot_size_filter: LotSizeFilter; lot_size_filter: LotSizeFilter;
} }
export interface TimeResult {
time_now: number;
}

View File

@@ -1,66 +1,93 @@
import { InverseFuturesClient } from "../../src/inverse-futures-client"; import { InverseFuturesClient } from '../../src/inverse-futures-client';
import { notAuthenticatedError, successResponseList, successResponseObject } from "../response.util"; import {
notAuthenticatedError,
successResponseList,
successResponseObject,
} from '../response.util';
describe('Public Inverse Futures REST API Endpoints', () => { describe('Public Inverse Futures REST API Endpoints', () => {
const useLivenet = true; 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 symbol = 'BTCUSD';
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('Inverse-Futures only endpoints', () => { describe('Inverse-Futures 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()
);
}); });
}); });
}); });

View File

@@ -80,6 +80,10 @@ describe('Public Inverse REST API Endpoints', () => {
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( expect(await api.getApiAnnouncements()).toMatchObject(
successResponseList() successResponseList()