sthewissen / Mynt

An Azure Functions-based crypto currency trading bot; featuring 10 exchanges, 25 indicators, custom strategy support, backtester and more
BSD 3-Clause "New" or "Revised" License
237 stars 128 forks source link

Wrong calculation of profit in ExecuteSellOrder method if the AmountOfBtcToInvestPerTrader is changed after the buy #4

Closed rjovic closed 6 years ago

rjovic commented 6 years ago

First of all I want to thank you on putting your effort and publishing the source of this awesome project. I'm also in process of playing with creation of trading bots and your project really helped me a lot, especially because it is on Azure and it uses .NET (environment where I'm most comfortable). So thumbs up!

Now on possible issue. I'm looking at the code and trying to understand it and following line in ExecuteSellOrder method confuses me:

https://github.com/sthewissen/Mynt/blob/bbe9dee5f1f0ee4ef6186791f7fba6ac3f75b264/functions/Mynt.Core/TradeManagers/BittrexTradeManager.cs#L383

So if I understood correctly the whole workflow, the problem will arise if I the system generate the buy order for amount of Constants.AmountOfBtcToInvestPerTrader and if after that buy user change the Constants.AmountOfBtcToInvestPerTrader the whole profit will be calculated using the old value which will mess up the calculation.

Should we use trade.StakeAmount which is persisted in the storage when buy is generated?

var investment = (trade.StakeAmount * (1 - Constants.TransactionFeePercentage));

sthewissen commented 6 years ago

That would probably work yeah. I'm currently a bit busy with other projects so feel free to submit a PR for this :)

rjovic commented 6 years ago

Done :)