Change the volume calculation so the trade stays market neutral #326
No reviewers
Labels
No labels
blocked
breaking
bug
dependencies
duplicate
enhancement
good first issue
help wanted
question
tech debt
testing
wontfix
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set.
Reference
scion/arbitrader!326
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-325"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The goal is to have a profit independent from the market moves.
I realize this is being super nitpicky and has no effect on how the code runs but I've tried really hard in the code to always do long then short so it's always in the same order. I think that kind of consistency helps make the code easier to read and more predictable.
Is this still a TODO? It looks like the lines following it are making the adjustment.
This is still a TODO. The next line only adjust the orders to the echange steps, they don't ensure that shortVolume = longVolume * feeFactor
No problem. I intend to refactor the volume calculation according to the maths in this comment: https://github.com/scionaltera/arbitrader/issues/325#issuecomment-776331413
@ -577,0 +612,4 @@tradeVolume.getShortOrderVolume(),shortLimitPrice,spread.getShortTicker().getBid().toPlainString(),spread.getCurrencyPair().counter.getSymbol(),Would it make sense to make a new object like
TradeVolumeswith twoBigDecimals in it so you could have a methodgetTradeVolumes(...)that just figures it all out in one shot and hands it to you?I do like having the lower level methods available to get long from short and short from long, but in the higher level trade logic it might be nice to hide the details.
I like how you broke these up. It would make it pretty easy to make them package private and write unit tests to guarantee they're doing the math correctly. ;)
@ -577,0 +612,4 @@tradeVolume.getShortOrderVolume(),shortLimitPrice,spread.getShortTicker().getBid().toPlainString(),spread.getCurrencyPair().counter.getSymbol(),I like the idea, a TradeVolumes could hold the 4 volumes (long, long adjusted for FeeComputation.CLIENT, short, short adjusted for FeeComputation.CLIENT) and hold the logic to adjust the volumes according to the fees/step size etc.
@ -577,0 +612,4 @@tradeVolume.getShortOrderVolume(),shortLimitPrice,spread.getShortTicker().getBid().toPlainString(),spread.getCurrencyPair().counter.getSymbol(),I will move the methods to a TradeVolumes class, and each public method of the class could be unit tested to make sure our volume related maths is correct.
Instead of calculating the volumes - that was leading to rounding issues for
FeeComputation.CLIENTexchanges - we now calculate the fees directly and we make sure everything is rounded properly.As we decided to remove support for certain configuration, I had to add a couple of
IllegalArgumentException, but ideally the exchange that would trigger those exceptions should be disabled during start up (this should be part of a future PR).The configuration not supported are:
FeeComputation.CLIENTexchanges with and amount step sizeFeeComputation.CLIENTexchanges with fees >= 1%. Calculating the volume to order is only an approximation that could have an error between -scale/2 and scale/2. For the fee calculation, that leads to an error margin ofscale/2 * feeand to make sure that the approximation is not causing a rounding issue, we limit the fee to 1%Also the exit trade does not check the amount step size or scale as the entry trade should have taken care of that, and will throw an exception if it happens.
Can you merge master into this branch?
@ -232,0 +257,4 @@return;}logEntryTrade(spread, shortExchangeName, longExchangeName, exitTarget, tradeVolume, longFeeComputation, shortFeeComputation, longLimitPrice, shortLimitPrice, isForcedOpenCondition);Can you pass in here the minimum profit and the market neutrality value and then format the email and instant notification (telegram message) to include them?
First you need to merge master into this branch otherwise you won't have this new instant message code.