module Finance.TradeKing.Types where
import qualified Data.Text as T
import Data.Time
import Data.String
import Data.Int
import Data.Number.Fixed
import Data.Aeson
import Data.Word
import Data.Time.Clock
data TradeKing = TradeKing {
apiBase :: String,
streamBase :: String,
authorizeURL :: String,
requestTokenResource :: String,
accessTokenResource :: String }
deriving (Show, Read, Eq, Ord)
data TradeKingApp = TradeKingApp {
tradeKing :: TradeKing,
consumerKey :: String,
consumerSecret :: String,
oAuthToken :: String,
oAuthTokenSecret :: String }
deriving (Show, Read, Eq, Ord)
data Format = JSON | XML
deriving (Show, Read, Eq, Ord, Bounded, Enum)
data Command = Accounts |
Clock |
Quote [Asset] [String]
deriving (Show, Read, Eq, Ord)
data Asset = StockAsset Stock |
OptionAsset Option |
NoteAsset Note |
FutureAsset Future
deriving (Show, Read, Eq, Ord)
newtype Stock = Stock { unStock :: T.Text }
deriving (Show, Read, Eq, Ord, IsString)
newtype CUSIP = CUSIP T.Text
deriving (Show, Read, Eq, Ord, IsString)
newtype Exchange = Exchange { unExchange :: T.Text }
deriving (Show, Read, Eq, Ord, IsString)
type Eps4 = EpsDiv10 (EpsDiv10 (EpsDiv10 (EpsDiv10 Eps1)))
type Fixed4 = Fixed Eps4
data Currency = USD |
GBP |
CAD |
Other T.Text
deriving (Show, Read, Eq, Ord)
data Price = Price Currency Fixed4
deriving (Show, Read, Eq, Ord)
data Option = Option {
optionType :: OptionType,
optionUnderlying :: Stock,
optionStrikePrice :: Price,
optionExpiration :: Day
}
deriving (Show, Read, Eq, Ord)
data OptionType = OptionType {
optionContract :: ContractType,
optionStyle :: OptionStyle
}
deriving (Show, Read, Eq, Ord)
data ContractType = Call | Put
deriving (Show, Read, Eq, Ord, Enum, Bounded)
data OptionStyle = American | European
deriving (Show, Read, Eq, Ord, Enum, Bounded)
data Note = Note deriving (Show, Read, Eq, Ord)
data Future = Future deriving (Show, Read, Eq, Ord)
data Period = Annually | SemiAnnually | Quarterly | Monthly
deriving (Show, Read, Eq, Ord)
data HighLow a = HighLow {
high :: a,
low :: a
} deriving (Show, Eq)
data StockQuote = StockQuote {
sqStock :: Stock,
sqTime :: UTCTime,
sqAsk :: Price,
sqAskTime :: UTCTime,
sqAskSz :: Word,
sqBid :: Price,
sqBidTime :: UTCTime,
sqBidSz :: Word,
sqLastPrice :: Price,
sqLastTradeVol :: Word,
sqCumVol :: Word
} deriving (Show, Eq)
data StockInfo = StockInfo {
siStock :: Stock,
siTime :: UTCTime,
siCompanyName :: T.Text,
siPrevClose :: Price,
siPrevOpen :: Price,
siOpen :: Price,
siCusip :: CUSIP,
siDiv :: Maybe Price,
siDivExDate :: Maybe Day,
siDivFrequency :: Maybe Period,
siDivPayDate :: Maybe Day,
siShares :: Integer,
siEps :: Maybe Price,
siExchange :: Exchange,
siDailyHiLo :: HighLow Price,
siYearlyHiLo :: HighLow (Day, Price),
siPE :: Maybe Double,
siBook :: Price,
siQuote :: StockQuote
} deriving (Show, Eq)
data StreamOutput = StreamStatus String
| StreamQuote
{ stqTime :: UTCTime
, stqSymbol :: Stock
, stqAsk :: Price
, stqAskSz :: Word
, stqBid :: Price
, stqBidSz :: Word
, stqQCond :: Maybe String }
| StreamTrade
{ tTime :: UTCTime
, tSymbol :: Stock
, tPrice :: Price
, tVol :: Word
, tCumVol :: Word
, tVWAP :: Maybe Float
, tCond :: Maybe String
, tExch :: Exchange }
| StreamJunk String
deriving (Show)
defaultTk :: TradeKing
defaultTk = TradeKing {
apiBase = "https://api.tradeking.com/v1/",
streamBase = "https://stream.tradeking.com/v1/",
authorizeURL = "https://developers.tradeking.com/oauth/authorize?oauth_token=",
requestTokenResource = "https://developers.tradeking.com/oauth/request_token",
accessTokenResource = "https://developers.tradeking.com/oauth/access_token" }