bot18
Version:
A high-frequency cryptocurrency trading bot by Zenbot creator @carlos8f
35 lines (28 loc) • 910 B
JavaScript
/*
* Copyright (c) 2012 Mathieu Turcotte
* Licensed under the MIT license.
*/
var util = require('util');
var BackoffStrategy = require('./strategy');
/**
* Exponential backoff strategy.
* @extends BackoffStrategy
*/
function ExponentialBackoffStrategy(options) {
BackoffStrategy.call(this, options);
this.backoffDelay_ = 0;
this.nextBackoffDelay_ = this.getInitialDelay();
}
util.inherits(ExponentialBackoffStrategy, BackoffStrategy);
/** @inheritDoc */
ExponentialBackoffStrategy.prototype.next_ = function() {
this.backoffDelay_ = Math.min(this.nextBackoffDelay_, this.getMaxDelay());
this.nextBackoffDelay_ = this.backoffDelay_ * 2;
return this.backoffDelay_;
};
/** @inheritDoc */
ExponentialBackoffStrategy.prototype.reset_ = function() {
this.backoffDelay_ = 0;
this.nextBackoffDelay_ = this.getInitialDelay();
};
module.exports = ExponentialBackoffStrategy;