fix(v4.0.0-beta.4): demo trading wss should only be used for private connections

This commit is contained in:
tiagosiebler
2025-02-06 11:11:36 +00:00
4 changed files with 12 additions and 7 deletions

View File

@@ -17,7 +17,12 @@ const logger = {
* - Heartbeats/ping/pong/reconnects are all handled automatically. * - Heartbeats/ping/pong/reconnects are all handled automatically.
* If a connection drops, the client will clean it up, respawn a fresh connection and resubscribe for you. * If a connection drops, the client will clean it up, respawn a fresh connection and resubscribe for you.
*/ */
const wsClient = new WebsocketClient({}, logger); const wsClient = new WebsocketClient(
{
// demoTrading: true,
},
logger,
);
wsClient.on('update', (data) => { wsClient.on('update', (data) => {
console.log('raw message received ', JSON.stringify(data)); console.log('raw message received ', JSON.stringify(data));

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "4.0.0-beta.3", "version": "4.0.0-beta.4",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bybit-api", "name": "bybit-api",
"version": "4.0.0-beta.3", "version": "4.0.0-beta.4",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.7.9", "axios": "^1.7.9",

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "4.0.0-beta.3", "version": "4.0.0-beta.4",
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -241,7 +241,7 @@ export function getWsUrl(
} }
// https://bybit-exchange.github.io/docs/v5/demo // https://bybit-exchange.github.io/docs/v5/demo
const demoTradingPrivateEndpoint = 'wss://stream-demo.bybit.com/v5/private'; const DEMO_TRADING_ENDPOINT = 'wss://stream-demo.bybit.com/v5/private';
const isDemoTrading = wsClientOptions.demoTrading; const isDemoTrading = wsClientOptions.demoTrading;
const isTestnet = wsClientOptions.testnet; const isTestnet = wsClientOptions.testnet;
@@ -250,13 +250,13 @@ export function getWsUrl(
switch (wsKey) { switch (wsKey) {
case WS_KEY_MAP.v5Private: { case WS_KEY_MAP.v5Private: {
if (isDemoTrading) { if (isDemoTrading) {
return demoTradingPrivateEndpoint; return DEMO_TRADING_ENDPOINT;
} }
return WS_BASE_URL_MAP.v5.private[networkKey]; return WS_BASE_URL_MAP.v5.private[networkKey];
} }
case WS_KEY_MAP.v5PrivateTrade: { case WS_KEY_MAP.v5PrivateTrade: {
if (isDemoTrading) { if (isDemoTrading) {
return demoTradingPrivateEndpoint; return DEMO_TRADING_ENDPOINT;
} }
return WS_BASE_URL_MAP[wsKey].private[networkKey]; return WS_BASE_URL_MAP[wsKey].private[networkKey];
} }