add unified margin private write tests
This commit is contained in:
@@ -16,6 +16,7 @@ export const API_ERROR_CODE = {
|
|||||||
SUCCESS: 0,
|
SUCCESS: 0,
|
||||||
/** This could mean bad request, incorrect value types or even incorrect/missing values */
|
/** This could mean bad request, incorrect value types or even incorrect/missing values */
|
||||||
PARAMS_MISSING_OR_WRONG: 10001,
|
PARAMS_MISSING_OR_WRONG: 10001,
|
||||||
|
INVALID_API_KEY_OR_PERMISSIONS: 10003,
|
||||||
INCORRECT_API_KEY_PERMISSIONS: 10005,
|
INCORRECT_API_KEY_PERMISSIONS: 10005,
|
||||||
/** Account not unified margin, update required */
|
/** Account not unified margin, update required */
|
||||||
ACCOUNT_NOT_UNIFIED: 10020,
|
ACCOUNT_NOT_UNIFIED: 10020,
|
||||||
|
|||||||
@@ -328,7 +328,10 @@ export class UnifiedMarginClient extends BaseRestClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Upgrade to unified margin account */
|
/**
|
||||||
|
* Upgrade to unified margin account.
|
||||||
|
* WARNING: This is currently not reversable!
|
||||||
|
*/
|
||||||
upgradeToUnifiedMargin(): Promise<APIResponseV3<any>> {
|
upgradeToUnifiedMargin(): Promise<APIResponseV3<any>> {
|
||||||
return this.postPrivate(
|
return this.postPrivate(
|
||||||
'/unified/v3/private/account/upgrade-unified-account'
|
'/unified/v3/private/account/upgrade-unified-account'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { API_ERROR_CODE, UnifiedMarginClient } from '../../src';
|
import { API_ERROR_CODE, UnifiedMarginClient } from '../../src';
|
||||||
import { successResponseObjectV3 } from '../response.util';
|
import { successResponseObjectV3 } from '../response.util';
|
||||||
|
|
||||||
describe('Private Account Asset REST API Endpoints', () => {
|
describe('Private Unified Margin REST API Endpoints', () => {
|
||||||
const useLivenet = true;
|
const useLivenet = true;
|
||||||
const API_KEY = process.env.API_KEY_COM;
|
const API_KEY = process.env.API_KEY_COM;
|
||||||
const API_SECRET = process.env.API_SECRET_COM;
|
const API_SECRET = process.env.API_SECRET_COM;
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import { API_ERROR_CODE, USDCPerpetualClient } from '../../../src';
|
import { API_ERROR_CODE, UnifiedMarginClient } from '../../src';
|
||||||
import {
|
|
||||||
successEmptyResponseObjectV3,
|
|
||||||
successResponseObjectV3,
|
|
||||||
} from '../../response.util';
|
|
||||||
|
|
||||||
describe('Private Account Asset REST API Endpoints', () => {
|
describe('Private Unified Margin REST API Endpoints', () => {
|
||||||
const useLivenet = true;
|
const useLivenet = true;
|
||||||
const API_KEY = process.env.API_KEY_COM;
|
const API_KEY = process.env.API_KEY_COM;
|
||||||
const API_SECRET = process.env.API_SECRET_COM;
|
const API_SECRET = process.env.API_SECRET_COM;
|
||||||
@@ -14,24 +10,30 @@ describe('Private Account Asset REST API Endpoints', () => {
|
|||||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||||
});
|
});
|
||||||
|
|
||||||
const api = new USDCPerpetualClient(API_KEY, API_SECRET, useLivenet);
|
const api = new UnifiedMarginClient(API_KEY, API_SECRET, useLivenet);
|
||||||
|
|
||||||
const symbol = 'BTCPERP';
|
const symbol = 'BTCUSDT';
|
||||||
|
const category = 'linear';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While it may seem silly, these tests simply validate the request is processed at all.
|
||||||
|
* Something very wrong would be a sign error or complaints about the endpoint/request method/server error.
|
||||||
|
*/
|
||||||
|
|
||||||
it('submitOrder()', async () => {
|
it('submitOrder()', async () => {
|
||||||
expect(
|
expect(
|
||||||
await api.submitOrder({
|
await api.submitOrder({
|
||||||
symbol,
|
symbol,
|
||||||
|
category,
|
||||||
side: 'Sell',
|
side: 'Sell',
|
||||||
orderType: 'Limit',
|
orderType: 'Limit',
|
||||||
orderFilter: 'Order',
|
qty: '1',
|
||||||
orderQty: '1',
|
price: '20000',
|
||||||
orderPrice: '20000',
|
|
||||||
orderLinkId: Date.now().toString(),
|
orderLinkId: Date.now().toString(),
|
||||||
timeInForce: 'GoodTillCancel',
|
timeInForce: 'GoodTillCancel',
|
||||||
})
|
})
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
retCode: API_ERROR_CODE.INSUFFICIENT_BALANCE_FOR_ORDER_COST,
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,12 +41,12 @@ describe('Private Account Asset REST API Endpoints', () => {
|
|||||||
expect(
|
expect(
|
||||||
await api.modifyOrder({
|
await api.modifyOrder({
|
||||||
symbol,
|
symbol,
|
||||||
|
category,
|
||||||
orderId: 'somethingFake',
|
orderId: 'somethingFake',
|
||||||
orderPrice: '20000',
|
price: '20000',
|
||||||
orderFilter: 'Order',
|
|
||||||
})
|
})
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -52,35 +54,134 @@ describe('Private Account Asset REST API Endpoints', () => {
|
|||||||
expect(
|
expect(
|
||||||
await api.cancelOrder({
|
await api.cancelOrder({
|
||||||
symbol,
|
symbol,
|
||||||
|
category,
|
||||||
orderId: 'somethingFake1',
|
orderId: 'somethingFake1',
|
||||||
orderFilter: 'Order',
|
orderFilter: 'Order',
|
||||||
})
|
})
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cancelActiveOrders()', async () => {
|
it('batchSubmitOrders()', async () => {
|
||||||
expect(await api.cancelActiveOrders(symbol, 'Order')).toMatchObject(
|
expect(
|
||||||
successEmptyResponseObjectV3()
|
await api.batchSubmitOrders(category, [
|
||||||
);
|
{
|
||||||
|
symbol,
|
||||||
|
side: 'Buy',
|
||||||
|
orderType: 'Limit',
|
||||||
|
qty: '1',
|
||||||
|
price: '10000',
|
||||||
|
timeInForce: 'FillOrKill',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
symbol,
|
||||||
|
side: 'Buy',
|
||||||
|
orderType: 'Limit',
|
||||||
|
qty: '1',
|
||||||
|
price: '10001',
|
||||||
|
timeInForce: 'FillOrKill',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
symbol,
|
||||||
|
side: 'Buy',
|
||||||
|
orderType: 'Limit',
|
||||||
|
qty: '1',
|
||||||
|
price: '10002',
|
||||||
|
timeInForce: 'FillOrKill',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setMarginMode()', async () => {
|
it('batchReplaceOrders()', async () => {
|
||||||
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject(
|
expect(
|
||||||
successResponseObjectV3()
|
await api.batchReplaceOrders(category, [
|
||||||
);
|
{
|
||||||
|
symbol,
|
||||||
|
orderLinkId: 'somethingFake1',
|
||||||
|
qty: '4',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
symbol,
|
||||||
|
orderLinkId: 'somethingFake2',
|
||||||
|
qty: '5',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
symbol,
|
||||||
|
orderLinkId: 'somethingFake3',
|
||||||
|
qty: '6',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('batchCancelOrders()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.batchCancelOrders(category, [
|
||||||
|
{
|
||||||
|
symbol,
|
||||||
|
orderLinkId: 'somethingFake1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
symbol,
|
||||||
|
orderLinkId: 'somethingFake2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
symbol,
|
||||||
|
orderLinkId: 'somethingFake3',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('cancelAllOrders()', async () => {
|
||||||
|
expect(await api.cancelAllOrders({ category })).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setLeverage()', async () => {
|
it('setLeverage()', async () => {
|
||||||
expect(await api.setLeverage(symbol, '10')).toMatchObject({
|
expect(await api.setLeverage(category, symbol, 5, 5)).toMatchObject({
|
||||||
retCode: API_ERROR_CODE.LEVERAGE_NOT_MODIFIED,
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setTPSLMode()', async () => {
|
||||||
|
expect(await api.setTPSLMode(category, symbol, 1)).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setRiskLimit()', async () => {
|
it('setRiskLimit()', async () => {
|
||||||
expect(await api.setRiskLimit(symbol, 1)).toMatchObject({
|
expect(await api.setRiskLimit(category, symbol, 1, 0)).toMatchObject({
|
||||||
retCode: API_ERROR_CODE.RISK_LIMIT_NOT_EXISTS,
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setTPSL()', async () => {
|
||||||
|
expect(await api.setTPSL({ category, symbol })).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('transferFunds()', async () => {
|
||||||
|
expect(
|
||||||
|
await api.transferFunds({
|
||||||
|
amount: '1',
|
||||||
|
coin: 'USDT',
|
||||||
|
from_account_type: 'SPOT',
|
||||||
|
to_account_type: 'CONTRACT',
|
||||||
|
transfer_id: 'testtransfer',
|
||||||
|
})
|
||||||
|
).toMatchObject({
|
||||||
|
ret_code: API_ERROR_CODE.INVALID_API_KEY_OR_PERMISSIONS,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
successResponseObjectV3,
|
successResponseObjectV3,
|
||||||
} from '../response.util';
|
} from '../response.util';
|
||||||
|
|
||||||
describe('Public USDC Options REST API Endpoints', () => {
|
describe('Public Unified Margin REST API Endpoints', () => {
|
||||||
const useLivenet = true;
|
const useLivenet = true;
|
||||||
const API_KEY = undefined;
|
const API_KEY = undefined;
|
||||||
const API_SECRET = undefined;
|
const API_SECRET = undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user