cosmology-tech / cosmology

CLI and TS library for the Cosmos ⚛️
MIT License
50 stars 20 forks source link

how can i get swap price using cosmology? #4

Open limitspro opened 2 years ago

limitspro commented 2 years ago

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?

pyramation commented 2 years ago

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.

limitspro commented 2 years ago

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.