bbgo_origin/bbgo/calc.go

40 lines
1.3 KiB
Go
Raw Normal View History

2020-06-18 15:46:59 +00:00
package bbgo
import (
"github.com/adshao/go-binance"
"math"
)
// this is for BTC
const MinQuantity = 0.00000100
// https://www.desmos.com/calculator/ircjhtccbn
func BuyVolumeModifier(price float64) float64 {
targetPrice := 7500.0 // we will get 1 at price 7500, and more below 7500
flatness := 1000.0 // higher number buys more in the middle section. higher number gets more flat line, reduced to 0 at price 2000 * 10
return math.Min(2, math.Exp(-(price-targetPrice)/flatness))
}
func SellVolumeModifier(price float64) float64 {
// \exp\left(\frac{x-10000}{500}\right)
targetPrice := 10500.0 // target to sell most x1 at 10000.0
flatness := 500.0 // higher number sells more in the middle section, lower number sells fewer in the middle section.
return math.Min(2, math.Exp((price-targetPrice)/flatness))
}
func VolumeByPriceChange(currentPrice float64, change float64, side binance.SideType) float64 {
volume := BaseVolumeByPriceChange(change)
if side == binance.SideTypeSell {
return volume * SellVolumeModifier(currentPrice)
}
return math.Max(MinQuantity, volume*BuyVolumeModifier(currentPrice))
}
func BaseVolumeByPriceChange(change float64) float64 {
return 0.12 * math.Exp((math.Abs(change)-3100.0)/1600.0)
// 0.116*math.Exp(math.Abs(change)/2400) - 0.1
}