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

Feature request: Getting the reverse exchange rate #3

Open
olekon opened this issue Jan 9, 2020 · 1 comment
Open

Feature request: Getting the reverse exchange rate #3

olekon opened this issue Jan 9, 2020 · 1 comment

Comments

@olekon
Copy link

olekon commented Jan 9, 2020

Let's suppose I need to get X amount of SomeToken, and I have AnotherToken

It would be nice to have a function that calculates the following:
How many of AnotherToken should I spend to obtain X amount of SomeToken.

A simple example, explaining why it can be needed and getRate is not enough sometimes.
Let's try to use the current getRate function to calculate how many BNT tokens one should spend to get 10 ETH:

const ethToken = {
 blockchainType: 'ethereum',
 blockchainId: '0xc0829421C1d260BD3cB3E0F06cfE2D52db2cE315'
};
const bntToken = {
 blockchainType: 'ethereum',
 blockchainId: '0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C'
}

const initialAmount = "10";
console.log(initialAmount);

const bntTokenAmount = await bancor.getRate(ethToken, bntToken, initialAmount);
console.log(bntTokenAmount);

//now check the conversion result
const ethTokenAmount = await bancor.getRate(bntToken, ethToken, bntTokenAmount);
console.log(ethTokenAmount);

In this example, ethTokenAmount is quite close to initial (for now it is 9.944, ~0.56% deviation), but as initialAmount grows, the difference becomes greater too.

with initialAmount set to "1000" resulting ethTokenAmount is "859.966" which is 14% deviation, and that is a lot.

Though I understand that it might be hard to get an exact value, but I guess it's OK to specify a precision.

@yudilevi
Copy link
Contributor

yudilevi commented Jan 9, 2020

@olekon yeah - makes sense and we'll definitely add that one - thanks :)

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

No branches or pull requests

2 participants