api/orders.js
function getOrders(account, options, callback) {
  var self = this;

  validate.address(account);
  validate.options(options);

  function getAccountOrders(prevResult) {
    var isAggregate = options.limit === 'all';
    if (prevResult && (!isAggregate || !prevResult.marker)) {
      return Promise.resolve(prevResult);
    }

    var promise = new Promise(function(resolve, reject) {
      var accountOrdersRequest;
      var marker;
      var ledger;
      var limit;

      if (prevResult) {
        marker = prevResult.marker;
        limit = prevResult.limit;
        ledger = prevResult.ledger_index;
      } else {
        marker = options.marker;
        limit = validator.isValid(options.limit, 'UINT32') ?
          Number(options.limit) : DefaultPageLimit;
        ledger = utils.parseLedger(options.ledger);
      }

      accountOrdersRequest = self.remote.requestAccountOffers({
        account: account,
        marker: marker,
        limit: limit,
        ledger: ledger
      });

      accountOrdersRequest.once('error', reject);
      accountOrdersRequest.once('success', function(nextResult) {
        nextResult.offers = prevResult ?
          nextResult.offers.concat(prevResult.offers) : nextResult.offers;
        resolve(nextResult);
      });
      accountOrdersRequest.request();
    });

    return promise.then(getAccountOrders);
  }

  function getParsedOrders(offers) {
    return _.reduce(offers, function(orders, off) {
      var sequence = off.seq;
      var type = off.flags & ripple.Remote.flags.offer.Sell ? 'sell' : 'buy';
      var passive = (off.flags & ripple.Remote.flags.offer.Passive) !== 0;

      var taker_gets = utils.parseCurrencyAmount(off.taker_gets);
      var taker_pays = utils.parseCurrencyAmount(off.taker_pays);

      orders.push({
        type: type,
        taker_gets: taker_gets,
        taker_pays: taker_pays,
        sequence: sequence,
        passive: passive
      });

      return orders;
    }, []);
  }

  function respondWithOrders(result) {
    var promise = new Promise(function(resolve) {
      var orders = {};

      if (result.marker) {
        orders.marker = result.marker;
      }

      orders.limit = result.limit;
      orders.ledger = result.ledger_index;
      orders.validated = result.validated;
      orders.orders = getParsedOrders(result.offers);

      resolve(callback(null, orders));
    });

    return promise;
  }

  getAccountOrders()
    .then(respondWithOrders)
    .catch(callback);
}
function getOrders(account, options, callback) {
  var self = this;

  validate.address(account);
  validate.options(options);

  function getAccountOrders(prevResult) {
    var isAggregate = options.limit === 'all';
    if (prevResult && (!isAggregate || !prevResult.marker)) {
      return Promise.resolve(prevResult);
    }

    var promise = new Promise(function(resolve, reject) {
      var accountOrdersRequest;
      var marker;
      var ledger;
      var limit;

      if (prevResult) {
        marker = prevResult.marker;
        limit = prevResult.limit;
        ledger = prevResult.ledger_index;
      } else {
        marker = options.marker;
        limit = validator.isValid(options.limit, 'UINT32') ?
          Number(options.limit) : DefaultPageLimit;
        ledger = utils.parseLedger(options.ledger);
      }

      accountOrdersRequest = self.remote.requestAccountOffers({
        account: account,
        marker: marker,
        limit: limit,
        ledger: ledger
      });

      accountOrdersRequest.once('error', reject);
      accountOrdersRequest.once('success', function(nextResult) {
        nextResult.offers = prevResult ?
          nextResult.offers.concat(prevResult.offers) : nextResult.offers;
        resolve(nextResult);
      });
      accountOrdersRequest.request();
    });

    return promise.then(getAccountOrders);
  }

  function getParsedOrders(offers) {
    return _.reduce(offers, function(orders, off) {
      var sequence = off.seq;
      var type = off.flags & ripple.Remote.flags.offer.Sell ? 'sell' : 'buy';
      var passive = (off.flags & ripple.Remote.flags.offer.Passive) !== 0;

      var taker_gets = utils.parseCurrencyAmount(off.taker_gets);
      var taker_pays = utils.parseCurrencyAmount(off.taker_pays);

      orders.push({
        type: type,
        taker_gets: taker_gets,
        taker_pays: taker_pays,
        sequence: sequence,
        passive: passive
      });

      return orders;
    }, []);
  }

  function respondWithOrders(result) {
    var promise = new Promise(function(resolve) {
      var orders = {};

      if (result.marker) {
        orders.marker = result.marker;
      }

      orders.limit = result.limit;
      orders.ledger = result.ledger_index;
      orders.validated = result.validated;
      orders.orders = getParsedOrders(result.offers);

      resolve(callback(null, orders));
    });

    return promise;
  }

  getAccountOrders()
    .then(respondWithOrders)
    .catch(callback);
}
function getOrders ( account , options , callback ) { var self = this ; validate . address ( account ) ; validate . options ( options ) ; function getAccountOrders ( prevResult ) { var isAggregate = options . limit === 'all' ; if ( prevResult && ( ! isAggregate || ! prevResult . marker ) ) { return Promise . resolve ( prevResult ) ; } var promise = new Promise ( function ( resolve , reject ) { var accountOrdersRequest ; var marker ; var ledger ; var limit ; if ( prevResult ) { marker = prevResult . marker ; limit = prevResult . limit ; ledger = prevResult . ledger_index ; } else { marker = options . marker ; limit = validator . isValid ( options . limit , 'UINT32' ) ? Number ( options . limit ) : DefaultPageLimit ; ledger = utils . parseLedger ( options . ledger ) ; } accountOrdersRequest = self . remote . requestAccountOffers ( { account : account , marker : marker , limit : limit , ledger : ledger } ) ; accountOrdersRequest . once ( 'error' , reject ) ; accountOrdersRequest . once ( 'success' , function ( nextResult ) { nextResult . offers = prevResult ? nextResult . offers . concat ( prevResult . offers ) : nextResult . offers ; resolve ( nextResult ) ; } ) ; accountOrdersRequest . request ( ) ; } ) ; return promise . then ( getAccountOrders ) ; } function getParsedOrders ( offers ) { return _ . reduce ( offers , function ( orders , off ) { var sequence = off . seq ; var type = off . flags & ripple . Remote . flags . offer . Sell ? 'sell' : 'buy' ; var passive = ( off . flags & ripple . Remote . flags . offer . Passive ) !== 0 ; var taker_gets = utils . parseCurrencyAmount ( off . taker_gets ) ; var taker_pays = utils . parseCurrencyAmount ( off . taker_pays ) ; orders . push ( { type : type , taker_gets : taker_gets , taker_pays : taker_pays , sequence : sequence , passive : passive } ) ; return orders ; } , [ ] ) ; } function respondWithOrders ( result ) { var promise = new Promise ( function ( resolve ) { var orders = { } ; if ( result . marker ) { orders . marker = result . marker ; } orders . limit = result . limit ; orders . ledger = result . ledger_index ; orders . validated = result . validated ; orders . orders = getParsedOrders ( result . offers ) ; resolve ( callback ( null , orders ) ) ; } ) ; return promise ; } getAccountOrders ( ) . then ( respondWithOrders ) . catch ( callback ) ; }
Get orders from the ripple network

@query
@param {String} [request.query.limit]
- Set a limit to the number of results returned
@param {String} [request.query.marker]
- Used to paginate results
@param {String} [request.query.ledger]
- The ledger index to query against
- (required if request.query.marker is present)

@url
@param {RippleAddress} request.params.account
- The ripple address to query orders
Get orders from the ripple network