MCPcopy Index your code
hub / github.com/ccxt/ccxt / roundTimeframe

Method roundTimeframe

java/lib/src/main/java/io/github/ccxt/base/Misc.java:64–86  ·  view source on GitHub ↗
(Object timeframe, Object timestamp, Object direction)

Source from the content-addressed store, hash-verified

62
63
64 public static Object roundTimeframe(Object timeframe, Object timestamp, Object direction) {
65
66 int dir;
67 if (direction == null) {
68 dir = ROUND_DOWN;
69 } else if (direction instanceof Number) {
70 dir = ((Number) direction).intValue();
71 } else {
72 throw new IllegalArgumentException("direction must be numeric or null");
73 }
74
75 long ms = parseTimeframe(timeframe) * 1000L;
76
77 if (!(timestamp instanceof Number)) {
78 throw new IllegalArgumentException("timestamp must be numeric");
79 }
80 long ts = ((Number) timestamp).longValue();
81
82 long offset = ts % ms;
83
84 long result = ts - offset + ((dir == ROUND_UP) ? ms : 0L);
85 return result;
86 }
87
88 public static Object roundTimeframe(Object timeframe, Object timestamp) {
89 return roundTimeframe(timeframe, timestamp, null);

Callers 1

roundTimeframeMethod · 0.95

Calls 1

parseTimeframeMethod · 0.95

Tested by

no test coverage detected