Skip to content

Commit 69ea166

Browse files
authored
Revert "Syncing"
1 parent 02e3fd5 commit 69ea166

11 files changed

+123
-362
lines changed

bot/Arbitrator.php

+3-15
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,12 @@ function trade( $sourceOrderbook, $targetOrderbook, $tradeable, $currency ) {
344344

345345
$undersellProtection = Config::get( Config::UNDERSELL_PROTECTION, Config::DEFAULT_UNDERSELL_PROTECTION );
346346

347-
$tradesMade = array( );
348347
$sellOrderID = $target->sell( $tradeable, $currency, $reducedSellRate, $sellAmount );
349348
$buyOrderID = null;
350349
if ( is_null( $sellOrderID ) ) {
351350
logg( "Sell order failed, we will not attempt a buy order to avoid incurring a loss." );
352351
} else {
353352
logg( "Placed sell order (" . $target->getName() . " ID: $sellOrderID)" );
354-
$tradesMade[ $target->getID() ] = array(
355-
$tradeable => -$sellAmount,
356-
);
357353

358354
$tradesSum = 0;
359355
$averageSellRate = 0;
@@ -366,7 +362,7 @@ function trade( $sourceOrderbook, $targetOrderbook, $tradeable, $currency ) {
366362
logg( "A sell order hasn't been filled. If this happens regulary you should increase the " . Config::ORDER_CHECK_DELAY . " setting!", true );
367363
}
368364

369-
$target->refreshWallets( $tradesMade );
365+
$target->refreshWallets();
370366

371367
$sellTrades = $this->tradeMatcher->handlePostTradeTasks( $this, $target, $tradeable, $currency, 'sell',
372368
$sellOrderID, $sellAmount );
@@ -425,10 +421,6 @@ function trade( $sourceOrderbook, $targetOrderbook, $tradeable, $currency ) {
425421
if ( !is_null( $buyOrderID ) &&
426422
$source->cancelOrder( $buyOrderID ) ) {
427423
logg( "A buy order hasn't been filled. If this happens regulary you should increase the " . Config::ORDER_CHECK_DELAY . " setting!", true );
428-
} else {
429-
$tradesMade[ $source->getID() ] = array(
430-
$tradeable => $tradeAmount,
431-
);
432424
}
433425
}
434426
}
@@ -442,9 +434,9 @@ function trade( $sourceOrderbook, $targetOrderbook, $tradeable, $currency ) {
442434

443435
logg( "Checking trade results ($i)..." );
444436

445-
$source->refreshWallets( $tradesMade );
437+
$source->refreshWallets();
446438
if ( !$undersellProtection || $i != 1 ) {
447-
$target->refreshWallets( $tradesMade );
439+
$target->refreshWallets();
448440
}
449441

450442
$buyTrades = $this->tradeMatcher->handlePostTradeTasks( $this, $source, $tradeable, $currency, 'buy',
@@ -454,10 +446,6 @@ function trade( $sourceOrderbook, $targetOrderbook, $tradeable, $currency ) {
454446
$sellOrderID, $sellAmount );
455447
}
456448

457-
if ( !is_null( $buyOrderID ) ) {
458-
$boughtAmount = min( $boughtAmount, array_reduce( $buyTrades, 'sumOfAmount', 0 ) );
459-
}
460-
461449
$totalCost = is_null( $buyOrderID ) ? 0 :
462450
$source->getFilledOrderPrice( 'buy', $tradeable, $currency, $buyOrderID );
463451
$totalRevenue = is_null( $sellOrderID ) ? 0 :

bot/BittrexLikeExchange.php

+28-10
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,35 @@ public function detectStuckTransfers() {
208208

209209
}
210210

211+
public function detectDuplicateWithdrawals() {
212+
213+
// TODO: Detect duplicate withdrawals!
214+
215+
}
216+
217+
public function getWalletsConsideringPendingDeposits() {
218+
219+
$result = [ ];
220+
foreach ( $this->wallets as $coin => $balance ) {
221+
$result[ $coin ] = $balance;
222+
}
223+
224+
$balances = $this->queryBalances();
225+
foreach ( $balances as $balance ) {
226+
$result[ strtoupper( $balance[ 'Currency' ] ) ] = $balance[ 'Balance' ] + $balance[ 'Pending' ];
227+
}
228+
229+
return $result;
230+
231+
}
232+
211233
public function dumpWallets() {
212234

213235
logg( $this->prefix() . print_r( $this->queryBalances(), true ) );
214236

215237
}
216238

217-
public function refreshWallets( $tradesMade = array() ) {
218-
219-
$this->preRefreshWallets();
239+
public function refreshWallets() {
220240

221241
$wallets = [ ];
222242

@@ -238,13 +258,11 @@ public function refreshWallets( $tradesMade = array() ) {
238258

239259
$balances = $this->queryBalances();
240260
foreach ( $balances as $balance ) {
241-
$wallets[ strtoupper( $balance[ 'Currency' ] ) ] = floatval( $balance[ 'Available' ] );
261+
$wallets[ strtoupper( $balance[ 'Currency' ] ) ] = floatval( $balance[ 'Balance' ] );
242262
}
243263

244264
$this->wallets = $wallets;
245265

246-
$this->postRefreshWallets( $tradesMade );
247-
248266
}
249267

250268
public function testAccess() {
@@ -263,14 +281,14 @@ private function queryDepositAddress( $coin ) {
263281
return isset( $data[ 'Address' ] ) ? $data[ 'Address' ] : null;
264282
}
265283
catch ( Exception $ex ) {
266-
if ( strpos( $ex->getMessage(), 'ADDRESS_GENERATING' ) !== false ) {
284+
$info = json_decode($ex->getTrace()[ 0 ][ 'args' ][ 0 ]);
285+
if (is_object( $info ) &&
286+
$info->success === false &&
287+
$info->message === 'ADDRESS_GENERATING') {
267288
// Wait while the address is being generated.
268289
sleep( 30 );
269290
continue;
270291
}
271-
if ( strpos( $ex->getMessage(), '_OFFLINE' ) !== false ) {
272-
$this->onMarketOffline( $coin );
273-
}
274292
throw $ex;
275293
}
276294
}

bot/CoinManager.php

+2-20
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@ private function takeProfit() {
552552
if ( $highestExchange->withdraw( 'BTC', $remainingProfit, $profitAddress ) ) {
553553
$txFee = $this->getSafeTxFee( $highestExchange, 'BTC', $averageBTC );
554554
Database::recordProfit( $remainingProfit - $txFee, 'BTC', $profitAddress, time() );
555-
Database::saveWithdrawal( 'BTC', $remainingProfit, $profitAddress, $highestExchange->getID(), 0,
556-
$highestExchange->getTransferFee( 'BTC', $remainingProfit ) );
555+
Database::saveWithdrawal( 'BTC', $remainingProfit, $profitAddress, $highestExchange->getID(), 0 );
557556

558557
// -------------------------------------------------------------------------
559558
$restockFunds = $this->stats[ self::STAT_AUTOBUY_FUNDS ];
@@ -670,14 +669,6 @@ private function autobuyAltcoins( &$arbitrator ) {
670669
Database::saveManagement( $coin, $buyAmount, $rate, $exchange->getID() );
671670
$this->stats[ self::STAT_AUTOBUY_FUNDS ] = formatBTC( $autobuyFunds - $buyPrice );
672671

673-
// Make sure the wallets are updated for pending deposit calculations.
674-
$tradesMade = array(
675-
$exchange->getID() => array(
676-
$coin => $buyAmount,
677-
)
678-
);
679-
$exchange->refreshWallets( $tradesMade );
680-
681672
$arbitrator->getTradeMatcher()->handlePostTradeTasks( $arbitrator, $exchange, $coin, 'BTC', 'buy',
682673
$orderID, $buyAmount );
683674
return;
@@ -830,14 +821,6 @@ private function liquidateAltcoins( &$arbitrator ) {
830821
logg( "Order executed!" );
831822
Database::saveManagement( $coin, $sellAmount * -1, $rate, $exchange->getID() );
832823

833-
// Make sure the wallets are updated for pending deposit calculations.
834-
$tradesMade = array(
835-
$exchange->getID() => array(
836-
$coin => -$sellAmount,
837-
)
838-
);
839-
$exchange->refreshWallets( $tradesMade );
840-
841824
$arbitrator->getTradeMatcher()->handlePostTradeTasks( $arbitrator, $exchange, $coin, 'BTC', 'sell',
842825
$orderID, $sellAmount );
843826
}
@@ -886,8 +869,7 @@ public function withdraw( $source, $target, $coin, $amount ) {
886869

887870
logg( "Deposit address: $address" );
888871
if ( $this->doWithdraw( $source, $coin, $amount, trim( $address ) ) ) {
889-
Database::saveWithdrawal( $coin, $amount, trim( $address ), $source->getID(), $target->getID(),
890-
$source->getTransferFee( $coin, $amount ) );
872+
Database::saveWithdrawal( $coin, $amount, trim( $address ), $source->getID(), $target->getID() );
891873
}
892874

893875
}

0 commit comments

Comments
 (0)