@@ -68,10 +68,10 @@ marketAveragePrice ::
68
68
forall (act :: BuyOrSell ) m .
69
69
( MonadUnliftIO m ,
70
70
MonadThrow m ,
71
- ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| act )),
71
+ ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| act )),
72
72
Typeable act
73
73
) =>
74
- Money (Tags 'Unsigned |+| 'Base |+| act ) ->
74
+ Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| act ) ->
75
75
CurrencyPair ->
76
76
m (Money (Tags 'Unsigned |+| 'QuotePerBase |+| act ))
77
77
marketAveragePrice amt sym =
@@ -119,9 +119,9 @@ spendableExchangeBalance ::
119
119
) =>
120
120
Env ->
121
121
CurrencyCode ->
122
- m (Money (Tags 'Unsigned))
122
+ m (Money (Tags 'Unsigned |+| 'MoneyAmount ))
123
123
spendableExchangeBalance env cc =
124
- maybe (newMoney 0 ) Wallets. availableBalance
124
+ maybe (Tagged 0 ) Wallets. availableBalance
125
125
. Map. lookup Wallets. Exchange
126
126
. Map. findWithDefault mempty cc
127
127
<$> wallets env
@@ -239,12 +239,13 @@ submitOrder ::
239
239
forall (bos :: BuyOrSell ) m .
240
240
( MonadUnliftIO m ,
241
241
MonadThrow m ,
242
- ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| bos )),
242
+ ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos )),
243
243
ToRequestParam (Money (Tags 'Unsigned |+| 'QuotePerBase |+| bos )),
244
+ Typeable bos ,
244
245
SingI bos
245
246
) =>
246
247
Env ->
247
- Money (Tags 'Unsigned |+| 'Base |+| bos ) ->
248
+ Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos ) ->
248
249
CurrencyPair ->
249
250
Money (Tags 'Unsigned |+| 'QuotePerBase |+| bos ) ->
250
251
SubmitOrder. Options bos ->
@@ -264,14 +265,14 @@ submitOrderMaker ::
264
265
forall (bos :: BuyOrSell ) m .
265
266
( MonadUnliftIO m ,
266
267
MonadThrow m ,
267
- ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| bos )),
268
+ ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos )),
268
269
ToRequestParam (Money (Tags 'Unsigned |+| 'QuotePerBase |+| bos )),
269
- MoneyTags (Tags 'Unsigned |+| 'Base |+| bos ),
270
+ MoneyTags (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos ),
270
271
MoneyTags (Tags 'Unsigned |+| 'QuotePerBase |+| bos ),
271
272
HasTag bos (Tags 'Unsigned |+| 'QuotePerBase |+| bos )
272
273
) =>
273
274
Env ->
274
- Money (Tags 'Unsigned |+| 'Base |+| bos ) ->
275
+ Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos ) ->
275
276
CurrencyPair ->
276
277
Money (Tags 'Unsigned |+| 'QuotePerBase |+| bos ) ->
277
278
SubmitOrder. Options bos ->
@@ -289,14 +290,14 @@ submitOrderMakerRec ::
289
290
forall (bos :: BuyOrSell ) m .
290
291
( MonadUnliftIO m ,
291
292
MonadThrow m ,
292
- ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| bos )),
293
+ ToRequestParam (Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos )),
293
294
ToRequestParam (Money (Tags 'Unsigned |+| 'QuotePerBase |+| bos )),
294
- MoneyTags (Tags 'Unsigned |+| 'Base |+| bos ),
295
+ MoneyTags (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos ),
295
296
MoneyTags (Tags 'Unsigned |+| 'QuotePerBase |+| bos ),
296
297
HasTag bos (Tags 'Unsigned |+| 'QuotePerBase |+| bos )
297
298
) =>
298
299
Env ->
299
- Money (Tags 'Unsigned |+| 'Base |+| bos ) ->
300
+ Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| bos ) ->
300
301
CurrencyPair ->
301
302
Int ->
302
303
Money (Tags 'Unsigned |+| 'QuotePerBase |+| bos ) ->
@@ -402,7 +403,7 @@ submitCounterOrder' ::
402
403
MonadThrow m
403
404
) =>
404
405
( Env ->
405
- Money (Tags 'Unsigned |+| 'Base |+| 'Sell) ->
406
+ Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| ' Sell) ->
406
407
CurrencyPair ->
407
408
Money (Tags 'Unsigned |+| 'QuotePerBase |+| 'Sell) ->
408
409
SubmitOrder. Options 'Sell ->
@@ -421,17 +422,17 @@ submitCounterOrder' submit env id0 feeB feeQ prof opts = do
421
422
SBuy | orderStatus remOrder == Executed -> do
422
423
(_, exitAmt, exitRate) <-
423
424
Math. newCounterOrder
424
- (tagMoney @ 'Gross (orderAmount remOrder))
425
- (tagMoney @ 'Net (orderRate remOrder))
425
+ (tag @ 'Gross (orderAmount remOrder))
426
+ (tag @ 'Net (orderRate remOrder))
426
427
feeB
427
428
feeQ
428
- (tagMoney @ 'Quote . tagMoney @ 'Buy $ tagMoney @ 'Net prof)
429
+ (tag @ 'Quote . tag @ 'Buy $ tag @ 'Net prof)
429
430
currentRate <-
430
- marketAveragePrice (unTagMoney @ 'Net exitAmt)
431
+ marketAveragePrice (unTag @ 'Net exitAmt)
431
432
$ orderSymbol remOrder
432
433
submit
433
434
env
434
- (unTagMoney @ 'Net exitAmt)
435
+ (unTag @ 'Net exitAmt)
435
436
(orderSymbol remOrder)
436
437
(max exitRate currentRate)
437
438
opts
@@ -444,7 +445,7 @@ dumpIntoQuote' ::
444
445
MonadThrow m
445
446
) =>
446
447
( Env ->
447
- Money (Tags 'Unsigned |+| 'Base |+| 'Sell) ->
448
+ Money (Tags 'Unsigned |+| 'Base |+| 'MoneyAmount |+| ' Sell) ->
448
449
CurrencyPair ->
449
450
Money (Tags 'Unsigned |+| 'QuotePerBase |+| 'Sell) ->
450
451
SubmitOrder. Options 'Sell ->
@@ -456,12 +457,12 @@ dumpIntoQuote' ::
456
457
m (Order 'Sell 'Remote)
457
458
dumpIntoQuote' submit env sym opts = do
458
459
amt <- spendableExchangeBalance env (currencyPairBase sym)
459
- rate <- marketAveragePrice (tagMoney @ 'Sell $ tagMoney @ 'Base amt) sym
460
+ rate <- marketAveragePrice (tag @ 'Sell $ tag @ 'Base amt) sym
460
461
catchAny
461
- (submit env (tagMoney @ 'Sell $ tagMoney @ 'Base amt) sym rate opts)
462
+ (submit env (tag @ 'Sell $ tag @ 'Base amt) sym rate opts)
462
463
. const
463
464
$ do
464
- newAmt <- Math. tweakMoneyPip (tagMoney @ 'Sell $ tagMoney @ 'Base amt)
465
+ newAmt <- Math. tweakMoneyPip (tag @ 'Sell $ tag @ 'Base amt)
465
466
submit env newAmt sym rate opts
466
467
467
468
dumpIntoQuote ::
@@ -492,7 +493,7 @@ netWorth ::
492
493
) =>
493
494
Env ->
494
495
CurrencyCode ->
495
- m (Money (Tags 'Unsigned))
496
+ m (Money (Tags 'Unsigned |+| 'MoneyAmount ))
496
497
netWorth env ccq = do
497
498
-- Simplify fees (assume it's alwayus Maker and Crypto2Crypto)
498
499
fee <- FeeSummary. makerCrypto2CryptoFee <$> feeSummary env
@@ -501,40 +502,42 @@ netWorth env ccq = do
501
502
res <-
502
503
foldrM
503
504
( \ (ccb, bs1) totalAcc -> do
504
- let localAcc :: Money (Tags 'Unsigned) =
505
+ let localAcc :: Money (Tags 'Unsigned |+| 'MoneyAmount ) =
505
506
foldr
506
507
( \ amt acc ->
507
508
Wallets. balance amt `addMoney` acc
508
509
)
509
- (newMoney 0 )
510
+ (Tagged 0 )
510
511
$ Map. elems bs1
511
512
if ccb == ccq
512
513
then pure $ totalAcc `addMoney` localAcc
513
514
else do
514
515
-- In this case we are dealing with Base
515
516
-- money, so we need transform from Quote
516
517
sym <- currencyPairCon (from ccb) $ Tagged @ 'Quote ccq
517
- baseMoney :: Money (Tags 'Unsigned |+| 'Base |+| 'Sell) <-
518
- fmap (tagMoney @ 'Base . tagMoney @ 'Sell) $ roundMoney localAcc
519
- if baseMoney == newMoney 0
518
+ baseMoney ::
519
+ Money (Tags 'Unsigned |+| 'Base |+| 'Sell |+| 'MoneyAmount) <-
520
+ fmap (tag @ 'Base . tag @ 'Sell) $ roundMoney localAcc
521
+ if baseMoney == Tagged 0
520
522
then pure totalAcc
521
523
else do
522
524
price :: Money (Tags 'Unsigned |+| 'QuotePerBase |+| 'Sell) <-
523
525
marketAveragePrice baseMoney sym
524
526
pure
525
527
. addMoney totalAcc
526
- . unTagMoney @ 'Net
527
- . unTagMoney @ 'Sell
528
- . unTagMoney @ 'Quote
528
+ . unTag @ 'Net
529
+ . unTag @ 'Sell
530
+ . unTag @ 'Quote
529
531
$ deductFee
532
+ @ (Tags 'Unsigned |+| 'FeeRate |+| 'Maker)
530
533
fee
531
- ( tagMoney @ 'Gross
534
+ ( tag @ 'Gross
532
535
$ exchangeMoney @ (Tags 'Unsigned |+| 'Sell)
533
536
price
534
537
baseMoney
535
538
)
536
539
)
537
- (newMoney 0 )
540
+ (Tagged 0 )
538
541
. filter
539
542
( \ (cc, _) ->
540
543
fromRight
0 commit comments