Skip to content

Commit eb5366f

Browse files
QuotedInt was not reading BitX data properly since BitX returns ints as decimals.
1 parent b48673e commit eb5366f

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

src/Network/Bitcoin/BitX/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ simpleBitXGet_ verb = withSocketsDo $ do
8181
consumeResponseIO
8282

8383
rateLimit :: IO (Either NetCon.HttpException c) -> (Either NetCon.HttpException c -> IO d) -> IO d
84-
rateLimit act1 act2 = go 500000
84+
rateLimit act1 act2 = go (500 * 000)
8585
where
8686
go del = do
8787
resp <- act1

src/Network/Bitcoin/BitX/Types/Internal.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, TypeFamilies,
2-
FlexibleContexts, FlexibleInstances, DataKinds, CPP, RecordWildCards #-}
1+
{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, TypeFamilies, FlexibleContexts,
2+
FlexibleInstances, DataKinds, CPP, RecordWildCards #-}
33

44
module Network.Bitcoin.BitX.Types.Internal
55
(
@@ -69,7 +69,7 @@ instance FromJSON QuotedScientific where
6969
parseJSON _ = mempty
7070

7171
instance FromJSON QuotedInt where
72-
parseJSON (String x) = return . QuotedInt . read . Txt.unpack $ x
72+
parseJSON (String x) = return . QuotedInt . (truncate :: Scientific -> Int) . read . Txt.unpack $ x
7373
parseJSON (Number x) = return . QuotedInt . (truncate :: Scientific -> Int) . read . show $ x
7474
parseJSON _ = mempty
7575

test/Network/Bitcoin/BitX/Spec/Specs/AesonRecordSpec.hs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ spec =
1919
BitXError {bitXErrorError = "oops", bitXErrorErrorCode = "ABadError"}
2020
it "Ticker is parsed properly" $
2121
recordAesCheck
22-
"{\"timestamp\":1431811395699,\"bid\":\"3083\",\"ask\":\"3115\",\
23-
\ \"last_trade\":\"3116\",\"rolling_24_hour_volume\":\"19.776608\",\"pair\":\"XBTZAR\"}"
22+
"{\"timestamp\":1431811395699,\"bid\":\"3083.00\",\"ask\":\"3115.00\",\
23+
\ \"last_trade\":\"3116.00\",\"rolling_24_hour_volume\":\"19.776608\",\"pair\":\"XBTZAR\"}"
2424
Ticker {
2525
tickerTimestamp = posixSecondsToUTCTime 1431811395.699,
2626
tickerBid = 3083,
@@ -30,18 +30,18 @@ spec =
3030
tickerPair = XBTZAR}
3131
it "Balance is parsed properly" $
3232
recordAesCheck
33-
"{\"account_id\":\"314159\",\"asset\":\"ZAR\",\"balance\":\"2159.15\",\"reserved\":\"320\",\
34-
\ \"unconfirmed\":\"175\"}"
33+
"{\"account_id\":\"314159\",\"asset\":\"ZAR\",\"balance\":\"2159.15\",\"reserved\":\"320.43\",\
34+
\ \"unconfirmed\":\"175.34\"}"
3535
Balance
3636
{balanceId = "314159",
3737
balanceAsset = ZAR,
3838
balanceBalance = 2159.15,
39-
balanceReserved = 320,
40-
balanceUnconfirmed = 175}
39+
balanceReserved = 320.43,
40+
balanceUnconfirmed = 175.34}
4141
it "Order is parsed properly" $
4242
recordAesCheck
43-
"{\"volume\":\"314159\",\"price\":4321}"
44-
Order {orderVolume = 314159, orderPrice = 4321}
43+
"{\"volume\":\"314159.26\",\"price\":4321.00}"
44+
Order {orderVolume = 314159.26, orderPrice = 4321}
4545
it "WithdrawalRequest is parsed properly" $
4646
recordAesCheck
4747
"{\"status\":\"PENDING\",\"id\":\"271828\"}"
@@ -50,35 +50,35 @@ spec =
5050
withdrawalRequestId = "271828" }
5151
it "Tickers is parsed properly" $
5252
recordAesCheck
53-
"{\"tickers\":[{\"timestamp\":1431811395699,\"bid\":\"3083\",\"ask\":\"3115\",\
54-
\ \"last_trade\":\"3116\",\"rolling_24_hour_volume\":\"19.776608\",\
53+
"{\"tickers\":[{\"timestamp\":1431811395699,\"bid\":\"3083.00\",\"ask\":\"3115.00\",\
54+
\ \"last_trade\":\"3116.00\",\"rolling_24_hour_volume\":\"19.776608\",\
5555
\ \"pair\":\"XBTZAR\"}]}"
5656
[tickerInner]
5757
it "Orderbook is parsed properly" $
5858
recordAesCheck
59-
"{\"timestamp\":1431811395699,\"bids\":[{\"volume\":\"654.98\",\"price\":\"3789\"}],\
60-
\ \"asks\":[{\"volume\":\"654.98\",\"price\":\"3789\"}]}"
59+
"{\"timestamp\":1431811395699,\"bids\":[{\"volume\":\"654.98\",\"price\":\"3789.00\"}],\
60+
\ \"asks\":[{\"volume\":\"654.98\",\"price\":\"3789.00\"}]}"
6161
Orderbook
6262
{orderbookTimestamp = posixSecondsToUTCTime 1431811395.699,
6363
orderbookBids = [orderInner],
6464
orderbookAsks = [orderInner]}
6565
it "Trade is parsed properly" $
6666
recordAesCheck
67-
"{\"timestamp\":1431811395699,\"volume\":\"6754.09\",\"price\":\"5327\"}"
67+
"{\"timestamp\":1431811395699,\"volume\":\"6754.09\",\"price\":\"5327.00\"}"
6868
Trade
6969
{tradeTimestamp = posixSecondsToUTCTime 1431811395.699,
7070
tradeVolume = 6754.09,
7171
tradePrice = 5327}
7272
it "PublicTrades is parsed properly" $
7373
recordAesCheck
7474
"{\"trades\":[{\"timestamp\":1431811395699,\"volume\":\"6754.09\",\
75-
\ \"price\":\"5327\"}],\"currency\":\"ZAR\"}"
75+
\ \"price\":\"5327.00\"}],\"currency\":\"ZAR\"}"
7676
[tradeInner]
7777
it "PrivateOrder is parsed properly" $
7878
recordAesCheck
7979
"{\"base\":\"568.7\", \"counter\":3764.2,\"creation_timestamp\":478873467, \
8080
\ \"expiration_timestamp\":8768834222, \"fee_base\":\"3687.3\", \"fee_counter\":12.9,\
81-
\ \"limit_price\":765,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
81+
\ \"limit_price\":765.00,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
8282
\ \"state\":\"COMPLETE\",\"type\":\"BID\"}"
8383
PrivateOrder
8484
{privateOrderBase = 568.7,
@@ -97,7 +97,7 @@ spec =
9797
recordAesCheck
9898
"{\"orders\":[{\"base\":\"568.7\", \"counter\":3764.2,\"creation_timestamp\":478873467, \
9999
\ \"expiration_timestamp\":8768834222, \"fee_base\":\"3687.3\", \"fee_counter\":12.9,\
100-
\ \"limit_price\":765,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
100+
\ \"limit_price\":765.00,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
101101
\ \"state\":\"COMPLETE\",\"type\":\"BID\"}]}"
102102
[privateOrderInner]
103103
it "OrderID is parsed properly" $
@@ -106,7 +106,7 @@ spec =
106106
("57983" :: OrderID)
107107
it "PublicTrades is parsed properly" $
108108
recordAesCheck
109-
"{\"trades\":[{\"timestamp\":1431811395699,\"volume\":\"6754.09\",\"price\":\"5327\"}], \
109+
"{\"trades\":[{\"timestamp\":1431811395699,\"volume\":\"6754.09\",\"price\":\"5327.00\"}], \
110110
\ \"currency\":\"ZAR\"}"
111111
[tradeInner]
112112
it "RequestSuccess is parsed properly" $
@@ -117,9 +117,9 @@ spec =
117117
recordAesCheck
118118
"{\"base\":\"568.7\", \"counter\":3764.2,\"creation_timestamp\":478873467, \
119119
\ \"expiration_timestamp\":8768834222, \"fee_base\":\"3687.3\", \"fee_counter\":12.9,\
120-
\ \"limit_price\":765,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
120+
\ \"limit_price\":765.00,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
121121
\ \"state\":\"COMPLETE\",\"type\":\"BID\", \"trades\":[{\"timestamp\":1431811395699, \
122-
\ \"volume\":\"6754.09\",\"price\":\"5327\"}]}"
122+
\ \"volume\":\"6754.09\",\"price\":\"5327.00\"}]}"
123123
PrivateOrderWithTrades
124124
{privateOrderWithTradesBase = 568.7,
125125
privateOrderWithTradesCounter = 3764.2,

test/Network/Bitcoin/BitX/Spec/Specs/JsonSpec.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ spec =
3131
(Order 314159 4321)
3232
it "QuotedInt is parsed when quoted" $
3333
recordAesCheck
34-
"{\"volume\":0,\"price\":\"4321\"}"
34+
"{\"volume\":0,\"price\":\"4321.00\"}"
3535
(Order 0 4321)
3636
it "QuotedInt is parsed when not quoted" $
3737
recordAesCheck
38-
"{\"volume\":0,\"price\":4321}"
38+
"{\"volume\":0,\"price\":4321.00}"
3939
(Order 0 4321)
4040
it "OrderType BUY is parsed properly" $
4141
recordAesCheck
4242
"{\"base\":\"568.7\", \"counter\":3764.2,\"creation_timestamp\":478873467, \
4343
\\"expiration_timestamp\":8768834222, \"fee_base\":\"3687.3\", \"fee_counter\":12.9,\
44-
\\"limit_price\":765,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
44+
\\"limit_price\":765.00,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
4545
\\"state\":\"COMPLETE\",\"type\":\"BUY\"}"
4646
PrivateOrder
4747
{privateOrderBase = 568.7,
@@ -60,7 +60,7 @@ spec =
6060
recordAesCheck
6161
"{\"base\":\"568.7\", \"counter\":3764.2,\"creation_timestamp\":478873467, \
6262
\\"expiration_timestamp\":8768834222, \"fee_base\":\"3687.3\", \"fee_counter\":12.9,\
63-
\\"limit_price\":765,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
63+
\\"limit_price\":765.00,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
6464
\\"state\":\"COMPLETE\",\"type\":\"BID\"}"
6565
PrivateOrder
6666
{privateOrderBase = 568.7,
@@ -79,7 +79,7 @@ spec =
7979
recordAesCheck
8080
"{\"base\":\"568.7\", \"counter\":3764.2,\"creation_timestamp\":478873467, \
8181
\\"expiration_timestamp\":8768834222, \"fee_base\":\"3687.3\", \"fee_counter\":12.9,\
82-
\\"limit_price\":765,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
82+
\\"limit_price\":765.00,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
8383
\\"state\":\"COMPLETE\",\"type\":\"ASK\"}"
8484
PrivateOrder
8585
{privateOrderBase = 568.7,
@@ -98,7 +98,7 @@ spec =
9898
recordAesCheck
9999
"{\"base\":\"568.7\", \"counter\":3764.2,\"creation_timestamp\":478873467, \
100100
\\"expiration_timestamp\":8768834222, \"fee_base\":\"3687.3\", \"fee_counter\":12.9,\
101-
\\"limit_price\":765,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
101+
\\"limit_price\":765.00,\"limit_volume\":55.2,\"order_id\":\"83YG\",\"pair\":\"NADXBT\",\
102102
\\"state\":\"COMPLETE\",\"type\":\"SELL\"}"
103103
PrivateOrder
104104
{privateOrderBase = 568.7,

test/Network/Bitcoin/BitX/Spec/Specs/PostSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec =
1717
{orderRequestPair = XBTZAR,
1818
orderRequestOrderType = BID,
1919
orderRequestVolume = 83.02,
20-
orderRequestPrice = 15 }
20+
orderRequestPrice = 15}
2121
`shouldBe`
2222
[("pair", "XBTZAR"),
2323
("type", "BID"),

test/Network/Bitcoin/BitX/Spec/Specs/PrivateSpec.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import Network.Bitcoin.BitX.Spec.Specs.NetSpec
1919
--import Text.Show.Pretty (parseValue, valToStr)
2020
import Safe
2121

22+
-- To use this spec, create a file called "PRIVATE_API_KEY" with the private key and secret, respectively.
23+
-- placed on their own lines.
24+
--
25+
-- To ensure that nothing funny happens, you can create an Api key without the Perm_W_Withdrawals
26+
-- permission.
27+
2228
spec :: Spec
2329
spec = describe "Private functionality test" $ do
2430
mauth <- runIO privateAuth

0 commit comments

Comments
 (0)