Skip to content

Commit

Permalink
bitfinex btc/usd subscription fix
Browse files Browse the repository at this point in the history
bitfinex datetime incorrectely parsed
  • Loading branch information
lfern committed Dec 10, 2018
1 parent 1cf4f64 commit 239362f
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions js/bitstamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ module.exports = class bitstamp extends Exchange {
this._websocketHandleSubscription (contextId, msg);
} else if (evt === 'data') {
let chan = this.safeString (msg, 'channel');
if (chan.indexOf ('order_book_') >= 0) {
if (chan.indexOf ('order_book') >= 0) {
this._websocketHandleOrderbook (contextId, msg);
}
}
Expand All @@ -932,10 +932,14 @@ module.exports = class bitstamp extends Exchange {
_websocketHandleOrderbook (contextId, msg) {
let chan = this.safeString (msg, 'channel');
let parts = chan.split ('_');
let symbol = this.findSymbol (parts[2]);
let id = 'btcusd';
if (parts.length > 2){
id = parts[2];
}
let symbol = this.findSymbol (id);
let data = this.safeValue (msg, 'data');
let timestamp = this.safeInteger (data, 'timestamp');
let ob = this.parseOrderBook (data, timestamp);
let ob = this.parseOrderBook (data, timestamp * 1000);
let symbolData = this._contextGetSymbolData (contextId, 'ob', symbol);
symbolData['ob'] = ob;
this.emit ('ob', symbol, this._cloneOrderBook (ob, symbolData['limit']));
Expand All @@ -944,9 +948,13 @@ module.exports = class bitstamp extends Exchange {

_websocketHandleSubscription (contextId, msg) {
let chan = this.safeString (msg, 'channel');
if (chan.indexOf ('order_book_') >= 0) {
if (chan.indexOf ('order_book') >= 0) {
let parts = chan.split ('_');
let symbol = this.findSymbol (parts[2]);
let id = 'btcusd';
if (parts.length > 2){
id = parts[2];
}
let symbol = this.findSymbol (id);
let symbolData = this._contextGetSymbolData (contextId, 'ob', symbol);
if ('sub-nonces' in symbolData) {
let nonces = symbolData['sub-nonces'];
Expand Down Expand Up @@ -977,23 +985,30 @@ module.exports = class bitstamp extends Exchange {
symbolData['sub-nonces'][nonceStr] = handle;
this._contextSetSymbolData (contextId, event, symbol, symbolData);
// send request
const id = this.marketId (symbol);
let channel = 'order_book';
if (symbol !== 'BTC/USD') {
const id = this.marketId (symbol);
channel = channel + '_' + id;
}
this.websocketSendJson ({
'event': 'subscribe',
'channel': 'order_book_' + id,
'channel': channel,
}, contextId);
}

_websocketUnsubscribe (contextId, event, symbol, nonce, params = {}) {
if (event !== 'ob') {
throw new NotSupported ('unsubscribe ' + event + '(' + symbol + ') not supported for exchange ' + this.id);
}
let id = this.market_id (symbol);
let payload = {
let channel = 'order_book';
if (symbol !== 'BTC/USD') {
const id = this.marketId (symbol);
channel = channel + '_' + id;
}
this.websocketSendJson ({
'event': 'unsubscribe',
'channel': 'order_book_' + id,
};
this.websocketSendJson (payload);
'channel': channel,
});
let nonceStr = nonce.toString ();
this.emit (nonceStr, true);
}
Expand Down

0 comments on commit 239362f

Please sign in to comment.