Merge pull request #201 from tiagosiebler/openinterestfix
v3.3.1: fix(#199) wrong endpoint for contract.getOpenInterestLimitInfo
This commit is contained in:
@@ -317,3 +317,7 @@ An early generation of this library was started by @pixtron. If this library hel
|
|||||||
|
|
||||||
### Contributions & Pull Requests
|
### Contributions & Pull Requests
|
||||||
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
|
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
|
||||||
|
|
||||||
|
## Star History
|
||||||
|
|
||||||
|
[](https://star-history.com/#tiagosiebler/ftx-api&tiagosiebler/bybit-api&tiagosiebler/binance&tiagosiebler/orderbooks&tiagosiebler/okx-api&tiagosiebler/awesome-crypto-examples&Date)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "bybit-api",
|
"name": "bybit-api",
|
||||||
"version": "3.3.0",
|
"version": "3.3.1",
|
||||||
"description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
|
"description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const API_ERROR_CODE = {
|
|||||||
INVALID_API_KEY_OR_PERMISSIONS: 10003,
|
INVALID_API_KEY_OR_PERMISSIONS: 10003,
|
||||||
SIGNATURE_NOT_VALID: 10004,
|
SIGNATURE_NOT_VALID: 10004,
|
||||||
INCORRECT_API_KEY_PERMISSIONS: 10005,
|
INCORRECT_API_KEY_PERMISSIONS: 10005,
|
||||||
|
DB_ERROR_WRONG_CURSOR: 10016,
|
||||||
INCORRECT_PRIVATE_OPERATIONS: 3303001,
|
INCORRECT_PRIVATE_OPERATIONS: 3303001,
|
||||||
/** Account not unified margin, update required */
|
/** Account not unified margin, update required */
|
||||||
ACCOUNT_NOT_UNIFIED: 10020,
|
ACCOUNT_NOT_UNIFIED: 10020,
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import {
|
|||||||
ContractUserExecutionHistoryRequest,
|
ContractUserExecutionHistoryRequest,
|
||||||
ContractClosedPNLRequest,
|
ContractClosedPNLRequest,
|
||||||
ContractWalletFundRecordRequest,
|
ContractWalletFundRecordRequest,
|
||||||
|
PaginatedResult,
|
||||||
|
ContractHistoricOrder,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { REST_CLIENT_TYPE_ENUM } from './util';
|
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
@@ -148,7 +150,7 @@ export class ContractClient extends BaseRestClient {
|
|||||||
/** Query order history. As order creation/cancellation is asynchronous, the data returned from the interface may be delayed. To access order information in real-time, call getActiveOrders() */
|
/** Query order history. As order creation/cancellation is asynchronous, the data returned from the interface may be delayed. To access order information in real-time, call getActiveOrders() */
|
||||||
getHistoricOrders(
|
getHistoricOrders(
|
||||||
params: ContractHistoricOrdersRequest
|
params: ContractHistoricOrdersRequest
|
||||||
): Promise<APIResponseV3<any>> {
|
): Promise<APIResponseV3<PaginatedResult<ContractHistoricOrder>>> {
|
||||||
return this.getPrivate('/contract/v3/private/order/list', params);
|
return this.getPrivate('/contract/v3/private/order/list', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,7 +295,7 @@ export class ContractClient extends BaseRestClient {
|
|||||||
|
|
||||||
/** Get the information of open interest limit. */
|
/** Get the information of open interest limit. */
|
||||||
getOpenInterestLimitInfo(symbol: string): Promise<APIResponseV3<any>> {
|
getOpenInterestLimitInfo(symbol: string): Promise<APIResponseV3<any>> {
|
||||||
return this.getPrivate('/contract/v3/private/position/closed-pnl', {
|
return this.getPrivate('/contract/v3/private/position/limit-info', {
|
||||||
symbol,
|
symbol,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/types/response/contract.ts
Normal file
35
src/types/response/contract.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
export interface PaginatedResult<TList = any> {
|
||||||
|
nextPageCursor: string;
|
||||||
|
list: TList[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ContractHistoricOrder {
|
||||||
|
symbol: string;
|
||||||
|
side: string;
|
||||||
|
orderType: string;
|
||||||
|
price: string;
|
||||||
|
qty: string;
|
||||||
|
reduceOnly: boolean;
|
||||||
|
timeInForce: string;
|
||||||
|
orderStatus: string;
|
||||||
|
leavesQty: string;
|
||||||
|
leavesValue: string;
|
||||||
|
cumExecQty: string;
|
||||||
|
cumExecValue: string;
|
||||||
|
cumExecFee: string;
|
||||||
|
lastPriceOnCreated: string;
|
||||||
|
rejectReason: string;
|
||||||
|
orderLinkId: string;
|
||||||
|
createdTime: string;
|
||||||
|
updatedTime: string;
|
||||||
|
orderId: string;
|
||||||
|
stopOrderType: string;
|
||||||
|
takeProfit: string;
|
||||||
|
stopLoss: string;
|
||||||
|
tpTriggerBy: string;
|
||||||
|
slTriggerBy: string;
|
||||||
|
triggerPrice: string;
|
||||||
|
closeOnTrigger: boolean;
|
||||||
|
triggerDirection: number;
|
||||||
|
positionIdx: number;
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from './contract';
|
||||||
export * from './shared';
|
export * from './shared';
|
||||||
export * from './spot';
|
export * from './spot';
|
||||||
export * from './usdt-perp';
|
export * from './usdt-perp';
|
||||||
|
|||||||
@@ -216,9 +216,11 @@ 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 : ''),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,6 +361,7 @@ export default abstract class BaseRestClient {
|
|||||||
|
|
||||||
const paramsStr = timestamp + key + recvWindow + signRequestParams;
|
const paramsStr = timestamp + key + recvWindow + signRequestParams;
|
||||||
res.sign = await signMessage(paramsStr, this.secret);
|
res.sign = await signMessage(paramsStr, this.secret);
|
||||||
|
res.serializedParams = signRequestParams;
|
||||||
|
|
||||||
// console.log('sign req: ', paramsStr);
|
// console.log('sign req: ', paramsStr);
|
||||||
return res;
|
return res;
|
||||||
@@ -378,12 +381,13 @@ export default abstract class BaseRestClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const sortProperties = true;
|
const sortProperties = true;
|
||||||
|
const encodeValues = false;
|
||||||
|
|
||||||
res.serializedParams = serializeParams(
|
res.serializedParams = serializeParams(
|
||||||
res.originalParams,
|
res.originalParams,
|
||||||
strictParamValidation,
|
strictParamValidation,
|
||||||
sortProperties,
|
sortProperties,
|
||||||
encodeSerialisedValues
|
encodeValues
|
||||||
);
|
);
|
||||||
res.sign = await signMessage(res.serializedParams, this.secret);
|
res.sign = await signMessage(res.serializedParams, this.secret);
|
||||||
res.paramsWithSign = {
|
res.paramsWithSign = {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export function serializeParams(
|
|||||||
return properties
|
return properties
|
||||||
.map((key) => {
|
.map((key) => {
|
||||||
const value = encodeSerialisedValues
|
const value = encodeSerialisedValues
|
||||||
? encodeURI(params[key])
|
? encodeURIComponent(params[key])
|
||||||
: params[key];
|
: params[key];
|
||||||
|
|
||||||
if (strict_validation === true && typeof value === 'undefined') {
|
if (strict_validation === true && typeof value === 'undefined') {
|
||||||
|
|||||||
@@ -23,6 +23,30 @@ describe('Private Contract REST API GET Endpoints', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getHistoricOrders() with hardcoded cursor', async () => {
|
||||||
|
const cursor =
|
||||||
|
'eyJza2lwX2xvY2FsX3N5bWJvbCI6ZmFsc2UsInBhZ2VfdG9rZW4iOiJleUpOSWpwN0luQnJJanA3SWtJaU9pSktSRmt6VG1wcmVFMXFaM2xNVkUwMFQwUlpkRTVFUlRKTmFURm9UakpPYWt4WFVUSk9lbFY1VDBSU2FrMVhXVEJOZHowOUluMHNJbDl6YTE4aU9uc2lRaUk2SWtaNFltMWFZMDV6TUROek1rNTZXVFZOVkVrMFRXa3dlazlFWnpKTVZGRjRUbXBKZEZsVVpHcFplVEZyVG1wak1VMXFaekJaZWtadFRrUk5QU0o5TENKZmRYTmZJanA3SWtJaU9pSkJLMmt2WkZGRlJ5SjlmWDA9In0=';
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await api.getHistoricOrders({ symbol, cursor, limit: 1 })
|
||||||
|
).toMatchObject({
|
||||||
|
retCode: API_ERROR_CODE.DB_ERROR_WRONG_CURSOR,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getHistoricOrders() with dynamic cursor', async () => {
|
||||||
|
const orders = await api.getHistoricOrders({ symbol, limit: 1 });
|
||||||
|
|
||||||
|
const cursor = orders.result.nextPageCursor;
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await api.getHistoricOrders({ symbol, cursor, limit: 1 })
|
||||||
|
).toMatchObject({
|
||||||
|
...successResponseObjectV3(),
|
||||||
|
retMsg: 'OK',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('getActiveOrders()', async () => {
|
it('getActiveOrders()', async () => {
|
||||||
expect(await api.getActiveOrders({ symbol })).toMatchObject(
|
expect(await api.getActiveOrders({ symbol })).toMatchObject(
|
||||||
successResponseObjectV3()
|
successResponseObjectV3()
|
||||||
@@ -47,10 +71,12 @@ describe('Private Contract REST API GET Endpoints', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getOpenInterestLimitInfo()', async () => {
|
// Doesn't work on e2e test account, something about account state. Investigating with bybit.
|
||||||
expect(await api.getOpenInterestLimitInfo(symbol)).toMatchObject(
|
it.skip('getOpenInterestLimitInfo()', async () => {
|
||||||
successResponseObjectV3()
|
expect(await api.getOpenInterestLimitInfo('ETHUSDT')).toMatchObject({
|
||||||
);
|
...successResponseObjectV3(),
|
||||||
|
retMsg: 'ok',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getBalances()', async () => {
|
it('getBalances()', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user