ethfinex / efx-api-node

Client library to interact with the DeversiFi API and smart-contracts for non-custodial trading
https://app.deversifi.com
22 stars 18 forks source link

Fees calculation #49

Open wnz99 opened 5 years ago

wnz99 commented 5 years ago

I was thinking that it would be nice to have a method that returns the fees given an order amount. Something like:

const price = 150
const pair = 'ETHUSD'
const orderAmount = 10
const fees =getBuyFees(orderAmount, pair, price)  

It would return the fees to buy 10 ETH at the ETH/USD ticker price of 150 USD per 1 ETH so that an user could then calculate the total cost of his order in USD as price * orderAmount + fees.

Similarly, there should be another method like:

const price = 150
const pair = 'ETHUSD'
const orderAmount = 10
const fees =getSellFees(orderAmount, pair, price)  

It returns the fees to sell 10 ETH, so that the revenue in USD would be orderAmount * price - fees

What do you think?

hems commented 5 years ago

I believe generally on all exchanges the fees are taking when feeling the order, so the user never has to "add the fee" when creating Buy or Sell orders, even when using the exchange website or when using the exchange apis.

In the other hand i agree with you having a function to calculate the fee would be very useful, for instance for displaying the fee on the interface ( which in turn might make the user adjust the amount ).

If we create a calculate fee function you could use that when creating a "web interface" which will show the user an order form. Then on the order form you can show the amount, but in the code create for the user an order that actually accounts for the fee.

Does that make sense and/or apply to your use case?

wnz99 commented 5 years ago

yes, that is the purpose of my proposal. It's a matter of accounting. Having an official source of fees amount would help an user to calculate the gross cost or net revenue of his order. If fees are not clearly shown on the order form, they become a hidden cost. Most exchanges do not show that information when placing an order, indeed, but I think there should be a away to get the exact amount if required.

Otherwise it may happen that on a UI the fees are somehow miscalculated or not shown correctly. A user would then place an order and pay/receive a total different amount than expected.

Once fees are introduced, external devs will have to keep them monitored to make sure that if anything change, and they are showing that information in their UI, their code is amended accordingly. I think that having this functionality embedded in the api would be helpful.

Alternatively, fees could be simply published at https://api.ethfinex.com/trustless/v1/r/get/conf , but still some sort of official utility may be desirable.

plutoegg commented 5 years ago

Yes, I think we should implement this - although it should just be getFees using amount as positive or negative to indicate a Buy or Sell.

Currency of the fee should be clear.

Particularly now that fee can be set dynamically by an API partner in their order request (this will need to be an input to the function as it is in createOrderV2