I was working with such data, but in cyrpto particularly the number of decimal places combind with the absence of more modern big float style calculators initially led me to all sorts of not so much as fruitful if at least instructive, endeavors. I finally resolved to simply use Rust via wasm-bindeng, which is not so complicated.
import { DirectCalculator as dc } from 'rusty';
export function onAggregationStart(nextStartKeyMs, t, prevVals) {
const opened = this.currentAccessor;
this.openingValuesHolderCache.egress(opened);
opened.startKeySeconds = nextStartKeyMs / 1000;
opened.nextStartKeySeconds = (nextStartKeyMs + this.timeframe.asMilliseconds) / 1000;
const price = t.p;
const qty = t.q;
opened.open = price;
opened.high = price;
opened.low = price;
opened.close = price;
opened.volume = qty;
opened.tradeCount = t.l - t.f;
if (t.m) {
opened.sellVolume = qty;
opened.buyVolume = 0;
opened.deltaVolume = dc.multiply(-1, qty);
opened.cumulativeDeltaVolume = dc.subtract(prevVals[1], qty);
} else {
opened.buyVolume = qty;
opened.sellVolume = 0;
opened.deltaVolume = qty;
opened.cumulativeDeltaVolume = dc.add(prevVals[1], qty);
}
opened.deltaVolumeRatio = dc.divide(opened.deltaVolume, qty);
this.updateDerived(t, opened, AGG_EVENTS.opened);
this.incrementOpenedCount();
this.onDataChanged(this.aggEventTransferCache.set(AGG_EVENTS.opened, this.offset, opened, this.peakMetadataValues()));
opened.release();
}
Which actually completely made the values usable, because otherwise due to round off error accumulation and the like, the js only versions were not cutting it.
Anyways, I can at least isolate the DirectCalculator and package with the necessary scripts, background to setup, etc and provide it as a pull request if anyone would be interested. DirectCalculator is stateless, and uses the Rust BigFloat crate, but comes with an api interface: add, subtract, multiply, divide, exp, ln, log10, pow, sqrt, abs, floor, ceil, round, cmp, eq, lt, lte, equalsZeroViaEpsilon, gt, gte, max, min, sin, cos, tan, addDiff.
I haven't added autoconverted strings as inputs to floats, but other than that it works if my last unit test suite is to be believed! Let me know, this project was certiainly helpful when I was trying to make sense of all the varieties of swappable assets and all that.
Also shout out to CCTX's standardized naming convention (base/quote-settlement-contractids). That really should be a standard protocol or schema...
I was working with such data, but in cyrpto particularly the number of decimal places combind with the absence of more modern big float style calculators initially led me to all sorts of not so much as fruitful if at least instructive, endeavors. I finally resolved to simply use Rust via wasm-bindeng, which is not so complicated.
Which actually completely made the values usable, because otherwise due to round off error accumulation and the like, the js only versions were not cutting it.
Anyways, I can at least isolate the DirectCalculator and package with the necessary scripts, background to setup, etc and provide it as a pull request if anyone would be interested. DirectCalculator is stateless, and uses the Rust BigFloat crate, but comes with an api interface: add, subtract, multiply, divide, exp, ln, log10, pow, sqrt, abs, floor, ceil, round, cmp, eq, lt, lte, equalsZeroViaEpsilon, gt, gte, max, min, sin, cos, tan, addDiff.
I haven't added autoconverted strings as inputs to floats, but other than that it works if my last unit test suite is to be believed! Let me know, this project was certiainly helpful when I was trying to make sense of all the varieties of swappable assets and all that.
Also shout out to CCTX's standardized naming convention (base/quote-settlement-contractids). That really should be a standard protocol or schema...