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

Inconsistent time delay between [ORDER] statusChange: FILLED and tradeCompleted Event #2449

Closed
cstegmann opened this issue Aug 15, 2018 · 10 comments

Comments

@cstegmann
Copy link

Note: this is the technical bug tracker, please use other platforms for getting support and starting a (non technical) discussion. See the getting help page for details.

I'm submitting a ...
[x ] bug report
[ ] question about the decisions made in the repository

Action taken (what you did)
I have gekko on develop branch running in pm2. In the config file I have the event Logger set to true with tradeCompleted being watched. The time between an order being filled and the tradeCompleted event is too long and varies wildly.

Expected result (what you hoped would happen)
Right after the [ORDER] statusChange: FILLED, a tradeCompleted Event should follow, maybe with 1-2 seconds delay.

Actual result (unexpected outcome)
tradeCompleted is delayed from anywhere between 25 seconds to 1 minute 40 seconds from what I observed today.

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc)

@askmike
Copy link
Owner

askmike commented Aug 16, 2018

[ORDER] statusChange: FILLED fires the millisecond Gekko Broker knows the order was filled. However Gekko needs more information than the simple fact it was filled (for example average execution cost, fees paid, etc). It figures this out by asking Gekko Broker to create a summary of the order, this involves fetching all orders that had a partial fill and calculating some statistics. That fetching takes up 99% of the time you described:

const checkOrders = _.keys(this.orders)
.map(id => next => {
if(!this.orders[id].filled) {
return next();
}
setTimeout(() => this.api.getOrder(id, next), this.timeout);
});

Though 1 minute and 40 seconds is very long.. Could you provide some more information like:

  • What exchange?
  • What kind of internet connection?
  • Did you trade a big amount (compared to the market you are trading on)?

@askmike
Copy link
Owner

askmike commented Aug 16, 2018

Looking at the code some more: that this.timeout is wrong, it should be this.checkInterval. Will push a fix, let's hope that solves your issue!

@askmike
Copy link
Owner

askmike commented Aug 16, 2018

I've updated the interval, let's hope that fixes your problem. If it doesn't, please see these questions: #2449 (comment)

I'm closing this since I don't think it's a bug, but just part of the current design. It IS possible to split up the events Gekko passes around in 2: one the second it's filled and another one later to follow up with more information regarding execution price. But before we do that I'd like to understand your problem a bit better first. For me the difference between the filled event and the tradeCompleted event is never more than 2 seconds.

@cstegmann
Copy link
Author

@askmike Thanks, I'm in the process of updating to the hotfix/binance-insufficient-funds and will change this as well. As for the additional info:

Exchange: Binance
Internet Connection: Root server in Frankfurt, so pretty fast
Trade Amount: like $2000 dollars , pairs have volume of ~1.5 million to ~16 million
Tickrate: 10 (don't know if that matters, i liked that more).

@askmike
Copy link
Owner

askmike commented Aug 16, 2018 via email

@cstegmann
Copy link
Author

That branch does not have this specific fix, so make you apply it manually as well!

I did, thanks.

@askmike
Copy link
Owner

askmike commented Aug 20, 2018

@cstegmann did the fix help get the speed down? Whichever case, I am afraid I have to close this as fetching details about trades is necessary to give information about the trade. And fetching details takes time. I might add partial fill events (Gekko Broker already emits them, but they are only logged and not exposed as a gekko event (though strats, plugins, etc).

@askmike askmike closed this as completed Aug 20, 2018
@cstegmann
Copy link
Author

@askmike Didn't really speed up, not sure if it slowed down or not but it usually takes a minute for the tradeCompleted event to show up in the debug logs. I'm not really fussed since I only use it for my telegrambot and it doesn't really matter if the the BUY/SELL notification is a little slow when I'm at work or whatever. I just thought it was weird that it took so long.

@askmike
Copy link
Owner

askmike commented Aug 20, 2018

I just thought it was weird that it took so long.

Thanks for watching out and reporting these things. I'm lacking documentation on most things so feel free to open issues for whatever you encounter.


I would advice to run your trader close to the exchange, if you trading on binance think about renting a server in AWS tokyo (same datacenter as binance), if you are trading on the other side of the world every API call (of which Gekko needs to do a few) can take considerable time.

@cstegmann
Copy link
Author

Ah, maybe I can do that next year. I am using the server that used to host my Teamspeak for a few friends before we switched to discord and I still have time left on that contract.

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

No branches or pull requests

2 participants