diff --git a/examples/configs/trader/sample_balanced.cfg b/examples/configs/trader/sample_balanced.cfg index 26b4adc87..372e89489 100644 --- a/examples/configs/trader/sample_balanced.cfg +++ b/examples/configs/trader/sample_balanced.cfg @@ -32,3 +32,6 @@ CARRYOVER_INCLUSION_PROBABILITY = 1.00 # virtual balance to use so we can smoothen out the curve. This also has the benefit of increasing order amounts placed by the bot. However, if this is set to a value greater than 0.0 then there is a likelihood that the bot will run out of the asset that has a virtual balance set. VIRTUAL_BALANCE_BASE = 0.0 VIRTUAL_BALANCE_QUOTE = 0.0 + +# additional spread to apply to the innermost level's spread (specified as a decimal number). This is useful when accounting for exchange fees. Leaving this at 0.0 disables this option. +SPREAD_PAD = 0.0 \ No newline at end of file diff --git a/plugins/balancedLevelProvider.go b/plugins/balancedLevelProvider.go index 148f0bdf3..8af3c72ab 100644 --- a/plugins/balancedLevelProvider.go +++ b/plugins/balancedLevelProvider.go @@ -29,6 +29,7 @@ type balancedLevelProvider struct { virtualBalanceQuote float64 // virtual balance to use so we can smoothen out the curve orderConstraints *model.OrderConstraints shouldRefresh bool // boolean for whether to generate levels, starts true + spreadPad float64 // precomputed before construction randGen *rand.Rand @@ -57,6 +58,7 @@ func makeBalancedLevelProvider( carryoverInclusionProbability float64, virtualBalanceBase float64, virtualBalanceQuote float64, + spreadPad float64, orderConstraints *model.OrderConstraints, ) api.LevelProvider { if minAmountSpread <= 0 { @@ -80,7 +82,7 @@ func makeBalancedLevelProvider( shouldRefresh := true return &balancedLevelProvider{ - spread: spread, + spread: spread, useMaxQuoteInTargetAmountCalc: useMaxQuoteInTargetAmountCalc, minAmountSpread: minAmountSpread, maxAmountSpread: maxAmountSpread, @@ -92,6 +94,7 @@ func makeBalancedLevelProvider( carryoverInclusionProbability: carryoverInclusionProbability, virtualBalanceBase: virtualBalanceBase, virtualBalanceQuote: virtualBalanceQuote, + spreadPad: spreadPad, orderConstraints: orderConstraints, randGen: randGen, shouldRefresh: shouldRefresh, @@ -106,6 +109,7 @@ func validateSpread(spread float64) { // GetLevels impl. func (p *balancedLevelProvider) GetLevels(maxAssetBase float64, maxAssetQuote float64) ([]api.Level, error) { + if !p.shouldRefresh { log.Println("no offers were taken, leave levels as they are") return p.lastLevels, nil @@ -183,7 +187,7 @@ func (p *balancedLevelProvider) getRandomSpread(minSpread float64, maxSpread flo } func (p *balancedLevelProvider) getLevel(maxAssetBase float64, maxAssetQuote float64) (api.Level, error) { - centerPrice := maxAssetQuote / maxAssetBase + centerPrice := (maxAssetQuote / maxAssetBase) * (1 + p.spreadPad) // price always adds the spread targetPrice := centerPrice * (1 + p.spread/2) diff --git a/plugins/balancedStrategy.go b/plugins/balancedStrategy.go index 9725327a3..370e41959 100644 --- a/plugins/balancedStrategy.go +++ b/plugins/balancedStrategy.go @@ -22,6 +22,7 @@ type balancedConfig struct { CarryoverInclusionProbability float64 `valid:"-" toml:"CARRYOVER_INCLUSION_PROBABILITY"` // probability of including the carryover at a level that will be added VirtualBalanceBase float64 `valid:"-" toml:"VIRTUAL_BALANCE_BASE"` // virtual balance to use so we can smoothen out the curve VirtualBalanceQuote float64 `valid:"-" toml:"VIRTUAL_BALANCE_QUOTE"` // virtual balance to use so we can smoothen out the curve + SpreadPad float64 `valid:"-" toml:"SPREAD_PAD"` } // String impl. @@ -58,6 +59,7 @@ func makeBalancedStrategy( config.CarryoverInclusionProbability, config.VirtualBalanceBase, config.VirtualBalanceQuote, + config.SpreadPad, orderConstraints), config.PriceTolerance, config.AmountTolerance, @@ -83,6 +85,7 @@ func makeBalancedStrategy( config.CarryoverInclusionProbability, config.VirtualBalanceQuote, config.VirtualBalanceBase, + config.SpreadPad, orderConstraints), config.PriceTolerance, config.AmountTolerance,