persistable sclass TickerSequence is IntSize { settable S market; // e.g. "TRBUSDT" new LongBuffer timestamps; new DoubleBuffer prices; void add(double price, long timestamp) { timestamps.add(timestamp); prices.add(price); } void add(double[] prices, long[] timestamps) { assertEquals(l(prices), l(timestamps)); this.prices.addAll(asList(prices)); this.timestamps.addAll(asList(timestamps)); } toString { ret "TickerSequence length " + n2(l(prices)); } TickerSequence subSequence(int start, int end) { new TickerSequence s; s.add( subDoubleArray(prices.toArray(), start, end), subArray(timestamps.toArray(), start, end)); ret s; } int indexOfTimestamp(long ts) { ret binarySearch_insertionPoint(timestamps.asVirtualList(), ts); } public int size() { ret l(prices); } public bool isEmpty() { ret size() == 0; } TimestampRange timeRange() { ret isEmpty() ? null : TimestampRange(first(timestamps), last(timestamps)); } double getPrice(int i) { ret prices.get(i); } long getTimestamp(int i) { ret timestamps.get(i); } TickerSequence removePlateaus() { new TickerSequence seq; seq.market(market); int n = size(); for i to n: { var value = getPrice(i); seq.prices.add(value); seq.timestamps.add(getTimestamp(i)); while (i+1 < n && getPrice(i+1) == value) ++i; } ret seq; } }