USDC Options test coverage
This commit is contained in:
@@ -13,6 +13,7 @@ export const positionTpSlModeEnum = {
|
||||
export const API_ERROR_CODE = {
|
||||
BALANCE_INSUFFICIENT_SPOT: -1131,
|
||||
ORDER_NOT_FOUND_OR_TOO_LATE_SPOT: -2013,
|
||||
SUCCESS: 0,
|
||||
/** This could mean bad request, incorrect value types or even incorrect/missing values */
|
||||
PARAMS_MISSING_OR_WRONG: 10001,
|
||||
ORDER_NOT_FOUND_OR_TOO_LATE: 20001,
|
||||
@@ -39,6 +40,12 @@ export const API_ERROR_CODE = {
|
||||
INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080,
|
||||
SAME_SLTP_MODE_LINEAR: 130150,
|
||||
RISK_ID_NOT_MODIFIED: 134026,
|
||||
ORDER_NOT_EXIST: 3100136,
|
||||
NO_ACTIVE_ORDER: 3100205,
|
||||
/** E.g. USDC Options trading when the account hasn't been opened for USDC Options yet */
|
||||
ACCOUNT_NOT_EXIST: 3200200,
|
||||
INCORRECT_MMP_PARAMETERS: 3500712,
|
||||
INSTITION_MMP_PROFILE_NOT_FOUND: 3500713,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { API_ERROR_CODE } from '../src';
|
||||
|
||||
export function successResponseList(successMsg: string | null = 'OK') {
|
||||
return {
|
||||
result: expect.any(Array),
|
||||
ret_code: 0,
|
||||
ret_code: API_ERROR_CODE.SUCCESS,
|
||||
ret_msg: successMsg,
|
||||
};
|
||||
}
|
||||
@@ -9,7 +11,7 @@ export function successResponseList(successMsg: string | null = 'OK') {
|
||||
export function successResponseObject(successMsg: string | null = 'OK') {
|
||||
return {
|
||||
result: expect.any(Object),
|
||||
ret_code: 0,
|
||||
ret_code: API_ERROR_CODE.SUCCESS,
|
||||
ret_msg: successMsg,
|
||||
};
|
||||
}
|
||||
@@ -17,8 +19,10 @@ export function successResponseObject(successMsg: string | null = 'OK') {
|
||||
export function successUSDCResponseObject() {
|
||||
return {
|
||||
result: expect.any(Object),
|
||||
retCode: 0,
|
||||
retMsg: expect.stringMatching(/OK|SUCCESS|success|success\./gim),
|
||||
retCode: API_ERROR_CODE.SUCCESS,
|
||||
retMsg: expect.stringMatching(
|
||||
/OK|SUCCESS|success|success\.|Request accepted/gim
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
169
test/usdc/options/private.write.test.ts
Normal file
169
test/usdc/options/private.write.test.ts
Normal file
@@ -0,0 +1,169 @@
|
||||
import { API_ERROR_CODE, USDCOptionsClient } from '../../../src';
|
||||
import {
|
||||
successResponseObject,
|
||||
successUSDCResponseObject,
|
||||
} from '../../response.util';
|
||||
|
||||
describe('Private Account Asset REST API Endpoints', () => {
|
||||
const useLivenet = true;
|
||||
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 USDCOptionsClient(API_KEY, API_SECRET, useLivenet);
|
||||
|
||||
const category = 'OPTION';
|
||||
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.ACCOUNT_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.ACCOUNT_NOT_EXIST },
|
||||
{ errorCode: API_ERROR_CODE.ACCOUNT_NOT_EXIST },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('modifyOrder()', async () => {
|
||||
expect(
|
||||
await api.modifyOrder({
|
||||
symbol,
|
||||
orderId: 'somethingFake',
|
||||
})
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.ORDER_NOT_EXIST,
|
||||
});
|
||||
});
|
||||
|
||||
it('batchModifyOrders()', async () => {
|
||||
expect(
|
||||
await api.batchModifyOrders([
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake1',
|
||||
},
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake2',
|
||||
},
|
||||
])
|
||||
).toMatchObject({
|
||||
result: [
|
||||
{ errorCode: API_ERROR_CODE.ORDER_NOT_EXIST },
|
||||
{ errorCode: API_ERROR_CODE.ORDER_NOT_EXIST },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelOrder()', async () => {
|
||||
expect(
|
||||
await api.cancelOrder({
|
||||
symbol,
|
||||
orderId: 'somethingFake1',
|
||||
})
|
||||
).toMatchObject({
|
||||
retCode: API_ERROR_CODE.ORDER_NOT_EXIST,
|
||||
});
|
||||
});
|
||||
|
||||
it('batchCancelOrders()', async () => {
|
||||
expect(
|
||||
await api.batchCancelOrders([
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake1',
|
||||
},
|
||||
{
|
||||
symbol,
|
||||
orderId: 'somethingFake2',
|
||||
},
|
||||
])
|
||||
).toMatchObject({
|
||||
result: [
|
||||
{ errorCode: API_ERROR_CODE.ORDER_NOT_EXIST },
|
||||
{ errorCode: API_ERROR_CODE.ORDER_NOT_EXIST },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('cancelActiveOrders()', async () => {
|
||||
expect(await api.cancelActiveOrders()).toMatchObject({
|
||||
retCode: API_ERROR_CODE.NO_ACTIVE_ORDER,
|
||||
});
|
||||
});
|
||||
|
||||
it('setMarginMode()', async () => {
|
||||
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject(
|
||||
successUSDCResponseObject()
|
||||
);
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
it('asdfasfasdfasdf()', async () => {
|
||||
expect(await api.asadfasdfasdfasf()).toStrictEqual('');
|
||||
});
|
||||
*/
|
||||
});
|
||||
Reference in New Issue
Block a user