Skip to content

Commit 7e1a7f4

Browse files
committed
fix: apply category-based WS URLs to demo and test environments too
1 parent 7d49420 commit 7e1a7f4

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/node-binance-api.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,24 @@ export default class Binance {
313313
}
314314

315315
getFStreamSingleUrl(category?: 'public' | 'market' | 'private') {
316+
if (category) {
317+
if (this.Options.demo) return `wss://fstream.binancefuture.com/${category}/ws/`;
318+
if (this.Options.test) return `wss://stream.binancefuture.${this.domain}/${category}/ws/`;
319+
return `wss://fstream.binance.${this.domain}/${category}/ws/`;
320+
}
316321
if (this.Options.demo) return this.fstreamSingleDemo;
317322
if (this.Options.test) return this.fstreamSingleTest;
318-
if (category) return `wss://fstream.binance.${this.domain}/${category}/ws/`;
319323
return this.fstreamSingle;
320324
}
321325

322326
getFStreamUrl(category?: 'public' | 'market' | 'private') {
327+
if (category) {
328+
if (this.Options.demo) return `wss://fstream.binancefuture.com/${category}/stream?streams=`;
329+
if (this.Options.test) return `wss://stream.binancefuture.${this.domain}/${category}/stream?streams=`;
330+
return `wss://fstream.binance.${this.domain}/${category}/stream?streams=`;
331+
}
323332
if (this.Options.demo) return this.fstreamDemo;
324333
if (this.Options.test) return this.fstreamTest;
325-
if (category) return `wss://fstream.binance.${this.domain}/${category}/stream?streams=`;
326334
return this.fstream;
327335
}
328336

tests/ws-endpoints-migration.test.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,22 @@ describe('getFStreamUrl with category', function () {
114114
});
115115
});
116116

117-
describe('Demo mode ignores category (uses legacy URLs)', function () {
118-
it('getFStreamSingleUrl returns demo URL regardless of category', function () {
119-
assert.equal(demoBinance.getFStreamSingleUrl('market'), 'wss://fstream.binancefuture.com/ws/');
120-
});
121-
it('getFStreamUrl returns demo URL regardless of category', function () {
122-
assert.equal(demoBinance.getFStreamUrl('market'), 'wss://fstream.binancefuture.com/stream?streams=');
117+
describe('Demo mode uses category-based URLs', function () {
118+
it('getFStreamSingleUrl returns demo URL with category', function () {
119+
assert.equal(demoBinance.getFStreamSingleUrl('public'), 'wss://fstream.binancefuture.com/public/ws/');
120+
assert.equal(demoBinance.getFStreamSingleUrl('market'), 'wss://fstream.binancefuture.com/market/ws/');
121+
assert.equal(demoBinance.getFStreamSingleUrl('private'), 'wss://fstream.binancefuture.com/private/ws/');
122+
});
123+
it('getFStreamUrl returns demo URL with category', function () {
124+
assert.equal(demoBinance.getFStreamUrl('public'), 'wss://fstream.binancefuture.com/public/stream?streams=');
125+
assert.equal(demoBinance.getFStreamUrl('market'), 'wss://fstream.binancefuture.com/market/stream?streams=');
126+
assert.equal(demoBinance.getFStreamUrl('private'), 'wss://fstream.binancefuture.com/private/stream?streams=');
127+
});
128+
it('getFStreamSingleUrl returns legacy demo URL without category', function () {
129+
assert.equal(demoBinance.getFStreamSingleUrl(), 'wss://fstream.binancefuture.com/ws/');
130+
});
131+
it('getFStreamUrl returns legacy demo URL without category', function () {
132+
assert.equal(demoBinance.getFStreamUrl(), 'wss://fstream.binancefuture.com/stream?streams=');
123133
});
124134
});
125135

0 commit comments

Comments
 (0)