bitx-bitcoin 0.9.0.0 → 0.9.0.1
raw patch · 9 files changed
+51/−10 lines, 9 filesdep +exceptionsPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: exceptions
API changes (from Hackage documentation)
+ Network.Bitcoin.BitX.Types: instance Data.String.IsString Network.Bitcoin.BitX.Types.BitXAuth
Files
- CHANGES +6/−0
- bitx-bitcoin.cabal +2/−1
- src/Network/Bitcoin/BitX/Internal.hs +16/−4
- src/Network/Bitcoin/BitX/Private.hs +10/−0
- src/Network/Bitcoin/BitX/Private/Quote.hs +0/−1
- src/Network/Bitcoin/BitX/Private/Withdrawal.hs +0/−1
- src/Network/Bitcoin/BitX/Public.hs +1/−1
- src/Network/Bitcoin/BitX/Types.hs +15/−1
- test/Doctests.hs +1/−1
CHANGES view
@@ -1,3 +1,9 @@+v0.9.0.1+* Compatibility with http-client-0.5.0 and http-client-tls-0.3.0.++v0.9.0.0+* The BitXAuth type can now be written as a string using the OverloadedStrings extension.+ v0.9.0.0 * Use (strict) Text consistantly instead of random string-like types. BREAKING CHANGE.
bitx-bitcoin.cabal view
@@ -1,5 +1,5 @@ name: bitx-bitcoin-version: 0.9.0.0+version: 0.9.0.1 synopsis: A Haskell library for working with the BitX bitcoin exchange. description:@@ -63,6 +63,7 @@ build-depends: base >=4.5 && <5, aeson >= 0.8,+ exceptions, text, time, bytestring,
src/Network/Bitcoin/BitX/Internal.hs view
@@ -32,6 +32,7 @@ import Data.Text (Text, pack) import Data.Text.Encoding (decodeUtf8) import Data.Monoid ((<>))+import Control.Monad.Catch (MonadThrow) #if __GLASGOW_HASKELL__ >= 710 -- <$> is in base since 4.8 (GHC 7.10) due to the AMP import Control.Applicative ((<|>))@@ -48,6 +49,13 @@ globalManager :: IO NetCon.Manager globalManager = NetCon.newManager NetCon.tlsManagerSettings +psUrl :: MonadThrow m => String -> m Request+#if MIN_VERSION_http_client(0,5,0)+psUrl = NetCon.parseRequest+#else+psUrl = NetCon.parseUrl+#endif+ authConnect :: BitXAuth -> Request -> IO (Either NetCon.HttpException (Response BL.ByteString)) authConnect auth req = do manager <- globalManager@@ -60,7 +68,7 @@ simpleBitXGetAuth_ auth verb = withSocketsDo $ rateLimit (authConnect auth- . fromJust . NetCon.parseUrl $ Txt.unpack (bitXAPIRoot <> verb))+ . fromJust . psUrl $ Txt.unpack (bitXAPIRoot <> verb)) consumeResponseIO simpleBitXPOSTAuth_ :: (BitXAesRecordConvert recd, POSTEncodeable inprec) => BitXAuth -> inprec@@ -69,21 +77,21 @@ rateLimit (authConnect auth . NetCon.urlEncodedBody (postEncode encrec)- . fromJust . NetCon.parseUrl $ Txt.unpack (bitXAPIRoot <> verb))+ . fromJust . psUrl $ Txt.unpack (bitXAPIRoot <> verb)) consumeResponseIO simpleBitXMETHAuth_ :: BitXAesRecordConvert recd => BitXAuth -> BS.ByteString -> Text -> IO (BitXAPIResponse recd) simpleBitXMETHAuth_ auth meth verb = withSocketsDo $ rateLimit- (authConnect auth (fromJust (NetCon.parseUrl $ Txt.unpack (bitXAPIRoot <> verb))) { method = meth })+ (authConnect auth (fromJust (psUrl $ Txt.unpack (bitXAPIRoot <> verb))) { method = meth }) consumeResponseIO simpleBitXGet_ :: BitXAesRecordConvert recd => Text -> IO (BitXAPIResponse recd) simpleBitXGet_ verb = withSocketsDo $ do manager <- globalManager rateLimit- (try . flip NetCon.httpLbs manager . fromJust . NetCon.parseUrl $ Txt.unpack (bitXAPIRoot <> verb))+ (try . flip NetCon.httpLbs manager . fromJust . psUrl $ Txt.unpack (bitXAPIRoot <> verb)) consumeResponseIO rateLimit :: IO (Either NetCon.HttpException c) -> (Either NetCon.HttpException c -> IO d) -> IO d@@ -127,5 +135,9 @@ eitherToMaybe (Right b) = Just b isRateLimited :: Either NetCon.HttpException a -> Bool+#if MIN_VERSION_http_client(0,5,0)+isRateLimited (Left (NetCon.HttpExceptionRequest _ (NetCon.StatusCodeException r _ ))) = (responseStatus r == status503) || (responseStatus r == status429)+#else isRateLimited (Left (NetCon.StatusCodeException st _ _)) = st == status503 || st == status429+#endif isRateLimited _ = False
src/Network/Bitcoin/BitX/Private.hs view
@@ -27,6 +27,12 @@ -- ... -- @ --+-- With the OverloadedStrings extension enabled, one may also simply write+-- @+-- let auth = "dude:mySecret" :: BitXAuth+-- @+-- with a colon separating the id from the secret.+-- -- =Permissions -- -- Each API key is granted a set of permissions when it is created. The key can only be used to call@@ -45,6 +51,10 @@ -- * @Perm_W_Withdrawals = 256@ (Create withdrawals) -- * @Perm_R_Merchant = 512@ (View merchant invoices) -- * @Perm_W_Merchant = 1024@ (Create merchant invoices)+-- * @Perm_W_ClientDebit = 8192@ (Debit accounts)+-- * @Perm_W_ClientCredit = 16384@ (Credit accounts)+-- * @Perm_R_Beneficiaries = 32768@ (View beneficiaries)+-- * @Perm_W_Beneficiaries = 65536@ (Create and delete beneficiaries) -- -- A set of permissions is represented as the bitwise OR of each permission in the set. For example -- the set of permissions required to view balances and orders is @Perm_R_Balance | Perm_R_Orders =
src/Network/Bitcoin/BitX/Private/Quote.hs view
@@ -36,7 +36,6 @@ import Network.Bitcoin.BitX.Internal import Network.Bitcoin.BitX.Types import Data.Text (Text)-import qualified Data.Text as Txt import Network.Bitcoin.BitX.Response import Data.Monoid ((<>))
src/Network/Bitcoin/BitX/Private/Withdrawal.hs view
@@ -22,7 +22,6 @@ import Network.Bitcoin.BitX.Internal import Network.Bitcoin.BitX.Types-import qualified Data.Text as Txt import Data.Text (Text) import Network.Bitcoin.BitX.Response import Data.Monoid ((<>))
src/Network/Bitcoin/BitX/Public.hs view
@@ -19,7 +19,7 @@ --import qualified Network.Bitcoin.BitX as BitX --import Data.Text (unpack) --import Network.HTTP.Types.Status (Status(..))---import Network.HTTP.Conduit (responseStatus)+--import Network.HTTP.Client (responseStatus) -- --main :: IO () --main = do
src/Network/Bitcoin/BitX/Types.hs view
@@ -130,11 +130,12 @@ ) where import Data.Aeson (FromJSON(..))-import Data.Text (Text)+import Data.Text (Text, pack) import Data.Time.Clock import GHC.Generics (Generic) import Data.Scientific (Scientific) import Lens.Micro.TH (makeFields)+import Data.String (IsString(..)) type OrderID = Text @@ -269,6 +270,19 @@ makeFields ''BitXAuth type BitXClientAuth = BitXAuth++instance IsString BitXAuth where+ fromString auth =+ BitXAuth (pack $ fst cut) (pack $ tail $ snd cut)+ where+ cut = span (/= ':') auth++-- |+-- >>> :set -XOverloadedStrings+-- >>> "id:secret" :: BitXAuth+-- BitXAuth {bitXAuthId = "id", bitXAuthSecret = "secret"}+-- >>> "id:se:cret" :: BitXAuth+-- BitXAuth {bitXAuthId = "id", bitXAuthSecret = "se:cret"} -- | A recently placed (private) order, containing a lot more information than is available on the -- public order book.
test/Doctests.hs view
@@ -1,3 +1,3 @@ import Test.DocTest -main = doctest ["-isrc", "src/Network/Bitcoin/BitX/Types/Internal/Decimal.hs","src/Network/Bitcoin/BitX/Types/Internal.hs"]+main = doctest ["-isrc", "src/Network/Bitcoin/BitX/Types/Internal/Decimal.hs","src/Network/Bitcoin/BitX/Types/Internal.hs", "src/Network/Bitcoin/BitX/Types.hs"]