-
Notifications
You must be signed in to change notification settings - Fork 2k
Wrong trade profit calculation #1174
Comments
It's worth noting that just an hour later the sell_stop_pct stop didn't trigger. I have the engine patched in such a way that the sell_stop triggers only if the last trade was 'buy': |
I can now confirm the above speculation about the last trade being "forgotten". I have added the last trade
These are the results:
You can see the last trade |
@defkev : The bug is in dashboard.ejs on master branch where you do my_trades.reverse(). It is probably already fixed by using XMLHttpRequest to obtain the trade data on unstable branch. |
my_trades are no longer reversed but sorted in unstable The array is populated by the time a trade got executed but we want it to show up by date.
|
The point is that you should never ever touch my_trades directly unless you are perfectly sure that what you have is my_trades deep copy. If you need to reverse or sort it, do it like my_trades.slice().sort(...) instead. If you manipulate the array directly, you are breaking the engine, because of the brain damaged way the JS arrays work. Edit: The master branch needs a hotfix for this. In the present state the dashboard breaks pretty much everything that depends on the my_trades state (no offense, @defkev). |
|
Not on the master branch. On unstable the dashboard is decoupled via XMLHttpRequest request to /trades. On master, however, the array is accessed directly. Try for yourself. I bet, that you can even do |
Again, as i said
But if what you say is true this would indeed be a huge security risk as the data exposed by /trades should be read-only, at least until we have some kind of API authentication in place. Let me take a look. |
I have just tried myself. I've added |
Btw, I can confirm that with the below patch applied, the last_trade stopped altering and consequently stop loss order stopped firing at "random".
|
This is indeed bad and absolutely not what we want. I have zero experience with express and wonder if this is document somewhere. Thanks for reporting it 👍 Let me prep a PR. |
System information
Describe the problem
As can be seen in the below live trading log, the profit calculated since the last trade diverts from the actual price movement. In this case from +0.89% to -1.72% despite the price growing by 0.51%.
Source code / logs
The text was updated successfully, but these errors were encountered: