mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 12:45:50 +00:00
Fixing OrderBook#_subscribe (WIP).
This commit is contained in:
@@ -37,9 +37,11 @@ function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pay
|
|||||||
this.on('newListener', function (type, listener) {
|
this.on('newListener', function (type, listener) {
|
||||||
if (~OrderBook.subscribe_events.indexOf(type)) {
|
if (~OrderBook.subscribe_events.indexOf(type)) {
|
||||||
if (!self._subs && self._remote._connected) {
|
if (!self._subs && self._remote._connected) {
|
||||||
self._subscribe();
|
|
||||||
}
|
|
||||||
self._subs += 1;
|
self._subs += 1;
|
||||||
|
self._subscribe();
|
||||||
|
} else {
|
||||||
|
self._subs += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,11 +57,8 @@ function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pay
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this._remote.on('connect', function () {
|
// ST: This *should* call _prepareSubscribe.
|
||||||
if (self._subs) {
|
this._remote.on('prepare_subscribe', this._subscribe.bind(this));
|
||||||
self._subscribe();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this._remote.on('disconnect', function () {
|
this._remote.on('disconnect', function () {
|
||||||
self._sync = false;
|
self._sync = false;
|
||||||
@@ -82,19 +81,43 @@ OrderBook.subscribe_events = ['transaction', 'model', 'trade'];
|
|||||||
*/
|
*/
|
||||||
OrderBook.prototype._subscribe = function () {
|
OrderBook.prototype._subscribe = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
var request = self._remote.request_subscribe();
|
if (self.is_valid() && self._subs) {
|
||||||
request.books([ self.to_json() ], true);
|
var request = this._remote.request_subscribe();
|
||||||
request.callback(function(err, res) {
|
request.addBook(self.to_json(), true);
|
||||||
if (err) {
|
request.once('success', function(res) {
|
||||||
// XXX What now?
|
|
||||||
} else {
|
|
||||||
self._sync = true;
|
self._sync = true;
|
||||||
self._offers = res.offers;
|
self._offers = res.offers;
|
||||||
self.emit('model', self._offers);
|
self.emit('model', self._offers);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
request.once('error', function(err) {
|
||||||
|
// XXX What now?
|
||||||
|
});
|
||||||
|
request.request();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds this orderbook to a subscription request.
|
||||||
|
|
||||||
|
// ST: Currently this is not working because the server cannot give snapshots
|
||||||
|
// for more than one order book in the same subscribe message.
|
||||||
|
|
||||||
|
OrderBook.prototype._prepareSubscribe = function (request) {
|
||||||
|
var self = this;
|
||||||
|
if (self.is_valid() && self._subs) {
|
||||||
|
request.addBook(self.to_json(), true);
|
||||||
|
request.once('success', function(res) {
|
||||||
|
self._sync = true;
|
||||||
|
self._offers = res.offers;
|
||||||
|
self.emit('model', self._offers);
|
||||||
|
});
|
||||||
|
request.once('error', function(err) {
|
||||||
|
// XXX What now?
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
OrderBook.prototype.to_json = function () {
|
OrderBook.prototype.to_json = function () {
|
||||||
var json = {
|
var json = {
|
||||||
taker_gets: {
|
taker_gets: {
|
||||||
|
|||||||
Reference in New Issue
Block a user