0

我收到此错误:

No instance for (Show (ClientM Bittrex)) arising from a use of ‘print

在构建以下代码时:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}

module Main where

import Data.Aeson
import Data.Proxy
import GHC.Generics
import Network.HTTP.Client (newManager, defaultManagerSettings)
import Servant.API
import Servant.Client

data Bittrex = Bittrex
  { success :: Bool,
    message :: String,
    result :: Inner
  } deriving (Generic, Show)

instance FromJSON Bittrex
instance ToJSON Bittrex

data Inner = Inner
  { bid :: Float,
    ask :: Float,
    last :: Float
  } deriving (Generic, Show)

instance FromJSON Inner
instance ToJSON Inner

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

-- https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC

type BittrexAPI = "api" :> "v1.1" :> "public" :> "getticker?market=BTC-LTC" :> Get '[JSON] Bittrex

-----------------------------------------------------------------------------
bittrexAPI :: Proxy BittrexAPI
bittrexAPI = Proxy

bittrex = client bittrexAPI

main :: IO ()
main = do
  manager <- newManager defaultManagerSettings
  res <- runClientM bittrex (ClientEnv manager (BaseUrl Http "bittrex.com" 80 ""))
  case res of
    Left err -> putStrLn $ "Error: " ++ show err
    Right test -> do
        print $ bittrex

我知道问题出在我有一个带有嵌入式 JSON 的 JSON 响应这一事实。我不知道如何纠正这个或更重要的是为什么会发生这种情况。请求链接是https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC

4

0 回答 0