diff --git a/roboquant-ta/src/main/kotlin/org/roboquant/ta/PriceBarSeries.kt b/roboquant-ta/src/main/kotlin/org/roboquant/ta/PriceBarSeries.kt index f5bfac698..8a31734d9 100644 --- a/roboquant-ta/src/main/kotlin/org/roboquant/ta/PriceBarSeries.kt +++ b/roboquant-ta/src/main/kotlin/org/roboquant/ta/PriceBarSeries.kt @@ -135,12 +135,12 @@ open class PriceBarSeries(capacity: Int) { * Returns a PriceBarSeries that includes the data that occured within the provided [timeframe] */ operator fun get(timeframe: Timeframe): PriceBarSeries { - val tl = timeline.toTypedArray() - val size = tl.filter { it in timeframe }.size val result = PriceBarSeries(size) - for (i in 0.. wsIEX.close(0, "closed called") - "fx" -> wsFX.close(0, "closed called") - "crypto" -> wsCrypto.close(0, "closed called") + "iex" -> wsIEX.close(1000, "closed called") + "fx" -> wsFX.close(1000, "closed called") + "crypto" -> wsCrypto.close(1000, "closed called") } } diff --git a/roboquant-tiingo/src/test/kotlin/org/roboquant/samples/TiingoSamples.kt b/roboquant-tiingo/src/test/kotlin/org/roboquant/samples/TiingoSamples.kt index ca9fee47f..0938f3e1b 100644 --- a/roboquant-tiingo/src/test/kotlin/org/roboquant/samples/TiingoSamples.kt +++ b/roboquant-tiingo/src/test/kotlin/org/roboquant/samples/TiingoSamples.kt @@ -20,12 +20,13 @@ import org.roboquant.Roboquant import org.roboquant.common.* import org.roboquant.feeds.AggregatorLiveFeed import org.roboquant.feeds.PriceAction -import org.roboquant.feeds.filter +import org.roboquant.feeds.apply import org.roboquant.loggers.ConsoleLogger import org.roboquant.metrics.ProgressMetric import org.roboquant.strategies.EMAStrategy import org.roboquant.tiingo.TiingoHistoricFeed import org.roboquant.tiingo.TiingoLiveFeed +import java.time.Instant import kotlin.test.Ignore import kotlin.test.Test @@ -79,14 +80,18 @@ internal class TiingoSamples { @Test @Ignore - internal fun testLiveFeedCryptoAll() { + internal fun testLiveFeedMeasureDelay() { val feed = TiingoLiveFeed.crypto() - feed.subscribe() - feed.filter(Timeframe.next(1.minutes)) { - println(it) - false + feed.subscribe() // subscribe to all crypto currencies + var n = 0 + var sum = 0L + feed.apply(Timeframe.next(1.minutes)) { _, time -> + val now = Instant.now() + sum += now.toEpochMilli() - time.toEpochMilli() + n++ } feed.close() + println("average delay is ${sum/n}ms") } @Test diff --git a/roboquant/src/main/kotlin/org/roboquant/feeds/LiveFeed.kt b/roboquant/src/main/kotlin/org/roboquant/feeds/LiveFeed.kt index c817b8257..76f02ed54 100644 --- a/roboquant/src/main/kotlin/org/roboquant/feeds/LiveFeed.kt +++ b/roboquant/src/main/kotlin/org/roboquant/feeds/LiveFeed.kt @@ -48,7 +48,7 @@ abstract class LiveFeed(var heartbeatInterval: Long = 10_000) : Feed { get() = channels.isNotEmpty() /** - * Subclasses should use this method or `sendAsync` to send an event. If no channel is active, any event + * Subclasses should call this method or [sendAsync] to send an event. If no channel is active, any event * sent will be dropped. */ protected fun send(event: Event) = runBlocking { @@ -56,7 +56,8 @@ abstract class LiveFeed(var heartbeatInterval: Long = 10_000) : Feed { } /** - * Subclasses should use this method to send an event. If no channel is active, any event sent will be dropped. + * Subclasses should call this method or [send] to send an event. If no channel is active, any + * event sent will be dropped. */ protected suspend fun sendAsync(event: Event) { for (channel in channels) {