chore(): remove dead usdc endpoint tests
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
import { USDCOptionClient } from '../../../src';
|
||||
import { getTestProxy } from '../../proxy.util';
|
||||
import { successResponseObjectV3 } from '../../response.util';
|
||||
|
||||
describe('Private USDC Options REST API GET Endpoints', () => {
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
const symbol = 'BTC-30SEP22-400000-C';
|
||||
|
||||
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 USDCOptionClient(
|
||||
{
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
},
|
||||
getTestProxy(),
|
||||
);
|
||||
const category = 'OPTION';
|
||||
|
||||
it('getActiveRealtimeOrders()', async () => {
|
||||
expect(await api.getActiveRealtimeOrders()).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getActiveOrders()', async () => {
|
||||
expect(await api.getActiveOrders({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getHistoricOrders()', async () => {
|
||||
expect(await api.getHistoricOrders({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getOrderExecutionHistory()', async () => {
|
||||
expect(await api.getOrderExecutionHistory({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getTransactionLog()', async () => {
|
||||
expect(await api.getTransactionLog({ type: 'TRADE' })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getBalances()', async () => {
|
||||
expect(await api.getBalances()).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getAssetInfo()', async () => {
|
||||
expect(await api.getAssetInfo()).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getMarginMode()', async () => {
|
||||
expect(await api.getMarginMode()).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getPositions()', async () => {
|
||||
expect(await api.getPositions({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getDeliveryHistory()', async () => {
|
||||
expect(await api.getDeliveryHistory({ symbol })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getPositionsInfoUponExpiry()', async () => {
|
||||
expect(await api.getPositionsInfoUponExpiry()).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,169 +0,0 @@
|
||||
import { API_ERROR_CODE, USDCOptionClient } from '../../../src';
|
||||
import { getTestProxy } from '../../proxy.util';
|
||||
// import { successResponseObjectV3 } from '../../response.util';
|
||||
|
||||
describe('Private USDC Options REST API POST 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 USDCOptionClient(
|
||||
{
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
},
|
||||
getTestProxy(),
|
||||
);
|
||||
|
||||
const currency = 'USDC';
|
||||
const symbol = 'BTC-30SEP22-400000-C';
|
||||
|
||||
it('submitOrder()', async () => {
|
||||
expect(
|
||||
await api.submitOrder({
|
||||
symbol,
|
||||
orderType: 'Limit',
|
||||
side: 'Sell',
|
||||
orderQty: '1000',
|
||||
orderPrice: '40',
|
||||
orderLinkId: Date.now().toString(),
|
||||
timeInForce: 'GoodTillCancel',
|
||||
}),
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST,
|
||||
});
|
||||
});
|
||||
|
||||
it('batchSubmitOrders()', async () => {
|
||||
expect(
|
||||
await api.batchSubmitOrders([
|
||||
{
|
||||
symbol,
|
||||
orderType: 'Limit',
|
||||
side: 'Sell',
|
||||
orderQty: '1000',
|
||||
orderPrice: '40',
|
||||
orderLinkId: Date.now().toString(),
|
||||
timeInForce: 'GoodTillCancel',
|
||||
},
|
||||
{
|
||||
symbol,
|
||||
orderType: 'Limit',
|
||||
side: 'Sell',
|
||||
orderQty: '1000',
|
||||
orderPrice: '40',
|
||||
orderLinkId: Date.now().toString(),
|
||||
timeInForce: 'GoodTillCancel',
|
||||
},
|
||||
]),
|
||||
).toMatchObject({
|
||||
result: [
|
||||
{ errorCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST },
|
||||
{ errorCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('modifyOrder()', async () => {
|
||||
expect(
|
||||
await api.modifyOrder({
|
||||
symbol,
|
||||
orderId: 'somethingFake',
|
||||
}),
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST,
|
||||
});
|
||||
});
|
||||
|
||||
it('batchModifyOrders()', async () => {
|
||||
expect(
|
||||
await api.batchModifyOrders([
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake1',
|
||||
},
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake2',
|
||||
},
|
||||
]),
|
||||
).toMatchObject({
|
||||
result: [
|
||||
{ errorCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST },
|
||||
{ errorCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelOrder()', async () => {
|
||||
expect(
|
||||
await api.cancelOrder({
|
||||
symbol,
|
||||
orderId: 'somethingFake1',
|
||||
}),
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST,
|
||||
});
|
||||
});
|
||||
|
||||
it('batchCancelOrders()', async () => {
|
||||
expect(
|
||||
await api.batchCancelOrders([
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake1',
|
||||
},
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake2',
|
||||
},
|
||||
]),
|
||||
).toMatchObject({
|
||||
result: [
|
||||
{ errorCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST },
|
||||
{ errorCode: API_ERROR_CODE.CONTRACT_NAME_NOT_EXIST },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelActiveOrders()', async () => {
|
||||
expect(await api.cancelActiveOrders()).toMatchObject({
|
||||
retCode: API_ERROR_CODE.NO_ACTIVE_ORDER,
|
||||
});
|
||||
});
|
||||
|
||||
// Reached out to bybit
|
||||
it.skip('setMarginMode()', async () => {
|
||||
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject(
|
||||
{
|
||||
retCode: API_ERROR_CODE.SET_MARGIN_MODE_FAILED_USDC,
|
||||
},
|
||||
// successResponseObjectV3()
|
||||
);
|
||||
});
|
||||
|
||||
it('modifyMMP()', async () => {
|
||||
expect(
|
||||
await api.modifyMMP({
|
||||
currency,
|
||||
windowMs: 0,
|
||||
frozenPeriodMs: 100,
|
||||
qtyLimit: '100',
|
||||
deltaLimit: '1',
|
||||
}),
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.INCORRECT_MMP_PARAMETERS,
|
||||
});
|
||||
});
|
||||
|
||||
it('resetMMP()', async () => {
|
||||
expect(await api.resetMMP(currency)).toMatchObject({
|
||||
retCode: API_ERROR_CODE.INSTITION_MMP_PROFILE_NOT_FOUND,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,61 +0,0 @@
|
||||
import { USDCOptionClient } from '../../../src';
|
||||
import { getTestProxy } from '../../proxy.util';
|
||||
import {
|
||||
successResponseObject,
|
||||
successResponseObjectV3,
|
||||
} from '../../response.util';
|
||||
|
||||
describe('Public USDC Options REST API Endpoints', () => {
|
||||
const API_KEY = undefined;
|
||||
const API_SECRET = undefined;
|
||||
|
||||
const api = new USDCOptionClient(
|
||||
{
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
},
|
||||
getTestProxy(),
|
||||
);
|
||||
const symbol = 'BTC-30SEP22-400000-C';
|
||||
|
||||
it('getOrderBook()', async () => {
|
||||
expect(await api.getOrderBook(symbol)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getContractInfo()', async () => {
|
||||
expect(await api.getContractInfo()).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getSymbolTicker()', async () => {
|
||||
expect(await api.getSymbolTicker(symbol)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getDeliveryPrice()', async () => {
|
||||
expect(await api.getDeliveryPrice()).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getLast500Trades()', async () => {
|
||||
expect(await api.getLast500Trades({ category: 'OPTION' })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getHistoricalVolatility()', async () => {
|
||||
expect(await api.getHistoricalVolatility()).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getServerTime()', async () => {
|
||||
expect(await api.getServerTime()).toMatchObject(successResponseObject());
|
||||
});
|
||||
});
|
||||
@@ -1,151 +0,0 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import {
|
||||
WSClientConfigurableOptions,
|
||||
WS_ERROR_ENUM,
|
||||
WS_KEY_MAP,
|
||||
WebsocketClient,
|
||||
} from '../../../src';
|
||||
import {
|
||||
WS_OPEN_EVENT_PARTIAL,
|
||||
fullLogger,
|
||||
getSilentLogger,
|
||||
logAllEvents,
|
||||
waitForSocketEvent,
|
||||
} from '../../ws.util';
|
||||
|
||||
describe('Private USDC Option Websocket Client', () => {
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
|
||||
const wsClientOptions: WSClientConfigurableOptions = {
|
||||
market: 'usdcOption',
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
};
|
||||
|
||||
const wsTopic = 'user.openapi.option.position';
|
||||
|
||||
describe('with invalid credentials', () => {
|
||||
it('should reject private subscribe if keys/signature are incorrect', async () => {
|
||||
const badClient = new WebsocketClient(
|
||||
{
|
||||
...wsClientOptions,
|
||||
key: 'bad',
|
||||
secret: 'bad',
|
||||
reconnectTimeout: 10000,
|
||||
},
|
||||
// fullLogger
|
||||
getSilentLogger('expect401')
|
||||
);
|
||||
// logAllEvents(badClient);
|
||||
|
||||
// const wsOpenPromise = waitForSocketEvent(badClient, 'open');
|
||||
const wsResponsePromise = waitForSocketEvent(badClient, 'response');
|
||||
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
badClient.connectPrivate();
|
||||
|
||||
const responsePartial = {
|
||||
ret_msg: WS_ERROR_ENUM.USDC_OPTION_AUTH_FAILED,
|
||||
success: false,
|
||||
type: 'AUTH_RESP',
|
||||
};
|
||||
expect(wsResponsePromise).rejects.toMatchObject(responsePartial);
|
||||
|
||||
try {
|
||||
await Promise.all([wsResponsePromise]);
|
||||
} catch (e) {
|
||||
// console.error()
|
||||
expect(e).toMatchObject(responsePartial);
|
||||
}
|
||||
|
||||
// badClient.subscribe(wsTopic);
|
||||
badClient.removeAllListeners();
|
||||
badClient.closeAll(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with valid API credentails', () => {
|
||||
let wsClient: WebsocketClient;
|
||||
|
||||
it('should have api credentials to test with', () => {
|
||||
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
wsClient = new WebsocketClient(
|
||||
wsClientOptions,
|
||||
getSilentLogger('expectSuccess')
|
||||
);
|
||||
// logAllEvents(wsClient);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
wsClient.closeAll(true);
|
||||
});
|
||||
|
||||
it('should open a private ws connection', async () => {
|
||||
wsClient.connectPrivate();
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcOptionPrivate,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
try {
|
||||
expect(await wsResponsePromise).toMatchObject({
|
||||
ret_msg: '0',
|
||||
success: true,
|
||||
type: 'AUTH_RESP',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Wait for "${wsTopic}" event exception: `, e);
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it(`should subscribe to private "${wsTopic}" events`, async () => {
|
||||
wsClient.connectPrivate();
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
// expect(wsUpdatePromise).resolves.toStrictEqual('');
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
expect(await wsResponsePromise).toMatchObject({
|
||||
data: {
|
||||
failTopics: [],
|
||||
successTopics: [wsTopic],
|
||||
},
|
||||
success: true,
|
||||
type: 'COMMAND_RESP',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`Wait for "${wsTopic}" subscription response exception: `,
|
||||
e
|
||||
);
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
expect(await wsUpdatePromise).toMatchObject({
|
||||
creationTime: expect.any(Number),
|
||||
data: {
|
||||
baseLine: expect.any(Number),
|
||||
dataType: expect.any(String),
|
||||
result: expect.any(Array),
|
||||
version: expect.any(Number),
|
||||
},
|
||||
topic: wsTopic,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,78 +0,0 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import {
|
||||
WSClientConfigurableOptions,
|
||||
WS_KEY_MAP,
|
||||
WebsocketClient,
|
||||
} from '../../../src';
|
||||
import {
|
||||
WS_OPEN_EVENT_PARTIAL,
|
||||
getSilentLogger,
|
||||
logAllEvents,
|
||||
waitForSocketEvent,
|
||||
} from '../../ws.util';
|
||||
|
||||
describe('Public USDC Option Websocket Client', () => {
|
||||
let wsClient: WebsocketClient;
|
||||
|
||||
const wsClientOptions: WSClientConfigurableOptions = {
|
||||
market: 'usdcOption',
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
wsClient = new WebsocketClient(
|
||||
wsClientOptions,
|
||||
getSilentLogger('expectSuccessNoAuth')
|
||||
);
|
||||
wsClient.connectPublic();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
wsClient.closeAll(true);
|
||||
});
|
||||
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcOptionPublic,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it('should subscribe to public trade events', async () => {
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
wsClient.subscribe([
|
||||
'recenttrades.BTC',
|
||||
'recenttrades.ETH',
|
||||
'recenttrades.SOL',
|
||||
]);
|
||||
|
||||
try {
|
||||
expect(await wsResponsePromise).toMatchObject({
|
||||
success: true,
|
||||
data: {
|
||||
failTopics: [],
|
||||
successTopics: expect.any(Array),
|
||||
},
|
||||
type: 'COMMAND_RESP',
|
||||
});
|
||||
} catch (e) {
|
||||
// sub failed
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
// Takes a while to get an event from USDC options - testing this manually for now
|
||||
// try {
|
||||
// expect(await wsUpdatePromise).toStrictEqual('asdfasdf');
|
||||
// } catch (e) {
|
||||
// // no data
|
||||
// expect(e).toBeFalsy();
|
||||
// }
|
||||
});
|
||||
});
|
||||
@@ -1,79 +0,0 @@
|
||||
import { USDCPerpetualClient } from '../../../src';
|
||||
import { getTestProxy } from '../../proxy.util';
|
||||
import { successResponseObjectV3 } from '../../response.util';
|
||||
|
||||
describe('Private USDC Perp REST API GET 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 USDCPerpetualClient(
|
||||
{
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
},
|
||||
getTestProxy(),
|
||||
);
|
||||
|
||||
const symbol = 'BTCPERP';
|
||||
const category = 'PERPETUAL';
|
||||
|
||||
it('getActiveOrders()', async () => {
|
||||
expect(await api.getActiveOrders({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getHistoricOrders()', async () => {
|
||||
expect(await api.getHistoricOrders({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getOrderExecutionHistory()', async () => {
|
||||
expect(await api.getOrderExecutionHistory({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getTransactionLog()', async () => {
|
||||
expect(await api.getTransactionLog({ type: 'TRADE' })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getBalances()', async () => {
|
||||
expect(await api.getBalances()).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getAssetInfo()', async () => {
|
||||
expect(await api.getAssetInfo()).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getMarginMode()', async () => {
|
||||
expect(await api.getMarginMode()).toMatchObject(successResponseObjectV3());
|
||||
});
|
||||
|
||||
it('getPositions()', async () => {
|
||||
expect(await api.getPositions({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getSettlementHistory()', async () => {
|
||||
expect(await api.getSettlementHistory({ symbol })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getPredictedFundingRate()', async () => {
|
||||
expect(await api.getPredictedFundingRate(symbol)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,95 +0,0 @@
|
||||
import { API_ERROR_CODE, USDCPerpetualClient } from '../../../src';
|
||||
import { getTestProxy } from '../../proxy.util';
|
||||
import { successEmptyResponseObjectV3 } from '../../response.util';
|
||||
|
||||
describe('Private USDC Perp REST API POST 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 USDCPerpetualClient(
|
||||
{
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
},
|
||||
getTestProxy(),
|
||||
);
|
||||
|
||||
const symbol = 'BTCPERP';
|
||||
|
||||
it('submitOrder()', async () => {
|
||||
expect(
|
||||
await api.submitOrder({
|
||||
symbol,
|
||||
side: 'Sell',
|
||||
orderType: 'Limit',
|
||||
orderFilter: 'Order',
|
||||
orderQty: '1',
|
||||
orderPrice: '20000',
|
||||
orderLinkId: Date.now().toString(),
|
||||
timeInForce: 'GoodTillCancel',
|
||||
}),
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.INSUFFICIENT_BALANCE_FOR_ORDER_COST,
|
||||
});
|
||||
});
|
||||
|
||||
it('modifyOrder()', async () => {
|
||||
expect(
|
||||
await api.modifyOrder({
|
||||
symbol,
|
||||
orderId: 'somethingFake',
|
||||
orderPrice: '20000',
|
||||
orderFilter: 'Order',
|
||||
}),
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelOrder()', async () => {
|
||||
expect(
|
||||
await api.cancelOrder({
|
||||
symbol,
|
||||
orderId: 'somethingFake1',
|
||||
orderFilter: 'Order',
|
||||
}),
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelActiveOrders()', async () => {
|
||||
expect(await api.cancelActiveOrders(symbol, 'Order')).toMatchObject(
|
||||
successEmptyResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
// Reached out to bybit
|
||||
it.skip('setMarginMode()', async () => {
|
||||
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject(
|
||||
{
|
||||
retCode: API_ERROR_CODE.SET_MARGIN_MODE_FAILED_USDC,
|
||||
retMsg: '',
|
||||
},
|
||||
// successResponseObjectV3()
|
||||
);
|
||||
});
|
||||
|
||||
it('setLeverage()', async () => {
|
||||
expect(await api.setLeverage(symbol, '5')).toMatchObject({
|
||||
retCode: API_ERROR_CODE.LEVERAGE_NOT_MODIFIED,
|
||||
});
|
||||
});
|
||||
|
||||
it('setRiskLimit()', async () => {
|
||||
expect(await api.setRiskLimit(symbol, 1)).toMatchObject({
|
||||
retCode: API_ERROR_CODE.RISK_LIMIT_NOT_EXISTS,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,102 +0,0 @@
|
||||
import { USDCKlineRequest, USDCPerpetualClient } from '../../../src';
|
||||
import {
|
||||
successResponseObject,
|
||||
successResponseObjectV3,
|
||||
} from '../../response.util';
|
||||
import { getTestProxy } from '../../proxy.util';
|
||||
|
||||
describe('Public USDC Perp REST API Endpoints', () => {
|
||||
const API_KEY = undefined;
|
||||
const API_SECRET = undefined;
|
||||
|
||||
const api = new USDCPerpetualClient(
|
||||
{
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
testnet: false,
|
||||
},
|
||||
getTestProxy(),
|
||||
);
|
||||
|
||||
const symbol = 'BTCPERP';
|
||||
const category = 'PERPETUAL';
|
||||
const startTime = Number((Date.now() / 1000).toFixed(0));
|
||||
|
||||
const candleRequest: USDCKlineRequest = { symbol, period: '1m', startTime };
|
||||
|
||||
it('getOrderBook()', async () => {
|
||||
expect(await api.getOrderBook(symbol)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getContractInfo()', async () => {
|
||||
expect(await api.getContractInfo()).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getSymbolTicker()', async () => {
|
||||
expect(await api.getSymbolTicker(symbol)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getCandles()', async () => {
|
||||
expect(await api.getCandles(candleRequest)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getMarkPrice()', async () => {
|
||||
expect(await api.getMarkPrice(candleRequest)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getIndexPrice()', async () => {
|
||||
expect(await api.getIndexPrice(candleRequest)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getIndexPremium()', async () => {
|
||||
expect(await api.getIndexPremium(candleRequest)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getOpenInterest()', async () => {
|
||||
expect(await api.getOpenInterest({ symbol, period: '1m' })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getLargeOrders()', async () => {
|
||||
expect(await api.getLargeOrders({ symbol })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getLongShortRatio()', async () => {
|
||||
expect(await api.getLongShortRatio({ symbol, period: '1m' })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getLast500Trades()', async () => {
|
||||
expect(await api.getLast500Trades({ category })).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getLastFundingRate()', async () => {
|
||||
expect(await api.getLastFundingRate(symbol)).toMatchObject(
|
||||
successResponseObjectV3(),
|
||||
);
|
||||
});
|
||||
|
||||
it('getServerTime()', async () => {
|
||||
expect(await api.getServerTime()).toMatchObject(successResponseObject());
|
||||
});
|
||||
});
|
||||
@@ -1,150 +0,0 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import {
|
||||
WSClientConfigurableOptions,
|
||||
WS_ERROR_ENUM,
|
||||
WS_KEY_MAP,
|
||||
WebsocketClient,
|
||||
} from '../../../src';
|
||||
import {
|
||||
WS_OPEN_EVENT_PARTIAL,
|
||||
fullLogger,
|
||||
getSilentLogger,
|
||||
logAllEvents,
|
||||
waitForSocketEvent,
|
||||
} from '../../ws.util';
|
||||
|
||||
describe.skip('Private USDC Perp Websocket Client', () => {
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
|
||||
const wsClientOptions: WSClientConfigurableOptions = {
|
||||
market: 'usdcPerp',
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
};
|
||||
|
||||
const wsTopic = 'user.openapi.perp.position';
|
||||
|
||||
describe('with invalid credentials', () => {
|
||||
it('should reject private subscribe if keys/signature are incorrect', async () => {
|
||||
const badClient = new WebsocketClient(
|
||||
{
|
||||
...wsClientOptions,
|
||||
key: 'bad',
|
||||
secret: 'bad',
|
||||
reconnectTimeout: 10000,
|
||||
},
|
||||
// fullLogger
|
||||
getSilentLogger('expect401'),
|
||||
);
|
||||
// logAllEvents(badClient);
|
||||
|
||||
// const wsOpenPromise = waitForSocketEvent(badClient, 'open');
|
||||
const wsResponsePromise = waitForSocketEvent(badClient, 'response');
|
||||
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
badClient.connectPrivate();
|
||||
|
||||
const responsePartial = {
|
||||
ret_msg: WS_ERROR_ENUM.USDC_OPTION_AUTH_FAILED,
|
||||
success: false,
|
||||
type: 'AUTH_RESP',
|
||||
};
|
||||
expect(wsResponsePromise).rejects.toMatchObject(responsePartial);
|
||||
|
||||
try {
|
||||
await Promise.all([wsResponsePromise]);
|
||||
} catch (e) {
|
||||
// console.error()
|
||||
expect(e).toMatchObject(responsePartial);
|
||||
}
|
||||
|
||||
// badClient.subscribe(wsTopic);
|
||||
badClient.removeAllListeners();
|
||||
badClient.closeAll(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with valid API credentails', () => {
|
||||
let wsClient: WebsocketClient;
|
||||
|
||||
it('should have api credentials to test with', () => {
|
||||
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
wsClient = new WebsocketClient(
|
||||
wsClientOptions,
|
||||
getSilentLogger('expectSuccess'),
|
||||
);
|
||||
wsClient.connectPrivate();
|
||||
// logAllEvents(wsClient);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
wsClient.closeAll(true);
|
||||
});
|
||||
|
||||
it('should open a private ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
|
||||
try {
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcPerpPrivate,
|
||||
});
|
||||
} catch (e) {
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
try {
|
||||
expect(await wsResponsePromise).toMatchObject({
|
||||
ret_msg: '0',
|
||||
success: true,
|
||||
type: 'AUTH_RESP',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Wait for "${wsTopic}" event exception: `, e);
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
|
||||
it(`should subscribe to private "${wsTopic}" events`, async () => {
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
// expect(wsUpdatePromise).resolves.toStrictEqual('');
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
expect(await wsResponsePromise).toMatchObject({
|
||||
data: {
|
||||
failTopics: [],
|
||||
successTopics: [wsTopic],
|
||||
},
|
||||
success: true,
|
||||
type: 'COMMAND_RESP',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`Wait for "${wsTopic}" subscription response exception: `,
|
||||
e,
|
||||
);
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
expect(await wsUpdatePromise).toMatchObject({
|
||||
creationTime: expect.any(Number),
|
||||
data: {
|
||||
baseLine: expect.any(Number),
|
||||
dataType: expect.any(String),
|
||||
result: expect.any(Array),
|
||||
version: expect.any(Number),
|
||||
},
|
||||
topic: wsTopic,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,76 +0,0 @@
|
||||
import {
|
||||
WSClientConfigurableOptions,
|
||||
WS_KEY_MAP,
|
||||
WebsocketClient,
|
||||
} from '../../../src';
|
||||
import {
|
||||
WS_OPEN_EVENT_PARTIAL,
|
||||
getSilentLogger,
|
||||
waitForSocketEvent,
|
||||
} from '../../ws.util';
|
||||
|
||||
describe.skip('Public USDC Perp Websocket Client', () => {
|
||||
let wsClient: WebsocketClient;
|
||||
|
||||
const wsClientOptions: WSClientConfigurableOptions = {
|
||||
market: 'usdcPerp',
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
wsClient = new WebsocketClient(
|
||||
wsClientOptions,
|
||||
getSilentLogger('expectSuccessNoAuth'),
|
||||
);
|
||||
wsClient.connectPublic();
|
||||
// logAllEvents(wsClient);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
wsClient.closeAll(true);
|
||||
});
|
||||
|
||||
it('should open a public ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
|
||||
expect(await wsOpenPromise).toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.usdcPerpPublic,
|
||||
});
|
||||
});
|
||||
|
||||
it('should subscribe to public trade events', async () => {
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
const topic = 'orderBook_200.100ms.BTCPERP';
|
||||
wsClient.subscribe(topic);
|
||||
|
||||
try {
|
||||
expect(await wsResponsePromise).toMatchObject({
|
||||
success: true,
|
||||
ret_msg: '',
|
||||
request: {
|
||||
op: 'subscribe',
|
||||
args: [topic],
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
// sub failed
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
try {
|
||||
expect(await wsUpdatePromise).toMatchObject({
|
||||
crossSeq: expect.any(String),
|
||||
data: { orderBook: expect.any(Array) },
|
||||
timestampE6: expect.any(String),
|
||||
topic: topic,
|
||||
type: 'snapshot',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('usdc perp ws public error: ', e);
|
||||
// no data
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user