chore(): moved tests to subfolder
This commit is contained in:
171
test/v2/private.read.test.ts
Normal file
171
test/v2/private.read.test.ts
Normal file
@@ -0,0 +1,171 @@
|
||||
import { RestClientV2 } from '../../src/rest-client-v2';
|
||||
import {
|
||||
errorResponseObjectV3,
|
||||
sucessEmptyResponseObject,
|
||||
} from '../response.util';
|
||||
|
||||
describe('Bitget Private REST API Read Endpoints', () => {
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
const API_PASSPHRASE = process.env.API_PASS_COM;
|
||||
|
||||
const api = new RestClientV2({
|
||||
apiKey: API_KEY!,
|
||||
apiSecret: API_SECRET!,
|
||||
apiPass: API_PASSPHRASE!,
|
||||
});
|
||||
|
||||
it('should have api credentials to use', () => {
|
||||
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||
expect(API_PASSPHRASE).toStrictEqual(expect.any(String));
|
||||
});
|
||||
|
||||
describe('Account Endpoints', () => {
|
||||
it('getSpotAccount()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotAccount();
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getSpotAccountAssets()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotAccountAssets();
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getSpotAccountBills()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotAccountBills();
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Trade Endpoints', () => {
|
||||
it('getSpotOrder()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotOrder({
|
||||
orderId: '123456789',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getSpotOpenOrders()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotOpenOrders();
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getSpotHistoricOrders()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotHistoricOrders();
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getSpotFills()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotFills({
|
||||
symbol: 'BTCUSDT',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Funding Endpoints', () => {
|
||||
it('getSpotDepositHistory()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotDepositHistory({
|
||||
startTime: '1715808000000',
|
||||
endTime: '1715894400000',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getSpotWithdrawalHistory()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotWithdrawalHistory({
|
||||
startTime: '1715808000000',
|
||||
endTime: '1715894400000',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getSpotTransferHistory()', async () => {
|
||||
try {
|
||||
const res = await api.getSpotTransferHistory({
|
||||
coin: 'BTC',
|
||||
fromType: 'spot',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Futures Endpoints', () => {
|
||||
it('getFuturesAccountAsset()', async () => {
|
||||
try {
|
||||
const res = await api.getFuturesAccountAsset({
|
||||
symbol: 'BTCUSDT',
|
||||
marginCoin: 'USDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getFuturesPositions()', async () => {
|
||||
try {
|
||||
const res = await api.getFuturesPositions({
|
||||
productType: 'USDT-FUTURES',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('getFuturesOrder()', async () => {
|
||||
try {
|
||||
const res = await api.getFuturesOrder({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
orderId: '123456789',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40109')); // The data of the order cannot be found, please confirm the order number
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
195
test/v2/private.write.test.ts
Normal file
195
test/v2/private.write.test.ts
Normal file
@@ -0,0 +1,195 @@
|
||||
import { RestClientV2 } from '../../src/rest-client-v2';
|
||||
import {
|
||||
errorResponseObjectV3,
|
||||
sucessEmptyResponseObject,
|
||||
} from '../response.util';
|
||||
|
||||
describe('Bitget Private REST API Write Endpoints', () => {
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
const API_PASSPHRASE = process.env.API_PASS_COM;
|
||||
|
||||
const api = new RestClientV2({
|
||||
apiKey: API_KEY!,
|
||||
apiSecret: API_SECRET!,
|
||||
apiPass: API_PASSPHRASE!,
|
||||
});
|
||||
|
||||
it('should have api credentials to use', () => {
|
||||
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||
expect(API_PASSPHRASE).toStrictEqual(expect.any(String));
|
||||
});
|
||||
|
||||
describe('Trade Endpoints', () => {
|
||||
it('spotSubmitOrder()', async () => {
|
||||
try {
|
||||
const res = await api.spotSubmitOrder({
|
||||
symbol: 'BTCUSDT',
|
||||
side: 'buy',
|
||||
orderType: 'limit',
|
||||
price: '20000',
|
||||
size: '0.001',
|
||||
force: 'gtc',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('43012')); // not enough balance
|
||||
}
|
||||
});
|
||||
|
||||
it('spotCancelOrder()', async () => {
|
||||
try {
|
||||
const res = await api.spotCancelOrder({
|
||||
symbol: 'BTCUSDT',
|
||||
orderId: '123456789',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('43001')); //The order does not exist
|
||||
}
|
||||
});
|
||||
|
||||
it('spotBatchSubmitOrders()', async () => {
|
||||
try {
|
||||
const res = await api.spotBatchSubmitOrders({
|
||||
symbol: 'BTCUSDT',
|
||||
orderList: [
|
||||
{
|
||||
symbol: 'BTCUSDT',
|
||||
side: 'buy',
|
||||
orderType: 'limit',
|
||||
price: '20000',
|
||||
size: '0.001',
|
||||
force: 'gtc',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('43001')); //The order does not exist
|
||||
}
|
||||
});
|
||||
|
||||
it('spotBatchCancelOrders()', async () => {
|
||||
try {
|
||||
const res = await api.spotBatchCancelOrders({
|
||||
symbol: 'BTCUSDT',
|
||||
orderList: [
|
||||
{
|
||||
symbol: 'BTCUSDT',
|
||||
orderId: '123456789',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('43001')); //The order does not exist
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Funding Endpoints', () => {
|
||||
it('spotTransfer()', async () => {
|
||||
try {
|
||||
const res = await api.spotTransfer({
|
||||
fromType: 'spot',
|
||||
toType: 'coin_futures',
|
||||
amount: '0.001',
|
||||
coin: 'BTC',
|
||||
symbol: 'BTCUSDT',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('43117')); // Exceeds the maximum amount that can be transferred
|
||||
}
|
||||
});
|
||||
|
||||
it('spotWithdraw()', async () => {
|
||||
try {
|
||||
const res = await api.spotWithdraw({
|
||||
coin: 'BTC',
|
||||
address: 'test_address',
|
||||
chain: 'BTC',
|
||||
transferType: 'on_chain',
|
||||
size: '0.001',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40014')); // Incorrect permissions
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Futures Endpoints', () => {
|
||||
it('futuresSubmitOrder()', async () => {
|
||||
try {
|
||||
const res = await api.futuresSubmitOrder({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
side: 'buy',
|
||||
orderType: 'limit',
|
||||
price: '20000',
|
||||
size: '0.001',
|
||||
marginMode: 'isolated',
|
||||
marginCoin: 'USDT',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40774')); // The order type for unilateral position must also be the unilateral position type.
|
||||
}
|
||||
});
|
||||
|
||||
it('futuresCancelOrder()', async () => {
|
||||
try {
|
||||
const res = await api.futuresCancelOrder({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
orderId: '123456789',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('40768')); // The order does not exist
|
||||
}
|
||||
});
|
||||
|
||||
it('futuresBatchSubmitOrders()', async () => {
|
||||
try {
|
||||
const res = await api.futuresBatchSubmitOrders({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
marginCoin: 'USDT',
|
||||
marginMode: 'crossed',
|
||||
orderList: [
|
||||
{
|
||||
side: 'buy',
|
||||
orderType: 'limit',
|
||||
price: '20000',
|
||||
size: '0.001',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('43001'));
|
||||
}
|
||||
});
|
||||
|
||||
it('futuresBatchCancelOrders()', async () => {
|
||||
try {
|
||||
const res = await api.futuresBatchCancelOrders({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
orderIdList: [
|
||||
{
|
||||
orderId: '123456789',
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
} catch (e) {
|
||||
expect(e).toMatchObject(errorResponseObjectV3('43001'));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
76
test/v2/public.test.ts
Normal file
76
test/v2/public.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { RestClientV2 } from '../../src/rest-client-v2';
|
||||
import { sucessEmptyResponseObject } from '../response.util';
|
||||
|
||||
describe('Bitget Public REST API Endpoints', () => {
|
||||
const api = new RestClientV2();
|
||||
|
||||
describe('public endpoints', () => {
|
||||
it('should succeed making a GET request without params', async () => {
|
||||
const res = await api.getServerTime();
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should succeed making a GET request with params', async () => {
|
||||
const res = await api.getSpotTicker({ symbol: 'BTCUSDT' });
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should return orderbook data', async () => {
|
||||
const res = await api.getSpotOrderBookDepth({
|
||||
symbol: 'BTCUSDT',
|
||||
type: 'step0',
|
||||
limit: '20',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should return candles data', async () => {
|
||||
const res = await api.getSpotCandles({
|
||||
symbol: 'BTCUSDT',
|
||||
granularity: '1min',
|
||||
limit: '100',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should return recent trades', async () => {
|
||||
const res = await api.getSpotRecentTrades({
|
||||
symbol: 'BTCUSDT',
|
||||
limit: '20',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should return historic trades', async () => {
|
||||
const res = await api.getSpotHistoricTrades({
|
||||
symbol: 'BTCUSDT',
|
||||
limit: '20',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should return funding rate data', async () => {
|
||||
const res = await api.getFuturesCurrentFundingRate({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should return open interest data', async () => {
|
||||
const res = await api.getFuturesOpenInterest({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
|
||||
it('should return contract config', async () => {
|
||||
const res = await api.getFuturesContractConfig({
|
||||
symbol: 'BTCUSDT',
|
||||
productType: 'USDT-FUTURES',
|
||||
});
|
||||
expect(res).toMatchObject(sucessEmptyResponseObject());
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user