packages feed

bittrex 0.2.0.0 → 0.3.0.0

raw patch · 5 files changed

+87/−24 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Bittrex.API: getOrderBook :: MarketName -> OrderBookType -> IO (Either ErrorMessage [OrderBook])
- Bittrex.Types: Both :: OrderBookType
- Bittrex.Types: Buy :: OrderBookType
- Bittrex.Types: Sell :: OrderBookType
- Bittrex.Types: data OrderBookType
- Bittrex.Types: instance GHC.Classes.Eq Bittrex.Types.OrderBookType
- Bittrex.Types: instance GHC.Show.Show Bittrex.Types.OrderBookType
+ Bittrex.API: getOrderBookBuys :: MarketName -> IO (Either ErrorMessage [OrderBookEntry])
+ Bittrex.API: getOrderBookSells :: MarketName -> IO (Either ErrorMessage [OrderBookEntry])
+ Bittrex.Types: MarketSummary :: MarketName -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Time -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Text -> Maybe Text -> MarketSummary
+ Bittrex.Types: Time :: UTCTime -> Time
+ Bittrex.Types: [mhAsk] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhBaseVolume] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhBid] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhCreated] :: MarketSummary -> Text
+ Bittrex.Types: [mhDisplayMarketName] :: MarketSummary -> Maybe Text
+ Bittrex.Types: [mhHigh] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhLast] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhLow] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhMarketName] :: MarketSummary -> MarketName
+ Bittrex.Types: [mhOpenBuyOrders] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhOpenSellOrders] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhPrevDay] :: MarketSummary -> Scientific
+ Bittrex.Types: [mhTimeStamp] :: MarketSummary -> Time
+ Bittrex.Types: [mhVolume] :: MarketSummary -> Scientific
+ Bittrex.Types: data MarketSummary
+ Bittrex.Types: instance Data.Aeson.Types.FromJSON.FromJSON Bittrex.Types.MarketName
+ Bittrex.Types: instance Data.Aeson.Types.FromJSON.FromJSON Bittrex.Types.MarketSummary
+ Bittrex.Types: instance Data.Aeson.Types.FromJSON.FromJSON Bittrex.Types.Time
+ Bittrex.Types: instance GHC.Classes.Eq Bittrex.Types.MarketSummary
+ Bittrex.Types: instance GHC.Classes.Eq Bittrex.Types.Time
+ Bittrex.Types: instance GHC.Generics.Generic Bittrex.Types.MarketSummary
+ Bittrex.Types: instance GHC.Read.Read Bittrex.Types.MarketName
+ Bittrex.Types: instance GHC.Show.Show Bittrex.Types.MarketSummary
+ Bittrex.Types: instance GHC.Show.Show Bittrex.Types.Time
+ Bittrex.Types: newtype Time
+ Bittrex.Util: parse :: String -> UTCTime
- Bittrex.API: getMarketSummaries :: IO (Either ErrorMessage Value)
+ Bittrex.API: getMarketSummaries :: IO (Either ErrorMessage [MarketSummary])
- Bittrex.API: getMarketSummary :: MarketName -> IO (Either ErrorMessage Value)
+ Bittrex.API: getMarketSummary :: MarketName -> IO (Either ErrorMessage [MarketSummary])
- Bittrex.Types: MarketHistory :: Integer -> Text -> Double -> Double -> Double -> Text -> Text -> MarketHistory
+ Bittrex.Types: MarketHistory :: Integer -> Time -> Double -> Double -> Double -> Text -> Text -> MarketHistory
- Bittrex.Types: Order :: Maybe Text -> Text -> Text -> OrderType -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Maybe Scientific -> Text -> Bool -> Text -> Text -> Scientific -> Bool -> Bool -> Bool -> Text -> Order
+ Bittrex.Types: Order :: Maybe Text -> Text -> Text -> OrderType -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Maybe Scientific -> Text -> Bool -> Text -> Time -> Scientific -> Bool -> Bool -> Bool -> Text -> Order
- Bittrex.Types: OrderHistory :: Text -> Text -> Text -> OrderType -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Maybe Scientific -> Bool -> Bool -> OrderHistory
+ Bittrex.Types: OrderHistory :: Text -> Text -> Time -> OrderType -> Scientific -> Scientific -> Scientific -> Scientific -> Scientific -> Maybe Scientific -> Bool -> Bool -> OrderHistory
- Bittrex.Types: [marketHistoryTimeStamp] :: MarketHistory -> Text
+ Bittrex.Types: [marketHistoryTimeStamp] :: MarketHistory -> Time
- Bittrex.Types: [oTimeStamp] :: Order -> Text
+ Bittrex.Types: [oTimeStamp] :: Order -> Time
- Bittrex.Types: [ohTimeStamp] :: OrderHistory -> Text
+ Bittrex.Types: [ohTimeStamp] :: OrderHistory -> Time

