Merge pull request #210 from tiagosiebler/types
v3.3.6: add response type for contract ticker
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bybit-api",
|
||||
"version": "3.3.5",
|
||||
"version": "3.3.6",
|
||||
"description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
||||
@@ -69,6 +69,7 @@ export const API_ERROR_CODE = {
|
||||
NO_ACTIVE_ORDER: 3100205,
|
||||
/** E.g. USDC Options trading when the account hasn't been opened for USDC Options yet */
|
||||
ACCOUNT_NOT_EXIST: 3200200,
|
||||
SET_MARGIN_MODE_FAILED_USDC: 3400045,
|
||||
INCORRECT_MMP_PARAMETERS: 3500712,
|
||||
INSTITION_MMP_PROFILE_NOT_FOUND: 3500713,
|
||||
} as const;
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
ContractWalletFundRecordRequest,
|
||||
PaginatedResult,
|
||||
ContractHistoricOrder,
|
||||
ContractSymbolTicker,
|
||||
} from './types';
|
||||
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||
import BaseRestClient from './util/BaseRestClient';
|
||||
@@ -67,9 +68,9 @@ export class ContractClient extends BaseRestClient {
|
||||
|
||||
/** Get a symbol price/statistics ticker */
|
||||
getSymbolTicker(
|
||||
category: UMCategory,
|
||||
category: UMCategory | '',
|
||||
symbol?: string
|
||||
): Promise<APIResponseV3<any>> {
|
||||
): Promise<APIResponseV3<ContractSymbolTicker[]>> {
|
||||
return this.get('/derivatives/v3/public/tickers', { category, symbol });
|
||||
}
|
||||
|
||||
|
||||
@@ -33,3 +33,27 @@ export interface ContractHistoricOrder {
|
||||
triggerDirection: number;
|
||||
positionIdx: number;
|
||||
}
|
||||
|
||||
export interface ContractSymbolTicker {
|
||||
symbol: string;
|
||||
bidPrice: string;
|
||||
askPrice: string;
|
||||
lastPrice: string;
|
||||
lastTickDirection: string;
|
||||
prevPrice24h: string;
|
||||
price24hPcnt: string;
|
||||
highPrice24h: string;
|
||||
lowPrice24h: string;
|
||||
prevPrice1h: string;
|
||||
markPrice: string;
|
||||
indexPrice: string;
|
||||
openInterest: string;
|
||||
turnover24h: string;
|
||||
volume24h: string;
|
||||
fundingRate: string;
|
||||
nextFundingTime: string;
|
||||
predictedDeliveryPrice: string;
|
||||
basisRate: string;
|
||||
deliveryFeeRate: string;
|
||||
deliveryTime: string;
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ export function getWsKeyForTopic(
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Failed to determine wskey for unified perps topic: "${topic}`
|
||||
`Failed to determine wskey for unified perps topic: "${topic}"`
|
||||
);
|
||||
}
|
||||
case 'contractInverse': {
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('Public Contract Inverse Websocket Client', () => {
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
const wsTopic = 'orderbook.25.BTCUSD';
|
||||
const wsTopic = 'orderbook.1.BTCUSD';
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('Public Contract USDT Websocket Client', () => {
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
const wsTopic = 'orderbook.25.BTCUSDT';
|
||||
const wsTopic = 'orderbook.1.BTCUSDT';
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
|
||||
@@ -58,18 +58,6 @@ describe('Public Spot V3 Websocket Client', () => {
|
||||
req_id: wsTopic,
|
||||
});
|
||||
|
||||
expect(wsUpdatePromise).resolves.toMatchObject({
|
||||
data: {
|
||||
a: expect.any(Array),
|
||||
b: expect.any(Array),
|
||||
s: symbol,
|
||||
t: expect.any(Number),
|
||||
},
|
||||
topic: wsTopic,
|
||||
ts: expect.any(Number),
|
||||
type: 'delta',
|
||||
});
|
||||
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
@@ -82,9 +70,20 @@ describe('Public Spot V3 Websocket Client', () => {
|
||||
}
|
||||
|
||||
try {
|
||||
await wsUpdatePromise;
|
||||
expect(await wsUpdatePromise).toMatchObject({
|
||||
data: {
|
||||
a: expect.any(Array),
|
||||
b: expect.any(Array),
|
||||
s: symbol,
|
||||
t: expect.any(Number),
|
||||
},
|
||||
topic: wsTopic,
|
||||
ts: expect.any(Number),
|
||||
type: 'snapshot',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Wait for "${wsTopic}" event exception: `, e);
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,12 +70,14 @@ describe('Public Unified Margin Websocket Client (Perps - USDC)', () => {
|
||||
s: 'BTCUSDT',
|
||||
u: expect.any(Number),
|
||||
},
|
||||
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
||||
topic: 'orderbook.25.BTCUSDC',
|
||||
ts: expect.any(Number),
|
||||
type: 'snapshot',
|
||||
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('unified margin perp ws public error: ', e);
|
||||
|
||||
// no data
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('Public Unified Margin Websocket Client (Perps - USDT)', () => {
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
// USDT should be detected and automatically routed through the USDT connection
|
||||
const topic = 'orderbook.25.BTCUSDT';
|
||||
const topic = 'orderbook.1.BTCUSDT';
|
||||
wsClient.subscribe(topic);
|
||||
|
||||
try {
|
||||
@@ -74,10 +74,11 @@ describe('Public Unified Margin Websocket Client (Perps - USDT)', () => {
|
||||
},
|
||||
topic: topic,
|
||||
ts: expect.any(Number),
|
||||
type: 'snapshot',
|
||||
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
||||
type: 'snapshot',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('unified margin perp usdt orderbook test fail', e);
|
||||
// no data
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,10 @@ describe('Private USDC Options REST API POST Endpoints', () => {
|
||||
|
||||
it('setMarginMode()', async () => {
|
||||
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject(
|
||||
successResponseObjectV3()
|
||||
{
|
||||
retCode: API_ERROR_CODE.SET_MARGIN_MODE_FAILED_USDC,
|
||||
}
|
||||
// successResponseObjectV3()
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -71,7 +71,10 @@ describe('Private USDC Perp REST API POST Endpoints', () => {
|
||||
|
||||
it('setMarginMode()', async () => {
|
||||
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject(
|
||||
successResponseObjectV3()
|
||||
{
|
||||
retCode: API_ERROR_CODE.SET_MARGIN_MODE_FAILED_USDC,
|
||||
}
|
||||
// successResponseObjectV3()
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ describe('Public USDC Perp Websocket Client', () => {
|
||||
type: 'snapshot',
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('usdc perp ws public error: ', e);
|
||||
// no data
|
||||
expect(e).toBeFalsy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user