chore(): moved tests to subfolder

This commit is contained in:
JJ-Cro
2025-03-25 17:31:55 +01:00
parent cde6f1b9a3
commit 34aeea065a
13 changed files with 18 additions and 18 deletions

View File

@@ -0,0 +1,398 @@
import { API_ERROR_CODE, FuturesClient } from '../../src';
import { sucessEmptyResponseObject } from '../response.util';
describe('Private Futures REST API GET Endpoints', () => {
const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_COM;
const API_PASS = process.env.API_PASS_COM;
it('should have api credentials to test with', () => {
expect(API_KEY).toStrictEqual(expect.any(String));
expect(API_SECRET).toStrictEqual(expect.any(String));
expect(API_PASS).toStrictEqual(expect.any(String));
});
const api = new FuturesClient({
apiKey: API_KEY,
apiSecret: API_SECRET,
apiPass: API_PASS,
});
const symbol = 'BTCUSDT_UMCBL';
const marginCoin = 'USDT';
const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60;
const from = timestampOneHourAgo.toFixed(0);
const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes
it('getAccount()', async () => {
try {
expect(await api.getAccount(symbol, marginCoin)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
available: expect.any(String),
btcEquity: expect.any(String),
equity: expect.any(String),
marginCoin: expect.any(String),
marginMode: expect.any(String),
},
});
} catch (e) {
console.error('getAccount: ', e);
expect(e).toBeNull();
}
});
it('getAccounts()', async () => {
try {
expect(await api.getAccounts('umcbl')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
} catch (e) {
console.error('getAccounts: ', e);
expect(e).toBeNull();
}
});
it('getOpenCount()', async () => {
try {
expect(
await api.getOpenCount(symbol, marginCoin, 20000, 1),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {
openCount: expect.any(Number),
},
});
} catch (e) {
console.error('getOpenCount: ', e);
expect(e).toBeNull();
}
});
it('getPosition()', async () => {
try {
expect(await api.getPosition(symbol, marginCoin)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
} catch (e) {
console.error('getPosition: ', e);
expect(e).toBeNull();
}
});
it('getPositions()', async () => {
try {
expect(await api.getPositions('umcbl')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
} catch (e) {
console.error('getPosition: ', e);
expect(e).toBeNull();
}
});
it('getAccountBill()', async () => {
try {
expect(
await api.getAccountBill({
startTime: from,
endTime: to,
marginCoin,
symbol,
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {
lastEndId: null,
nextFlag: false,
preFlag: false,
result: expect.any(Array),
},
});
} catch (e) {
console.error('getAccountBill: ', e);
expect(e).toBeNull();
}
});
it('getBusinessBill()', async () => {
try {
expect(
await api.getBusinessBill({
startTime: from,
endTime: to,
productType: 'umcbl',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {
lastEndId: null,
nextFlag: false,
preFlag: false,
result: expect.any(Array),
},
});
} catch (e) {
console.error('getBusinessBill: ', e);
expect(e).toBeNull();
}
});
it('getOpenSymbolOrders()', async () => {
try {
expect(await api.getOpenSymbolOrders(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
} catch (e) {
console.error('getOpenSymbolOrders: ', e);
expect(e).toBeNull();
}
});
it('getOpenOrders()', async () => {
try {
expect(await api.getOpenOrders('umcbl', marginCoin)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
} catch (e) {
console.error('getOpenOrders: ', e);
expect(e).toBeNull();
}
});
it('getOrderHistory()', async () => {
try {
expect(await api.getOrderHistory(symbol, from, to, '10')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
console.error('getOrderHistory: ', e);
expect(e).toBeNull();
}
});
it('getProductTypeOrderHistory()', async () => {
try {
expect(
await api.getProductTypeOrderHistory('umcbl', from, to, '10'),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
console.error('getProductTypeOrderHistory: ', e);
expect(e).toBeNull();
}
});
it('getOrder() should throw FUTURES_ORDER_NOT_FOUND', async () => {
try {
expect(await api.getOrder(symbol, '12345')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_ORDER_GET_NOT_FOUND,
});
}
});
it('getOrderFills() should throw FUTURES_ORDER_NOT_FOUND', async () => {
try {
expect(await api.getOrderFills(symbol, '12345')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_ORDER_GET_NOT_FOUND,
});
}
});
it('getProductTypeOrderFills() ', async () => {
try {
expect(
await api.getProductTypeOrderFills('umcbl', {
startTime: from,
endTime: to,
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
console.error('getProductTypeOrderFills: ', e);
expect(e).toBeNull();
}
});
it('getPlanOrderTPSLs()', async () => {
try {
expect(await api.getPlanOrderTPSLs(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
console.error('getPlanOrderTPSLs: ', e);
expect(e).toBeNull();
}
});
it('getHistoricPlanOrdersTPSL()', async () => {
try {
expect(
await api.getHistoricPlanOrdersTPSL({
startTime: from,
endTime: to,
symbol,
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
console.error('getHistoricPlanOrdersTPSL: ', e);
expect(e).toBeNull();
}
});
it.skip('getCopyTraderOpenOrder()', async () => {
try {
expect(
await api.getCopyTraderOpenOrder(symbol, 'umcbl', 1, 0),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it('getCopyFollowersOpenOrder()', async () => {
try {
expect(
await api.getCopyFollowersOpenOrder(symbol, 'umcbl', 1, 0),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it.skip('getCopyTraderOrderHistory()', async () => {
try {
expect(await api.getCopyTraderOrderHistory(from, to, 1, 0)).toMatchObject(
{
...sucessEmptyResponseObject(),
data: expect.any(Object),
},
);
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it('getCopyTraderProfitSummary()', async () => {
try {
expect(await api.getCopyTraderProfitSummary()).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it('getCopyTraderHistoricProfitSummary()', async () => {
try {
expect(await api.getCopyTraderHistoricProfitSummary()).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it('getCopyTraderHistoricProfitSummaryByDate()', async () => {
try {
expect(
await api.getCopyTraderHistoricProfitSummaryByDate(
marginCoin,
from,
1,
1,
),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it('getCopyTraderHistoricProfitDetail()', async () => {
try {
expect(
await api.getCopyTraderHistoricProfitDetail(marginCoin, from, 1, 1),
).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it('getCopyTraderProfitDetails()', async () => {
try {
expect(await api.getCopyTraderProfitDetails(1, 1)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it('getCopyTraderSymbols()', async () => {
try {
expect(await api.getCopyTraderSymbols()).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Object),
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
});

View File

@@ -0,0 +1,352 @@
import { API_ERROR_CODE, FuturesClient } from '../../src';
import { sucessEmptyResponseObject } from '../response.util';
jest.setTimeout(10000);
describe('Private Futures REST API POST Endpoints', () => {
const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_COM;
const API_PASS = process.env.API_PASS_COM;
it('should have api credentials to test with', () => {
expect(API_KEY).toStrictEqual(expect.any(String));
expect(API_SECRET).toStrictEqual(expect.any(String));
expect(API_PASS).toStrictEqual(expect.any(String));
});
const api = new FuturesClient({
apiKey: API_KEY,
apiSecret: API_SECRET,
apiPass: API_PASS,
});
const symbol = 'BTCUSDT_UMCBL';
const marginCoin = 'USDT';
// const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60;
// const from = timestampOneHourAgo.toFixed(0);
// const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes
it('setLeverage()', async () => {
try {
expect(await api.setLeverage(symbol, marginCoin, '20')).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
console.error('setLeverage: ', e);
expect(e).toBeNull();
}
});
it('setMargin()', async () => {
try {
expect(await api.setMargin(symbol, marginCoin, '-10')).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
// expect(e).toBeNull();
expect(e.body).toMatchObject({
code: API_ERROR_CODE.PARAMETER_EXCEPTION,
});
}
});
it('setMarginMode()', async () => {
try {
expect(
await api.setMarginMode(symbol, marginCoin, 'crossed'),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
console.error('setMarginMode: ', e);
expect(e).toBeNull();
}
});
it('submitOrder()', async () => {
const symbol = 'BTCUSDT_UMCBL';
const marginCoin = 'USDT';
try {
expect(
await api.submitOrder({
marginCoin,
orderType: 'market',
symbol,
size: '1',
side: 'open_long',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_KYC_REQUIRED,
});
}
});
it('batchSubmitOrder()', async () => {
try {
expect(
await api.batchSubmitOrder(symbol, marginCoin, [
{
orderType: 'market',
size: '1',
side: 'open_long',
},
]),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_KYC_REQUIRED,
});
}
});
it('cancelOrder()', async () => {
try {
expect(
await api.cancelOrder(symbol, marginCoin, '1234656'),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_ORDER_CANCEL_NOT_FOUND,
});
}
});
it('batchCancelOrder()', async () => {
try {
expect(
await api.batchCancelOrder(symbol, marginCoin, ['1234656']),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
console.error('batchCancelOrder: ', e);
expect(e).toBeNull();
}
});
it('cancelAllOrders()', async () => {
try {
expect(await api.cancelAllOrders('umcbl', marginCoin)).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.NO_ORDER_TO_CANCEL,
});
}
});
it.skip('submitPlanOrder()', async () => {
try {
expect(
await api.submitPlanOrder({
marginCoin,
orderType: 'market',
side: 'open_long',
size: '0.1',
symbol,
triggerPrice: '1000',
triggerType: 'market_price',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
// {"code": "40889", "data": null, "msg": "The plan order of this contract has reached the upper limit"
// if the above error is seen, you need to cancel trigger orders on the test account (in futures)
console.error('submitPlanOrder: ', e);
expect(e).toBeNull();
}
});
it.skip('modifyPlanOrder()', async () => {
try {
expect(
await api.modifyPlanOrder({
orderId: '123456',
marginCoin,
orderType: 'market',
symbol,
triggerPrice: '100',
triggerType: 'market_price',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.PLAN_ORDER_NOT_FOUND,
});
}
});
it('modifyPlanOrderTPSL()', async () => {
try {
expect(
await api.modifyPlanOrderTPSL({
orderId: '123456',
marginCoin,
symbol,
presetTakeProfitPrice: '100',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
// expect(e).toBeNull();
expect(e.body).toMatchObject({
code: API_ERROR_CODE.PLAN_ORDER_NOT_FOUND,
});
}
});
it.skip('submitStopOrder()', async () => {
try {
expect(
await api.submitStopOrder({
marginCoin,
symbol,
planType: 'profit_plan',
holdSide: 'long',
triggerPrice: '100',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
// console.log(e.body);
expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_INSUFFICIENT_POSITION_NO_TPSL,
});
}
});
it('submitPositionTPSL()', async () => {
try {
expect(
await api.submitPositionTPSL({
marginCoin,
symbol,
holdSide: 'long',
planType: 'profit_plan',
triggerPrice: '50',
triggerType: 'market_price',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_INSUFFICIENT_POSITION_NO_TPSL,
});
}
});
it('modifyStopOrder()', async () => {
try {
expect(
await api.modifyStopOrder({
marginCoin,
symbol,
orderId: '123456',
planType: 'profit_plan',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
// expect(e).toBeNull();
expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_ORDER_TPSL_NOT_FOUND,
});
}
});
it('cancelPlanOrderTPSL()', async () => {
try {
expect(
await api.cancelPlanOrderTPSL({
marginCoin,
symbol,
orderId: '123456',
planType: 'profit_plan',
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.FUTURES_ORDER_TPSL_NOT_FOUND,
});
}
});
it.skip('closeCopyTraderPosition()', async () => {
try {
expect(await api.closeCopyTraderPosition(symbol, '123456')).toMatchObject(
{
...sucessEmptyResponseObject(),
data: {},
},
);
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it.skip('modifyCopyTraderTPSL()', async () => {
try {
expect(
await api.modifyCopyTraderTPSL(symbol, '123456', {
stopLossPrice: 1234,
}),
).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
it.skip('setCopyTraderSymbols()', async () => {
try {
expect(await api.setCopyTraderSymbols(symbol, 'delete')).toMatchObject({
...sucessEmptyResponseObject(),
data: {},
});
} catch (e) {
expect(e.body).toMatchObject({
code: API_ERROR_CODE.ACCOUNT_NOT_COPY_TRADER,
});
}
});
});

View File

@@ -0,0 +1,143 @@
import { FuturesClient } from '../../src';
import { sucessEmptyResponseObject } from '../response.util';
describe('Public Spot REST API Endpoints', () => {
const api = new FuturesClient();
const symbol = 'BTCUSDT_UMCBL';
const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60;
const from = Number(timestampOneHourAgo.toFixed(0));
const to = from + 1000 * 60 * 30; // 30 minutes
// it('should throw for unauthenticated private calls', async () => {
// expect(() => api.getOpenOrders()).rejects.toMatchObject(
// notAuthenticatedError()
// );
// expect(() => api.getBalances()).rejects.toMatchObject(
// notAuthenticatedError()
// );
// });
/**
*
* Market
*
*/
it('getSymbols()', async () => {
expect(await api.getSymbols('umcbl')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getDepth()', async () => {
expect(await api.getDepth(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
bids: expect.any(Array),
asks: expect.any(Array),
},
});
});
it('getTicker()', async () => {
expect(await api.getTicker(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
bestAsk: expect.any(String),
bestBid: expect.any(String),
},
});
});
it('getAllTickers()', async () => {
expect(await api.getAllTickers('umcbl')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getMarketTrades()', async () => {
expect(await api.getMarketTrades(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getCandles()', async () => {
expect(
await api.getCandles(symbol, '1m', `${from}`, `${to}`),
).toMatchObject(expect.any(Array));
});
it('getIndexPrice()', async () => {
expect(await api.getIndexPrice(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
index: expect.any(String),
symbol: expect.any(String),
timestamp: expect.any(String),
},
});
});
it('getNextFundingTime()', async () => {
expect(await api.getNextFundingTime(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
fundingTime: expect.any(String),
symbol: expect.any(String),
},
});
});
it('getHistoricFundingRate()', async () => {
expect(await api.getHistoricFundingRate(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getCurrentFundingRate()', async () => {
expect(await api.getCurrentFundingRate(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
fundingRate: expect.any(String),
symbol: expect.any(String),
},
});
});
it('getOpenInterest()', async () => {
expect(await api.getOpenInterest(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
amount: expect.any(String),
symbol: expect.any(String),
timestamp: expect.any(String),
},
});
});
it('getMarkPrice()', async () => {
expect(await api.getMarkPrice(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
markPrice: expect.any(String),
symbol: expect.any(String),
timestamp: expect.any(String),
},
});
});
it('getLeverageMinMax()', async () => {
expect(await api.getLeverageMinMax(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
maxLeverage: expect.any(String),
minLeverage: expect.any(String),
symbol: expect.any(String),
},
});
});
});