move test to v5 folder
This commit is contained in:
265
test/v5/private.read.test.ts
Normal file
265
test/v5/private.read.test.ts
Normal file
@@ -0,0 +1,265 @@
|
||||
import { API_ERROR_CODE, RestClientV5 } from '../../src';
|
||||
import { successResponseObjectV3 } from '../response.util';
|
||||
|
||||
describe('Private READ V5 REST API Endpoints', () => {
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
|
||||
it('should have api credentials to test with', () => {
|
||||
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||
});
|
||||
|
||||
const api = new RestClientV5({
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
});
|
||||
|
||||
const settleCoin = 'USDT';
|
||||
const linearSymbol = 'BTCUSDT';
|
||||
|
||||
describe('misc endpoints', () => {
|
||||
it('fetchServerTime()', async () => {
|
||||
expect(await api.fetchServerTime()).toEqual(expect.any(Number));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Trade APIs', () => {
|
||||
it('getActiveOrders()', async () => {
|
||||
expect(
|
||||
await api.getActiveOrders({ category: 'linear', settleCoin })
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getHistoricOrders()', async () => {
|
||||
expect(await api.getHistoricOrders({ category: 'linear' })).toMatchObject(
|
||||
{ ...successResponseObjectV3() }
|
||||
);
|
||||
});
|
||||
|
||||
it('getSpotBorrowCheck()', async () => {
|
||||
expect(await api.getSpotBorrowCheck(linearSymbol, 'Buy')).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Position APIs', () => {
|
||||
it('getPositionInfo()', async () => {
|
||||
expect(
|
||||
await api.getPositionInfo({ category: 'linear', settleCoin })
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getExecutionList()', async () => {
|
||||
expect(
|
||||
await api.getExecutionList({ category: 'linear', symbol: linearSymbol })
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getClosedPnL()', async () => {
|
||||
expect(
|
||||
await api.getClosedPnL({ category: 'linear', symbol: linearSymbol })
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Account APIs', () => {
|
||||
it('getWalletBalance()', async () => {
|
||||
expect(
|
||||
await api.getWalletBalance({ accountType: 'CONTRACT' })
|
||||
).toMatchObject({ ...successResponseObjectV3() });
|
||||
});
|
||||
|
||||
it('getBorrowHistory()', async () => {
|
||||
expect(await api.getBorrowHistory()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getCollateralInfo()', async () => {
|
||||
expect(await api.getCollateralInfo()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
// Not available on this test account
|
||||
it.skip('getCoinGreeks()', async () => {
|
||||
expect(await api.getCoinGreeks()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
retMsg: '',
|
||||
});
|
||||
});
|
||||
|
||||
it('getFeeRate()', async () => {
|
||||
expect(await api.getFeeRate()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
// Fails on this test account, since it's not upgraded
|
||||
it.skip('getAccountInfo()', async () => {
|
||||
expect(await api.getAccountInfo()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
retMsg: '',
|
||||
});
|
||||
});
|
||||
|
||||
it('getTransactionLog()', async () => {
|
||||
expect(await api.getTransactionLog()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
// Not available on this test account
|
||||
it.skip('getMMPState()', async () => {
|
||||
expect(await api.getMMPState(settleCoin)).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
retMsg: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Asset APIs', () => {
|
||||
it('getCoinExchangeRecords()', async () => {
|
||||
expect(await api.getCoinExchangeRecords()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getDeliveryRecord()', async () => {
|
||||
expect(await api.getDeliveryRecord({ category: 'option' })).toMatchObject(
|
||||
{ ...successResponseObjectV3() }
|
||||
);
|
||||
});
|
||||
|
||||
it('getSettlementRecords()', async () => {
|
||||
expect(
|
||||
await api.getSettlementRecords({ category: 'linear' })
|
||||
).toMatchObject({ ...successResponseObjectV3() });
|
||||
});
|
||||
|
||||
it('getAssetInfo()', async () => {
|
||||
expect(await api.getAssetInfo({ accountType: 'SPOT' })).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getAllCoinsBalance()', async () => {
|
||||
expect(
|
||||
await api.getAllCoinsBalance({ accountType: 'SPOT' })
|
||||
).toMatchObject({ ...successResponseObjectV3() });
|
||||
});
|
||||
|
||||
it('getCoinBalance()', async () => {
|
||||
expect(
|
||||
await api.getCoinBalance({ accountType: 'SPOT', coin: settleCoin })
|
||||
).toMatchObject({ ...successResponseObjectV3() });
|
||||
});
|
||||
|
||||
it('getTransferableCoinList()', async () => {
|
||||
expect(
|
||||
await api.getTransferableCoinList('SPOT', 'CONTRACT')
|
||||
).toMatchObject({ ...successResponseObjectV3() });
|
||||
});
|
||||
|
||||
it('getInternalTransferRecords()', async () => {
|
||||
expect(await api.getInternalTransferRecords()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getSubUID()', async () => {
|
||||
expect(await api.getSubUID()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getUniversalTransferRecords()', async () => {
|
||||
expect(await api.getUniversalTransferRecords()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getAllowedDepositCoinInfo()', async () => {
|
||||
expect(await api.getAllowedDepositCoinInfo()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getDepositRecords()', async () => {
|
||||
expect(await api.getDepositRecords()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getSubAccountDepositRecords()', async () => {
|
||||
expect(
|
||||
await api.getSubAccountDepositRecords({ subMemberId: 'fakeid' })
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// Expected, since sub account ID is fake
|
||||
retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG,
|
||||
});
|
||||
});
|
||||
|
||||
it('getMasterDepositAddress()', async () => {
|
||||
expect(await api.getMasterDepositAddress(settleCoin)).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('querySubMemberAddress()', async () => {
|
||||
expect(
|
||||
await api.querySubMemberAddress(settleCoin, 'TRC20', 'fakeid')
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// Expected, since sub account ID is fake
|
||||
retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG,
|
||||
});
|
||||
});
|
||||
|
||||
it('getCoinInfo()', async () => {
|
||||
expect(await api.getCoinInfo()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getWithdrawalRecords()', async () => {
|
||||
expect(await api.getWithdrawalRecords()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('User APIs', () => {
|
||||
it('getSubUIDList()', async () => {
|
||||
expect(await api.getSubUIDList()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('getQueryApiKey()', async () => {
|
||||
expect(await api.getQueryApiKey()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Spot Leverage Token APIs', () => {
|
||||
it('getSpotLeveragedTokenOrderHistory()', async () => {
|
||||
expect(await api.getSpotLeveragedTokenOrderHistory()).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
464
test/v5/private.write.test.ts
Normal file
464
test/v5/private.write.test.ts
Normal file
@@ -0,0 +1,464 @@
|
||||
import {
|
||||
API_ERROR_CODE,
|
||||
LeverageTokenInfoV5,
|
||||
OrderSideV5,
|
||||
OrderTypeV5,
|
||||
RestClientV5,
|
||||
} from '../../src';
|
||||
import { successResponseObjectV3 } from '../response.util';
|
||||
|
||||
describe('Private WRITE V5 REST API Endpoints', () => {
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
|
||||
it('should have api credentials to test with', () => {
|
||||
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||
});
|
||||
|
||||
const api = new RestClientV5({
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
});
|
||||
|
||||
const settleCoin = 'USDT';
|
||||
const linearSymbol = 'BTCUSDT';
|
||||
const orderType: OrderTypeV5 = 'Market';
|
||||
const orderSide: OrderSideV5 = 'Buy';
|
||||
const fakeOrderId = 'fakeOrderId';
|
||||
|
||||
const fakeTransferId = '42c0cfb0-6bca-c242-bc76-4e6df6cbcb16';
|
||||
|
||||
describe('misc endpoints', () => {
|
||||
it('fetchServerTime()', async () => {
|
||||
expect(await api.fetchServerTime()).toEqual(expect.any(Number));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Trade APIs', () => {
|
||||
it('submitOrder()', async () => {
|
||||
expect(
|
||||
await api.submitOrder({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
orderType: orderType,
|
||||
side: orderSide,
|
||||
qty: '1',
|
||||
positionIdx: 1,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_INSUFFICIENT_BALANCE,
|
||||
});
|
||||
});
|
||||
|
||||
it('amendOrder()', async () => {
|
||||
expect(
|
||||
await api.amendOrder({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
qty: '2',
|
||||
orderId: fakeOrderId,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_ORDER_NOT_FOUND,
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelOrder()', async () => {
|
||||
expect(
|
||||
await api.cancelOrder({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
orderId: fakeOrderId,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_ORDER_NOT_FOUND,
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelAllOrders()', async () => {
|
||||
expect(
|
||||
await api.cancelAllOrders({
|
||||
category: 'linear',
|
||||
settleCoin: settleCoin,
|
||||
})
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
describe('options only methods', () => {
|
||||
// These should use a real symbol from the options category
|
||||
let optionsSymbol: string;
|
||||
beforeAll(async () => {
|
||||
const deliveryPriceResponse = await api.getOptionDeliveryPrice({
|
||||
category: 'option',
|
||||
});
|
||||
const resultsList = deliveryPriceResponse.result.list;
|
||||
optionsSymbol = resultsList[0].symbol;
|
||||
});
|
||||
|
||||
it('batchSubmitOrders()', async () => {
|
||||
expect(
|
||||
await api.batchSubmitOrders('option', [
|
||||
{
|
||||
orderLinkId: 'customOrderId1',
|
||||
orderType: orderType,
|
||||
qty: '1',
|
||||
side: orderSide,
|
||||
symbol: optionsSymbol,
|
||||
},
|
||||
{
|
||||
orderLinkId: 'customOrderId2',
|
||||
orderType: orderType,
|
||||
qty: '2',
|
||||
side: orderSide,
|
||||
symbol: optionsSymbol,
|
||||
},
|
||||
])
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('batchAmendOrders()', async () => {
|
||||
expect(
|
||||
await api.batchAmendOrders('option', [
|
||||
{
|
||||
orderLinkId: 'customOrderId1',
|
||||
qty: '3',
|
||||
symbol: optionsSymbol,
|
||||
},
|
||||
{
|
||||
orderLinkId: 'customOrderId2',
|
||||
qty: '4',
|
||||
symbol: optionsSymbol,
|
||||
},
|
||||
])
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('batchCancelOrders()', async () => {
|
||||
expect(
|
||||
await api.batchCancelOrders('option', [
|
||||
{
|
||||
orderLinkId: 'customOrderId1',
|
||||
symbol: optionsSymbol,
|
||||
},
|
||||
{
|
||||
orderLinkId: 'customOrderId2',
|
||||
symbol: optionsSymbol,
|
||||
},
|
||||
])
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('setDisconnectCancelAllWindow()', async () => {
|
||||
expect(await api.setDisconnectCancelAllWindow('option', 5)).toMatchObject(
|
||||
{
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_API_KEY_PERMISSION_DENIED,
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Position APIs', () => {
|
||||
it('setLeverage()', async () => {
|
||||
expect(
|
||||
await api.setLeverage({
|
||||
category: 'linear',
|
||||
buyLeverage: '10',
|
||||
sellLeverage: '10',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_LEVERAGE_NOT_CHANGED,
|
||||
});
|
||||
});
|
||||
|
||||
it('switchIsolatedMargin()', async () => {
|
||||
expect(
|
||||
await api.switchIsolatedMargin({
|
||||
category: 'linear',
|
||||
buyLeverage: '10',
|
||||
sellLeverage: '10',
|
||||
symbol: linearSymbol,
|
||||
// isolated
|
||||
tradeMode: 1,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_CROSS_ISOLATED_MARGIN_NOT_CHANGED,
|
||||
});
|
||||
});
|
||||
|
||||
it('setTPSLMode()', async () => {
|
||||
expect(
|
||||
await api.setTPSLMode({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
tpSlMode: 'Full',
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_TPSL_NOT_CHANGED,
|
||||
});
|
||||
});
|
||||
|
||||
it('switchPositionMode()', async () => {
|
||||
expect(
|
||||
await api.switchPositionMode({
|
||||
category: 'linear',
|
||||
// both sides
|
||||
mode: 3,
|
||||
coin: settleCoin,
|
||||
})
|
||||
).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('setRiskLimit()', async () => {
|
||||
expect(
|
||||
await api.setRiskLimit({
|
||||
category: 'linear',
|
||||
positionIdx: 1,
|
||||
riskId: 1,
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_RISK_ID_NOT_CHANGED,
|
||||
});
|
||||
});
|
||||
|
||||
it('setTradingStop()', async () => {
|
||||
expect(
|
||||
await api.setTradingStop({
|
||||
category: 'linear',
|
||||
positionIdx: 1,
|
||||
symbol: linearSymbol,
|
||||
slSize: '100',
|
||||
slTriggerBy: 'LastPrice',
|
||||
stopLoss: '25000',
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_TPSL_ERROR_NO_POSITION,
|
||||
});
|
||||
});
|
||||
|
||||
it('setAutoAddMargin()', async () => {
|
||||
expect(
|
||||
await api.setAutoAddMargin({
|
||||
category: 'linear',
|
||||
autoAddMargin: 0,
|
||||
symbol: linearSymbol,
|
||||
positionIdx: 0,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_AUTO_ADD_MARGIN_NOT_CHANGED,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Account APIs', () => {
|
||||
it('setMarginMode()', async () => {
|
||||
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.V5_MARGIN_MODE_NOT_CHANGED,
|
||||
});
|
||||
});
|
||||
|
||||
it('setMMP()', async () => {
|
||||
expect(
|
||||
await api.setMMP({
|
||||
baseCoin: settleCoin,
|
||||
deltaLimit: '1',
|
||||
frozenPeriod: '1',
|
||||
qtyLimit: '1',
|
||||
window: '1',
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.INSTITION_MMP_PROFILE_NOT_FOUND,
|
||||
});
|
||||
});
|
||||
|
||||
it('resetMMP()', async () => {
|
||||
expect(await api.resetMMP(settleCoin)).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.INSTITION_MMP_PROFILE_NOT_FOUND,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Asset APIs', () => {
|
||||
it('createInternalTransfer()', async () => {
|
||||
expect(
|
||||
await api.createInternalTransfer(
|
||||
fakeTransferId,
|
||||
settleCoin,
|
||||
'100',
|
||||
'SPOT',
|
||||
'CONTRACT'
|
||||
)
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: expect.any(Number),
|
||||
});
|
||||
});
|
||||
|
||||
it('enableUniversalTransferForSubUIDs()', async () => {
|
||||
expect(await api.enableUniversalTransferForSubUIDs([])).toMatchObject({
|
||||
...successResponseObjectV3(),
|
||||
});
|
||||
});
|
||||
|
||||
it('createUniversalTransfer()', async () => {
|
||||
expect(
|
||||
await api.createUniversalTransfer({
|
||||
amount: '100',
|
||||
coin: settleCoin,
|
||||
fromAccountType: 'SPOT',
|
||||
fromMemberId: 1,
|
||||
toAccountType: 'CONTRACT',
|
||||
toMemberId: 2,
|
||||
transferId: fakeTransferId,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: expect.any(Number),
|
||||
});
|
||||
});
|
||||
|
||||
it('submitWithdrawal()', async () => {
|
||||
expect(
|
||||
await api.submitWithdrawal({
|
||||
address: '0x000000',
|
||||
amount: '100',
|
||||
chain: 'TRC20',
|
||||
coin: settleCoin,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelWithdrawal()', async () => {
|
||||
expect(await api.cancelWithdrawal('fakeId')).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('User APIs', () => {
|
||||
it('createSubMember()', async () => {
|
||||
expect(
|
||||
await api.createSubMember({
|
||||
memberType: 1,
|
||||
username: 'sub1account',
|
||||
switch: 1,
|
||||
note: 'created via e2e test',
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.SUB_USER_ALREADY_EXISTS,
|
||||
});
|
||||
});
|
||||
|
||||
it('setSubUIDFrozenState()', async () => {
|
||||
expect(await api.setSubUIDFrozenState(0, 1)).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.SUB_USER_NOT_FOUND,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Spot Leverage Token APIs', () => {
|
||||
let leverageToken: LeverageTokenInfoV5;
|
||||
|
||||
beforeAll(async () => {
|
||||
const tokenResult = await api.getLeveragedTokenInfo();
|
||||
leverageToken = tokenResult.result.list[0];
|
||||
});
|
||||
|
||||
// Still failing - in contact with bybit
|
||||
it.skip('purchaseSpotLeveragedToken()', async () => {
|
||||
expect(
|
||||
await api.purchaseSpotLeveragedToken({
|
||||
ltAmount: '100',
|
||||
ltCoin: leverageToken.ltCoin,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE,
|
||||
retMsg: '',
|
||||
});
|
||||
});
|
||||
|
||||
it('redeemSpotLeveragedToken()', async () => {
|
||||
expect(
|
||||
await api.redeemSpotLeveragedToken({
|
||||
quantity: '100',
|
||||
ltCoin: leverageToken.ltCoin,
|
||||
})
|
||||
).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE,
|
||||
// retMsg: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Spot Margin APIs', () => {
|
||||
it('toggleSpotMarginTrade()', async () => {
|
||||
expect(await api.toggleSpotMarginTrade('1')).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.SPOT_MARGIN_QUESTIONNAIRE_NOT_SUBMIT,
|
||||
});
|
||||
});
|
||||
|
||||
it('setSpotMarginLeverage()', async () => {
|
||||
expect(await api.setSpotMarginLeverage('2')).toMatchObject({
|
||||
// ...successResponseObjectV3(),
|
||||
// retMsg: '',
|
||||
retCode: API_ERROR_CODE.SPOT_MARGIN_NOT_ENABLED,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
153
test/v5/public.read.test.ts
Normal file
153
test/v5/public.read.test.ts
Normal file
@@ -0,0 +1,153 @@
|
||||
import { RestClientV5 } from '../../src';
|
||||
import { successResponseObjectV3 } from '../response.util';
|
||||
|
||||
describe('Public V5 REST API Endpoints', () => {
|
||||
const API_KEY = undefined;
|
||||
const API_SECRET = undefined;
|
||||
|
||||
const api = new RestClientV5({
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
});
|
||||
|
||||
const linearSymbol = 'BTCUSDT';
|
||||
|
||||
describe('Misc Endpoints', () => {
|
||||
it('fetchServerTime()', async () => {
|
||||
expect(await api.fetchServerTime()).toEqual(expect.any(Number));
|
||||
});
|
||||
|
||||
it('getServerTime()', async () => {
|
||||
expect(await api.getServerTime()).toMatchObject(
|
||||
successResponseObjectV3()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Market Endpoints', () => {
|
||||
it('getKline()', async () => {
|
||||
expect(
|
||||
await api.getKline({
|
||||
category: 'linear',
|
||||
interval: '1',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getMarkPriceKline()', async () => {
|
||||
expect(
|
||||
await api.getMarkPriceKline({
|
||||
category: 'linear',
|
||||
interval: '1',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getIndexPriceKline()', async () => {
|
||||
expect(
|
||||
await api.getIndexPriceKline({
|
||||
category: 'linear',
|
||||
interval: '1',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getPremiumIndexPriceKline()', async () => {
|
||||
expect(
|
||||
await api.getPremiumIndexPriceKline({
|
||||
category: 'linear',
|
||||
interval: '1',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getInstrumentsInfo()', async () => {
|
||||
expect(
|
||||
await api.getInstrumentsInfo({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getOrderbook()', async () => {
|
||||
expect(
|
||||
await api.getOrderbook({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getTickers()', async () => {
|
||||
expect(
|
||||
await api.getTickers({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getFundingRateHistory()', async () => {
|
||||
expect(
|
||||
await api.getFundingRateHistory({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getPublicTradingHistory()', async () => {
|
||||
expect(
|
||||
await api.getPublicTradingHistory({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getOpenInterest()', async () => {
|
||||
expect(
|
||||
await api.getOpenInterest({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
intervalTime: '15min',
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getHistoricalVolatility()', async () => {
|
||||
expect(
|
||||
await api.getHistoricalVolatility({
|
||||
category: 'option',
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getInsurance()', async () => {
|
||||
expect(await api.getInsurance()).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getRiskLimit()', async () => {
|
||||
expect(
|
||||
await api.getRiskLimit({
|
||||
category: 'linear',
|
||||
symbol: linearSymbol,
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getOptionDeliveryPrice()', async () => {
|
||||
expect(
|
||||
await api.getOptionDeliveryPrice({
|
||||
category: 'option',
|
||||
})
|
||||
).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user