Skip to content

Commit

Permalink
Limit to 25000 OSRs and 10000 trades on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgrosner committed Feb 5, 2015
1 parent d2497c5 commit aa8b600
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/service/broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class OrderBroker implements Interfaces.IOrderBroker {

this._oeGateway.OrderUpdate.on(this.onOrderUpdate);

this._orderPersister.load(this._baseBroker.exchange(), this._baseBroker.pair).then(osrs => {
this._orderPersister.load(this._baseBroker.exchange(), this._baseBroker.pair, 25000).then(osrs => {
_.each(osrs, osr => {
this._exchIdsToClientIds[osr.exchangeId] = osr.orderId;

Expand All @@ -279,7 +279,7 @@ export class OrderBroker implements Interfaces.IOrderBroker {
this._log("loaded %d osrs from %d orders", this._allOrdersFlat.length, Object.keys(this._allOrders).length);
});

this._tradePersister.load(this._baseBroker.exchange(), this._baseBroker.pair).then(trades => {
this._tradePersister.load(this._baseBroker.exchange(), this._baseBroker.pair, 10000).then(trades => {
_.each(trades, t => this._trades.push(t));
this._log("loaded %d trades", this._trades.length);
});
Expand Down
5 changes: 3 additions & 2 deletions src/service/persister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ export function loadDb() {
export class Persister<T> {
_log : Utils.Logger = Utils.log("tribeca:exchangebroker:persister");

public load = (exchange : Models.Exchange, pair : Models.CurrencyPair) : Q.Promise<T[]> => {
public load = (exchange : Models.Exchange, pair : Models.CurrencyPair, limit : number = null) : Q.Promise<T[]> => {
var deferred = Q.defer<T[]>();
this.collection.then(coll => {
var selector = {exchange: exchange, pair: pair};
coll.find(selector, (err, docs) => {
var options = (limit !== null ? {limit: limit}: {});
coll.find(selector, options, (err, docs) => {
if (err) deferred.reject(err);
else {
docs.toArray((err, arr) => {
Expand Down

0 comments on commit aa8b600

Please sign in to comment.