v3.3.4: fix optional param in contract client, add js/ts samples for contract client, fix e2e open interest limit test, update readme
This commit is contained in:
@@ -28,6 +28,7 @@ Check out my related projects:
|
|||||||
- [binance](https://www.npmjs.com/package/binance)
|
- [binance](https://www.npmjs.com/package/binance)
|
||||||
- [bybit-api](https://www.npmjs.com/package/bybit-api)
|
- [bybit-api](https://www.npmjs.com/package/bybit-api)
|
||||||
- [okx-api](https://www.npmjs.com/package/okx-api)
|
- [okx-api](https://www.npmjs.com/package/okx-api)
|
||||||
|
- [bitget-api](https://www.npmjs.com/package/bitget-api)
|
||||||
- [ftx-api](https://www.npmjs.com/package/ftx-api)
|
- [ftx-api](https://www.npmjs.com/package/ftx-api)
|
||||||
- Try my misc utilities:
|
- Try my misc utilities:
|
||||||
- [orderbooks](https://www.npmjs.com/package/orderbooks)
|
- [orderbooks](https://www.npmjs.com/package/orderbooks)
|
||||||
|
|||||||
21
examples/rest-contract-public.js
Normal file
21
examples/rest-contract-public.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* This is the pure javascript version of the `rest-contract-public.ts` sample
|
||||||
|
*/
|
||||||
|
|
||||||
|
// To use a local build (testing with the repo directly), make sure to `npm run build` first from the repo root
|
||||||
|
// const { ContractClient } = require('../dist');
|
||||||
|
|
||||||
|
// or, use the version installed with npm
|
||||||
|
const { ContractClient } = require('bybit-api');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const client = new ContractClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const orderbookResult = await client.getOrderBook('BTCUSDT', 'linear');
|
||||||
|
console.log('orderbook result: ', orderbookResult);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('request failed: ', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
20
examples/rest-contract-public.ts
Normal file
20
examples/rest-contract-public.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* This is the TypeScript version of the `rest-contract-public.js` sample.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// For testing with the repo directly, import from the src folder
|
||||||
|
import { ContractClient } from '../src';
|
||||||
|
|
||||||
|
// or, use the version installed with npm
|
||||||
|
// import { ContractClient } from 'bybit-api';
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const client = new ContractClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const orderbookResult = await client.getOrderBook('BTCUSDT', 'linear');
|
||||||
|
console.log('orderbook result: ', orderbookResult);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('request failed: ', e);
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "bybit-api",
|
"name": "bybit-api",
|
||||||
"version": "3.3.3",
|
"version": "3.3.4",
|
||||||
"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",
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export class ContractClient extends BaseRestClient {
|
|||||||
/** Query order book info. Each side has a depth of 25 orders. */
|
/** Query order book info. Each side has a depth of 25 orders. */
|
||||||
getOrderBook(
|
getOrderBook(
|
||||||
symbol: string,
|
symbol: string,
|
||||||
category: string,
|
category?: string,
|
||||||
limit?: number
|
limit?: number
|
||||||
): Promise<APIResponseV3<any>> {
|
): Promise<APIResponseV3<any>> {
|
||||||
return this.get('/derivatives/v3/public/order-book/L2', {
|
return this.get('/derivatives/v3/public/order-book/L2', {
|
||||||
|
|||||||
@@ -544,6 +544,7 @@ export class WebsocketClient extends EventEmitter {
|
|||||||
|
|
||||||
private reconnectWithDelay(wsKey: WsKey, connectionDelayMs: number) {
|
private reconnectWithDelay(wsKey: WsKey, connectionDelayMs: number) {
|
||||||
this.clearTimers(wsKey);
|
this.clearTimers(wsKey);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.wsStore.getConnectionState(wsKey) !==
|
this.wsStore.getConnectionState(wsKey) !==
|
||||||
WsConnectionStateEnum.CONNECTING
|
WsConnectionStateEnum.CONNECTING
|
||||||
|
|||||||
@@ -71,11 +71,11 @@ describe('Private Contract REST API GET Endpoints', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Doesn't work on e2e test account, something about account state. Investigating with bybit.
|
// Doesn't work on e2e test account. This endpoint throws this error if the account never opened a position before.
|
||||||
it.skip('getOpenInterestLimitInfo()', async () => {
|
it('getOpenInterestLimitInfo()', async () => {
|
||||||
expect(await api.getOpenInterestLimitInfo('ETHUSDT')).toMatchObject({
|
expect(await api.getOpenInterestLimitInfo('ETHUSDT')).toMatchObject({
|
||||||
...successResponseObjectV3(),
|
retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG,
|
||||||
retMsg: 'ok',
|
retMsg: expect.stringMatching(/OI group don't exist/gim),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export function successResponseObjectV3() {
|
|||||||
return {
|
return {
|
||||||
result: expect.any(Object),
|
result: expect.any(Object),
|
||||||
...successEmptyResponseObjectV3(),
|
...successEmptyResponseObjectV3(),
|
||||||
|
// retMsg: 'ok',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user