module Zero.Bitfinex.Internal
  (
    Ticker(..)

  , defaultTicker
  ) where

import           GHC.Generics (Generic)
import           Data.Aeson
import           Data.Text (Text)

------------------------------------------------------------------------------
--
------------------------------------------------------------------------------

data Ticker = Ticker {
    t_mid :: Text
  , t_bid :: Text
  , t_ask :: Text
  , t_lastPrice :: Text
  , t_low :: Text
  , t_high :: Text
  , t_volume :: Text
  , t_timestamp :: Text
  } deriving (Show, Generic)

defaultTicker =
  Ticker "0.0" "0.0" "0.0" "0.0" "0.0" "0.0" "0.0" "TIMESTAMP"

instance FromJSON Ticker where
  parseJSON = withObject "Ticker" $ \v -> Ticker
    <$> v .: "mid"
    <*> v .: "bid"
    <*> v .: "ask"
    <*> v .: "last_price"
    <*> v .: "low"
    <*> v .: "high"
    <*> v .: "volume"
    <*> v .: "timestamp"

instance ToJSON Ticker where
  toJSON (Ticker a1 a2 a3 a4 a5 a6 a7 a8) =
    object [
      "mid" .= a1
    , "bid" .= a2
    , "ask" .= a3
    , "last_price" .= a4
    , "low" .= a5
    , "high" .= a6
    , "volume" .= a7
    , "timestamp" .= a8
    ]
