etherdelta / etherdelta.github.io

https://etherdelta.com
555 stars 689 forks source link

amount parameter in takeOrder function #581

Open bugduino opened 6 years ago

bugduino commented 6 years ago

Hi I'm trying to take orders (both a buys orders and sells orders), following the taker.js example the problem I have is with the amount parameter. The example is doing the following things

desiredAmountBase = 0.001;
fraction = Math.min(desiredAmountBase} / order.ethAvailableVolumeBase, 1);
const amount = order.amountGet.times(new BigNumber(String(fraction)));

I have the following questions: 1) should I always use ethAvailableVolumeBase both for buys and sells? 2) fraction would obviously be a floating point and so would be amount, but amount should always be in amountGet terms which is in wei and so don't need to be a floating point, is it correct and safe to do

`amount = amount.toNumber();`

to truncate decimals?

3) the amount should be written as something like

`const amount = (order.amountGet - order.amountFilled).times(new BigNumber(String(fraction)));`

because otherwise you could potentially trying to get more quantity than the available one, is this reasoning correct?