Skip to content

Commit b948146

Browse files
committed
Asc or Desc parameter for bfx candle history
1 parent e5d0e2c commit b948146

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

pub/bfx/src/Bfx.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ candlesLast tf sym opts =
466466
Generic.pub
467467
@'CandlesLast
468468
( catMaybes
469-
[ SomeQueryParam "limit" <$> Candles.limit opts,
469+
[ SomeQueryParam "sort" <$> Candles.ascOrDesc opts,
470+
SomeQueryParam "limit" <$> Candles.limit opts,
470471
SomeQueryParam "start" <$> Candles.start opts,
471472
SomeQueryParam "end" <$> Candles.end opts
472473
]
@@ -490,7 +491,8 @@ candlesHist tf sym opts =
490491
Generic.pub
491492
@'CandlesHist
492493
( catMaybes
493-
[ SomeQueryParam "limit" <$> Candles.limit opts,
494+
[ SomeQueryParam "sort" <$> Candles.ascOrDesc opts,
495+
SomeQueryParam "limit" <$> Candles.limit opts,
494496
SomeQueryParam "start" <$> Candles.start opts,
495497
SomeQueryParam "end" <$> Candles.end opts
496498
]

pub/bfx/src/Bfx/Class/ToRequestParam.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ instance ToRequestParam QuotePerBase where
6767
. abs
6868
. from @(Ratio Natural) @Rational
6969
. unQuotePerBase
70+
71+
instance ToRequestParam AscOrDesc where
72+
toTextParam = \case
73+
Asc -> "1"
74+
Desc -> "-1"

pub/bfx/src/Bfx/Data/Candles.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ data Request = Request
4848
)
4949

5050
data Options = Options
51-
{ limit :: Maybe Natural,
51+
{ ascOrDesc :: Maybe AscOrDesc,
52+
limit :: Maybe Natural,
5253
start :: Maybe UTCTime,
5354
end :: Maybe UTCTime
5455
}
@@ -64,7 +65,8 @@ data Options = Options
6465
optsDef :: Options
6566
optsDef =
6667
Options
67-
{ limit = Just 10000,
68+
{ ascOrDesc = Nothing,
69+
limit = Just 10000,
6870
start = Nothing,
6971
end = Nothing
7072
}

pub/bfx/test/BfxSpec.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,22 @@ spec = before sysEnv $ do
108108
res <- tryAny . Bfx.netWorth env $ CurrencyCode "BTC"
109109
res `shouldSatisfy` isRight
110110
it "candlesLast succeeds" . const $ do
111-
res <- tryAny $ Bfx.candlesLast Ctf1h adaBtc Candles.optsDef
111+
res <-
112+
tryAny
113+
. Bfx.candlesLast Ctf1h adaBtc
114+
$ Candles.optsDef
115+
& #ascOrDesc
116+
.~ Just Desc
112117
res `shouldSatisfy` isRight
113118
it "candlesHist succeeds" . const $ do
114-
res <- tryAny $ Bfx.candlesHist Ctf1h adaBtc Candles.optsDef
119+
res <-
120+
tryAny
121+
. Bfx.candlesHist Ctf1h btcUsd
122+
$ Candles.optsDef
123+
& #ascOrDesc
124+
.~ Just Asc
125+
& #limit
126+
.~ Just 5
115127
res `shouldSatisfy` isRight
116128
it "mkOrder" . const $ do
117129
let req =

pub/functora/functora.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ test-suite functora-test
518518
build-depends:
519519
, aes
520520
, bolt11
521-
, card-lib
522521
, cfg
523522
, elm2miso-lib
524523
, functora

pub/functora/src/cfg/Functora/CfgOrphan.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Data.Binary.Instances ()
1616
import Functora.Prelude
1717
import qualified GHC.Generics as Generics
1818
import qualified Text.URI as URI
19+
import Toml (HasCodec, HasItemCodec)
1920
import qualified Toml
2021
#if defined(__GHCJS__) || defined(ghcjs_HOST_OS) || defined(wasi_HOST_OS)
2122
import Data.JSString (JSString)
@@ -237,3 +238,7 @@ instance Toml.HasItemCodec JSString where
237238
$ Toml.Text
238239
. from @JSString @Text
239240
#endif
241+
242+
deriving via GenericEnum AscOrDesc instance HasCodec AscOrDesc
243+
244+
deriving via GenericEnum AscOrDesc instance HasItemCodec AscOrDesc

pub/functora/src/prelude/Functora/Prelude.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ module Functora.Prelude
118118
Mono,
119119
dropAround,
120120
dropWhileEnd,
121+
AscOrDesc (..),
121122

122123
-- * DerivingVia
123124
-- $derivingVia
@@ -1129,6 +1130,20 @@ dropWhileEnd f =
11291130
)
11301131
mempty
11311132

1133+
data AscOrDesc
1134+
= Asc
1135+
| Desc
1136+
deriving stock
1137+
( Eq,
1138+
Ord,
1139+
Show,
1140+
Read,
1141+
Data,
1142+
Generic,
1143+
Enum,
1144+
Bounded
1145+
)
1146+
11321147
-- $derivingVia
11331148
-- Newtypes to simplify deriving via.
11341149
-- We have to expose default constructors/accessors

0 commit comments

Comments
 (0)