module Bittrex.API
(
getMarkets
, getCurrencies
, getTicker
, getMarketSummaries
, getMarketSummary
, getOrderBookBuys
, getOrderBookSells
, getMarketHistory
, buyLimit
, sellLimit
, cancel
, getOpenOrders
, getBalances
, getBalance
, getDepositAddress
, withdraw
, getOrder
, getOrderHistory
, getWithdrawalHistory
, getDepositHistory
) where
import Data.Aeson
import Data.Char
import Data.Monoid
import Data.Scientific
import Data.Text (Text)
import qualified Data.Text as T
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", toMarket market)]
, path = "getticker"
}
getMarketSummaries
:: IO (Either ErrorMessage [MarketSummary])
getMarketSummaries =
callAPI defOpts { path = "getmarketsummaries" }
getMarketSummary
:: MarketName
-> IO (Either ErrorMessage [MarketSummary])
getMarketSummary market =
callAPI defOpts {
qParams = pure ("market", toMarket market)
, path = "getmarketsummary"
}
getOrderBookBuys
:: MarketName
-> IO (Either ErrorMessage [OrderBookEntry])
getOrderBookBuys market =
callAPI defOpts {
path = "getorderbook"
, qParams = [ ("market", toMarket market)
, ("type", "buy")
]
}
getOrderBookSells
:: MarketName
-> IO (Either ErrorMessage [OrderBookEntry])
getOrderBookSells market =
callAPI defOpts {
path = "getorderbook"
, qParams = [ ("market", toMarket market)
, ("type", "sell")
]
}
getMarketHistory
:: MarketName
-> IO (Either ErrorMessage [MarketHistory])
getMarketHistory market =
callAPI defOpts {
path = "getmarkethistory"
, qParams = pure ("market", toMarket market)
}
getOpenOrders
:: APIKeys
-> MarketName
-> IO (Either ErrorMessage [OpenOrder])
getOpenOrders keys market =
callAPI defOpts {
path = "getopenorders"
, apiType = MarketAPI
, qParams = pure ("market", toMarket 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", toMarket market )
, ("quantity", show quantity )
, ("rate", show 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", toMarket market )
, ("quantity", show quantity )
, ("rate", show 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", toMarket 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", show 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
]
}