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

Fix candle history warmup to work when no data has been imported #2112

Closed
wants to merge 1 commit into from

Conversation

jtran
Copy link

@jtran jtran commented Apr 20, 2018

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix.

  • What is the current behavior? (You can also link to an open issue here)

Steps to reproduce:

  1. Choose a market you have not imported any data for.
  2. Set candleSize to 1 and historySize to 10 in config.js.
  3. Run live from CLI using a strategy that logs during update(). (No talib or tulip indicators. This has nothing to do with async.)

I expect the strategy to log 10 times immediately using recent historical candle data fetched from the exchange. But what actually happens is that it doesn't log immediately. I assume that it takes 10 minutes to log 10 times.

Note: if you've imported data for this exchange/currency/asset, the behavior is different and works in certain cases.

  • What is the new behavior (if this is a feature change)?

This branch makes it so that you do not need to import data in order to run a strategy live and have it start giving advice immediately. The recent trade/candle history is fetched from the exchange to warm up the strategy.

  • Other information:

I tested on GDAX. Not sure if that's relevant.

@Exmoond
Copy link

Exmoond commented May 8, 2018

Hmm can you point on what did you change in the file besides comments ? cannot find anything different

@xFFFFF
Copy link
Contributor

xFFFFF commented May 8, 2018

Is outside {} so outside else statement

@jtran
Copy link
Author

jtran commented May 9, 2018

The code is moved outside of the else block. This way, it always gets executed, not just in the else case. Without this change, idealExchangeStartTimeTS is computed in the other cases but never used.

@xerviami
Copy link

Dear,
I have the same issue (gdax or kraken).
AFAIK, the fix is not in the stable branch.
How to use this fix ?
Thanks a lot
Xavier

@jtran
Copy link
Author

jtran commented May 13, 2018

@xaviermiss, cherry-pick it on your clone of the repo. If it solves your problem, please report back. Keep commenting or posting about it, here, on related GitHub issues (or even a new one), in the forum, or in discord, in the hopes that someone merges it.

@xerviami
Copy link

xerviami commented May 14, 2018

Hi @jtran , I took the new datasticher.js file.
Unfortunately, it does not solve my problem...
Live identifies the local history but does not use it as a warmup -> advices come after hours of waiting.

@jtran
Copy link
Author

jtran commented May 15, 2018

@xaviermiss, this fix is for when you don't have local history. Please read the description and steps to reproduce.

@xerviami
Copy link

@jtran, the subject of this issue is:
"Fix candle history warmup to work even when no data has been imported"
As fas as I understand english, the "even" litteraly means that this issue occurs when "no data has been imported" or not (i.e., data has been iimported).

The given example is when no data is imported but it never explicitely narrows it to "non imported data".

Sorry but it is not clear.

I will test on my side with no import.

@jtran jtran changed the title Fix candle history warmup to work even when no data has been imported Fix candle history warmup to work when no data has been imported May 15, 2018
@jtran
Copy link
Author

jtran commented May 15, 2018

I updated the title to be clearer.

@xerviami
Copy link

xerviami commented May 16, 2018

I just tested with no history.
The begavior is not easy to understand.
Here are some logs:

2018-05-16 09:26:35 (INFO):             The trading method requests 1390 minutes of historic data. Checking availablity..
2018-05-16 09:26:35 (INFO):

2018-05-16 09:26:35 (INFO):             No usable local data available, trying to get as much as possible from the exchange..
2018-05-16 09:26:35 (INFO):             Preventing Gekko from requesting 1390 minutes of history.
2018-05-16 09:26:35 (DEBUG):            Fetching exchange data since 240 minutes ago
2018-05-16 09:26:37 (DEBUG):            Available exchange data:
2018-05-16 09:26:37 (DEBUG):                    from: 240 minutes ago
2018-05-16 09:26:37 (DEBUG):                    to: 168 minutes ago
2018-05-16 09:26:37 (DEBUG):            Unable to stitch datasets.
[...]
2018-05-16 09:26:40 (INFO):     Starting to watch the market: Kraken XBT/EUR
2018-05-16 09:26:40 (DEBUG):    scheduling ticks
2018-05-16 09:26:40 (DEBUG):    Requested XBT/EUR trade data from Kraken ...
2018-05-16 09:26:41 (DEBUG):    Processing 1000 new trades. From 2018-05-15 08:16:04 UTC to 2018-05-15 09:05:13 UTC. (an hour)
2018-05-16 09:26:49 (DEBUG):    Requested XBT/EUR trade data from Kraken ...
2018-05-16 09:26:49 (DEBUG):    Processing 1000 new trades. From 2018-05-16 06:36:34 UTC to 2018-05-16 07:26:52 UTC. (an hour)
2018-05-16 09:26:50 (ERROR):    Failed to get average tp from indicator.
2018-05-16 09:26:58 (DEBUG):    Requested XBT/EUR trade data from Kraken ...
2018-05-16 09:26:59 (DEBUG):    Processing 2 new trades. From 2018-05-16 07:26:56 UTC to 2018-05-16 07:26:56 UTC. (a few seconds)

Gekko:

  • does not want to fetch the needed history
  • fetches non continue history (from 240mn to 168mn)
  • then watches the market

@Exmoond
Copy link

Exmoond commented May 16, 2018

point of this patch is to do not import any data and start trading right away.
ignore that 240 and 168

