JS: Added class OrderBook for listening to order books.

This commit is contained in:
Stefan Thomas
2013-02-19 17:35:42 +01:00
parent 6357a906d3
commit a38e17beed
2 changed files with 139 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ var UInt160 = require('./amount').UInt160;
var Transaction = require('./transaction').Transaction;
var Account = require('./account').Account;
var Meta = require('./meta').Meta;
var OrderBook = require('./orderbook').OrderBook;
var utils = require('./utils');
var config = require('./config');
@@ -181,6 +182,31 @@ Request.prototype.rt_accounts = function (accounts) {
return this.accounts(accounts, true);
};
Request.prototype.books = function (books) {
var procBooks = [];
for (var i = 0, l = books.length; i < l; i++) {
var book = books[i];
var json = {
"CurrencyOut": Currency.json_rewrite(book["CurrencyOut"]),
"CurrencyIn": Currency.json_rewrite(book["CurrencyIn"])
};
if (json["CurrencyOut"] !== "XRP") {
json["IssuerOut"] = UInt160.json_rewrite(book["IssuerOut"]);
}
if (json["CurrencyIn"] !== "XRP") {
json["IssuerIn"] = UInt160.json_rewrite(book["IssuerIn"]);
}
procBooks.push(json);
}
this.message.books = procBooks;
return this;
};
//
// Remote - access to a remote Ripple server via websocket.
//
@@ -1036,6 +1062,15 @@ Remote.prototype.account = function (accountId) {
return this._accounts[account.to_json()] = account;
};
Remote.prototype.book = function (currency_out, issuer_out,
currency_in, issuer_in) {
var book = new OrderBook(this,
currency_out, issuer_out,
currency_in, issuer_in);
return book;
}
// Return the next account sequence if possible.
// <-- undefined or Sequence
Remote.prototype.account_seq = function (account, advance) {