Fee correction
Correct the sell/exit order amount
Last updated
Correct the sell/exit order amount
Last updated
Call PlaceExitPositionOrder
in order to close your position to prevent overselling due to fees.
When using unmanaged trade signals it good to think about the fee. When we buy 1 BTC, it doesn't mean we get 1 BTC. The exchange will deduct its portion of the fees from either your traded amount or your wallet, leaving us with a little less than 1 BTC. Let's say we pay 0.2% fee. After buying 1 BTC, we get 0.998 BTC and the exchange takes 0.002. Now, if we execute a sell order of 1 BTC, it might not execute if we didn't have a little extra BTC already.
Not taking fee in consideration can have a domino effect. Let's say we are scripting a market making bot. The bot has 3 slots. It places 3 buy orders of 1 BTC each and they are all filled. The exchange deducts the fees of 0.006 BTC and we are left with 2.994 BTC. The scripts executes 3 sell orders. After the first sell order, the position is 1.994 BTC, after the second order, 0.994 BTC. Once the third order is completed the open position is closed and we are left with 0.006 BTC - 0.002 BTC the exchange takes. At this moment the bot has sold 0.004 BTC more than it has bought. It has an unintended short position. If this cycle happens again, the bot has an open short position of 0.008 BTC.
Although this is a very inconvenient issue, it's also very easily solved. When we want to exit the position (sell what we have bought) we use the PlaceExitPositionOrder command. This will place an order with the exact amount as your open position, keeping fees into consideration.
The Marking Making Slot is a perfect example on how this can be applied