Failure to fetch $SLI price from ICPSwap into a webpage

I’m trying to fetch the price of $SLI from ICPSwap into a webpage. Here is a Javascript code that isn’t working as expected. Is there anything I’m doing wrong? Please advice:

// Import the required dependencies
import { Principal } from “@dfinity/principal”;
import { Actor, HttpAgent } from ‘@dfinity/agent’;
import fetch from ‘isomorphic-fetch’;

async function getPrice() {
const host = “https://ic0.io”;
const agent = new HttpAgent({ fetch, host });
const canisterId = ‘yr4hc-viaaa-aaaag-qcirq-cai’; // ICPSwap canister ID

const actor = Actor.createActor(canisterId, {
agent,
canisterId: Principal.fromText(canisterId),
});

try {
const operator = ‘yr4hc-viaaa-aaaag-qcirq-cai’;
const amountIn = ‘100000000’;
const zeroForOne = false;
const amountOutMinimum = ‘0’;

const request = { operator, amountIn, zeroForOne, amountOutMinimum };
const quoteResponse = await actor.quote(request);

if (quoteResponse.ok !== null) {
  console.log(`price: ${quoteResponse.ok}`);
} else {
  console.log('Error: Failed to get price');
}

} catch (error) {
console.log(Error: ${error});
}
}

window.addEventListener(‘load’, getPrice);

Hello, sir.

Do you have any error messages when running the code?

And what specific outcome are you aiming to achieve?

If it’s convenient for you, could you please record a video of the code execution and the error messages and send it to us at “contact@icpswap.org”? Let us see how we can help you!

Thank you.

3 Likes

I appreciate your response. I aim pull the number of ICPs required per slice or the number of slices required per ICP and proceed display on page. I thought I was missing some dependencies, that’s why i posted here. I can get from from Internet Computer dashboard using pair ID. However, the code presented doesn’t seem to fetch price on webpage. I’ll contact your team as suggested. Thank you.

2 Likes

Are there any docs on the icpswap interfaces?
Like canister IDs and a short description what various queries/update calls do

This is our API interface, and the API documentation is currently quite basic. We will send you the updated documentation once we have it finalized. Thank you.
https://uvevg-iyaaa-aaaak-ac27q-cai.raw.ic0.app/tickers

1 Like

Sir, @let4be Here is a basic API document. Please see if it can address your initial requirements.

## Swap Pool Info

Url: GET https://uvevg-iyaaa-aaaak-ac27q-cai.raw.ic0.app/tickers

Response: 

```json
[
   {
        "ticker_id":"xmiu5-jqaaa-aaaag-qbz7q-cai",
        "ticker_name":"ckBTC_ICP",
        "base_id":"mxzaz-hqaaa-aaaar-qaada-cai",
        "base_currency":"ckBTC",
        "target_id":"mxzaz-hqaaa-aaaar-qaada-cai",
        "target_currency":"ICP",
        "last_price":"0.000116",
        "base_volume":"211198.622355",
        "target_volume":"128359.964731"
    },
    {
        "ticker_id":"nm7k6-wyaaa-aaaag-qcasa-cai",
        "ticker_name":"CHAT_ckBTC",
        "base_id":"2ouva-viaaa-aaaaq-aaamq-cai",
        "base_currency":"CHAT",
        "target_id":"2ouva-viaaa-aaaaq-aaamq-cai",
        "target_currency":"ckBTC",
        "last_price":"149164.263992",
        "base_volume":"636.387938",
        "target_volume":"327.550608"
    }
]
Name Description
ticker_id swap pool id
ticker_name swap pool name
base_id token0 id
base_currency token0 symbol
target_id token1 id
target_currency token1 symbol
last_price last price of the pool
base_volume token0 total volume
target_volume token1 total volume
2 Likes

What other endpoints are available? I’m interested in reading last trades on a pool with certain ID

Hello, sir.

Devs has made updates, please check out this latest docs:

1 Like