fix tests and incorrect v5 endpoint

This commit is contained in:
tiagosiebler
2023-02-21 12:31:40 +00:00
parent 860e2561a1
commit bf602c8d58
6 changed files with 94 additions and 80 deletions

View File

@@ -76,6 +76,7 @@ export const API_ERROR_CODE = {
CONTRACT_RISK_LIMIT_INFO_NOT_EXISTS: 140031,
CONTRACT_SET_LEVERAGE_NOT_MODIFIED: 140043,
SUB_USER_NOT_FOUND: 141009,
SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE: 175006,
SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND: 175007,
SPOT_MARGIN_NOT_ENABLED: 176008,
SPOT_MARGIN_QUESTIONNAIRE_NOT_SUBMIT: 176037,

View File

@@ -738,7 +738,7 @@ export class RestClientV5 extends BaseRestClient {
* Once the mmp triggered, you can unfreeze the account via this endpoint
*/
resetMMP(baseCoin: string): Promise<APIResponseV3<undefined>> {
return this.postPrivate('/v5/account/mmp-modify', { baseCoin });
return this.postPrivate('/v5/account/mmp-reset', { baseCoin });
}
/**

View File

@@ -62,7 +62,7 @@ interface UnsignedRequest<T> {
paramsWithSign: T;
}
type SignMethod = 'keyInBody' | 'usdc';
type SignMethod = 'v2auth' | 'v5auth';
export default abstract class BaseRestClient {
private timeOffset: number | null = null;
@@ -233,7 +233,7 @@ export default abstract class BaseRestClient {
const signResult = await this.prepareSignParams(
method,
'usdc',
'v5auth',
params,
isPublicApi
);
@@ -245,11 +245,9 @@ export default abstract class BaseRestClient {
options.headers['X-BAPI-RECV-WINDOW'] = signResult.recvWindow;
if (method === 'GET') {
// const serialisedParams = signResult.serializedParams;
return {
...options,
params: signResult.originalParams,
// url: url + (serialisedParams ? '?' + serialisedParams : ''),
};
}
@@ -261,7 +259,7 @@ export default abstract class BaseRestClient {
const signResult = await this.prepareSignParams(
method,
'keyInBody',
'v2auth',
params,
isPublicApi
);
@@ -376,7 +374,7 @@ export default abstract class BaseRestClient {
res.recvWindow = recvWindow;
// usdc is different for some reason
if (signMethod === 'usdc') {
if (signMethod === 'v5auth') {
const sortProperties = false;
const signRequestParams =
method === 'GET'
@@ -397,7 +395,7 @@ export default abstract class BaseRestClient {
}
// spot/v2 derivatives
if (signMethod === 'keyInBody') {
if (signMethod === 'v2auth') {
res.originalParams.api_key = key;
res.originalParams.timestamp = timestamp;

View File

@@ -258,9 +258,7 @@ describe('Private READ V5 REST API Endpoints', () => {
describe('Spot Leverage Token APIs', () => {
it('getSpotLeveragedTokenOrderHistory()', async () => {
expect(await api.getSpotLeveragedTokenOrderHistory()).toMatchObject({
// ...successResponseObjectV3(),
// retMsg: '',
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND,
...successResponseObjectV3(),
});
});
});

View File

@@ -1,5 +1,6 @@
import {
API_ERROR_CODE,
LeverageTokenInfoV5,
OrderSideV5,
OrderTypeV5,
RestClientV5,
@@ -93,62 +94,74 @@ describe('Private WRITE V5 REST API Endpoints', () => {
});
});
it('batchSubmitOrders()', async () => {
expect(
await api.batchSubmitOrders('option', [
{
orderLinkId: 'customOrderId1',
orderType: orderType,
qty: '1',
side: orderSide,
symbol: linearSymbol,
},
{
orderLinkId: 'customOrderId2',
orderType: orderType,
qty: '2',
side: orderSide,
symbol: linearSymbol,
},
])
).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('batchAmendOrders()', async () => {
expect(
await api.batchAmendOrders('option', [
{
orderLinkId: 'customOrderId1',
qty: '3',
symbol: linearSymbol,
},
{
orderLinkId: 'customOrderId2',
qty: '4',
symbol: linearSymbol,
},
])
).toMatchObject({
...successResponseObjectV3(),
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('batchCancelOrders()', async () => {
expect(
await api.batchCancelOrders('option', [
{
orderLinkId: 'customOrderId1',
symbol: linearSymbol,
},
{
orderLinkId: 'customOrderId2',
symbol: linearSymbol,
},
])
).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(),
});
});
});
@@ -296,13 +309,11 @@ describe('Private WRITE V5 REST API Endpoints', () => {
});
});
it.skip('resetMMP()', async () => {
it('resetMMP()', async () => {
expect(await api.resetMMP(settleCoin)).toMatchObject({
...successResponseObjectV3(),
retMsg: '',
retCode: 3500715,
// Contacted bybit for info
// + "retMsg": "Parameter window cannot be empty.",
// ...successResponseObjectV3(),
// retMsg: '',
retCode: API_ERROR_CODE.INSTITION_MMP_PROFILE_NOT_FOUND,
});
});
});
@@ -397,18 +408,24 @@ describe('Private WRITE V5 REST API Endpoints', () => {
});
});
// Not currently working. In touch with bybit.
describe.skip('Spot Leverage Token APIs', () => {
it('purchaseSpotLeveragedToken()', async () => {
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: 'EOS3L',
serialNo: 'purchase-001',
ltCoin: leverageToken.ltCoin,
})
).toMatchObject({
// ...successResponseObjectV3(),
retCode: 0,
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE,
retMsg: '',
});
});
@@ -417,13 +434,12 @@ describe('Private WRITE V5 REST API Endpoints', () => {
expect(
await api.redeemSpotLeveragedToken({
quantity: '100',
ltCoin: 'EOS3L',
serialNo: 'redeem-001',
ltCoin: leverageToken.ltCoin,
})
).toMatchObject({
// ...successResponseObjectV3(),
retCode: 0,
retMsg: '',
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE,
// retMsg: '',
});
});
});

View File

@@ -82,7 +82,8 @@ describe('Private Spot REST API GET Endpoints', () => {
it('getLeveragedTokenPRHistory()', async () => {
expect(await api.getLeveragedTokenPRHistory()).toMatchObject({
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_LEVERAGED_TOKEN,
...successResponseObjectV3(),
// retCode: API_ERROR_CODE.ORDER_NOT_FOUND_LEVERAGED_TOKEN,
});
});