Skip to content

Commit

Permalink
Random delay added to combat API lag.
Browse files Browse the repository at this point in the history
A random delay, up to one second, is now artificially added after
receiving the transaction/trade and before creating its bubble. This
tries to mitigate the API "lurching" as it sends a bunch of recent
transactions at a time.
  • Loading branch information
MaxLaumeister committed Apr 4, 2013
1 parent a803ea6 commit 778273a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions socket.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var satoshi = 100000000;

var DELAY_CAP = 1000;

var lastBlockHeight = 0;

function TransactionSocket() {
Expand Down Expand Up @@ -70,7 +72,10 @@ TransactionSocket.init = function() {
}
}

new Transaction(bitcoins);
setTimeout(function() {
new Transaction(bitcoins);
}, Math.random() * DELAY_CAP);

} else if (data.op == "block") {
var blockHeight = data.x.height;
var transactions = data.x.nTx;
Expand Down Expand Up @@ -151,8 +156,10 @@ TradeSocket.init = function() {
var bitcoins = message.trade.amount_int / satoshi;
var currency = (message.trade.price * message.trade.amount_int / satoshi);
var currencyName = message.trade.price_currency;

new Transaction(bitcoins, false, currency, currencyName);

setTimeout(function() {
new Transaction(bitcoins, false, currency, currencyName);
}, Math.random() * DELAY_CAP);
}
});

Expand Down

0 comments on commit 778273a

Please sign in to comment.