cosmology-tech/cosmology

how can i get swap price using cosmology?

limitspro opened this issue · 2 comments

if i choose cosmology swap, it will just do swap, but how can i get swap ratio( how many a tokens can be swapped by b tokens) before i swap?

You can calculate it using our core functions. Currently we're using coingecko prices, and then going from that to correlate two assets.

Here is an example of how to calculate these values

https://github.com/cosmology-finance/cosmology/blob/master/packages/cli/src/commands/swap.ts#L125-L159

I'm happy to also add this as a top-level function, let me know if you have specific ideas for the API/interface, I'd be happy to build it in.

thanks, maybe just like the swap api?

cosmology swap_simulate \
    --chainId osmosis-1 \
    --restEndpoint https://lcd-osmosis.blockapsis.com \
    --rpcEndpoint https://osmosis.validator.network \
    --sell token_out \
    --buy token_in \
    --amt 100 \
    --slippage 1

return token_in amt, i change the value param to amt param, bc in swap, we expect out and in value would roughly the same.