Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Bittrex and Insufficient Funds (#708) (#711)
Browse files Browse the repository at this point in the history
Added if statements so the exchange can have it's cut out of the purchase of the asset.
Most exchanges want their cut in BTC rather than the alt-coin being processed.
This modification allows for the exchange fee to be removed from the overall purchase price allowing for 100% of the currency balance to be spent without an insufficient funds error popping up.
  • Loading branch information
KryptoNova authored and DeviaVir committed Nov 15, 2017
1 parent 9e85485 commit b53abcc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,15 @@ module.exports = function container (get, set, clear) {
if (signal === 'buy') {
price = n(quote.bid).subtract(n(quote.bid).multiply(so.markup_pct / 100)).format(s.product.increment, Math.floor)
if (!size) {
size = n(s.balance.currency).multiply(so.buy_pct).divide(100).divide(price).format('0.00000000')
if (so.mode === 'live') {
if (so.order_type === 'maker')
size = n(s.balance.currency).multiply(so.buy_pct).divide(100).multiply(s.exchange.makerFee / 100).format('0.00000000');
else
size = n(s.balance.currency).multiply(so.buy_pct).divide(100).multiply(s.exchange.takerFee / 100).format('0.00000000');
size = n(s.balance.currency - size).divide(price).format('0.00000000')
} else {
size = n(s.balance.currency).multiply(so.buy_pct).divide(100).divide(price).format('0.00000000')
}
}
if ((s.product.min_size && Number(size) >= Number(s.product.min_size)) || ('min_total' in s.product && s.product.min_total && n(size).multiply(price).value() >= Number(s.product.min_total))) {
if (s.product.max_size && Number(size) > Number(s.product.max_size)) {
Expand Down

4 comments on commit b53abcc

@Jamby93
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for not doing this also for selling signals?

@KryptoNova
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My experience has been that when you convert an asset into currency the exchange fee is deducted from the resulting balance of that swap. So there will always end up being enough currency to cover the fee in sell situations.

With buy situations, especially when the buy percent is 100%, it is necessary to leave enough currency in the account to cover the exchange fee. This is why it is necessary to have this calculation performed on buy scenarios.

With Bittrex it gets tricky, because they do not allow transactions that result in less than 0.00050000 BTC. They consider those "dust trades" and are not allowed. If the balance ever gets that low, then it is going to take manual intevention to either add more asset to allow the sell or increase the BTC balance to cover the buy. However, if everything goes well, balances should never drop to less then 0.00050000. ;-)

Hope this explanation helps.

@brucetus
Copy link
Contributor

@brucetus brucetus commented on b53abcc Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this broke buy_pct. My buy_pct command doesnt work anymore and it always buys 100%. Also your if and esle statements dont have brackets on them. Please fix this.

(edit) I have confirmed this being the reason for buy_pct not working by replacing the new lines with the old and it works again.

@KryptoNova
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goodness @brucetus, you are absolutely right. I see the problem and will put in the fix for it very shortly. Just need to test it. My deepest apologies.

Please sign in to comment.