module BitMEXClient.WebSockets.Types.Response
( Response(..)
, RespAffiliate(..)
, RespAnnouncement(..)
, RespChat(..)
, RespConnectedUsers(..)
, RespExecution(..)
, RespFunding(..)
, RespInstrument(..)
, RespInsurance(..)
, RespLiquidation(..)
, RespMargin(..)
, RespNotification(..)
, RespOrder(..)
, RespOrderBookL2(..)
, RespOrderBook10(..)
, RespPosition(..)
, RespQuote(..)
, RespSettlement(..)
, RespTrade(..)
, RespTransaction(..)
, RespWallet(..)
, TABLE(..)
, STATUS(..)
, INFO(..)
, ERROR(..)
, Action(..)
) where
import BitMEX.Core
( DateTime
)
import BitMEXClient.CustomPrelude
import BitMEXClient.WebSockets.Types.General
import Data.Text
( Text
)
import Data.Vector
( Vector
)
data Action
= Partial
| Update
| Insert
| Delete
deriving (Eq, Show, Generic)
instance FromJSON Action where
parseJSON = genericParseJSON opts
where
opts =
defaultOptions
{ constructorTagModifier =
\xs ->
case xs of
[] -> xs
(x:xs') -> (toLower x : xs')
}
data NotificationType
= NERROR
| NINFO
| NSUCCESS
deriving (Eq, Show, Generic)
instance FromJSON NotificationType where
parseJSON = genericParseJSON opts
where
opts =
defaultOptions
{ constructorTagModifier =
((drop 1) . (map toLower))
}
data TABLE a = TABLE
{ _table :: !Text
, _action :: !Action
, _data :: !(Vector a)
, _keys :: !(Maybe (Vector Text))
, _foreignKeys :: !(Maybe Value)
, _types :: !(Maybe Value)
, _filter :: !(Maybe Value)
, _attributes :: !(Maybe Value)
} deriving (Eq, Show, Generic)
instance (FromJSON a) => FromJSON (TABLE a)
data STATUS = STATUS
{ success :: !Bool
, subscribe :: !(Maybe Text)
, request :: !Value
} deriving (Eq, Show, Generic)
instance FromJSON STATUS
data INFO = INFO
{ info :: !Text
, version :: !Text
, timestamp :: !Text
, docs :: !Text
, limit :: !Value
} deriving (Eq, Show, Generic)
instance FromJSON INFO
data ERROR = ERROR
{ error :: !Text
, status :: !(Maybe Int)
, meta :: !(Maybe Value)
, request :: !(Maybe Value)
} deriving (Eq, Show, Generic)
instance FromJSON ERROR
data RespAffiliate = RespAffiliate
{ account :: !Double
, currency :: !Currency
, prevPayout :: !(Maybe Double)
, prevTurnover :: !(Maybe Double)
, prevComm :: !(Maybe Double)
, prevTimestamp :: !(Maybe DateTime)
, execTurnover :: !(Maybe Double)
, execComm :: !(Maybe Double)
, totalReferrals :: !(Maybe Double)
, totalTurnover :: !(Maybe Double)
, totalComm :: !(Maybe Double)
, payoutPcnt :: !(Maybe Double)
, pendingPayout :: !(Maybe Double)
, timestamp :: !(Maybe DateTime)
, referrerAccount :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespAffiliate
data RespAnnouncement = RespAnnouncement
{ id :: !Double
, link :: !(Maybe Text)
, title :: !(Maybe Text)
, content :: !(Maybe Text)
, date :: !(Maybe DateTime)
} deriving (Show, Eq, Generic)
instance FromJSON RespAnnouncement
data RespChat = RespChat
{ id :: !(Maybe Double)
, date :: !DateTime
, user :: !Text
, message :: !Text
, html :: !Text
, fromBot :: !(Maybe Bool)
, channelID :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespChat
data RespConnectedUsers = RespConnectedUsers
{ users :: !(Maybe Int)
, bots :: !(Maybe Int)
} deriving (Show, Eq, Generic)
instance FromJSON RespConnectedUsers
data RespExecution = RespExecution
{ execID :: !Text
, orderID :: !(Maybe Text)
, clOrdID :: !(Maybe Text)
, clOrdLinkID :: !(Maybe Text)
, account :: !(Maybe Double)
, symbol :: !(Maybe Symbol)
, side :: !(Maybe Side)
, lastQty :: !(Maybe Double)
, lastPx :: !(Maybe Double)
, underlyingLastPx :: !(Maybe Double)
, lastMkt :: !(Maybe Text)
, lastLiquidityInd :: !(Maybe Text)
, simpleOrderQty :: !(Maybe Double)
, orderQty :: !(Maybe Double)
, price :: !(Maybe Double)
, displayQty :: !(Maybe Double)
, stopPx :: !(Maybe Double)
, pegOffsetValue :: !(Maybe Double)
, pegPriceType :: !(Maybe Text)
, currency :: !(Maybe Currency)
, settlCurrency :: !(Maybe Currency)
, execType :: !(Maybe Text)
, ordType :: !(Maybe Text)
, timeInForce :: !(Maybe Text)
, execInst :: !(Maybe Text)
, contingencyType :: !(Maybe Text)
, exDestination :: !(Maybe Text)
, ordStatus :: !(Maybe Text)
, triggered :: !(Maybe Text)
, workingIndicator :: !(Maybe Bool)
, ordRejReason :: !(Maybe Text)
, simpleLeavesQty :: !(Maybe Double)
, leavesQty :: !(Maybe Double)
, simpleCumQty :: !(Maybe Double)
, cumQty :: !(Maybe Double)
, avgPx :: !(Maybe Double)
, commission :: !(Maybe Double)
, tradePublishIndicator :: !(Maybe Text)
, multiLegReportingType :: !(Maybe Text)
, text :: !(Maybe Text)
, trdMatchID :: !(Maybe Text)
, execCost :: !(Maybe Double)
, execComm :: !(Maybe Double)
, homeNotional :: !(Maybe Double)
, foreignNotional :: !(Maybe Double)
, transactTime :: !(Maybe DateTime)
, timestamp :: !(Maybe DateTime)
} deriving (Show, Eq, Generic)
instance FromJSON RespExecution
data RespFunding = RespFunding
{ timestamp :: !DateTime
, symbol :: !Text
, fundingInterval :: !(Maybe DateTime)
, fundingRate :: !(Maybe Double)
, fundingRateDaily :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespFunding
data RespInstrument = RespInstrument
{ symbol :: !Symbol
, rootSymbol :: !(Maybe Currency)
, state :: !(Maybe Text)
, typ :: !(Maybe Text)
, listing :: !(Maybe DateTime)
, front :: !(Maybe DateTime)
, expiry :: !(Maybe DateTime)
, settle :: !(Maybe DateTime)
, relistInterval :: !(Maybe DateTime)
, inverseLeg :: !(Maybe Text)
, sellLeg :: !(Maybe Text)
, buyLeg :: !(Maybe Text)
, positionCurrency :: !(Maybe Currency)
, underlying :: !(Maybe Currency)
, quoteCurrency :: !(Maybe Currency)
, underlyingSymbol :: !(Maybe Text)
, reference :: !(Maybe Text)
, referenceSymbol :: !(Maybe Text)
, calcInterval :: !(Maybe DateTime)
, publishInterval :: !(Maybe DateTime)
, publishTime :: !(Maybe DateTime)
, maxOrderQty :: !(Maybe Double)
, maxPrice :: !(Maybe Double)
, lotSize :: !(Maybe Double)
, tickSize :: !(Maybe Double)
, multiplier :: !(Maybe Double)
, settlCurrency :: !(Maybe Currency)
, underlyingToPositionMultiplier :: !(Maybe Double)
, underlyingToSettleMultiplier :: !(Maybe Double)
, quoteToSettleMultiplier :: !(Maybe Double)
, isQuanto :: !(Maybe Bool)
, isInverse :: !(Maybe Bool)
, initMargin :: !(Maybe Double)
, maintMargin :: !(Maybe Double)
, riskLimit :: !(Maybe Double)
, riskStep :: !(Maybe Double)
, limit :: !(Maybe Double)
, capped :: !(Maybe Bool)
, taxed :: !(Maybe Bool)
, deleverage :: !(Maybe Bool)
, makerFee :: !(Maybe Double)
, takerFee :: !(Maybe Double)
, settlementFee :: !(Maybe Double)
, insuranceFee :: !(Maybe Double)
, fundingBaseSymbol :: !(Maybe Text)
, fundingQuoteSymbol :: !(Maybe Text)
, fundingPremiumSymbol :: !(Maybe Text)
, fundingTimestamp :: !(Maybe DateTime)
, fundingInterval :: !(Maybe DateTime)
, fundingRate :: !(Maybe Double)
, indicativeFundingRate :: !(Maybe Double)
, rebalanceTimestamp :: !(Maybe DateTime)
, rebalanceInterval :: !(Maybe DateTime)
, openingTimestamp :: !(Maybe DateTime)
, closingTimestamp :: !(Maybe DateTime)
, sessionInterval :: !(Maybe DateTime)
, prevClosePrice :: !(Maybe Double)
, limitDownPrice :: !(Maybe Double)
, limitUpPrice :: !(Maybe Double)
, bankruptLimitDownPrice :: !(Maybe Double)
, bankruptLimitUpPrice :: !(Maybe Double)
, prevTotalVolume :: !(Maybe Double)
, totalVolume :: !(Maybe Double)
, volume :: !(Maybe Double)
, volume24h :: !(Maybe Double)
, prevTotalTurnover :: !(Maybe Double)
, totalTurnover :: !(Maybe Double)
, turnover :: !(Maybe Double)
, turnover24h :: !(Maybe Double)
, prevPrice24h :: !(Maybe Double)
, vwap :: !(Maybe Double)
, highPrice :: !(Maybe Double)
, lowPrice :: !(Maybe Double)
, lastPrice :: !(Maybe Double)
, lastPriceProtected :: !(Maybe Double)
, lastTickDirection :: !(Maybe Text)
, lastChangePcnt :: !(Maybe Double)
, bidPrice :: !(Maybe Double)
, midPrice :: !(Maybe Double)
, askPrice :: !(Maybe Double)
, impactBidPrice :: !(Maybe Double)
, impactMidPrice :: !(Maybe Double)
, impactAskPrice :: !(Maybe Double)
, hasLiquidity :: !(Maybe Bool)
, openInterest :: !(Maybe Double)
, openValue :: !(Maybe Double)
, fairMethod :: !(Maybe Text)
, fairBasisRate :: !(Maybe Double)
, fairBasis :: !(Maybe Double)
, fairPrice :: !(Maybe Double)
, markMethod :: !(Maybe Text)
, markPrice :: !(Maybe Double)
, indicativeTaxRate :: !(Maybe Double)
, indicativeSettlePrice :: !(Maybe Double)
, settledPrice :: !(Maybe Double)
, timestamp :: !(Maybe DateTime)
} deriving (Show, Eq, Generic)
instance FromJSON RespInstrument
data RespInsurance = RespInsurance
{ currency :: !Currency
, timestamp :: !DateTime
, walletBalance :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespInsurance
data RespLiquidation = RespLiquidation
{ orderID :: !Text
, symbol :: !(Maybe Symbol)
, side :: !(Maybe Side)
, price :: !(Maybe Double)
, leavesQty :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespLiquidation
data RespMargin = RespMargin
{ account :: !Double
, currency :: !Currency
, riskLimit :: !(Maybe Double)
, prevState :: !(Maybe Text)
, state :: !(Maybe Text)
, action :: !(Maybe Text)
, amount :: !(Maybe Double)
, pendingCredit :: !(Maybe Double)
, pendingDebit :: !(Maybe Double)
, confirmedDebit :: !(Maybe Double)
, prevRealisedPnl :: !(Maybe Double)
, prevUnrealisedPnl :: !(Maybe Double)
, grossComm :: !(Maybe Double)
, grossOpenCost :: !(Maybe Double)
, grossOpenPremium :: !(Maybe Double)
, grossExecCost :: !(Maybe Double)
, grossMarkValue :: !(Maybe Double)
, riskValue :: !(Maybe Double)
, taxableMargin :: !(Maybe Double)
, initMargin :: !(Maybe Double)
, maintMargin :: !(Maybe Double)
, sessionMargin :: !(Maybe Double)
, targetExcessMargin :: !(Maybe Double)
, varMargin :: !(Maybe Double)
, realisedPnl :: !(Maybe Double)
, unrealisedPnl :: !(Maybe Double)
, indicativeTax :: !(Maybe Double)
, unrealisedProfit :: !(Maybe Double)
, syntheticMargin :: !(Maybe Double)
, walletBalance :: !(Maybe Double)
, marginBalance :: !(Maybe Double)
, marginBalancePcnt :: !(Maybe Double)
, marginLeverage :: !(Maybe Double)
, marginUsedPcnt :: !(Maybe Double)
, excessMargin :: !(Maybe Double)
, excessMarginPcnt :: !(Maybe Double)
, availableMargin :: !(Maybe Double)
, withdrawableMargin :: !(Maybe Double)
, timestamp :: !(Maybe DateTime)
, grossLastValue :: !(Maybe Double)
, commission :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespMargin
data RespNotification = RespNotification
{ _id :: !(Maybe Int)
, _date :: !DateTime
, _title :: !Text
, _body :: !Text
, _ttl :: !Int
, _type :: !(Maybe NotificationType)
, _closable :: !(Maybe Bool)
, _persist :: !(Maybe Bool)
, _waitForVisibility :: !(Maybe Bool)
, _sound :: !(Maybe Text)
} deriving (Show, Eq, Generic)
instance FromJSON RespNotification where
parseJSON = genericParseJSON opts
where
opts = defaultOptions {fieldLabelModifier = drop 1}
data RespOrder = RespOrder
{ orderID :: !Text
, clOrdID :: !(Maybe Text)
, clOrdLinkID :: !(Maybe Text)
, account :: !(Maybe Double)
, symbol :: !(Maybe Symbol)
, side :: !(Maybe Side)
, simpleOrderQty :: !(Maybe Double)
, orderQty :: !(Maybe Double)
, price :: !(Maybe Double)
, displayQty :: !(Maybe Double)
, stopPx :: !(Maybe Double)
, pegOffsetValue :: !(Maybe Double)
, pegPriceType :: !(Maybe Text)
, currency :: !(Maybe Currency)
, settlCurrency :: !(Maybe Currency)
, ordType :: !(Maybe Text)
, timeInForce :: !(Maybe Text)
, execInst :: !(Maybe Text)
, contingencyType :: !(Maybe Text)
, exDestination :: !(Maybe Text)
, ordStatus :: !(Maybe Text)
, triggered :: !(Maybe Text)
, workingIndicator :: !(Maybe Bool)
, ordRejReason :: !(Maybe Text)
, simpleLeavesQty :: !(Maybe Double)
, leavesQty :: !(Maybe Double)
, simpleCumQty :: !(Maybe Double)
, cumQty :: !(Maybe Double)
, avgPx :: !(Maybe Double)
, multiLegReportingType :: !(Maybe Text)
, text :: !(Maybe Text)
, transactTime :: !(Maybe DateTime)
, timestamp :: !(Maybe DateTime)
} deriving (Show, Eq, Generic)
instance FromJSON RespOrder
data RespOrderBookL2 = RespOrderBookL2
{ symbol :: !Symbol
, id :: !Double
, side :: !Side
, size :: !(Maybe Double)
, price :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespOrderBookL2
data RespOrderBook10 = RespOrderBook10
{ symbol :: !Symbol
, timestamp :: !Text
, asks :: !(Vector (Vector Double))
, bids :: !(Vector (Vector Double))
} deriving (Eq, Show, Generic)
instance FromJSON RespOrderBook10
data RespPosition = RespPosition
{ account :: !Double
, symbol :: !Symbol
, currency :: !Currency
, underlying :: !(Maybe Currency)
, quoteCurrency :: !(Maybe Currency)
, commission :: !(Maybe Double)
, initMarginReq :: !(Maybe Double)
, maintMarginReq :: !(Maybe Double)
, riskLimit :: !(Maybe Double)
, leverage :: !(Maybe Double)
, crossMargin :: !(Maybe Bool)
, deleveragePercentile :: !(Maybe Double)
, rebalancedPnl :: !(Maybe Double)
, prevRealisedPnl :: !(Maybe Double)
, prevUnrealisedPnl :: !(Maybe Double)
, prevClosePrice :: !(Maybe Double)
, openingTimestamp :: !(Maybe DateTime)
, openingQty :: !(Maybe Double)
, openingCost :: !(Maybe Double)
, openingComm :: !(Maybe Double)
, openOrderBuyQty :: !(Maybe Double)
, openOrderBuyCost :: !(Maybe Double)
, openOrderBuyPremium :: !(Maybe Double)
, openOrderSellQty :: !(Maybe Double)
, openOrderSellCost :: !(Maybe Double)
, openOrderSellPremium :: !(Maybe Double)
, execBuyQty :: !(Maybe Double)
, execBuyCost :: !(Maybe Double)
, execSellQty :: !(Maybe Double)
, execSellCost :: !(Maybe Double)
, execQty :: !(Maybe Double)
, execCost :: !(Maybe Double)
, execComm :: !(Maybe Double)
, currentTimestamp :: !(Maybe DateTime)
, currentQty :: !(Maybe Double)
, currentCost :: !(Maybe Double)
, currentComm :: !(Maybe Double)
, realisedCost :: !(Maybe Double)
, unrealisedCost :: !(Maybe Double)
, grossOpenCost :: !(Maybe Double)
, grossOpenPremium :: !(Maybe Double)
, grossExecCost :: !(Maybe Double)
, isOpen :: !(Maybe Bool)
, markPrice :: !(Maybe Double)
, markValue :: !(Maybe Double)
, riskValue :: !(Maybe Double)
, homeNotional :: !(Maybe Double)
, foreignNotional :: !(Maybe Double)
, posState :: !(Maybe Text)
, posCost :: !(Maybe Double)
, posCost2 :: !(Maybe Double)
, posCross :: !(Maybe Double)
, posInit :: !(Maybe Double)
, posComm :: !(Maybe Double)
, posLoss :: !(Maybe Double)
, posMargin :: !(Maybe Double)
, posMaint :: !(Maybe Double)
, posAllowance :: !(Maybe Double)
, taxableMargin :: !(Maybe Double)
, initMargin :: !(Maybe Double)
, maintMargin :: !(Maybe Double)
, sessionMargin :: !(Maybe Double)
, targetExcessMargin :: !(Maybe Double)
, varMargin :: !(Maybe Double)
, realisedGrossPnl :: !(Maybe Double)
, realisedTax :: !(Maybe Double)
, realisedPnl :: !(Maybe Double)
, unrealisedGrossPnl :: !(Maybe Double)
, longBankrupt :: !(Maybe Double)
, shortBankrupt :: !(Maybe Double)
, taxBase :: !(Maybe Double)
, indicativeTaxRate :: !(Maybe Double)
, indicativeTax :: !(Maybe Double)
, unrealisedTax :: !(Maybe Double)
, unrealisedPnl :: !(Maybe Double)
, unrealisedPnlPcnt :: !(Maybe Double)
, unrealisedRoePcnt :: !(Maybe Double)
, simpleQty :: !(Maybe Double)
, simpleCost :: !(Maybe Double)
, simpleValue :: !(Maybe Double)
, simplePnl :: !(Maybe Double)
, simplePnlPcnt :: !(Maybe Double)
, avgCostPrice :: !(Maybe Double)
, avgEntryPrice :: !(Maybe Double)
, breakEvenPrice :: !(Maybe Double)
, marginCallPrice :: !(Maybe Double)
, liquidationPrice :: !(Maybe Double)
, bankruptPrice :: !(Maybe Double)
, timestamp :: !(Maybe DateTime)
, lastPrice :: !(Maybe Double)
, lastValue :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespPosition
data RespQuote = RespQuote
{ timestamp :: !DateTime
, symbol :: !Symbol
, bidSize :: !(Maybe Double)
, bidPrice :: !(Maybe Double)
, askPrice :: !(Maybe Double)
, askSize :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespQuote
data RespSettlement = RespSettlement
{ timestamp :: !DateTime
, symbol :: !Symbol
, settlementType :: !(Maybe Text)
, settledPrice :: !(Maybe Double)
, bankrupt :: !(Maybe Double)
, taxBase :: !(Maybe Double)
, taxRate :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespSettlement
data RespTrade = RespTrade
{ timestamp :: !DateTime
, symbol :: !Symbol
, side :: !(Maybe Side)
, size :: !(Maybe Double)
, price :: !(Maybe Double)
, tickDirection :: !(Maybe Text)
, trdMatchID :: !(Maybe Text)
, grossValue :: !(Maybe Double)
, homeNotional :: !(Maybe Double)
, foreignNotional :: !(Maybe Double)
} deriving (Show, Eq, Generic)
instance FromJSON RespTrade
data RespTransaction = RespTransaction
{ transactID :: !Text
, account :: !(Maybe Double)
, currency :: !(Maybe Currency)
, transactType :: !(Maybe Text)
, amount :: !(Maybe Double)
, fee :: !(Maybe Double)
, transactStatus :: !(Maybe Text)
, address :: !(Maybe Text)
, tx :: !(Maybe Text)
, text :: !(Maybe Text)
, transactTime :: !(Maybe DateTime)
, timestamp :: !(Maybe DateTime)
} deriving (Show, Eq, Generic)
instance FromJSON RespTransaction
data RespWallet = RespWallet
{ account :: !Double
, currency :: !Currency
, prevDeposited :: !(Maybe Double)
, prevWithdrawn :: !(Maybe Double)
, prevTransferIn :: !(Maybe Double)
, prevTransferOut :: !(Maybe Double)
, prevAmount :: !(Maybe Double)
, prevTimestamp :: !(Maybe DateTime)
, deltaDeposited :: !(Maybe Double)
, deltaWithdrawn :: !(Maybe Double)
, deltaTransferIn :: !(Maybe Double)
, deltaTransferOut :: !(Maybe Double)
, deltaAmount :: !(Maybe Double)
, deposited :: !(Maybe Double)
, withdrawn :: !(Maybe Double)
, transferIn :: !(Maybe Double)
, transferOut :: !(Maybe Double)
, amount :: !(Maybe Double)
, pendingCredit :: !(Maybe Double)
, pendingDebit :: !(Maybe Double)
, confirmedDebit :: !(Maybe Double)
, timestamp :: !(Maybe DateTime)
, addr :: !(Maybe Text)
, script :: !(Maybe Text)
, withdrawalLock :: !(Maybe (Vector Text))
} deriving (Show, Eq, Generic)
instance FromJSON RespWallet
data Response
= Aff (TABLE RespAffiliate)
| Ann (TABLE RespAnnouncement)
| C (TABLE RespChat)
| CU (TABLE RespConnectedUsers)
| Exe (TABLE RespExecution)
| F (TABLE RespFunding)
| I (TABLE RespInstrument)
| Insu (TABLE RespInsurance)
| L (TABLE RespLiquidation)
| M (TABLE RespMargin)
| N (TABLE RespNotification)
| O (TABLE RespOrder)
| OB (TABLE RespOrderBookL2)
| OB10 (TABLE RespOrderBook10)
| P (TABLE RespPosition)
| Q (TABLE RespQuote)
| Setl (TABLE RespSettlement)
| T (TABLE RespTrade)
| TX (TABLE RespTransaction)
| W (TABLE RespWallet)
| Status STATUS
| Info INFO
| Error ERROR
deriving (Eq, Show, Generic)
instance FromJSON Response where
parseJSON =
withObject "Response" $ \o -> do
kind <- o .:? "table"
success <- o .:? "success"
info <- o .:? "info"
error <- o .:? "error"
case (kind :: Maybe Text) of
Just "affiliate" ->
Aff <$> genericParseJSON opts (Object o)
Just "announcement" ->
Ann <$> genericParseJSON opts (Object o)
Just "chat" ->
C <$> genericParseJSON opts (Object o)
Just "connected" ->
CU <$> genericParseJSON opts (Object o)
Just "execution" ->
Exe <$> genericParseJSON opts (Object o)
Just "funding" ->
F <$> genericParseJSON opts (Object o)
Just "instrument" ->
I <$> genericParseJSON opts (Object o)
Just "insurance" ->
Insu <$>
genericParseJSON opts (Object o)
Just "liquidation" ->
L <$> genericParseJSON opts (Object o)
Just "margin" ->
M <$> genericParseJSON opts (Object o)
Just "order" ->
O <$> genericParseJSON opts (Object o)
Just "orderBookL2" ->
OB <$> genericParseJSON opts (Object o)
Just "orderBook10" ->
OB10 <$>
genericParseJSON opts (Object o)
Just "position" ->
P <$> genericParseJSON opts (Object o)
Just "privateNotifications" ->
N <$> genericParseJSON opts (Object o)
Just "publicNotifications" ->
N <$> genericParseJSON opts (Object o)
Just "quote" ->
Q <$> genericParseJSON opts (Object o)
Just "settlement" ->
Setl <$>
genericParseJSON opts (Object o)
Just "trade" ->
T <$> genericParseJSON opts (Object o)
Just "transact" ->
TX <$> genericParseJSON opts (Object o)
Just "wallet" ->
W <$> genericParseJSON opts (Object o)
Just _ ->
fail
"Cannot parse response: the kind of the response is not supported"
Nothing ->
case (success :: Maybe Bool) of
Just _ ->
Status <$> parseJSON (Object o)
Nothing ->
case (info :: Maybe Text) of
Just _ ->
Info <$>
parseJSON (Object o)
Nothing ->
case (error :: Maybe Text) of
Just _ ->
Error <$>
parseJSON
(Object o)
Nothing ->
fail
"Cannot parse response: unknown response format"
where
opts =
defaultOptions
{ fieldLabelModifier = drop 1
, sumEncoding = UntaggedValue
}