Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huobi - watchTicker - allow different topics #16198

Merged
merged 2 commits into from Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion js/huobi.js
Expand Up @@ -1766,9 +1766,20 @@ module.exports = class huobi extends Exchange {
// askSize: 0.4156
// }
//
// watchTikcer - bbo
// {
// seqId: 161499562790,
// ask: 16829.51,
// askSize: 0.707776,
// bid: 16829.5,
// bidSize: 1.685945,
// quoteTime: 1671941599612,
// symbol: 'btcusdt'
// }
//
const marketId = this.safeString2 (ticker, 'symbol', 'contract_code');
const symbol = this.safeSymbol (marketId, market);
const timestamp = this.safeInteger (ticker, 'ts');
const timestamp = this.safeInteger2 (ticker, 'ts', 'quoteTime');
let bid = undefined;
let bidVolume = undefined;
let ask = undefined;
Expand Down
31 changes: 28 additions & 3 deletions js/pro/huobi.js
Expand Up @@ -15,11 +15,11 @@ module.exports = class huobi extends huobiRest {
'ws': true,
'watchOrderBook': true,
'watchOrders': true,
'watchTickers': false, // for now
'watchTickers': false,
'watchTicker': true,
'watchTrades': true,
'watchMyTrades': true,
'watchBalance': true, // for now
'watchBalance': true,
'watchOHLCV': true,
},
'urls': {
Expand Down Expand Up @@ -89,6 +89,9 @@ module.exports = class huobi extends huobiRest {
'ws': {
'gunzip': true,
},
'watchTicker': {
'name': 'market.{marketId}.detail', // 'market.{marketId}.bbo' or 'market.{marketId}.ticker'
},
},
'exceptions': {
'ws': {
Expand Down Expand Up @@ -123,13 +126,19 @@ module.exports = class huobi extends huobiRest {
await this.loadMarkets ();
const market = this.market (symbol);
symbol = market['symbol'];
const messageHash = 'market.' + market['id'] + '.detail';
const options = this.safeValue (this.options, 'watchTicker', {});
const topic = this.safeString (options, 'name', 'market.{marketId}.detail');
if (topic === 'market.{marketId}.ticker' && market['type'] !== 'spot') {
throw new BadRequest (this.id + ' watchTicker() with name market.{marketId}.ticker is only allowed for spot markets, use market.{marketId}.detail instead');
}
const messageHash = this.implodeParams (topic, { 'marketId': market['id'] });
const url = this.getUrlByMarketType (market['type'], market['linear']);
return await this.subscribePublic (url, symbol, messageHash, undefined, params);
}

handleTicker (client, message) {
//
// 'market.btcusdt.detail'
// {
// ch: 'market.btcusdt.detail',
// ts: 1583494163784,
Expand All @@ -145,6 +154,20 @@ module.exports = class huobi extends huobiRest {
// count: 265673
// }
// }
// 'market.btcusdt.bbo'
// {
// ch: 'market.btcusdt.bbo',
// ts: 1671941599613,
// tick: {
// seqId: 161499562790,
// ask: 16829.51,
// askSize: 0.707776,
// bid: 16829.5,
// bidSize: 1.685945,
// quoteTime: 1671941599612,
// symbol: 'btcusdt'
// }
// }
//
const tick = this.safeValue (message, 'tick', {});
const ch = this.safeString (message, 'ch');
Expand Down Expand Up @@ -1572,6 +1595,8 @@ module.exports = class huobi extends huobiRest {
'depth': this.handleOrderBook,
'mbp': this.handleOrderBook,
'detail': this.handleTicker,
'bbo': this.handleTicker,
'ticker': this.handleTicker,
'trade': this.handleTrades,
'kline': this.handleOHLCV,
};
Expand Down