Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Fix baseAmount used when placing orders (closes #435) (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsaraf authored Jun 8, 2020
1 parent f7927c7 commit 25f3862
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion model/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var NumberConstants = struct {
One: NumberFromFloat(1.0, 16),
}

// InvertPrecision is the precision of the number after it is inverted
const InvertPrecision = 15

// Number abstraction
type Number struct {
value float64
Expand Down Expand Up @@ -131,7 +134,7 @@ func InvertNumber(n *Number) *Number {
if n == nil {
return nil
}
return NumberConstants.One.Divide(*n)
return NumberFromFloat(1.0/n.AsFloat(), InvertPrecision)
}

// NumberByCappingPrecision returns a number with a precision that is at max the passed in precision
Expand Down
5 changes: 4 additions & 1 deletion model/number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestUnaryOperations(t *testing.T) {
n: NumberFromFloat(0.2812, 3),
wantAbs: 0.281,
wantNegate: -0.281,
wantInvert: 3.559,
wantInvert: 3.558718861209964,
},
}

Expand All @@ -261,6 +261,9 @@ func TestUnaryOperations(t *testing.T) {
if !assert.Equal(t, kase.wantInvert, inverted.AsFloat()) {
return
}
if !assert.Equal(t, int8(15), inverted.precision) {
return
}
})
}
}
Expand Down

0 comments on commit 25f3862

Please sign in to comment.