Browse Source

Merge commit 'a3464483ea429aafa5049b32886490f2373a6a5e' into stable

stable
Denis Tereshkin 6 years ago
parent
commit
03d60a5ccd
  1. 2
      robocom-zero.cabal
  2. 43
      src/ATrade/BarAggregator.hs
  3. 3
      src/ATrade/Driver/Real/QuoteSourceThread.hs
  4. 26
      src/ATrade/RoboCom.hs

2
robocom-zero.cabal

@ -28,6 +28,8 @@ library
, ATrade.Driver.Real , ATrade.Driver.Real
, ATrade.Driver.Backtest , ATrade.Driver.Backtest
, ATrade.BarAggregator , ATrade.BarAggregator
, ATrade.RoboCom
other-modules: Paths_robocom_zero
build-depends: base >= 4.7 && < 5 build-depends: base >= 4.7 && < 5
, libatrade >= 0.9.0.0 && < 0.10.0.0 , libatrade >= 0.9.0.0 && < 0.10.0.0
, text , text

43
src/ATrade/BarAggregator.hs

@ -186,51 +186,26 @@ updateTime tick = runState $ do
handleBar :: Bar -> BarAggregator -> (Maybe Bar, BarAggregator) handleBar :: Bar -> BarAggregator -> (Maybe Bar, BarAggregator)
handleBar bar = runState $ do handleBar bar = runState $ do
tws <- gets tickTimeWindows
mybars <- gets bars mybars <- gets bars
if (any (isInTimeInterval bar) tws)
then
case M.lookup (barSecurity bar) mybars of case M.lookup (barSecurity bar) mybars of
Just series -> case bsBars series of Just series -> case bsBars series of
(b:bs) -> do (_:bs) -> do
let currentBn = barNumber (barTimestamp b) (tfSeconds $ bsTimeframe series) lBars %= M.insert (barSecurity bar) series { bsBars = emptyBarFrom bar : bar : bs }
if return . Just $ bar
| currentBn == barNumber (barTimestamp bar) (tfSeconds $ bsTimeframe series) -> do
lBars %= M.insert (barSecurity bar) series { bsBars = updateBar b bar : bs }
return Nothing
| currentBn < barNumber (barTimestamp bar) (tfSeconds $ bsTimeframe series) -> do
if barEndTime b (tfSeconds $ bsTimeframe series) == barTimestamp bar
then do
lBars %= M.insert (barSecurity bar) series { bsBars = emptyBarFrom bar : (updateBar b bar : bs) }
return . Just $ updateBar b bar
else do
lBars %= M.insert (barSecurity bar) series { bsBars = bar : b : bs }
return . Just $ b
| otherwise -> return Nothing
_ -> do _ -> do
lBars %= M.insert (barSecurity bar) series { bsBars = [bar] } lBars %= M.insert (barSecurity bar) series { bsBars = emptyBarFrom bar : [bar] }
return Nothing return Nothing
_ -> return Nothing _ -> return Nothing
else
return Nothing
where where
isInTimeInterval bar' (a, b) = (utctDayTime . barTimestamp) bar' >= a && (utctDayTime . barTimestamp) bar' <= b emptyBarFrom bar' = newBar
updateBar !bar' newbar = where
let newHigh = max (barHigh bar') (barHigh newbar) newBar = Bar {
newLow = min (barLow bar') (barLow newbar) in
bar' {
barTimestamp = barTimestamp newbar,
barHigh = newHigh,
barLow = newLow,
barClose = barClose newbar,
barVolume = barVolume bar' + (abs . barVolume $ newbar) }
emptyBarFrom bar' = Bar {
barSecurity = barSecurity bar', barSecurity = barSecurity bar',
barTimestamp = 0.000001 `addUTCTime` barTimestamp bar', barTimestamp = barTimestamp bar',
barOpen = barClose bar', barOpen = barClose bar',
barHigh = barClose bar', barHigh = barClose bar',
barLow = barClose bar', barLow = barClose bar',
barClose = barClose bar', barClose = barClose bar',
barVolume = 0 } barVolume = 0 }

3
src/ATrade/Driver/Real/QuoteSourceThread.hs

@ -31,7 +31,7 @@ startQuoteSourceThread ctx qsEp strategy eventChan agg tickFilter maybeSourceTim
bracket (startQuoteSourceClient tickChan tickersList ctx qsEp defaultClientSecurityParams) bracket (startQuoteSourceClient tickChan tickersList ctx qsEp defaultClientSecurityParams)
(\qs -> do (\qs -> do
stopQuoteSourceClient qs stopQuoteSourceClient qs
debugM "Strategy" "Quotesource client: stop") debugM "QSThread" "Quotesource client: stop")
(\_ -> forever $ do (\_ -> forever $ do
qdata <- readChan tickChan qdata <- readChan tickChan
case qdata of case qdata of
@ -46,6 +46,7 @@ startQuoteSourceThread ctx qsEp strategy eventChan agg tickFilter maybeSourceTim
Just _ -> return () Just _ -> return ()
QDBar (incomingTf, bar) -> do QDBar (incomingTf, bar) -> do
aggValue <- readIORef agg aggValue <- readIORef agg
-- debugM "QSThread" $ "Incoming bar: " ++ show incomingTf ++ ": " ++ show bar
case maybeSourceTimeframe of case maybeSourceTimeframe of
Just tf -> when (tf == unBarTimeframe incomingTf) $ Just tf -> when (tf == unBarTimeframe incomingTf) $
case handleBar bar aggValue of case handleBar bar aggValue of

26
src/ATrade/RoboCom.hs

@ -0,0 +1,26 @@
{-# LANGUAGE TemplateHaskell #-}
module ATrade.RoboCom
(
robocom_version
) where
import Data.Version
import Paths_robocom_zero
import Development.GitRev
robocom_version :: Version
robocom_version = version
robocom_gitrev :: String
robocom_gitrev = concat [ "robocom-zero-",
$(gitBranch),
"@",
$(gitHash),
dirty ]
where
dirty | $(gitDirty) = "+"
| otherwise = ""
Loading…
Cancel
Save