In order to compute the traded volume of icebergs (if any), we can iterate using either Java syntax or JS syntax:
Code: Select all
api.addConsolidatedTradeDataListener((price, size, tradeInfo) => { let icebergVolumeJava = tradeInfo.executedOrders.stream().filter(x => x.isIceberg).mapToInt(x => x.tradeSize).sum() // or let icebergVolumeJs = tradeInfo.executedOrders.filter(x => x.isIceberg).map(x => x.tradeSize).reduce((a, b) => a + b, 0) })
My code is as shown below:
Code: Select all
let myICE = api.registerIndicator('myICE', GraphType.BOTTOM, 0)
api.addConsolidatedTradeDataListener((price, size, tradeInfo) => {
let icebergVolumeJava = tradeInfo.executedOrders.stream().filter(x => x.isIceberg).mapToInt(x => x.tradeSize).sum()
// let icebergVolumeJs = tradeInfo.executedOrders.filter(x => x.isIceberg).map(x => x.tradeSize).reduce((a, b) => a + b, 0)
myICE.addPoint(icebergVolumeJava)
})
When I compile using the code associated with icebergVolumeJava, the script is able to compile and Bookmap runs, but no data is computed.
However, if I use the code associated with icebergVolumeJs, the JS add-on crashes and I am given the error warning as shown below (tradeInfo.executedOrders.filter is not a function).
Any help is appreciated.
Thanks,
Jonathan
<eval>:56 TypeError: tradeInfo.executedOrders.filter is not a function
at org.openjdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
at org.openjdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:212)
at org.openjdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:184)
at org.openjdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:171)
at org.openjdk.nashorn.internal.runtime.Undefined.lookup(Undefined.java:100)
at org.openjdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:106)
at org.openjdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:96)
at jdk.dynalink/jdk.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(Unknown Source)
at jdk.dynalink/jdk.dynalink.linker.support.CompositeGuardingDynamicLinker.getGuardedInvocation(Unknown Source)
at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.lambda$getGuardedInvocation$0(Unknown Source)
at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getWithLookupInternal(Unknown Source)
at jdk.dynalink/jdk.dynalink.LinkerServicesImpl.getGuardedInvocation(Unknown Source)
at jdk.dynalink/jdk.dynalink.DynamicLinker.relink(Unknown Source)
at org.openjdk.nashorn.internal.scripts.Script$Recompilation$53$1944AAA$\^eval\_.L:54(<eval>:56)
at org.openjdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:652)
at org.openjdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
at org.openjdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:520)
at org.openjdk.nashorn.javaadapters.velox_api_layer1_simplified_TradeDataListener.onTrade(Unknown Source)
at com.bookmap.js.flat.v.a(Unknown Source)
at java.base/java.util.ArrayList.forEach(Unknown Source)
at com.bookmap.js.flat.v.a(Unknown Source)
at com.bookmap.js.flat.v.cancel(Unknown Source)
at com.bookmap.js.flat.h.a(Unknown Source)
at java.base/java.util.ArrayList.forEach(Unknown Source)
at com.bookmap.js.flat.h.cancel(Unknown Source)
at velox.api.layer1.simplified.InstanceWrapper.cancel(InstanceWrapper.java:422)
at velox.api.layer1.simplified.DeactivatableStrategyUpdateGeneratorWithFilter.onMboCancel(DeactivatableStrategyUpdateGeneratorWithFilter.java:135)
at jdk.internal.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at velox.api.layer1.exceptionwrapper.a$b.invoke(SourceFile:64)
at com.sun.proxy.$Proxy60.onMboCancel(Unknown Source)
at velox.bookmap.by.onMboCancel(SourceFile:60)
at velox.api.layer1.layers.aY.a(SourceFile:912)
at velox.api.layer1.layers.aY.a(SourceFile:858)
at velox.api.layer1.layers.aY.b(SourceFile:715)
at java.base/java.lang.Thread.run(Unknown Source)