-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhadan.hs
50 lines (44 loc) · 1.36 KB
/
hadan.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE
OverloadedStrings
, TemplateHaskell
#-}
module Main where
import System.Environment(getArgs)
import Blaze.ByteString.Builder
import Blaze.ByteString.Builder.Char.Utf8
import Control.Exception (bracket)
import Control.Monad.IO.Class
import Data.Conduit
import Data.Conduit.Binary
import Data.Conduit.HDBI
import Data.Function (on)
import Data.Time
import Database.HDBI
import Database.HDBI.SQlite
import Hadan.Data.Candle
import Hadan.Finam
import Hadan.URL
import Network.HTTP.Conduit
import Network.URL
import qualified Data.Conduit.List as L
import qualified Data.Text as T
import Debug.Trace
-- sinkCandle :: (MonadIO m) => Sink (PositionRange, Candle) m ()
-- sinkCandle = do
-- c <- await
-- case c of
-- Nothing -> return ()
-- Just (_, cndl) -> do
-- liftIO $ print cndl
-- sinkCandle
strs x = trace (show x) x
main = bracket (connectSqlite3 "out.sqlite") disconnect $ \con -> do
args <- getArgs
let ticker = args !! 0
year = read $ args !! 1
month = read $ args !! 2
day = read $ args !! 3
withManagerSettings (def {managerResponseTimeout = Just 180000000}) $ \man -> do
downloadTicks man 3 ticker (fromGregorian 2000 1 1) (fromGregorian year month day)
$= flushBy ((==) `on` utctDay . tTime)
$$ insertAllTrans con "insert into ticks (board, ticker, time, price, volume) values (?,?,?,?,?)"