Files

bittrex.cabal view
@@ -1,5 +1,5 @@ name:                bittrex-version:             0.2.0.0+version:             0.3.0.0 synopsis:            API bindings to bittrex.com description:         Haskell bindings to the Bittrex exchange homepage:            https://github.com/dmjio/bittrex
example/Main.hs view
@@ -26,8 +26,16 @@   Right t <- getMarketSummary BTC_DOGE   print t -  putStrLn "Order book for BTC-DOGE market"-  book <- getOrderBook BTC_DOGE Both+  putStrLn "Get market summaries"+  Right t <- getMarketSummaries+  print t++  putStrLn "Order book sells for for BTC-DOGE market"+  book <- getOrderBookSells BTC_DOGE+  print book++  putStrLn "Order book buys for for BTC-DOGE market"+  book <- getOrderBookBuys BTC_DOGE   print book    putStrLn "Market history for BTC-DOGE"
src/Bittrex/API.hs view
@@ -13,7 +13,8 @@   , getTicker   , getMarketSummaries   , getMarketSummary-  , getOrderBook+  , getOrderBookBuys+  , getOrderBookSells   , getMarketHistory     -- * Market   , buyLimit@@ -77,14 +78,14 @@  -- | Used to get the last 24 hour summary of all active exchanges getMarketSummaries-  :: IO (Either ErrorMessage Value)+  :: IO (Either ErrorMessage [MarketSummary]) getMarketSummaries =   callAPI defOpts { path = "getmarketsummaries" }  -- | Used to get the last 24 hour summary of all active exchanges getMarketSummary   :: MarketName -- ^ a string literal for the market (ex: `BTC-LTC`)-  -> IO (Either ErrorMessage Value)+  -> IO (Either ErrorMessage [MarketSummary]) getMarketSummary market =   callAPI defOpts {       qParams = pure ("market", camelToDash $ show market)@@ -92,15 +93,28 @@     }  -- | Used to get retrieve the orderbook for a given market-getOrderBook+getOrderBookBuys   :: MarketName -- ^ a string literal for the market (ex: `BTC-LTC`)-  -> OrderBookType -- ^ buy, sell or both to identify the type of orderbook to return.-  -> IO (Either ErrorMessage [OrderBook])-getOrderBook market orderBookType =+--  -> OrderBookType -- ^ buy, sell or both to identify the type of orderbook to return.+  -> IO (Either ErrorMessage [OrderBookEntry])+getOrderBookBuys market =   callAPI defOpts {       path = "getorderbook"     , qParams = [ ("market", camelToDash $ show market)-                , ("type", map toLower $ show orderBookType)+                , ("type", "buy")+                ]+    }++-- | Used to get retrieve the orderbook for a given market+getOrderBookSells+  :: MarketName -- ^ a string literal for the market (ex: `BTC-LTC`)+--  -> OrderBookType -- ^ buy, sell or both to identify the type of orderbook to return.+  -> IO (Either ErrorMessage [OrderBookEntry])+getOrderBookSells market =+  callAPI defOpts {+      path = "getorderbook"+    , qParams = [ ("market", camelToDash $ show market)+                , ("type", "sell")                 ]     } 
src/Bittrex/Types.hs view
@@ -2,8 +2,9 @@ {-# LANGUAGE DeriveGeneric     #-} module Bittrex.Types where +import           Bittrex.Util         (parse) import           Data.Aeson-import           Data.Aeson.Types+import           Data.Aeson.Types     hiding (parse) import           Data.ByteString      (ByteString) import qualified Data.ByteString      as B import qualified Data.ByteString.Lazy as L@@ -12,6 +13,7 @@ import qualified Data.Text            as T import           Data.Time import           GHC.Generics+import           Text.Read            (readMaybe)  type Params = [(String,String)] type Rate = Scientific@@ -22,6 +24,13 @@   | MarketAPI   deriving (Eq) +newtype Time = Time UTCTime+  deriving (Show, Eq)++instance FromJSON Time where+  parseJSON = withText "Time" $ \t -> do+    pure $ Time $ parse (T.unpack t)+ instance Show APIType where   show AccountAPI = "account"   show PublicAPI  = "public"@@ -324,9 +333,16 @@   | ETH_ADA   | BTC_ENG   | ETH_ENG-  deriving (Show, Eq, Generic)+  deriving (Show, Eq, Generic, Read) -data Ticker = Ticker+instance FromJSON MarketName where+  parseJSON = withText "MarketName" $ \s ->+    case readMaybe $ T.unpack (T.replace "-" "_" s) of+      Nothing -> error $ "Couldn't parse MarketName: " ++ T.unpack s+      Just k -> pure k++data Ticker+  = Ticker   { bid :: Double   , ask :: Double   , last :: Double@@ -383,12 +399,6 @@       <*> o .: "CoinType"       <*> o .: "BaseAddress" -data OrderBookType-  = Buy-  | Sell-  | Both-  deriving (Show, Eq)- data OrderBookEntry   = OrderBookEntry   { quantity :: Double@@ -414,7 +424,7 @@ data MarketHistory   = MarketHistory   { marketHistoryId :: Integer-  , marketHistoryTimeStamp :: Text+  , marketHistoryTimeStamp :: Time   , marketHistoryQuantity :: Double   , marketHistoryPrice :: Double   , marketHistoryTotal :: Double@@ -552,7 +562,7 @@   = OrderHistory     { ohOrderUuid :: Text     , ohExchange :: Text-    , ohTimeStamp :: Text+    , ohTimeStamp :: Time     , ohOrderType :: OrderType     , ohLimit :: Scientific     , ohQuantity :: Scientific@@ -588,7 +598,7 @@     , oOpen :: Text     , oIsOpen :: Bool     , oSentinal :: Text-    , oTimeStamp :: Text+    , oTimeStamp :: Time     , oCommission :: Scientific     , oIsConditional :: Bool     , oImmediateOrCancel :: Bool@@ -599,4 +609,27 @@ instance FromJSON Order where   parseJSON = genericParseJSON defaultOptions {     fieldLabelModifier = drop 1+  }++data MarketSummary+  = MarketSummary+  { mhMarketName :: MarketName+  , mhHigh :: Scientific+  , mhLow :: Scientific+  , mhVolume :: Scientific+  , mhLast :: Scientific+  , mhBaseVolume :: Scientific+  , mhTimeStamp :: Time+  , mhBid :: Scientific+  , mhAsk :: Scientific+  , mhOpenBuyOrders :: Scientific+  , mhOpenSellOrders :: Scientific+  , mhPrevDay :: Scientific+  , mhCreated :: Text+  , mhDisplayMarketName :: Maybe Text+  } deriving (Show, Eq, Generic)++instance FromJSON MarketSummary where+  parseJSON = genericParseJSON defaultOptions {+    fieldLabelModifier = drop 2   }
src/Bittrex/Util.hs view
@@ -1,6 +1,14 @@-module Bittrex.Util ( camelToDash ) where+module Bittrex.Util ( camelToDash, parse ) where +import Data.Time+import Data.Time.Format+ camelToDash :: String -> String camelToDash [] = [] camelToDash ('_':xs) = '-':camelToDash xs camelToDash (x:xs) = x:camelToDash xs++parse :: String -> UTCTime+parse =+  parseTimeOrError True defaultTimeLocale $+    iso8601DateFormat (Just "%H:%M:%S%Q")