mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
fixedpoint: fix fixedpoint value int64 cast
This commit is contained in:
parent
ecf888dfd6
commit
ac71a392c6
|
@ -55,7 +55,11 @@ func (v Value) String() string {
|
|||
}
|
||||
|
||||
func (v Value) Int64() int64 {
|
||||
return int64(v)
|
||||
return int64(v.Float64())
|
||||
}
|
||||
|
||||
func (v Value) Int() int {
|
||||
return int(v.Float64())
|
||||
}
|
||||
|
||||
func (v Value) Mul(v2 Value) Value {
|
||||
|
@ -82,6 +86,10 @@ func (v Value) Floor() Value {
|
|||
return NewFromFloat(math.Floor(v.Float64()))
|
||||
}
|
||||
|
||||
func (v Value) Ceil() Value {
|
||||
return NewFromFloat(math.Ceil(v.Float64()))
|
||||
}
|
||||
|
||||
func (v Value) Sub(v2 Value) Value {
|
||||
return Value(int64(v) - int64(v2))
|
||||
}
|
||||
|
@ -292,7 +300,7 @@ func NumFractionalDigits(a Value) int {
|
|||
numPow++
|
||||
}
|
||||
numZeros := 0
|
||||
for v := a.Int64(); v%10 == 0; v /= 10 {
|
||||
for v := int64(a); v%10 == 0; v /= 10 {
|
||||
numZeros++
|
||||
}
|
||||
return numPow - numZeros
|
||||
|
|
|
@ -54,10 +54,10 @@ func (slice PriceVolumeSlice) First() (PriceVolume, bool) {
|
|||
}
|
||||
|
||||
func (slice PriceVolumeSlice) IndexByVolumeDepth(requiredVolume fixedpoint.Value) int {
|
||||
var tv int64 = 0
|
||||
var tv fixedpoint.Value = 0
|
||||
for x, el := range slice {
|
||||
tv += el.Volume.Int64()
|
||||
if tv >= requiredVolume.Int64() {
|
||||
tv += el.Volume
|
||||
if tv >= requiredVolume {
|
||||
return x
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user