def DoManyWithdraw(self): #BTC precoinrAcc = Account.objects.get(accountName='precoinr') mainBtcFund = AccountFund.objects.get(accountId=precoinrAcc, currencyCode='BTC') notWithdrawn = Transaction.objects.filter(transactionType= 'withdraw', ccTxId='', fundIdIn= mainBtcFund.id) btcOutList = [] for tx in notWithdrawn: btcOutList.append(tx) if len(btcOutList)>0: btcOutDict = {} totalAmount = 0 for tx in btcOutList: btcOutDict[tx.withdrawAddress] = float(tx.amount-tx.precoinrFee) totalAmount += btcOutDict[tx.withdrawAddress] try: with transaction.commit_on_success(): fee = 0.00005 outTx = self.CreateSystemOutTransaction(mainBtcFund, totalAmount, fee) outTx.save() ccTxId = BtcAPIInterface.sendMany(mainBtcFund.fundAddress, btcOutDict) outTx.ccTxId=ccTxId outTx.save() for t in btcOutList: t.ccTxId=ccTxId FundDataHelpers.RecalculateFunds(t) t.save() except Exception as e: logger.error('Could not make system withdraw: '+e.message) transaction.rollback()
def SearchForNewBTCTransactions(self): ''' logging.basicConfig(stream=sys.stdout, level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S", format="[%(asctime)-15s] %(message)s") ''' logger.info("Checking for new transaction data...") conn = bitcoinrpc.connect_to_local() for fund in AccountFund.objects.filter(currencyCode='BTC'): actualIn = BtcAPIInterface.getTotalReceived(conn, fund.fundAddress) transactions = BtcAPIInterface.getLastTransactions(conn, fund.fundAddress, fund.numTransactionsSeen) noSeen = self.WorkTroughNewTransactions(transactions, fund) if len(transactions)==noSeen: fund.numTransactionsSeen+=noSeen fund.totalIn=actualIn fund.save()