chore(): reuploaded tests for legacy client
This commit is contained in:
202
test/spot/private.read.test.ts
Normal file
202
test/spot/private.read.test.ts
Normal file
@@ -0,0 +1,202 @@
|
||||
import { SpotClient } from '../../src';
|
||||
import { sucessEmptyResponseObject } from '../response.util';
|
||||
|
||||
describe('Private Spot 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 SpotClient({
|
||||
apiKey: API_KEY,
|
||||
apiSecret: API_SECRET,
|
||||
apiPass: API_PASS,
|
||||
});
|
||||
|
||||
const symbol = 'BTCUSDT_SPBL';
|
||||
const coin = 'BTC';
|
||||
const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60;
|
||||
const from = timestampOneHourAgo.toFixed(0);
|
||||
const to = String(Number(from) + 1000 * 60 * 30); // 30 minutes
|
||||
|
||||
// Seems to throw a permission error, probably because withdrawal permissions aren't set on this key (requires IP whitelist)
|
||||
it.skip('getDepositAddress()', async () => {
|
||||
try {
|
||||
expect(await api.getDepositAddress(coin)).toStrictEqual('');
|
||||
} catch (e) {
|
||||
console.error('exception: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getWithdrawals()', async () => {
|
||||
try {
|
||||
expect(await api.getWithdrawals(coin, from, to)).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getWithdrawals: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getDeposits()', async () => {
|
||||
try {
|
||||
expect(await api.getDeposits(coin, from, to)).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getDeposits: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getApiKeyInfo()', async () => {
|
||||
// No auth error == test pass
|
||||
try {
|
||||
expect(await api.getApiKeyInfo()).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: {
|
||||
user_id: expect.any(String),
|
||||
authorities: expect.any(Array),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getApiKeyInfo: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getBalance()', async () => {
|
||||
try {
|
||||
// expect(await api.getWithdrawals(coin, from, to)).toStrictEqual('');
|
||||
expect(await api.getBalance()).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getBalance: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getTransactionHistory()', async () => {
|
||||
try {
|
||||
expect(await api.getTransactionHistory()).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getTransactionHistory: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
// Sees exception now about requiring coinId. Question sent to bitget 7th feb.
|
||||
it.skip('getTransferHistory()', async () => {
|
||||
try {
|
||||
expect(await api.getTransferHistory()).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getTransferHistory: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getOrder()', async () => {
|
||||
try {
|
||||
expect(await api.getOrder(symbol, '12345')).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getOrder: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getOpenOrders()', async () => {
|
||||
try {
|
||||
expect(await api.getOpenOrders()).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getOpenOrders: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getOrderHistory()', async () => {
|
||||
try {
|
||||
expect(await api.getOrderHistory(symbol)).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getOrderHistory: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getOrderFills()', async () => {
|
||||
try {
|
||||
expect(await api.getOrderFills(symbol, '12345')).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getOrderFills: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getCurrentPlanOrders()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.getCurrentPlanOrders({ symbol, pageSize: '20' }),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: {
|
||||
nextFlag: false,
|
||||
orderList: expect.any(Array),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getCurrentPlanOrders: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('getHistoricPlanOrders()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.getHistoricPlanOrders({
|
||||
symbol,
|
||||
pageSize: '20',
|
||||
startTime: '1667889483000',
|
||||
endTime: '1668134732000',
|
||||
}),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: {
|
||||
endId: null,
|
||||
nextFlag: false,
|
||||
orderList: expect.any(Array),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('getHistoricPlanOrders: ', e);
|
||||
expect(e).toBeNull();
|
||||
}
|
||||
});
|
||||
});
|
||||
302
test/spot/private.write.test.ts
Normal file
302
test/spot/private.write.test.ts
Normal file
@@ -0,0 +1,302 @@
|
||||
import { API_ERROR_CODE, SpotClient } from '../../src';
|
||||
import { sucessEmptyResponseObject } from '../response.util';
|
||||
|
||||
describe('Private Spot 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 SpotClient({
|
||||
apiKey: API_KEY,
|
||||
apiSecret: API_SECRET,
|
||||
apiPass: API_PASS,
|
||||
});
|
||||
|
||||
const symbol = 'BTCUSDT_SPBL';
|
||||
const coin = 'USDT';
|
||||
|
||||
describe('transfers', () => {
|
||||
it('transfer()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.transfer({
|
||||
amount: '100',
|
||||
coin,
|
||||
fromType: 'spot',
|
||||
toType: 'mix_usdt',
|
||||
}),
|
||||
).toStrictEqual('');
|
||||
} catch (e) {
|
||||
// console.error('transfer: ', e);
|
||||
expect(e.body).toMatchObject({
|
||||
// not sure what this error means, probably no kyc. Seems to change?
|
||||
code: expect.stringMatching(/42013|43117|40035/gim),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('transferV2()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.transferV2({
|
||||
amount: '100',
|
||||
coin,
|
||||
fromType: 'spot',
|
||||
toType: 'mix_usdt',
|
||||
}),
|
||||
).toStrictEqual('');
|
||||
} catch (e) {
|
||||
// console.error('transferV2: ', e);
|
||||
expect(e.body).toMatchObject({
|
||||
// not sure what this error means, probably no kyc. Seems to change?
|
||||
code: expect.stringMatching(/42013|43117|40035/gim),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('subTransfer()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.subTransfer({
|
||||
fromUserId: '123',
|
||||
toUserId: '456',
|
||||
amount: '100',
|
||||
clientOid: '123456',
|
||||
coin,
|
||||
fromType: 'spot',
|
||||
toType: 'mix_usdt',
|
||||
}),
|
||||
).toStrictEqual('');
|
||||
} catch (e) {
|
||||
// console.error('transferV2: ', e);
|
||||
expect(e.body).toMatchObject({
|
||||
// not sure what this error means, probably no balance. Seems to change?
|
||||
code: expect.stringMatching(/42013|43117|40018/gim),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('withdraw()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.withdraw({
|
||||
amount: '100',
|
||||
coin,
|
||||
chain: 'TRC20',
|
||||
address: '123456',
|
||||
}),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.INCORRECT_PERMISSIONS,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it.skip('withdrawV2()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.withdrawV2({
|
||||
amount: '100',
|
||||
coin,
|
||||
chain: 'TRC20',
|
||||
address: '123456',
|
||||
}),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`"${expect.getState().currentTestName}"`,
|
||||
JSON.stringify(e.body),
|
||||
);
|
||||
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.INCORRECT_PERMISSIONS,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('innerWithdraw()', async () => {
|
||||
try {
|
||||
expect(await api.innerWithdraw(coin, '12345', '1')).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.INCORRECT_PERMISSIONS,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it.skip('innerWithdrawV2()', async () => {
|
||||
try {
|
||||
expect(await api.innerWithdrawV2(coin, '12345', '1')).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`"${expect.getState().currentTestName}"`,
|
||||
JSON.stringify(e.body),
|
||||
);
|
||||
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.INCORRECT_PERMISSIONS,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
describe('orders', () => {
|
||||
it('submitOrder()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.submitOrder({
|
||||
symbol,
|
||||
side: 'buy',
|
||||
orderType: 'market',
|
||||
quantity: '1',
|
||||
force: 'normal',
|
||||
}),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.ACCOUNT_KYC_REQUIRED,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('batchSubmitOrder()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.batchSubmitOrder(symbol, [
|
||||
{
|
||||
side: 'buy',
|
||||
orderType: 'market',
|
||||
quantity: '1',
|
||||
force: 'normal',
|
||||
},
|
||||
]),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: {
|
||||
resultList: expect.any(Array),
|
||||
failure: [{ errorCode: API_ERROR_CODE }],
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
// console.log(`fn() exception: `, e.body);
|
||||
|
||||
expect(e?.body).toMatchObject({
|
||||
code: API_ERROR_CODE.ACCOUNT_KYC_REQUIRED,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('cancelOrder()', async () => {
|
||||
try {
|
||||
expect(await api.cancelOrder(symbol, '123456')).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: '123456', //expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('cancelorder err', e);
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.ORDER_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('batchCancelOrder()', async () => {
|
||||
try {
|
||||
expect(await api.batchCancelOrder(symbol, ['123456'])).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.ORDER_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('plan orders', () => {
|
||||
let planOrderId: string;
|
||||
|
||||
it('submitPlanOrder()', async () => {
|
||||
try {
|
||||
const result = await api.submitPlanOrder({
|
||||
symbol,
|
||||
side: 'buy',
|
||||
orderType: 'market',
|
||||
size: 100,
|
||||
triggerPrice: 100,
|
||||
triggerType: 'fill_price',
|
||||
});
|
||||
|
||||
planOrderId = result.data.orderId;
|
||||
expect(result).toMatchObject({
|
||||
code: API_ERROR_CODE.ACCOUNT_KYC_REQUIRED,
|
||||
});
|
||||
} catch (e) {
|
||||
// console.error('submitPlanOrder(): ', e);
|
||||
expect(e?.body).toMatchObject({
|
||||
code: API_ERROR_CODE.ACCOUNT_KYC_REQUIRED,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('modifyPlanOrder()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.modifyPlanOrder({
|
||||
orderType: 'market',
|
||||
triggerPrice: 100,
|
||||
orderId: '123456',
|
||||
}),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.PLAN_ORDER_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('cancelPlanOrder()', async () => {
|
||||
try {
|
||||
expect(
|
||||
await api.cancelPlanOrder({
|
||||
orderId: planOrderId || '123456',
|
||||
}),
|
||||
).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(String),
|
||||
});
|
||||
} catch (e) {
|
||||
// console.error('cancelPlanOrder(): ', e);
|
||||
// expect(e).toBeNull();
|
||||
expect(e.body).toMatchObject({
|
||||
code: API_ERROR_CODE.PLAN_ORDER_NOT_FOUND,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
105
test/spot/public.test.ts
Normal file
105
test/spot/public.test.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { SpotClient } from '../../src';
|
||||
import {
|
||||
successResponseString,
|
||||
sucessEmptyResponseObject,
|
||||
} from '../response.util';
|
||||
|
||||
describe('Public Spot REST API Endpoints', () => {
|
||||
const api = new SpotClient();
|
||||
|
||||
const symbol = 'BTCUSDT_SPBL';
|
||||
|
||||
// it('should throw for unauthenticated private calls', async () => {
|
||||
// expect(() => api.getOpenOrders()).rejects.toMatchObject(
|
||||
// notAuthenticatedError()
|
||||
// );
|
||||
// expect(() => api.getBalances()).rejects.toMatchObject(
|
||||
// notAuthenticatedError()
|
||||
// );
|
||||
// });
|
||||
|
||||
/**
|
||||
*
|
||||
* Public
|
||||
*
|
||||
*/
|
||||
|
||||
it('getServerTime()', async () => {
|
||||
// expect(await api.getServerTime()).toStrictEqual('');
|
||||
expect(await api.getServerTime()).toMatchObject(successResponseString());
|
||||
});
|
||||
|
||||
it('fetchServertime() returns number', async () => {
|
||||
expect(await api.fetchServerTime()).toStrictEqual(expect.any(Number));
|
||||
});
|
||||
|
||||
it('getCoins()', async () => {
|
||||
expect(await api.getCoins()).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
});
|
||||
|
||||
it('getSymbols()', async () => {
|
||||
expect(await api.getSymbols()).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
});
|
||||
|
||||
it('getSymbol()', async () => {
|
||||
expect(await api.getSymbol(symbol)).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: {
|
||||
baseCoin: expect.any(String),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
* Market
|
||||
*
|
||||
*/
|
||||
|
||||
it('getTicker()', async () => {
|
||||
expect(await api.getTicker(symbol)).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: {
|
||||
askSz: expect.any(String),
|
||||
baseVol: expect.any(String),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('getAllTickers()', async () => {
|
||||
expect(await api.getAllTickers()).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, '1min')).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: expect.any(Array),
|
||||
});
|
||||
});
|
||||
|
||||
it('getDepth()', async () => {
|
||||
expect(await api.getDepth(symbol, 'step0')).toMatchObject({
|
||||
...sucessEmptyResponseObject(),
|
||||
data: {
|
||||
bids: expect.any(Array),
|
||||
asks: expect.any(Array),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user