module Bittrex.API
(
getMarkets
, getCurrencies
, getTicker
, getMarketSummaries
, getMarketSummary
, getOrderBook
, getMarketHistory
, buyLimit
, sellLimit
, cancel
, getOpenOrders
, getBalances
, getBalance
, getDepositAddress
, withdraw
, getOrder
, getOrderHistory
, getWithdrawalHistory
, getDepositHistory
) where
import Data.Aeson
import Data.Monoid
import Data.Text (Text)
import qualified Data.Text as T
import Data.Scientific
import Bittrex.Types
import Bittrex.Util
import Bittrex.Internal
getMarkets
:: IO (Either ErrorMessage [Market])
getMarkets = callAPI defOpts { path = "getmarkets" }
getCurrencies
:: IO (Either ErrorMessage [Currency])
getCurrencies = callAPI defOpts { path = "getcurrencies" }
getTicker
:: MarketName
-> IO (Either ErrorMessage Ticker)
getTicker market =
callAPI defOpts {
qParams = [("market", show market)]
, path = "getticker"
}
getMarketSummaries
:: IO (Either ErrorMessage Value)
getMarketSummaries =
callAPI defOpts { path = "getmarketsummaries" }
getMarketSummary
:: MarketName
-> IO (Either ErrorMessage Value)
getMarketSummary market =
callAPI defOpts {
qParams = [("market", show market)]
, path = "getmarketsummary"
}
getOrderBook
:: MarketName
-> OrderBookType
-> IO (Either ErrorMessage OrderBook)
getOrderBook market orderBookType =
callAPI defOpts {
path = "getorderbook"
, qParams = [ ("market", show market)
, ("type", show orderBookType)
]
}
getMarketHistory
:: MarketName
-> IO (Either ErrorMessage [MarketHistory])
getMarketHistory market =
callAPI defOpts {
path = "getmarkethistory"
, qParams = pure ("market", show market)
}
getOpenOrders
:: APIKeys
-> MarketName
-> IO (Either ErrorMessage [OpenOrder])
getOpenOrders keys market =
callAPI defOpts {
path = "getopenorders"
, apiType = MarketAPI
, qParams = pure ("market", camelToDash $ show market)
, keys = keys
}
buyLimit
:: APIKeys
-> MarketName
-> Quantity
-> Rate
-> IO (Either ErrorMessage UUID)
buyLimit keys market quantity rate =
callAPI defOpts {
path = "buylimit"
, keys = keys
, apiType = MarketAPI
, qParams = [ ("market", camelToDash $ show market )
, ("quantity", formatScientific Fixed Nothing quantity )
, ("rate", formatScientific Fixed Nothing rate )
]
}
sellLimit
:: APIKeys
-> MarketName
-> Quantity
-> Rate
-> IO (Either ErrorMessage UUID)
sellLimit keys market quantity rate =
callAPI defOpts {
path = "selllimit"
, keys = keys
, apiType = MarketAPI
, qParams = [ ("market", camelToDash $ show market )
, ("quantity", formatScientific Fixed Nothing quantity )
, ("rate", formatScientific Fixed Nothing rate )
]
}
cancel
:: APIKeys
-> UUID
-> IO (Either ErrorMessage (Maybe Text))
cancel keys (UUID uuid) =
callAPI defOpts {
path = "cancel"
, keys = keys
, apiType = MarketAPI
, qParams = [ ("uuid", T.unpack uuid ) ]
}
getBalances
:: APIKeys
-> IO (Either ErrorMessage [Balance])
getBalances keys =
callAPI defOpts {
path = "getbalances"
, keys = keys
, apiType = AccountAPI
}
getBalance
:: APIKeys
-> CurrencyName
-> IO (Either ErrorMessage Balance)
getBalance keys currency =
callAPI defOpts {
path = "getbalance"
, keys = keys
, apiType = AccountAPI
, qParams = pure ("currency", T.unpack currency )
}
getDepositAddress
:: APIKeys
-> CurrencyName
-> IO (Either ErrorMessage DepositAddress)
getDepositAddress keys currency =
callAPI defOpts {
path = "getdepositaddress"
, apiType = AccountAPI
, keys = keys
, qParams = pure ("currency", T.unpack currency )
}
getWithdrawalHistory
:: APIKeys
-> CurrencyName
-> IO (Either ErrorMessage [WithdrawalHistory])
getWithdrawalHistory keys currency =
callAPI defOpts {
path = "getwithdrawalhistory"
, apiType = AccountAPI
, keys = keys
, qParams = pure ( "currency"
, show currency
)
}
getOrderHistory
:: APIKeys
-> Maybe MarketName
-> IO (Either ErrorMessage [OrderHistory] )
getOrderHistory keys market =
callAPI defOpts {
path = "getorderhistory"
, apiType = AccountAPI
, keys = keys
, qParams = [ ("market", camelToDash (show m) )
| Just m <- pure market
]
}
getOrder
:: APIKeys
-> UUID
-> IO (Either ErrorMessage Order)
getOrder keys (UUID uuid) =
callAPI defOpts {
path = "getorder"
, keys = keys
, apiType = AccountAPI
, qParams = [ ("uuid", T.unpack uuid) ]
}
withdraw
:: APIKeys
-> CurrencyName
-> Quantity
-> Address
-> Maybe PaymentId
-> IO (Either ErrorMessage UUID)
withdraw keys currency quantity address payment =
callAPI defOpts {
path = "withdraw"
, keys = keys
, apiType = AccountAPI
, qParams = [ ("currency", T.unpack currency )
, ("quantity", formatScientific Fixed Nothing quantity )
, ("address", address )
] <> [ ("paymentid", show p )
| Just p <- pure payment
]
}
getDepositHistory
:: APIKeys
-> Maybe CurrencyName
-> IO (Either ErrorMessage [DepositHistory])
getDepositHistory keys currency =
callAPI defOpts {
path = "getdeposithistory"
, apiType = AccountAPI
, keys = keys
, qParams = [ ("currency", show c)
| Just c <- pure currency
]
}