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

Method parseTimeframe

java/lib/src/main/java/io/github/ccxt/Exchange.java:1377–1424  ·  view source on GitHub ↗
(Object timeframe2)

Source from the content-addressed store, hash-verified

1375 }
1376
1377 public int parseTimeframe(Object timeframe2) {
1378 if (timeframe2 == null) {
1379 throw new IllegalArgumentException("timeframe cannot be null");
1380 }
1381 String timeframe = String.valueOf(timeframe2);
1382 if (timeframe.length() < 2) {
1383 throw new IllegalArgumentException("Invalid timeframe: " + timeframe);
1384 }
1385
1386 String amountStr = timeframe.substring(0, timeframe.length() - 1);
1387 String unit = timeframe.substring(timeframe.length() - 1); // last char as 1-length string
1388
1389 int amount;
1390 try {
1391 amount = Integer.parseInt(amountStr);
1392 } catch (NumberFormatException e) {
1393 throw new IllegalArgumentException("Invalid timeframe amount: " + timeframe, e);
1394 }
1395
1396 int scale;
1397 switch (unit) {
1398 case "y":
1399 scale = 60 * 60 * 24 * 365;
1400 break;
1401 case "M":
1402 scale = 60 * 60 * 24 * 30;
1403 break; // months
1404 case "w":
1405 scale = 60 * 60 * 24 * 7;
1406 break;
1407 case "d":
1408 scale = 60 * 60 * 24;
1409 break;
1410 case "h":
1411 scale = 60 * 60;
1412 break;
1413 case "m":
1414 scale = 60;
1415 break;
1416 case "s":
1417 scale = 1;
1418 break;
1419 default:
1420 throw new IllegalArgumentException("Invalid timeframe unit: " + timeframe);
1421 }
1422
1423 return amount * scale;
1424 }
1425
1426 public static Double parseNumber(Object value) {
1427 return parseNumber(value, null);

Callers 8

testParseTimeframeFunction · 0.95
buildOHLCVCMethod · 0.95
testParseTimeframeFunction · 0.95
buildOHLCVCMethod · 0.95
buildOHLCVCMethod · 0.95

Calls 2

parseIntMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected