MCPcopy
hub / github.com/ccxt/ccxt / filterByLimit

Method filterByLimit

java/lib/src/main/java/io/github/ccxt/Exchange.java:4510–4558  ·  view source on GitHub ↗
(Object array, Object... optionalArgs)

Source from the content-addressed store, hash-verified

4508 }
4509
4510 public Object filterByLimit(Object array, Object... optionalArgs)
4511 {
4512 // array = ascending ? this.arraySlice (array, 0, limit) : this.arraySlice (array, -limit);
4513 // array = ascending ? this.arraySlice (array, -limit) : this.arraySlice (array, 0, limit);
4514 Object limit = Helpers.getArg(optionalArgs, 0, null);
4515 Object key = Helpers.getArg(optionalArgs, 1, "timestamp");
4516 Object fromStart = Helpers.getArg(optionalArgs, 2, false);
4517 if (Helpers.isTrue(this.valueIsDefined(limit)))
4518 {
4519 Object arrayLength = Helpers.getArrayLength(array);
4520 if (Helpers.isTrue(Helpers.isGreaterThan(arrayLength, 0)))
4521 {
4522 Object ascending = true;
4523 if (Helpers.isTrue((Helpers.inOp(Helpers.GetValue(array, 0), key))))
4524 {
4525 Object first = Helpers.GetValue(Helpers.GetValue(array, 0), key);
4526 Object last = Helpers.GetValue(Helpers.GetValue(array, Helpers.subtract(arrayLength, 1)), key);
4527 if (Helpers.isTrue(Helpers.isTrue(!Helpers.isEqual(first, null)) && Helpers.isTrue(!Helpers.isEqual(last, null))))
4528 {
4529 ascending = Helpers.isLessThanOrEqual(first, last); // true if array is sorted in ascending order based on 'timestamp'
4530 }
4531 }
4532 if (Helpers.isTrue(fromStart))
4533 {
4534 if (Helpers.isTrue(Helpers.isGreaterThan(limit, arrayLength)))
4535 {
4536 limit = arrayLength;
4537 }
4538 if (Helpers.isTrue(ascending))
4539 {
4540 array = this.arraySlice(array, 0, limit);
4541 } else
4542 {
4543 array = this.arraySlice(array, Helpers.opNeg(limit));
4544 }
4545 } else
4546 {
4547 if (Helpers.isTrue(ascending))
4548 {
4549 array = this.arraySlice(array, Helpers.opNeg(limit));
4550 } else
4551 {
4552 array = this.arraySlice(array, 0, limit);
4553 }
4554 }
4555 }
4556 }
4557 return array;
4558 }
4559
4560 public Object filterBySinceLimit(Object array, Object... optionalArgs)
4561 {

Callers 3

filterBySinceLimitMethod · 0.95

Calls 12

getArgMethod · 0.95
isTrueMethod · 0.95
valueIsDefinedMethod · 0.95
getArrayLengthMethod · 0.95
isGreaterThanMethod · 0.95
inOpMethod · 0.95
GetValueMethod · 0.95
subtractMethod · 0.95
isEqualMethod · 0.95
isLessThanOrEqualMethod · 0.95
arraySliceMethod · 0.95
opNegMethod · 0.95

Tested by

no test coverage detected