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