mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
fix: set backtest cancel Delta to be 1e-11
This commit is contained in:
parent
7455279517
commit
a3a262783f
|
@ -790,8 +790,7 @@ func (dn Value) Int64() int64 {
|
|||
return 0
|
||||
}
|
||||
if dn.sign != signNegInf && dn.sign != signPosInf {
|
||||
if 0 < dn.exp && dn.exp < digitsMax &&
|
||||
(dn.coef%pow10[digitsMax-dn.exp]) == 0 { // usual case
|
||||
if 0 < dn.exp && dn.exp < digitsMax {
|
||||
return int64(dn.sign) * int64(dn.coef/pow10[digitsMax-dn.exp])
|
||||
} else if dn.exp <= 0 && dn.coef != 0 {
|
||||
result := math.Log10(float64(dn.coef)) - float64(digitsMax) + float64(dn.exp)
|
||||
|
|
|
@ -149,6 +149,12 @@ func (s *Strategy) generateGridSellOrders(session *bbgo.ExchangeSession) ([]type
|
|||
numGrids := fixedpoint.NewFromInt(s.GridNum)
|
||||
gridSpread := priceRange.Div(numGrids)
|
||||
|
||||
if gridSpread.IsZero() {
|
||||
return nil, fmt.Errorf(
|
||||
"either numGrids(%v) is too big or priceRange(%v) is too small, "+
|
||||
"the differences of grid prices become zero", numGrids, priceRange)
|
||||
}
|
||||
|
||||
// find the nearest grid price from the current price
|
||||
startPrice := fixedpoint.Max(
|
||||
s.LowerPrice,
|
||||
|
@ -156,9 +162,9 @@ func (s *Strategy) generateGridSellOrders(session *bbgo.ExchangeSession) ([]type
|
|||
s.UpperPrice.Sub(currentPrice).Div(gridSpread).Trunc().Mul(gridSpread)))
|
||||
|
||||
if startPrice.Compare(s.UpperPrice) > 0 {
|
||||
return nil, fmt.Errorf("current price %s exceeded the upper price boundary %s",
|
||||
currentPrice.String(),
|
||||
s.UpperPrice.String())
|
||||
return nil, fmt.Errorf("current price %v exceeded the upper price boundary %v",
|
||||
currentPrice,
|
||||
s.UpperPrice)
|
||||
}
|
||||
|
||||
balances := session.Account.Balances()
|
||||
|
@ -230,13 +236,20 @@ func (s *Strategy) generateGridBuyOrders(session *bbgo.ExchangeSession) ([]types
|
|||
}
|
||||
|
||||
if currentPrice.Compare(s.LowerPrice) < 0 {
|
||||
return nil, fmt.Errorf("current price %s is lower than the lower price %s", currentPrice.String(), s.LowerPrice.String())
|
||||
return nil, fmt.Errorf("current price %v is lower than the lower price %v",
|
||||
currentPrice, s.LowerPrice)
|
||||
}
|
||||
|
||||
priceRange := s.UpperPrice.Sub(s.LowerPrice)
|
||||
numGrids := fixedpoint.NewFromInt(s.GridNum)
|
||||
gridSpread := priceRange.Div(numGrids)
|
||||
|
||||
if gridSpread.IsZero() {
|
||||
return nil, fmt.Errorf(
|
||||
"either numGrids(%v) is too big or priceRange(%v) is too small, "+
|
||||
"the differences of grid prices become zero", numGrids, priceRange)
|
||||
}
|
||||
|
||||
// Find the nearest grid price for placing buy orders:
|
||||
// buyRange = currentPrice - lowerPrice
|
||||
// numOfBuyGrids = Floor(buyRange / gridSpread)
|
||||
|
@ -250,7 +263,7 @@ func (s *Strategy) generateGridBuyOrders(session *bbgo.ExchangeSession) ([]types
|
|||
currentPrice.Sub(s.LowerPrice).Div(gridSpread).Trunc().Mul(gridSpread)))
|
||||
|
||||
if startPrice.Compare(s.LowerPrice) < 0 {
|
||||
return nil, fmt.Errorf("current price %s exceeded the lower price boundary %v",
|
||||
return nil, fmt.Errorf("current price %v exceeded the lower price boundary %v",
|
||||
currentPrice,
|
||||
s.UpperPrice)
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ func (a *Account) UseLockedBalance(currency string, fund fixedpoint.Value) error
|
|||
return fmt.Errorf("trying to use more than locked: locked %v < want to use %v", balance.Locked, fund)
|
||||
}
|
||||
|
||||
var QuantityDelta = fixedpoint.MustNewFromString("0.0000000000001")
|
||||
var QuantityDelta = fixedpoint.MustNewFromString("0.00000000001")
|
||||
|
||||
func (a *Account) UnlockBalance(currency string, unlocked fixedpoint.Value) error {
|
||||
a.Lock()
|
||||
|
|
Loading…
Reference in New Issue
Block a user