Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Fix Poloniex not fetching all available trades (#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Risse authored and DeviaVir committed Apr 25, 2018
1 parent cf9630e commit ef32e9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions commands/backfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = function (program, conf) {
var target_time, start_time
var mode = exchange.historyScan
var last_batch_id, last_batch_opts
var offset = exchange.offset
var markers, trades
if (!mode) {
console.error('cannot backfill ' + selector.normalized + ': exchange does not offer historical data')
Expand Down Expand Up @@ -74,6 +75,9 @@ module.exports = function (program, conf) {
if (marker.to) opts.from = marker.to + 1
else opts.from = exchange.getCursor(start_time)
}
if (offset) {
opts.offset = offset
}
last_batch_opts = opts
exchange.getTrades(opts, function (err, results) {
trades = results
Expand Down
11 changes: 9 additions & 2 deletions extensions/exchanges/poloniex/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = function container (conf) {
historyScan: 'backward',
makerFee: 0.15,
takerFee: 0.25,
offset: 43200,

getProducts: function () {
return require('./products.json')
Expand All @@ -59,11 +60,11 @@ module.exports = function container (conf) {
}
if (args.start && !args.end) {
// add 12 hours
args.end = args.start + 43200
args.end = args.start + opts.offset
}
else if (args.end && !args.start) {
// subtract 12 hours
args.start = args.end - 43200
args.start = args.end - opts.offset
}

client._public('returnTradeHistory', args, function (err, body) {
Expand All @@ -76,6 +77,12 @@ module.exports = function container (conf) {
console.error(body)
return retry('getTrades', func_args)
}

if (body.length >= 50000) {
func_args[0].offset = opts.offset / 2;
return retry('getTrades', func_args)
}

var trades = body.map(function (trade) {
return {
trade_id: trade.tradeID,
Expand Down

0 comments on commit ef32e9f

Please sign in to comment.