-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from horizontalsystems/time-period-all
Time period all
- Loading branch information
Showing
14 changed files
with
161 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 37 additions & 11 deletions
48
marketkit/src/main/java/io/horizontalsystems/marketkit/chart/HsChartRequestHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,50 @@ | ||
package io.horizontalsystems.marketkit.chart | ||
|
||
import io.horizontalsystems.marketkit.models.HsPeriodType | ||
import io.horizontalsystems.marketkit.models.HsPointTimePeriod | ||
import io.horizontalsystems.marketkit.models.HsTimePeriod | ||
import java.util.* | ||
|
||
object HsChartRequestHelper { | ||
|
||
fun pointInterval(interval: HsTimePeriod): HsPointTimePeriod { | ||
return when (interval) { | ||
HsTimePeriod.Day1 -> HsPointTimePeriod.Minute30 | ||
HsTimePeriod.Week1 -> HsPointTimePeriod.Hour4 | ||
HsTimePeriod.Week2 -> HsPointTimePeriod.Hour8 | ||
else -> HsPointTimePeriod.Day1 | ||
fun pointInterval(periodType: HsPeriodType) = when (periodType) { | ||
is HsPeriodType.ByPeriod -> { | ||
when (periodType.timePeriod) { | ||
HsTimePeriod.Day1 -> HsPointTimePeriod.Minute30 | ||
HsTimePeriod.Week1 -> HsPointTimePeriod.Hour4 | ||
HsTimePeriod.Week2 -> HsPointTimePeriod.Hour8 | ||
else -> HsPointTimePeriod.Day1 | ||
} | ||
} | ||
is HsPeriodType.ByStartTime -> { | ||
val currentTime = Date().time / 1000 | ||
val seconds = currentTime - periodType.startTime | ||
|
||
when { | ||
seconds <= HsTimePeriod.Day1.range -> HsPointTimePeriod.Minute30 | ||
seconds <= HsTimePeriod.Week1.range -> HsPointTimePeriod.Hour4 | ||
seconds <= HsTimePeriod.Week2.range -> HsPointTimePeriod.Hour8 | ||
seconds <= HsTimePeriod.Year2.range -> HsPointTimePeriod.Day1 | ||
else -> HsPointTimePeriod.Week1 | ||
} | ||
} | ||
} | ||
|
||
fun fromTimestamp(timestamp: Long, interval: HsTimePeriod, indicatorPoints: Int) : Long { | ||
// time needed for build indicators | ||
val pointInterval = pointInterval(interval) | ||
val additionalTime = indicatorPoints * pointInterval.interval | ||
fun fromTimestamp(timestamp: Long, periodType: HsPeriodType, indicatorPoints: Int) : Long { | ||
return when (periodType) { | ||
is HsPeriodType.ByPeriod -> { | ||
val timePeriod = periodType.timePeriod | ||
val range = timePeriod.range | ||
|
||
return timestamp - interval.range - additionalTime | ||
// time needed for build indicators | ||
val pointInterval = pointInterval(periodType) | ||
val additionalTime = indicatorPoints * pointInterval.interval | ||
|
||
return timestamp - range - additionalTime | ||
} | ||
is HsPeriodType.ByStartTime -> { | ||
periodType.startTime | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.