getLevel2BookStatus method
Get level2 book status.
poolId the pool id.
lowerPrice lower price you want to query in the level2 book, eg: 18000000000. The number must be an integer float scaled by FLOAT_SCALING_FACTOR.
higherPrice higher price you want to query in the level2 book, eg: 20000000000. The number must be an integer float scaled by FLOAT_SCALING_FACTOR.
side { 'bid' | 'ask' | 'both' } bid or ask or both sides.
Implementation
Future<dynamic> getLevel2BookStatus({
required String poolId,
required int lowerPrice,
required int higherPrice,
required OrderType side
}) async {
final txb = TransactionBlock();
final typeArgs = await getPoolTypeArgs(poolId);
if (side == OrderType.both) {
txb.moveCall(
"$PACKAGE_ID::$MODULE_CLOB::get_level2_book_status_bid_side",
typeArguments: typeArgs,
arguments: [
txb.object(poolId),
txb.pureInt(lowerPrice),
txb.pureInt(higherPrice),
txb.object(SUI_CLOCK_OBJECT_ID),
],
);
txb.moveCall(
"$PACKAGE_ID::$MODULE_CLOB::get_level2_book_status_ask_side",
typeArguments: typeArgs,
arguments: [
txb.object(poolId),
txb.pureInt(lowerPrice),
txb.pureInt(higherPrice),
txb.object(SUI_CLOCK_OBJECT_ID),
]
);
} else {
txb.moveCall(
"$PACKAGE_ID::$MODULE_CLOB::get_level2_book_status_${side.name}_side",
typeArguments: typeArgs,
arguments: [
txb.object(poolId),
txb.pureInt(lowerPrice),
txb.pureInt(higherPrice),
txb.object(SUI_CLOCK_OBJECT_ID),
]
);
}
final results = await suiClient.devInspectTransactionBlock(
currentAddress,
txb,
);
if (side == OrderType.both) {
final bidSide = (results.results![0].returnValues as List).map((vals) =>
bcs.de('vector<u64>', Uint8List.fromList((vals[0] as List).cast<int>()))
).toList();
final askSide = (results.results![1].returnValues as List).map((vals) =>
bcs.de('vector<u64>', Uint8List.fromList((vals[0] as List).cast<int>()))
).toList();
List<Level2BookStatusPoint> bidSideList = [];
(bidSide[0] as List).asMap().forEach((i, value) {
bidSideList.add(Level2BookStatusPoint(int.parse(value), int.parse(bidSide[1][i])));
});
List<Level2BookStatusPoint> askSideList = [];
(askSide[0] as List).asMap().forEach((i, value) {
askSideList.add(Level2BookStatusPoint(int.parse(value), int.parse(askSide[1][i])));
});
return [
bidSideList,
askSideList,
];
} else {
final result = (results.results![0].returnValues as List).map((vals) =>
bcs.de('vector<u64>', Uint8List.fromList((vals[0] as List).cast<int>()))
).toList();
List<Level2BookStatusPoint> statusPoints = [];
(result[0] as List).asMap().forEach((i, value) {
statusPoints.add(Level2BookStatusPoint(int.parse(value), int.parse(result[1][i])));
});
return statusPoints;
}
}