cryptoeax / arbbot

Arbitrator, a bitcoin/altcoin arbitrage trading bot
https://gitter.im/cryptoeax-arbbot/Lobby
GNU General Public License v3.0
198 stars 78 forks source link

post refresh wallets is overadding to pending deposits #171

Open Exalovic opened 6 years ago

Exalovic commented 6 years ago

People are experiencing the bot giving incorrect balances after the pending deposits update.

After looking at trade data I have identified that the function responsible for the problem is this one:

starts on line 268 in exchange.php

protected function postRefreshWallets( $tradesMade ) { $id = $this->getID(); foreach ( $this->wallets as $coin => $balance ) { if ( !isset( $this->walletsBackup[ $coin ] ) ) { $this->walletsBackup[ $coin ] = 0; } if ( $balance != $this->walletsBackup[ $coin ] ) { // Assume that a change in the balance when we aren't trading may be an incoming // deposit being credited, look for one! $change = $balance - $this->walletsBackup[ $coin ]; if ( isset( $tradesMade[ $id ][ $coin ] ) ) { // If we have made a trade at this exchange of this coin, make sure to discount // the change if it's less than the trade amount. if ( abs( $change ) < abs( $tradesMade[ $id ][ $coin ] ) ) { $change = 0; } else { $change += -$tradesMade[ $id ][ $coin ]; } } $pendingDeposit = Database::getPendingDeposit( $coin, $id ); if ( $pendingDeposit > 0 && $change != 0 ) { Database::savePendingDeposit( $coin, -$change, $id ); } } } Database::saveWallets( $id, $this->wallets );

However I'm unsure how to deal with fixing it