-
Notifications
You must be signed in to change notification settings - Fork 2k
Conversation
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.
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this overwrites the result of your if at :417
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. I use "size" as a transitional holding variable in a live run of Zenbot. This is because there could be two different fees if the bot is running in maker or taker mode with the exchange.
The size variable that is calculated at :418 and :420 represents the amount of the exchange fee that is going to be taken if the purchase is completed after the buy_pct is calculated.
The final size variable at :421 represents the fee adjusted size of the amount of asset to purchase at the selected price.
This allows enough BTC to remain in the account to allow 100% buy of an asset without having a problem with insufficient funds. The side effect is that if you use a 50% buy_pct, it will not be the full 50% due to the fee coming out of the size. This is the formula, where fee represents maker or taker fee:
size = (balance * buy_pct - (balance * buy_pct * fee)) / price
Let me know if this needs more clarification or if there is a clearer way. This worked really well with the Bittrex exchange and eliminated the Insufficient Funds problems that I was running into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I looked over - size
there. Gotcha.
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.