public v3 spot tests

This commit is contained in:
tiagosiebler
2022-09-10 12:39:08 +01:00
parent c287495052
commit f7b251c26d
4 changed files with 80 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ export * from './inverse-client';
export * from './inverse-futures-client';
export * from './linear-client';
export * from './spot-client';
export * from './spot-client-v3';
export * from './usdc-option-client';
export * from './usdc-perpetual-client';
export * from './websocket-client';

View File

@@ -18,7 +18,7 @@ import BaseRestClient from './util/BaseRestClient';
/**
* REST API client for newer Spot V3 APIs.
*/
export class SpotV3Client extends BaseRestClient {
export class SpotClientV3 extends BaseRestClient {
getClientType() {
// Follows the same authentication mechanism as other v3 APIs (e.g. USDC)
return REST_CLIENT_TYPE_ENUM.v3;
@@ -46,7 +46,7 @@ export class SpotV3Client extends BaseRestClient {
}
/** Get merged orderbook for symbol */
getOrderBookMerged(
getMergedOrderBook(
symbol: string,
scale?: number,
limit?: number

View File

@@ -16,14 +16,14 @@ export function successResponseObject(successMsg: string | null = 'OK') {
};
}
export function successUSDCResponseObject() {
export function successResponseObjectV3() {
return {
result: expect.any(Object),
...successUSDCEmptyResponseObject(),
...successEmptyResponseObjectV3(),
};
}
export function successUSDCEmptyResponseObject() {
export function successEmptyResponseObjectV3() {
return {
retCode: API_ERROR_CODE.SUCCESS,
retMsg: expect.stringMatching(

View File

@@ -0,0 +1,74 @@
import { SpotClientV3 } from '../../src';
import {
notAuthenticatedError,
successResponseList,
successResponseObject,
successResponseObjectV3,
} from '../response.util';
describe('Public Spot REST API Endpoints', () => {
const useLivenet = true;
const api = new SpotClientV3(undefined, undefined, useLivenet);
const symbol = 'BTCUSDT';
const interval = '15m';
const timestampOneHourAgo = new Date().getTime() / 1000 - 1000 * 60 * 60;
const from = Number(timestampOneHourAgo.toFixed(0));
it('should throw for unauthenticated private calls', async () => {
expect(() => api.getOpenOrders()).rejects.toMatchObject(
notAuthenticatedError()
);
expect(() => api.getBalances()).rejects.toMatchObject(
notAuthenticatedError()
);
});
it('getSymbols()', async () => {
expect(await api.getSymbols()).toMatchObject(successResponseObjectV3());
});
it('getOrderBook()', async () => {
expect(await api.getOrderBook(symbol)).toMatchObject(
successResponseObjectV3()
);
});
it('getMergedOrderBook()', async () => {
expect(await api.getMergedOrderBook(symbol)).toMatchObject(
successResponseObjectV3()
);
});
it('getTrades()', async () => {
expect(await api.getTrades(symbol)).toMatchObject(
successResponseObjectV3()
);
});
it('getCandles()', async () => {
expect(await api.getCandles(symbol, interval)).toMatchObject(
successResponseObjectV3()
);
});
it('get24hrTicker()', async () => {
expect(await api.get24hrTicker()).toMatchObject(successResponseObjectV3());
});
it('getLastTradedPrice()', async () => {
expect(await api.getLastTradedPrice()).toMatchObject(
successResponseObjectV3()
);
});
it('getBestBidAskPrice()', async () => {
expect(await api.getBestBidAskPrice()).toMatchObject(
successResponseObjectV3()
);
});
it('fetchServertime() returns number', async () => {
expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number));
});
});