Skip to content

Commit ab6ccd4

Browse files
committed
Fix Bfx.mkOrder rounding on Sell
1 parent 1f601a0 commit ab6ccd4

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

pub/bfx/bfx.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ test-suite bfx-test
192192
, base >=4.7 && <5
193193
, base16-bytestring
194194
, bytestring
195+
, conduit
195196
, containers
196197
, cryptonite
197198
, envparse

pub/bfx/src/Bfx.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,14 @@ mkOrder args = do
564564
pure
565565
$ mkOrderNetBaseAmt args
566566
grossBaseAmt <-
567-
case bos of
568-
Buy ->
569-
tweakMoneyAmount Buy
570-
. MoneyAmount
571-
$ unMoneyAmount netBaseAmt
572-
/ (1 - unFeeRate (mkOrderFee args))
573-
Sell ->
574-
pure netBaseAmt
567+
tweakMoneyAmount bos
568+
$ case bos of
569+
Buy ->
570+
MoneyAmount
571+
$ unMoneyAmount netBaseAmt
572+
/ (1 - unFeeRate (mkOrderFee args))
573+
Sell ->
574+
netBaseAmt
575575
price <-
576576
mkOrderMarketAveragePrice
577577
args

pub/bfx/test/BfxSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ spec = before sysEnv $ do
126126
& #limit
127127
.~ Just 5
128128
res `shouldSatisfy` isRight
129+
it "roundMoneyAmount" . const $ do
130+
amt <- roundMoneyAmount . MoneyAmount $ 3391591 % 10000000000
131+
amt `shouldBe` MoneyAmount (8479 % 25000000)
129132
it "mkOrder" . const $ do
130133
let req =
131134
Bfx.MkOrder

0 commit comments

Comments
 (0)