Closed werkkrew closed 6 years ago
What makes you think the strategy didn't start in this case?
@askmike I have a lot of logging. I should have been more clear in that the "check" method of a strategy is delayed or never starts.
It seems like once the bot runs for the "requiredHistory" amount of time, in real time, it will work. Sometimes the history does work, sometimes it does not.
I believe I have narrowed this down a bit and I don't think it is necessarily unique to GDAX.
Once a strategy gets sufficiently complicated it seems like if certain things can't happen fast enough between the "tickrate" timeframe, Gekko starts to act strange.
In this case of this snippet the tickrate was set to 5. If I increased it to 20, it behaved more like I expected.
Once my strategy got even more complicated, I had to increase the tickrate to 30, otherwise even if the strategy did start to execute the "check" method, the results of about 10% of my tulip indicators would come back with NaN as a result.
It seems that adjusting the tickrate to exceed the time it takes for the "update" method to fully complete is a workaround.
So I did a bit more testing and this time I used Binance and I am still able to re-create the issue. I am honestly not sure exactly what one must do to re-create the issue but it happens to be pretty regularly.
I usually do a fresh import just before I try to run Gekko to ensure it has as much locally available history as possible.
In my config I have requiredHistory set to 60 and candlesize set to either 1 or 5. tickrate is set at the default of 20
I added a line to baseTradingMethod.js at line 224 just below the definition of isAllowedToCheck
with the following:
log.debug('REQUIRED HISTORY:', this.requiredHistory, 'AGE:', this.age, 'IS ALLOWED TO CHECK:', isAllowedToCheck);
The output is attached at the bottom of this comment. My suspicion is that relatively complex strategies have an update method that exceeds some amount of time to complete and it breaks something, but I am not 100% sure.
______ ________ __ __ __ __ ______
/ \ / |/ | / |/ | / | / \ /$$$$$$ |$$$$$$$$/ $$ | /$$/ $$ | /$$/ /$$$$$$ | $$ | $$/ $$ | $$ |/$$/ $$ |/$$/ $$ | $$ | $$ |/ |$$ | $$ $$< $$ $$< $$ | $$ | $$ |$$$$ |$$$$$/ $$$$$ \ $$$$$ \ $$ | $$ | $$ \$$ |$$ |____ $$ |$$ \ $$ |$$ \ $$ __$$ | $$ $$/ $$ |$$ | $$ |$$ | $$ |$$ $$/ $$$$$$/ $$$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/
Gekko v0.5.12 I'm gonna make you rich, Bud Fox.
2018-01-22 12:18:17 (INFO): Setting up Gekko in realtime mode 2018-01-22 12:18:17 (INFO): 2018-01-22 12:18:17 (INFO): Setting up: 2018-01-22 12:18:17 (INFO): Candle writer 2018-01-22 12:18:17 (INFO): Store candles in a database 2018-01-22 12:18:17 (INFO):
2018-01-22 12:18:17 (INFO): Setting up: 2018-01-22 12:18:17 (INFO): Trading Advisor 2018-01-22 12:18:17 (INFO): Calculate trading advice 2018-01-22 12:18:17 (INFO): Using the strategy: private-uber 2018-01-22 12:18:17 (WARN): TALIB indicators could not be loaded, they will be unavailable. 2018-01-22 12:18:18 (INFO): The trading method requests 300 minutes of historic data. Checking availablity.. 2018-01-22 12:18:18 (INFO):
2018-01-22 12:18:18 (DEBUG): Available local data: 2018-01-22 12:18:18 (DEBUG): from: 138 minutes ago 2018-01-22 12:18:18 (DEBUG): to: 2 minutes ago 2018-01-22 12:18:18 (INFO): Usable local data available, trying to match with exchange data.. 2018-01-22 12:18:18 (DEBUG): Fetching exchange data since 17 minutes ago 2018-01-22 12:18:19 (DEBUG): Available exchange data: 2018-01-22 12:18:19 (DEBUG): from: 17 minutes ago 2018-01-22 12:18:19 (DEBUG): to: 0 minutes ago 2018-01-22 12:18:19 (DEBUG): Stitching datasets 2018-01-22 12:18:19 (INFO): Partial history locally available, but 162 minutes are missing. 2018-01-22 12:18:19 (INFO): Seeding the trading method with partial historical data (Gekko needs more time before it can give advice). 2018-01-22 12:18:19 (DEBUG): Seeding with: 2018-01-22 12:18:19 (DEBUG): from: 138 minutes ago 2018-01-22 12:18:19 (DEBUG): to: 18 minutes ago 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 1 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 2 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 3 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 4 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 5 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 6 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 7 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 8 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 9 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 10 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 11 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 12 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 13 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 14 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 15 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 16 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 17 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 18 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 19 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 20 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 21 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 22 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 23 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (DEBUG): REQUIRED HISTORY: 60 AGE: 24 IS ALLOWED TO CHECK: false 2018-01-22 12:18:19 (INFO): Setting up: 2018-01-22 12:18:19 (INFO): Advice logger 2018-01-22 12:18:19 (INFO): 2018-01-22 12:18:19 (INFO): Setting up: 2018-01-22 12:18:19 (INFO): Trader 2018-01-22 12:18:19 (INFO): Follows the advice and create real orders. 2018-01-22 12:18:19 (DEBUG): Trade timer is active. Trades will expire after 60 seconds. 2018-01-22 12:18:19 (DEBUG): The exchange does not provide a websocket feed (or Gekko doesn't support listening to it) 2018-01-22 12:18:19 (DEBUG): Getting ticker, balance & fee from binance 2018-01-22 12:18:19 (INFO): 2018-01-22 12:18:21 (DEBUG): [binance.js] entering "setBalance" callback after api call, err: null, data: [object Object] 2018-01-22 12:18:21 (INFO): Trading at binance ACTIVE 2018-01-22 12:18:21 (INFO): binance trading fee will be: 0.1% 2018-01-22 12:18:21 (INFO): binance portfolio: 2018-01-22 12:18:21 (INFO): ETH: 0.000323320000 2018-01-22 12:18:21 (INFO): ADA: 0.000000000000 2018-01-22 12:18:21 (INFO): Setting up: 2018-01-22 12:18:21 (INFO): Performance Analyzer 2018-01-22 12:18:21 (INFO): Analyzes performances of trades 2018-01-22 12:18:21 (INFO):
2018-01-22 12:18:21 (INFO): Starting to watch the market: Binance ADA/ETH 2018-01-22 12:18:21 (DEBUG): Scheduling ticks... 2018-01-22 12:18:21 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:18:22 (DEBUG): Processing 351 new trades. From 2018-01-22 17:01:01 UTC to 2018-01-22 17:18:15 UTC. (17 minutes) 2018-01-22 12:18:22 (DEBUG): REQUIRED HISTORY: 60 AGE: 25 IS ALLOWED TO CHECK: false 2018-01-22 12:18:22 (DEBUG): REQUIRED HISTORY: 60 AGE: 26 IS ALLOWED TO CHECK: false 2018-01-22 12:18:22 (DEBUG): REQUIRED HISTORY: 60 AGE: 27 IS ALLOWED TO CHECK: false 2018-01-22 12:18:41 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:18:42 (DEBUG): Processing 11 new trades. From 2018-01-22 17:18:23 UTC to 2018-01-22 17:18:41 UTC. (a few seconds) 2018-01-22 12:19:01 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:19:02 (DEBUG): Processing 3 new trades. From 2018-01-22 17:18:49 UTC to 2018-01-22 17:18:56 UTC. (a few seconds) 2018-01-22 12:19:21 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:19:22 (DEBUG): Processing 20 new trades. From 2018-01-22 17:19:03 UTC to 2018-01-22 17:19:21 UTC. (a few seconds) 2018-01-22 12:19:41 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:19:42 (DEBUG): Processing 7 new trades. From 2018-01-22 17:19:27 UTC to 2018-01-22 17:19:36 UTC. (a few seconds) 2018-01-22 12:20:01 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:20:03 (DEBUG): Processing 6 new trades. From 2018-01-22 17:19:43 UTC to 2018-01-22 17:19:58 UTC. (a few seconds) 2018-01-22 12:20:21 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:20:22 (DEBUG): Processing 5 new trades. From 2018-01-22 17:20:09 UTC to 2018-01-22 17:20:22 UTC. (a few seconds) 2018-01-22 12:20:22 (DEBUG): REQUIRED HISTORY: 60 AGE: 28 IS ALLOWED TO CHECK: false 2018-01-22 12:20:41 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:20:43 (DEBUG): Processing 7 new trades. From 2018-01-22 17:20:22 UTC to 2018-01-22 17:20:42 UTC. (a few seconds) 2018-01-22 12:21:01 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:21:02 (DEBUG): Processing 4 new trades. From 2018-01-22 17:20:45 UTC to 2018-01-22 17:21:01 UTC. (a few seconds) 2018-01-22 12:21:21 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:21:22 (DEBUG): Processing 2 new trades. From 2018-01-22 17:21:10 UTC to 2018-01-22 17:21:16 UTC. (a few seconds) 2018-01-22 12:21:41 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:21:43 (DEBUG): Processing 12 new trades. From 2018-01-22 17:21:26 UTC to 2018-01-22 17:21:37 UTC. (a few seconds) 2018-01-22 12:22:01 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:22:02 (DEBUG): Processing 9 new trades. From 2018-01-22 17:21:42 UTC to 2018-01-22 17:21:58 UTC. (a few seconds) 2018-01-22 12:22:21 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:22:22 (DEBUG): Processing 11 new trades. From 2018-01-22 17:22:04 UTC to 2018-01-22 17:22:22 UTC. (a few seconds) 2018-01-22 12:22:41 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:22:43 (DEBUG): Processing 15 new trades. From 2018-01-22 17:22:22 UTC to 2018-01-22 17:22:41 UTC. (a few seconds) 2018-01-22 12:23:01 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:23:02 (DEBUG): Processing 5 new trades. From 2018-01-22 17:22:43 UTC to 2018-01-22 17:22:54 UTC. (a few seconds) 2018-01-22 12:23:21 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:23:22 (DEBUG): Processing 3 new trades. From 2018-01-22 17:23:08 UTC to 2018-01-22 17:23:19 UTC. (a few seconds) 2018-01-22 12:23:41 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:23:43 (DEBUG): Processing 6 new trades. From 2018-01-22 17:23:24 UTC to 2018-01-22 17:23:38 UTC. (a few seconds) 2018-01-22 12:24:01 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:24:03 (DEBUG): Processing 3 new trades. From 2018-01-22 17:23:43 UTC to 2018-01-22 17:23:52 UTC. (a few seconds) 2018-01-22 12:24:21 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:24:22 (DEBUG): Processing 12 new trades. From 2018-01-22 17:24:05 UTC to 2018-01-22 17:24:18 UTC. (a few seconds) 2018-01-22 12:24:41 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:24:42 (DEBUG): Processing 5 new trades. From 2018-01-22 17:24:40 UTC to 2018-01-22 17:24:41 UTC. (a few seconds) 2018-01-22 12:25:01 (DEBUG): Requested ADA/ETH trade data from Binance ... 2018-01-22 12:25:03 (DEBUG): Processing 10 new trades. From 2018-01-22 17:24:46 UTC to 2018-01-22 17:25:02 UTC. (a few seconds) 2018-01-22 12:25:03 (DEBUG): REQUIRED HISTORY: 60 AGE: 29 IS ALLOWED TO CHECK: false 2018-01-22 12:25:21 (DEBUG): Requested ADA/ETH trade data from Binance ...
I can confirm this issue with Kraken. Not too complicated a strategy either. Seems to me to be to do with the required history. If I use less than an hour, it seems fine, any longer than 1 hr 20 or so and it'll just hang and do the same as above. It shows that it grabs local data and stitches, but the strategy never seems to start when logging should show output from log.info in the strategy of gekko showing tulip EMAs and whatnot.
Looks to me from that output that the importer doesn't get a chance to finish grabbing history before the tradeadvisor starts, and then it doesn't bother after that.
I was experiencing a similar issue because my strategy.requiredHistory
value was greater than the trading advisor history size. This was easily fixed by setting this in my strategy.init
method:
this.requiredHistory = this.tradingAdvisor.historySize;
So the second similar issue I was facing was that, even though it was priming the strategy.update
method with backdata, it wasn't starting to trade on the first live candle, it was delaying a full candle before starting trades on the live market. This is because it defines:
isPremature = candle.start < startTime;
If it's premature, it doesn't start trading, though the first whole live candle was being called premature, although I wanted to start trading right away. The way I use the bot I need it to instantly start trading, so I modified baseTradingMethod.js
to subtract the candle size from the start time to determine if it's premature.
// in live mode we might receive more candles
// than minimally needed. In that case check
// whether candle start time is > startTime
var isPremature;
// Subtract number of minutes in current candle for instant start
let startTimeMinusCandleSize = startTime.clone();
startTimeMinusCandleSize.subtract(this.tradingAdvisor.candleSize, "minutes");
if(mode === 'realtime'){
isPremature = candle.start < startTimeMinusCandleSize;
}
else{
isPremature = false;
}
This causes it to start trading on the first live candle. Perhaps this is related to your issue?
No, that's not the issue for either of us. We've discussed it on Discord and it seems to be a race condition caused by the use of tulip indicators.
I'm running into this problem also. I'm not using TALIB or Tulip, so I think the problem may be something else. I don't have any recent local data, so it's only exchange data fetching. I'm setting candleSize to 1 and historySize to 10 as a test.
I'm reading through dataStitcher.js
. I see that in seedLocalData()
it uses candles from local data and passes them to the batcher. However, where is the exchange data ever used? In checkExchangeTrades()
, it seems like the resulting trades from the exchange are discarded. Only the from and to dates are passed to the callback. What am I missing here? Does getTrades()
have some magic in it that propagates the trades?
Here is my CLI output. Strategy's check() isn't getting called for a long time.
2018-04-12 17:13:18 (INFO): Setting up Gekko in realtime mode
2018-04-12 17:13:18 (INFO):
2018-04-12 17:13:18 (INFO): Setting up:
2018-04-12 17:13:18 (INFO): Trading Advisor
2018-04-12 17:13:18 (INFO): Calculate trading advice
2018-04-12 17:13:18 (INFO): Using the strategy: MACD
2018-04-12 17:13:18 (WARN): TALIB indicators could not be loaded, they will be unavailable.
2018-04-12 17:13:18 (WARN): TULIP indicators could not be loaded, they will be unavailable.
2018-04-12 17:13:19 (INFO): The trading method requests 10 minutes of historic data. Checking availablity..
2018-04-12 17:13:19 (INFO):
2018-04-12 17:13:19 (INFO): No usable local data available, trying to get as much as possible from the exchange..
2018-04-12 17:13:19 (DEBUG): Fetching exchange data since 10 minutes ago
2018-04-12 17:13:19 (DEBUG): Scanning back in the history needed...
2018-04-12 17:13:19 (DEBUG): 2018-04-12T21:03:00Z
2018-04-12 17:13:19 (DEBUG): Scanning backwards...2018-04-12T21:09:25.402Z
2018-04-12 17:13:19 (DEBUG): Scanning backwards...2018-04-12T21:03:26.859Z
2018-04-12 17:13:20 (DEBUG): Backwards: 2018-04-12T20:58:10.082Z (41498351) to 2018-04-12T20:59:25.664Z (41498450)
2018-04-12 17:13:20 (DEBUG): Backwards: 2018-04-12T20:59:25.664Z (41498451) to 2018-04-12T20:59:46.191Z (41498550)
2018-04-12 17:13:21 (DEBUG): Backwards: 2018-04-12T20:59:46.191Z (41498551) to 2018-04-12T21:03:26.859Z (41498650)
2018-04-12 17:13:21 (DEBUG): Backwards: 2018-04-12T21:03:26.859Z (41498651) to 2018-04-12T21:06:48.829Z (41498750)
2018-04-12 17:13:22 (DEBUG): Backwards: 2018-04-12T21:06:49.589Z (41498751) to 2018-04-12T21:09:25.402Z (41498850)
2018-04-12 17:13:22 (DEBUG): Backwards: 2018-04-12T21:09:25.402Z (41498851) to 2018-04-12T21:13:17.061Z (41498950)
2018-04-12 17:13:23 (DEBUG): Backwards: 2018-04-12T21:09:25.402Z (41498851) to 2018-04-12T21:13:17.061Z (41498950)
2018-04-12 17:13:23 (DEBUG): Scan finished: data found:700
2018-04-12 17:13:23 (DEBUG): Available exchange data:
2018-04-12 17:13:23 (DEBUG): from: 15 minutes ago
2018-04-12 17:13:23 (DEBUG): to: 0 minutes ago
2018-04-12 17:13:23 (DEBUG): Unable to stitch datasets.
2018-04-12 17:13:23 (INFO): Not seeding locally available data to the trading method.
2018-04-12 17:13:23 (INFO): However the exchange returned enough data anyway!
2018-04-12 17:13:23 (INFO): Starting to watch the market: GDAX BTC/USD
2018-04-12 17:13:23 (DEBUG): scheduling ticks
2018-04-12 17:13:23 (DEBUG): Requested BTC/USD trade data from GDAX ...
2018-04-12 17:13:23 (DEBUG): Processing 100 new trades. From 2018-04-12 21:09:25 UTC to 2018-04-12 21:13:17 UTC. (4 minutes)
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.
Note: for support questions, please join our Discord server
I'm submitting a ... [x] bug report [ ] feature request [ ] question about the decisions made in the repository
Action taken (what you did) Started a cli instance of gekko against a working config file
Expected result (what you hoped would happen) Gekko fills in the needed history to meet "requiredHistory" and starts the strategy.
Actual result (unexpected outcome) Gekko just collects new trades during the present timeframe but does not start the strategy. Occassionally after some time (10-30 minutes) the strategy will start, others it seems to go on like this indefinitely.
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc)