1

I have written a simple program to swap assets using the strict_send method available stellar sdk for interacting with Horizon HTTP API.

Below is the code construct - it's not productionized however, when I test it with public network - it keeps failing - with below reason code:

'result_codes': {
'transaction': 'tx_failed', 'operations': ['op_under_dest_min']}, 'result_xdr': 'AAAAAAAAAGT/////AAAAAQAAAAAAAAAN////9AAAAAA='}

The code block used is give as under:

   def do_send(self, from_asset: Asset, from_amount, to_asset: Asset, to_amount,
                path_asset: List[Asset]) -> Optional[str]:
        source_account = self.__server.load_account(self.source_keypair.public_key)
        try:
            transaction = (
                TransactionBuilder(
                    source_account=source_account,
                    network_passphrase=self.NETWORK_PASS_PHRASE,
                    base_fee=100,
                )
                # set a trust line with account & asset / issuer
                # .append_change_trust_op(from_asset.code, from_asset.issuer, source=self.trading_keypair.public_key)
                # .append_change_trust_op(to_asset.code, to_asset.issuer, source=self.trading_keypair.public_key)
                .append_path_payment_strict_send_op(
                    source=self.trading_keypair.public_key,
                    destination=self.trading_keypair.public_key,
                    send_code=from_asset.code,
                    send_issuer=from_asset.issuer,
                    send_amount=self.AMT_FORMAT.format(from_amount),
                    dest_code=to_asset.code,
                    dest_issuer=to_asset.issuer,
                    dest_min=self.AMT_FORMAT.format(to_amount),
                    path=path_asset,
                )
                .set_timeout(30)
                .build()
            )
            transaction.sign(self.trading_keypair)
            transaction.sign(self.source_keypair)
            response = self.__server.submit_transaction(transaction)
            print(f"Transaction hash: {response['hash']}")
            return response['hash']
        except BadRequestError as ber:
            print('Transaction Failed.')
            print(ber.extras)
            return None

Also note that before I create the transaction, I'm using the below method to find out the destination amount and the path.

self.__server.strict_send_paths(from_asset, self.AMT_FORMAT.format(amount), [to_asset])

Out of like 20 odd calls - only couple of them succeeds rest all fail with above error.

I'm kinda thinking that probably it might be due to the reason that I'm using the publicly hosted horizon server and it might be impacting the speed of my order submission and hence the order book might be moving up before I can fill the asks/bids.

0

Your Answer

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

Browse other questions tagged or ask your own question.