Code
def choice_for_algo():
Choice = client.fetch_asset(297995609)
ALGO = client.fetch_asset(0)
pool = client.fetch_pool(Choice, ALGO)
quote = pool.fetch_fixed_input_swap_quote(ALGO(1_000_000), slippage=0.01)
print(quote)
print(f'Choice per ALGO: {quote.price}')
print(f'Choice per ALGO (worst case): {quote.price_with_slippage}')
print("Do you still want to go through this transaction? Type Y for 'Yes' and N for 'No'")
binary = input()
if binary == "Y":
new = int(input("How much ALGO do you want to spend? ")) * 1000000
quote = pool.fetch_fixed_input_swap_quote(ALGO(new), slippage=0.01)
print(f'Swapping {quote.amount_in} to {quote.amount_out_with_slippage}')
transaction_group = pool.prepare_swap_transactions_from_quote(quote)
# Sign the group with our key
transaction_group.sign_with_private_key(address, private_key)
# Submit transactions to the network and wait for confirmation
result = client.submit(transaction_group, wait=True)
Error
How much ALGO do you want to spend? 1
Swapping ALGO('1') to Choice('181.91')
Traceback (most recent call last):
File "Wrap.py", line 183, in <module>
choice_for_algo()
File "Wrap.py", line 39, in choice_for_algo
result = client.submit(transaction_group, wait=True)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tinyman/v1/client.py", line 34, in submit
raise Exception(json.loads(e.args[0])['message']) from None
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)