@Dalekxy
Copy link
Contributor

Dalekxy commented May 17, 2018

I tried to reproduce your error, but it works for me without your commit.
Pair: XBT/EUR
Exchange: Kraken
History: 10
CandleSize: 1

2018-05-17 10:48:12 (INFO):     Setting up Gekko in realtime mode
2018-05-17 10:48:12 (INFO):
2018-05-17 10:48:12 (INFO):     Setting up:
2018-05-17 10:48:12 (INFO):              Trading Advisor
2018-05-17 10:48:12 (INFO):              Calculate trading advice
2018-05-17 10:48:12 (INFO):              Using the strategy: MACD
2018-05-17 10:48:12 (ERROR):    Failed to load indicator STC
2018-05-17 10:48:13 (INFO):             The trading method requests 10 minutes of historic data. Checking availablity..
2018-05-17 10:48:13 (INFO):

2018-05-17 10:48:13 (INFO):             No usable local data available, trying to get as much as possible from the exchange..
2018-05-17 10:48:13 (DEBUG):            Fetching exchange data since 10 minutes ago
2018-05-17 10:48:13 (DEBUG):            Available exchange data:
2018-05-17 10:48:13 (DEBUG):                    from: 10 minutes ago
2018-05-17 10:48:13 (DEBUG):                    to: 0 minutes ago
2018-05-17 10:48:13 (DEBUG):            Unable to stitch datasets.
2018-05-17 10:48:13 (INFO):             Not seeding locally available data to the trading method.
2018-05-17 10:48:13 (INFO):     Setting up:
2018-05-17 10:48:13 (INFO):              Paper Trader
2018-05-17 10:48:13 (INFO):              Paper trader that simulates fake trades.
2018-05-17 10:48:13 (INFO):

2018-05-17 10:48:13 (INFO):     Setting up:
2018-05-17 10:48:13 (INFO):              Performance Analyzer
2018-05-17 10:48:13 (INFO):              Analyzes performances of trades
2018-05-17 10:48:13 (INFO):

2018-05-17 10:48:13 (INFO):     Starting to watch the market: Kraken XBT/EUR
2018-05-17 10:48:13 (DEBUG):    scheduling ticks
2018-05-17 10:48:13 (DEBUG):    Requested XBT/EUR trade data from Kraken ...
2018-05-17 10:48:14 (DEBUG):    Processing 1000 new trades. From 2018-05-17 07:52:37 UTC to 2018-05-17 08:48:15 UTC. (an hour)
2018-05-17 10:48:33 (DEBUG):    Requested XBT/EUR trade data from Kraken ...
2018-05-17 10:48:34 (DEBUG):    Processing 29 new trades. From 2018-05-17 08:48:19 UTC to 2018-05-17 08:48:30 UTC. (a few seconds)
2018-05-17 10:48:53 (DEBUG):    Requested XBT/EUR trade data from Kraken ...
2018-05-17 10:48:54 (DEBUG):    Processing 1 new trades. From 2018-05-17 08:48:54 UTC to 2018-05-17 08:48:54 UTC. (a few seconds)
2018-05-17 10:49:13 (DEBUG):    Requested XBT/EUR trade data from Kraken ...
2018-05-17 10:49:14 (DEBUG):    Processing 1 new trades. From 2018-05-17 08:49:11 UTC to 2018-05-17 08:49:11 UTC. (a few seconds)
2018-05-17 10:49:14 (DEBUG):    calculated MACD properties for candle:
2018-05-17 10:49:14 (DEBUG):             short: 7004.22771910
2018-05-17 10:49:14 (DEBUG):             long: 7003.81034121
2018-05-17 10:49:14 (DEBUG):             macd: 0.41737788
2018-05-17 10:49:14 (DEBUG):             signal: 1.08818201
2018-05-17 10:49:14 (DEBUG):             macdiff: -0.67080412
2018-05-17 10:49:14 (DEBUG):    In downtrend since 1 candle(s)
2018-05-17 10:49:14 (INFO):     (PROFIT REPORT) original simulated balance:      7054.40000000 EUR
2018-05-17 10:49:14 (INFO):     (PROFIT REPORT) current simulated balance:       7088.89420000 EUR
2018-05-17 10:49:14 (INFO):     (PROFIT REPORT) simulated profit:                34.49420000 EUR (0.48897426%)

mmvasa added a commit to mmvasa/gekko that referenced this pull request Jun 18, 2018
Copy link
Owner

@askmike askmike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the late reply. The psuedo code for the code you intend to change is:

  • pull latest window from DB
  • if(!window) { // there is no data }
  • else if(window is too old) { // no usable data we can stitch }
  • else { // we can use data! Note this fact by registering it in the config }

Only in the last situation do we actually want to work with local data. Which is why the statement right now only resides in the latest "else".

@jtran
Copy link
Author

jtran commented Oct 9, 2018

@askmike, the point is not to work with local data. The point is to fetch farther back in time from the exchange. As the long description already explains, this change is specifically for when you have not imported any local data. To see where firstFetchSince is used, see marketFetcher.js.

@stale
Copy link

stale bot commented Jan 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you feel this is very a important issue please reach out the maintainer of this project directly via e-mail: gekko at mvr dot me.

@stale stale bot added the wontfix label Jan 13, 2019
@stale stale bot closed this Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants