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

Hotfix make sure bitfinex importer fetches all trades #2354

Merged
merged 3 commits into from
Jul 23, 2018

Conversation

askmike
Copy link
Owner

@askmike askmike commented Jul 23, 2018

Should fix the issues described in #2307.

NOTE: while it currently already is an improvement (stores fatter candles with more trades) I am still seeing discrepancies with running this VS running a live trader on bitfinex.

I need to dig deeper, possible reasons:

  • live trader is filtering valid trades
  • importer uses BFX V2 API, live trader uses V1, maybe different results?

@3pm
Copy link

3pm commented Jul 23, 2018

"importer uses BFX V2 API, live trader uses V1"
Don't think this is an issue. Because in my tests both live processes sometimes produced different result, but using the same API.

@askmike
Copy link
Owner Author

askmike commented Jul 23, 2018 via email

@askmike
Copy link
Owner Author

askmike commented Jul 23, 2018

Sometimes bfx reponds with a 500 even though the input is wrong, for example:

{ err: { Error: StatusCodeError: 500 - ["error",10020,"time_interval: invalid"]
    at rp.then.catch (/Users/pear/projects/gekko/node_modules/bitfinex-api-node/rest2.js:85:26)
    at tryCatcher (/Users/pear/projects/gekko/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/pear/projects/gekko/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/pear/projects/gekko/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/pear/projects/gekko/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/pear/projects/gekko/node_modules/bluebird/js/release/promise.js:689:18)
    at Async._drainQueue (/Users/pear/projects/gekko/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/pear/projects/gekko/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/pear/projects/gekko/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:763:18)
    at tryOnImmediate (timers.js:734:5)
    at processImmediate (timers.js:716:5) notFatal: true },

@askmike
Copy link
Owner Author

askmike commented Jul 23, 2018

importer uses BFX V2 API, live trader uses V1, maybe different results?

This appears to be true, here are raw logs of the trades from the live trader (api v1) and the importer (api v2):

Each line logs a trade as seen by Gekko: trade ID - hour & minute it was executed - price - amount

LIVE TRADER

271717762 '12:38' 7670 0.04383337
271717763 '12:38' 7669.9 0.01295757
271717773 '12:38' 7669.9 0.002
271717778 '12:38' 7669.59089929 0.01
271717791 '12:38' 7669.1 0.00655994
271717795 '12:38' 7669.1 0.27582
271717801 '12:38' 7669.1 0.09
271717813 '12:38' 7669.1 0.09088924
271717814 '12:38' 7669.1 0.01161956
271717815 '12:38' 7669.1 0.09296478
271717822 '12:38' 7669.0048965 0.15
271717823 '12:38' 7669 0.53473013
271717824 '12:38' 7669 0.35178495
271717825 '12:38' 7668.8 0.03
271717826 '12:38' 7668.7 0.1
271717828 '12:38' 7668.65226376 0.98
271717829 '12:38' 7668.6 0.38239492
271717833 '12:38' 7668.1 0.00900822
271717834 '12:38' 7668.1 0.00751232
271717836 '12:38' 7668 0.01036
271717839 '12:38' 7668 0.01998
271717845 '12:38' 7668 0.2
271717847 '12:38' 7668.1 0.17227508
271717852 '12:38' 7668.1 0.00263902
271717854 '12:38' 7668.1 0.01607076
271717856 '12:39' 7668 2

IMPORTER

271717762 '12:37' 7670 0.04383337
271717763 '12:38' 7669.9 0.01295757
271717773 '12:38' 7669.9 0.002
271717778 '12:38' 7669.59089929 0.01
271717791 '12:38' 7669.1 0.00655994
271717795 '12:38' 7669.1 0.27582
271717801 '12:38' 7669.1 0.09
271717813 '12:38' 7669.1 0.09088924
271717814 '12:38' 7669.1 0.01161956
271717815 '12:38' 7669.1 0.09296478
271717822 '12:38' 7669.0048965 0.15
271717823 '12:38' 7669 0.53473013
271717824 '12:38' 7669 0.35178495
271717825 '12:38' 7668.8 0.03
271717826 '12:38' 7668.7 0.1
271717828 '12:38' 7668.65226376 0.98
271717829 '12:38' 7668.6 0.38239492
271717833 '12:38' 7668.1 0.00900822
271717834 '12:38' 7668.1 0.00751232
271717836 '12:38' 7668 0.01036
271717839 '12:38' 7668 0.01998
271717845 '12:38' 7668 0.2
271717847 '12:38' 7668.1 0.17227508
271717852 '12:38' 7668.1 0.00263902
271717854 '12:38' 7668.1 0.01607076
271717856 '12:38' 7668 2

In this snippet the first and last line of the live trader and importer have different minutes.

Source of discrepancy

  • The v2 api returns times with millisecond accuracy (see here)
  • The v1 api returns times with second accuracy ROUNDED (see here).

This means that a trade happening at ms timestamp: 1532350079[595] would be part of a different candle based on which API was used to fetch:

  • the v1 (live gekko) would put this trade in candle: 2018-07-23T12:48:00
  • the v2 (importer) would put this trade in candle: 2018-07-23T12:47:00

A few weeks back I was trying to port all gekko integration with bitfinex to their v2 API However I ran into some issues (such as this one bitfinexcom/bitfinex-api-node#321).

@3pm please try this branch, I am unable to reproduce different candles for live gekkos (except for the first one). This PR makes the output of live VS import extremely similar, with some candles having tiny differences due to the issue above. Unfortunately there is not much we can do about it until we move bfx to their v2 api.

@askmike askmike merged commit afefb14 into develop Jul 23, 2018
@askmike askmike mentioned this pull request Jul 26, 2018
@askmike askmike deleted the hotfix/bfx-importer branch July 26, 2018 02:01
@askmike askmike changed the title [WIP] Hotfix make sure bitfinex importer fetches all trades Hotfix make sure bitfinex importer fetches all trades Jul 26, 2018
askmike added a commit that referenced this pull request Aug 10, 2018
* [docs] install indicator libs without updating package.json

* add tulip example strat configs, see #2341

* uppercase default macd strat

* temp revert bfx dep to main repo (fixes importer)

* binance set default fee as percentage

* rename bitx to luno (#2352)

* v0.6 support for bitx (aka Luno)

* v0.6 support for bitx (aka Luno)

* remove log

* move dependency to gb

* rename bitx to luno

* rename bitx to luno

* make sure we pass amount as positive value

* make sure we overlap when importing trades

* rm 500 as retryable error, see #2354

* only try to set fee when live trading, see #2358

* make gekko pic path relative

* make select arrow path relative

* Fix method name for stratNotification event

* make sure we parse both TS (backtest) & moment strings (live)

* make sure GB throws errors

* only render warmup warning when there is required history

* v0.6.4

* fix plugin event wire warning

* check portfolio data before calculating report (#2369)

* Changed several log messages from debug to warn (#2374)

Changed "Not creating order" message and "exchange did not provide fee info" from debug to warn messages so users can see these issues even when debug is set to false.

* make sure we pass on exchange error (#2379)

* fix backtest result exporter in standalone mode (#2382)

* make sure to pass order id in cancel edge flow, fix #2386 (#2387)

* Emit trade and trade errors via Telegram (#2385)

* Emit trade and trade errors via Telegram

* Added semi-colons

Added missing semi-colons in processTradeCompleted and processTradeErrored methods.

* Register methods only if set to true in config

* catch undefined CPU cores on ARM (#2391)

* export portfolio values as part of stratCandles (#2402)

* rm space in backtest export file location

* [GB/Binance] retry on 403 (#2404)

* completely disable broken limit order for now, fix #2398

* rewire cancelfix cb, see #2386

* remove slack dependency that is triggering warnings (#2408)

* move slack plugin dep out of main repo

* remove twitter & pushbullet plugin dependencies from main repo (#2409)

* move slack dependency out of main repo

* rm slack dep from main repo

* also remove pushbullet & twitter deps from main repo

* use forked bittrex dep with updated dependencies (#2410)

* use bittrex fork with updated deps

* [GB] introduce optimizedConnection flag in binance

* [GB] catch strange networking error

* update binance market files, see #2406

* [GB] point to supported_exchanges doc

* [GB] add example usage, fix #2414

* assume CF maintainance to be recoverable, fix #2407

* use npm version of of forked bittrex dep

* catch gb init errors

* [sqlite] wait for 10 seconds on busy

* throw errors, not strings

* [GB] update bfx & cf markets

* Update Luno (#2417)

* v0.6 support for bitx (aka Luno)

* v0.6 support for bitx (aka Luno)

* remove log

* move dependency to gb

* rename bitx to luno

* rename bitx to luno

* temp fix simultaneous advice error

* - re-add logging
- Retry insufficient balance due to server update delay
- Enhanced getPorfolio
- getOrder now return fees

* update

* update

* update

* revert 4b5d09f

* v.0.6.5
@MaxPovver
Copy link

Also some trades are not returned by v2 trades endpoint, and returned by v1 trades endpoint. But that only applies to 2015-and-older trades, so I guess it is not your case :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants