fix tests and incorrect v5 endpoint
This commit is contained in:
@@ -76,6 +76,7 @@ export const API_ERROR_CODE = {
|
|||||||
CONTRACT_RISK_LIMIT_INFO_NOT_EXISTS: 140031,
|
CONTRACT_RISK_LIMIT_INFO_NOT_EXISTS: 140031,
|
||||||
CONTRACT_SET_LEVERAGE_NOT_MODIFIED: 140043,
|
CONTRACT_SET_LEVERAGE_NOT_MODIFIED: 140043,
|
||||||
SUB_USER_NOT_FOUND: 141009,
|
SUB_USER_NOT_FOUND: 141009,
|
||||||
|
SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE: 175006,
|
||||||
SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND: 175007,
|
SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND: 175007,
|
||||||
SPOT_MARGIN_NOT_ENABLED: 176008,
|
SPOT_MARGIN_NOT_ENABLED: 176008,
|
||||||
SPOT_MARGIN_QUESTIONNAIRE_NOT_SUBMIT: 176037,
|
SPOT_MARGIN_QUESTIONNAIRE_NOT_SUBMIT: 176037,
|
||||||
|
|||||||
@@ -738,7 +738,7 @@ export class RestClientV5 extends BaseRestClient {
|
|||||||
* Once the mmp triggered, you can unfreeze the account via this endpoint
|
* Once the mmp triggered, you can unfreeze the account via this endpoint
|
||||||
*/
|
*/
|
||||||
resetMMP(baseCoin: string): Promise<APIResponseV3<undefined>> {
|
resetMMP(baseCoin: string): Promise<APIResponseV3<undefined>> {
|
||||||
return this.postPrivate('/v5/account/mmp-modify', { baseCoin });
|
return this.postPrivate('/v5/account/mmp-reset', { baseCoin });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ interface UnsignedRequest<T> {
|
|||||||
paramsWithSign: T;
|
paramsWithSign: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignMethod = 'keyInBody' | 'usdc';
|
type SignMethod = 'v2auth' | 'v5auth';
|
||||||
|
|
||||||
export default abstract class BaseRestClient {
|
export default abstract class BaseRestClient {
|
||||||
private timeOffset: number | null = null;
|
private timeOffset: number | null = null;
|
||||||
@@ -233,7 +233,7 @@ export default abstract class BaseRestClient {
|
|||||||
|
|
||||||
const signResult = await this.prepareSignParams(
|
const signResult = await this.prepareSignParams(
|
||||||
method,
|
method,
|
||||||
'usdc',
|
'v5auth',
|
||||||
params,
|
params,
|
||||||
isPublicApi
|
isPublicApi
|
||||||
);
|
);
|
||||||
@@ -245,11 +245,9 @@ export default abstract class BaseRestClient {
|
|||||||
options.headers['X-BAPI-RECV-WINDOW'] = signResult.recvWindow;
|
options.headers['X-BAPI-RECV-WINDOW'] = signResult.recvWindow;
|
||||||
|
|
||||||
if (method === 'GET') {
|
if (method === 'GET') {
|
||||||
// const serialisedParams = signResult.serializedParams;
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
params: signResult.originalParams,
|
params: signResult.originalParams,
|
||||||
// url: url + (serialisedParams ? '?' + serialisedParams : ''),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +259,7 @@ export default abstract class BaseRestClient {
|
|||||||
|
|
||||||
const signResult = await this.prepareSignParams(
|
const signResult = await this.prepareSignParams(
|
||||||
method,
|
method,
|
||||||
'keyInBody',
|
'v2auth',
|
||||||
params,
|
params,
|
||||||
isPublicApi
|
isPublicApi
|
||||||
);
|
);
|
||||||
@@ -376,7 +374,7 @@ export default abstract class BaseRestClient {
|
|||||||
res.recvWindow = recvWindow;
|
res.recvWindow = recvWindow;
|
||||||
|
|
||||||
// usdc is different for some reason
|
// usdc is different for some reason
|
||||||
if (signMethod === 'usdc') {
|
if (signMethod === 'v5auth') {
|
||||||
const sortProperties = false;
|
const sortProperties = false;
|
||||||
const signRequestParams =
|
const signRequestParams =
|
||||||
method === 'GET'
|
method === 'GET'
|
||||||
@@ -397,7 +395,7 @@ export default abstract class BaseRestClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// spot/v2 derivatives
|
// spot/v2 derivatives
|
||||||
if (signMethod === 'keyInBody') {
|
if (signMethod === 'v2auth') {
|
||||||
res.originalParams.api_key = key;
|
res.originalParams.api_key = key;
|
||||||
res.originalParams.timestamp = timestamp;
|
res.originalParams.timestamp = timestamp;
|
||||||
|
|
||||||
|
|||||||
@@ -258,9 +258,7 @@ describe('Private READ V5 REST API Endpoints', () => {
|
|||||||
describe('Spot Leverage Token APIs', () => {
|
describe('Spot Leverage Token APIs', () => {
|
||||||
it('getSpotLeveragedTokenOrderHistory()', async () => {
|
it('getSpotLeveragedTokenOrderHistory()', async () => {
|
||||||
expect(await api.getSpotLeveragedTokenOrderHistory()).toMatchObject({
|
expect(await api.getSpotLeveragedTokenOrderHistory()).toMatchObject({
|
||||||
// ...successResponseObjectV3(),
|
...successResponseObjectV3(),
|
||||||
// retMsg: '',
|
|
||||||
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
API_ERROR_CODE,
|
API_ERROR_CODE,
|
||||||
|
LeverageTokenInfoV5,
|
||||||
OrderSideV5,
|
OrderSideV5,
|
||||||
OrderTypeV5,
|
OrderTypeV5,
|
||||||
RestClientV5,
|
RestClientV5,
|
||||||
@@ -93,6 +94,17 @@ describe('Private WRITE V5 REST API Endpoints', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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('batchSubmitOrders()', async () => {
|
it('batchSubmitOrders()', async () => {
|
||||||
expect(
|
expect(
|
||||||
await api.batchSubmitOrders('option', [
|
await api.batchSubmitOrders('option', [
|
||||||
@@ -101,14 +113,14 @@ describe('Private WRITE V5 REST API Endpoints', () => {
|
|||||||
orderType: orderType,
|
orderType: orderType,
|
||||||
qty: '1',
|
qty: '1',
|
||||||
side: orderSide,
|
side: orderSide,
|
||||||
symbol: linearSymbol,
|
symbol: optionsSymbol,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
orderLinkId: 'customOrderId2',
|
orderLinkId: 'customOrderId2',
|
||||||
orderType: orderType,
|
orderType: orderType,
|
||||||
qty: '2',
|
qty: '2',
|
||||||
side: orderSide,
|
side: orderSide,
|
||||||
symbol: linearSymbol,
|
symbol: optionsSymbol,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
@@ -122,12 +134,12 @@ describe('Private WRITE V5 REST API Endpoints', () => {
|
|||||||
{
|
{
|
||||||
orderLinkId: 'customOrderId1',
|
orderLinkId: 'customOrderId1',
|
||||||
qty: '3',
|
qty: '3',
|
||||||
symbol: linearSymbol,
|
symbol: optionsSymbol,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
orderLinkId: 'customOrderId2',
|
orderLinkId: 'customOrderId2',
|
||||||
qty: '4',
|
qty: '4',
|
||||||
symbol: linearSymbol,
|
symbol: optionsSymbol,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
@@ -140,17 +152,18 @@ describe('Private WRITE V5 REST API Endpoints', () => {
|
|||||||
await api.batchCancelOrders('option', [
|
await api.batchCancelOrders('option', [
|
||||||
{
|
{
|
||||||
orderLinkId: 'customOrderId1',
|
orderLinkId: 'customOrderId1',
|
||||||
symbol: linearSymbol,
|
symbol: optionsSymbol,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
orderLinkId: 'customOrderId2',
|
orderLinkId: 'customOrderId2',
|
||||||
symbol: linearSymbol,
|
symbol: optionsSymbol,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
...successResponseObjectV3(),
|
...successResponseObjectV3(),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('setDisconnectCancelAllWindow()', async () => {
|
it('setDisconnectCancelAllWindow()', async () => {
|
||||||
expect(await api.setDisconnectCancelAllWindow('option', 5)).toMatchObject(
|
expect(await api.setDisconnectCancelAllWindow('option', 5)).toMatchObject(
|
||||||
@@ -296,13 +309,11 @@ describe('Private WRITE V5 REST API Endpoints', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('resetMMP()', async () => {
|
it('resetMMP()', async () => {
|
||||||
expect(await api.resetMMP(settleCoin)).toMatchObject({
|
expect(await api.resetMMP(settleCoin)).toMatchObject({
|
||||||
...successResponseObjectV3(),
|
// ...successResponseObjectV3(),
|
||||||
retMsg: '',
|
// retMsg: '',
|
||||||
retCode: 3500715,
|
retCode: API_ERROR_CODE.INSTITION_MMP_PROFILE_NOT_FOUND,
|
||||||
// Contacted bybit for info
|
|
||||||
// + "retMsg": "Parameter window cannot be empty.",
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -397,18 +408,24 @@ describe('Private WRITE V5 REST API Endpoints', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Not currently working. In touch with bybit.
|
describe('Spot Leverage Token APIs', () => {
|
||||||
describe.skip('Spot Leverage Token APIs', () => {
|
let leverageToken: LeverageTokenInfoV5;
|
||||||
it('purchaseSpotLeveragedToken()', async () => {
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const tokenResult = await api.getLeveragedTokenInfo();
|
||||||
|
leverageToken = tokenResult.result.list[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Still failing - in contact with bybit
|
||||||
|
it.skip('purchaseSpotLeveragedToken()', async () => {
|
||||||
expect(
|
expect(
|
||||||
await api.purchaseSpotLeveragedToken({
|
await api.purchaseSpotLeveragedToken({
|
||||||
ltAmount: '100',
|
ltAmount: '100',
|
||||||
ltCoin: 'EOS3L',
|
ltCoin: leverageToken.ltCoin,
|
||||||
serialNo: 'purchase-001',
|
|
||||||
})
|
})
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
// ...successResponseObjectV3(),
|
// ...successResponseObjectV3(),
|
||||||
retCode: 0,
|
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE,
|
||||||
retMsg: '',
|
retMsg: '',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -417,13 +434,12 @@ describe('Private WRITE V5 REST API Endpoints', () => {
|
|||||||
expect(
|
expect(
|
||||||
await api.redeemSpotLeveragedToken({
|
await api.redeemSpotLeveragedToken({
|
||||||
quantity: '100',
|
quantity: '100',
|
||||||
ltCoin: 'EOS3L',
|
ltCoin: leverageToken.ltCoin,
|
||||||
serialNo: 'redeem-001',
|
|
||||||
})
|
})
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
// ...successResponseObjectV3(),
|
// ...successResponseObjectV3(),
|
||||||
retCode: 0,
|
retCode: API_ERROR_CODE.SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE,
|
||||||
retMsg: '',
|
// retMsg: '',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ describe('Private Spot REST API GET Endpoints', () => {
|
|||||||
|
|
||||||
it('getLeveragedTokenPRHistory()', async () => {
|
it('getLeveragedTokenPRHistory()', async () => {
|
||||||
expect(await api.getLeveragedTokenPRHistory()).toMatchObject({
|
expect(await api.getLeveragedTokenPRHistory()).toMatchObject({
|
||||||
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_LEVERAGED_TOKEN,
|
...successResponseObjectV3(),
|
||||||
|
// retCode: API_ERROR_CODE.ORDER_NOT_FOUND_LEVERAGED_TOKEN,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user