1

I have created a bot using the python3 library stellar_sdk and i running multiple but with different coin pairs instances of this bot on my server but after a few times I get this error "tx_bad_seq". And I know it occurs when the sequence number doesn't match. So here is my trade function can you guys help me solve this error.

 def trade(self, send_amount, dest_min):
        # Build the transaction
        paths = self.server.strict_send_paths(
            source_asset=self.source_asset,
            source_amount=send_amount,
            destination=[self.destination_asset],
        ).call()

        # Build optimal Path
        first_path = paths['_embedded']['records'][0]

        optimal_path = []

        for item in first_path['path']:
            if item['asset_type'] == 'native':
                optimal_path.append(Asset.native())
            else:
                optimal_path.append(Asset(item['asset_code'], item['asset_issuer']))

        account = self.server.load_account(account_id=self.keypair.public_key)
        transaction = (
            TransactionBuilder(
                source_account=account,
                network_passphrase=bot.passphrase,
                base_fee=self.BASE_FEE,
            )
            .append_path_payment_strict_send_op(
                destination=self.keypair.public_key,  # sending to ourselves
                send_asset=self.source_asset,
                send_amount=send_amount,
                dest_asset=self.destination_asset,
                dest_min=dest_min,
                path=optimal_path,
            )
            .set_timeout(80)
            .build()
        )

        # Sign and submit the transaction
        print('Submitting')
        transaction.sign(self.keypair)
        response = self.server.submit_transaction(transaction)
        print("Successfully Submitted")
        return response

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.