Skip to content

Commit 926518a

Browse files
committed
bfx wip
1 parent 231333a commit 926518a

File tree

5 files changed

+98
-6
lines changed

5 files changed

+98
-6
lines changed

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ else
7373
pub/universum/*.cabal
7474
pub/functora/*.cabal
7575
pub/xlsx/*.cabal
76+
pub/bfx/*.cabal
7677
ghcjs/*/*.cabal
7778
optional-packages:
7879
prv/*/*.cabal

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import Bfx.Orphan ()
4545
import Data.Aeson (withText)
4646
import qualified Data.Aeson as A
4747
import qualified Data.Text as T
48-
import Language.Haskell.TH.Syntax as TH (Lift)
4948
import qualified Network.HTTP.Client as Web
5049
import qualified Prelude
5150

@@ -394,8 +393,7 @@ data CurrencyPair = CurrencyPair
394393
( Eq,
395394
Ord,
396395
Show,
397-
Generic,
398-
TH.Lift
396+
Generic
399397
)
400398

401399
instance FromJSON CurrencyPair where

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ instance From RawResponse ByteString
110110

111111
instance Show RawResponse where
112112
show x =
113-
case decodeUtf8' bs of
113+
case decodeUtf8Strict bs of
114114
Left {} -> "ByteString RawResponse" <> inspect (BS.unpack bs)
115115
Right res -> "Text RawResponse " <> T.unpack res
116116
where

pub/bfx/src/Bfx/Rpc/Generic.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ pub qs req = do
5050
Web.setQueryString
5151
(unQueryParam <$> qs)
5252
$ webReq0
53-
{ Web.method = inspect $ toRequestMethod @method
53+
{ Web.method =
54+
encodeUtf8
55+
. inspect @Text
56+
$ toRequestMethod @method
5457
}
5558
webRes <-
5659
liftIO $ Web.httpLbs webReq1 manager
@@ -94,7 +97,7 @@ prv env req = do
9497
let nonce = encodeUtf8 (inspect nonce' :: Text)
9598
let webReq1 =
9699
webReq0
97-
{ Web.method = inspect $ toRequestMethod @method,
100+
{ Web.method = encodeUtf8 . inspect @Text $ toRequestMethod @method,
98101
Web.requestBody = Web.RequestBodyLBS reqBody,
99102
Web.requestHeaders =
100103
[ ( "Content-Type",

pub/functora/src/money/Functora/MoneySing.hs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,93 @@ instance TestEquality (Sing :: GainOrLose -> Type) where
133133
testEquality SGain SGain = Just Refl
134134
testEquality SLose SLose = Just Refl
135135
testEquality _ _ = Nothing
136+
137+
--
138+
-- BaseOrQuote
139+
--
140+
141+
data instance Sing (x :: BaseOrQuote) where
142+
SBase :: Sing 'Base
143+
SQuote :: Sing 'Quote
144+
145+
instance SingKind BaseOrQuote where
146+
type Demote BaseOrQuote = BaseOrQuote
147+
fromSing SBase = Base
148+
fromSing SQuote = Quote
149+
toSing Base = SomeSing SBase
150+
toSing Quote = SomeSing SQuote
151+
152+
instance SingI 'Base where sing = SBase
153+
154+
instance SingI 'Quote where sing = SQuote
155+
156+
instance TestEquality (Sing :: BaseOrQuote -> Type) where
157+
testEquality SBase SBase = Just Refl
158+
testEquality SQuote SQuote = Just Refl
159+
testEquality _ _ = Nothing
160+
161+
--
162+
-- MoneyKind
163+
--
164+
165+
data instance Sing (x :: MoneyKind) where
166+
SMoneyAmount :: Sing 'MoneyAmount
167+
SCurrency :: Sing 'Currency
168+
SQuotePerBase :: Sing 'QuotePerBase
169+
SFeeRate :: Sing 'FeeRate
170+
SProfitRate :: Sing 'ProfitRate
171+
172+
instance SingKind MoneyKind where
173+
type Demote MoneyKind = MoneyKind
174+
fromSing SMoneyAmount = MoneyAmount
175+
fromSing SCurrency = Currency
176+
fromSing SQuotePerBase = QuotePerBase
177+
fromSing SFeeRate = FeeRate
178+
fromSing SProfitRate = ProfitRate
179+
toSing MoneyAmount = SomeSing SMoneyAmount
180+
toSing Currency = SomeSing SCurrency
181+
toSing QuotePerBase = SomeSing SQuotePerBase
182+
toSing FeeRate = SomeSing SFeeRate
183+
toSing ProfitRate = SomeSing SProfitRate
184+
185+
instance SingI 'MoneyAmount where sing = SMoneyAmount
186+
187+
instance SingI 'Currency where sing = SCurrency
188+
189+
instance SingI 'QuotePerBase where sing = SQuotePerBase
190+
191+
instance SingI 'FeeRate where sing = SFeeRate
192+
193+
instance SingI 'ProfitRate where sing = SProfitRate
194+
195+
instance TestEquality (Sing :: MoneyKind -> Type) where
196+
testEquality SMoneyAmount SMoneyAmount = Just Refl
197+
testEquality SCurrency SCurrency = Just Refl
198+
testEquality SQuotePerBase SQuotePerBase = Just Refl
199+
testEquality SFeeRate SFeeRate = Just Refl
200+
testEquality SProfitRate SProfitRate = Just Refl
201+
testEquality _ _ = Nothing
202+
203+
--
204+
-- MakerOrTaker
205+
--
206+
207+
data instance Sing (x :: MakerOrTaker) where
208+
SMaker :: Sing 'Maker
209+
STaker :: Sing 'Taker
210+
211+
instance SingKind MakerOrTaker where
212+
type Demote MakerOrTaker = MakerOrTaker
213+
fromSing SMaker = Maker
214+
fromSing STaker = Taker
215+
toSing Maker = SomeSing SMaker
216+
toSing Taker = SomeSing STaker
217+
218+
instance SingI 'Maker where sing = SMaker
219+
220+
instance SingI 'Taker where sing = STaker
221+
222+
instance TestEquality (Sing :: MakerOrTaker -> Type) where
223+
testEquality SMaker SMaker = Just Refl
224+
testEquality STaker STaker = Just Refl
225+
testEquality _ _ = Nothing

0 commit comments

Comments
 (0)