Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/configs/trader/sample_balanced.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions plugins/balancedLevelProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,7 @@ func makeBalancedLevelProvider(
carryoverInclusionProbability float64,
virtualBalanceBase float64,
virtualBalanceQuote float64,
spreadPad float64,
orderConstraints *model.OrderConstraints,
) api.LevelProvider {
if minAmountSpread <= 0 {
Expand All @@ -80,7 +82,7 @@ func makeBalancedLevelProvider(
shouldRefresh := true

return &balancedLevelProvider{
spread: spread,
spread: spread,
useMaxQuoteInTargetAmountCalc: useMaxQuoteInTargetAmountCalc,
minAmountSpread: minAmountSpread,
maxAmountSpread: maxAmountSpread,
Expand All @@ -92,6 +94,7 @@ func makeBalancedLevelProvider(
carryoverInclusionProbability: carryoverInclusionProbability,
virtualBalanceBase: virtualBalanceBase,
virtualBalanceQuote: virtualBalanceQuote,
spreadPad: spreadPad,
orderConstraints: orderConstraints,
randGen: randGen,
shouldRefresh: shouldRefresh,
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions plugins/balancedStrategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -58,6 +59,7 @@ func makeBalancedStrategy(
config.CarryoverInclusionProbability,
config.VirtualBalanceBase,
config.VirtualBalanceQuote,
config.SpreadPad,
orderConstraints),
config.PriceTolerance,
config.AmountTolerance,
Expand All @@ -83,6 +85,7 @@ func makeBalancedStrategy(
config.CarryoverInclusionProbability,
config.VirtualBalanceQuote,
config.VirtualBalanceBase,
config.SpreadPad,
orderConstraints),
config.PriceTolerance,
config.AmountTolerance,
Expand Down