Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetRates params seems not work in @ton-api/client #221

Open
WaterSo0910 opened this issue Jan 11, 2025 · 2 comments
Open

GetRates params seems not work in @ton-api/client #221

WaterSo0910 opened this issue Jan 11, 2025 · 2 comments
Labels

Comments

@WaterSo0910
Copy link

WaterSo0910 commented Jan 11, 2025

Reproduction steps

  1. Install @ton-api/[email protected], @ton/[email protected]

  2. use it to get rates of tsTON, TON

const client = new TonApiClient()
const rates = client.rates.getRates({
        tokens: [
            "ton", 
            "EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav" // tsTON
        ], 
        currencies: ["USD"],
});
console.log(rates)

Actual result

Unknown error

Expected result

rates {
  EQC98QAmNEptUtPc7W6xdHhZHrBUFpw5FtIzNU20QAJav: {
    prices: { USD: 5.690988722212151 },
    diff24h: { USD: '+3.97%' },
    diff7d: { USD: '−6.50%' },
    diff30d: { USD: '−15.08%' }
  },
  TON: {
    prices: { USD: 5.41985 },
    diff24h: { USD: '+3.96%' },
    diff7d: { USD: '−6.57%' },
    diff30d: { USD: '−15.35%' }
  }
}

However, if I change code to the below:

const client = new TonApiClient()
const rates = client.rates.getRates({
        tokens: [
            "ton,EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav" // split with comma in a list item
        ],
        currencies: ["USD"],
});
console.log(rates)

It works but I think it's not what we expect.

@WaterSo0910 WaterSo0910 changed the title GetRates params seems not work in @ton-api/client GetRates params seems not work in @ton-api/client Jan 11, 2025
@mois-ilya
Copy link
Collaborator

Yes, the issue is present and reproducible.

I found that it is caused by the current version of the SDK incorrectly handling the passing of multiple tokens as an array. The explode: false setting from the OpenAPI specification is not being processed properly, which leads to the server failing to interpret the request correctly when multiple elements are passed in the tokens parameter.

Current Workaround

As a temporary solution, you can pass a single string where tokens are listed separated by commas, even within the array. Here's the corrected code:

const rates = await client.rates.getRates({
    tokens: ['ton,EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav'], // Comma-separated in one string
    currencies: ['USD'],
});
console.log(rates);

Notes:

  • If only one token is passed, there is no error.
  • The issue occurs whenever more than one token is included in the tokens array.

I will fix this behavior in future SDK versions. Thank you for bringing it to my attention!

@WaterSo0910
Copy link
Author

WaterSo0910 commented Jan 12, 2025

@mois-ilya Thank you for the support. 🤟

Also, I found another problem based on this. If I call getRates in SDK as following:

const rates = await client.rates.getRates({
    tokens: ['ton,EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav'], // Comma-separated in one string
    currencies: ['USD'],
});
console.log(rates);

Then I will get the results:

{
  rates: {
    TON: {
      prices: [Object],
      diff24h: [Object],
      diff7d: [Object],
      diff30d: [Object]
    },
    EQC98QAmNEptUtPc7W6xdHhZHrBUFpw5FtIzNU20QAJav: {
      prices: [Object],
      diff24h: [Object],
      diff7d: [Object],
      diff30d: [Object]
    }
  }
}

Let's focus on the address key of the result object, and that is different from the original address:

EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav // original
EQC98QAmNEptUtPc7W6xdHhZHrBUFpw5FtIzNU20QAJav // key of rates (output)

The underlines are missing, so I use raw address as key to skip this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants