Skip to content

Commit

Permalink
Merge pull request #89 from KomodoPlatform/orderbook-v2
Browse files Browse the repository at this point in the history
Fix - Order book showing incorrect values
  • Loading branch information
ca333 authored Dec 18, 2023
2 parents a9fa266 + 7fe0b94 commit 93c4041
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 2 additions & 4 deletions lib/screens/markets/order_book_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class OrderBookChart extends StatelessWidget {
Widget build(BuildContext context) {
final List<double> _askTotals = [];
final List<double> _bidTotals = [];
double _maxAmount;

for (int i = 0; i < sortedAsks.length; i++) {
final double prevTotal = i > 0 ? _askTotals[_askTotals.length - 1] : 0;
Expand All @@ -26,11 +25,10 @@ class OrderBookChart extends StatelessWidget {
for (int i = 0; i < sortedBids.length; i++) {
final double prevTotal = i > 0 ? _bidTotals[_bidTotals.length - 1] : 0;
final Ask bid = sortedBids[i];
_bidTotals.add(
prevTotal + (bid.maxvolume.toDouble() * double.parse(bid.price)));
_bidTotals.add(prevTotal + (bid.maxvolume.toDouble()));
}

_maxAmount = max(
double _maxAmount = max(
_askTotals.isNotEmpty ? _askTotals[_askTotals.length - 1] : 0,
_bidTotals.isNotEmpty ? _bidTotals[_bidTotals.length - 1] : 0,
);
Expand Down
18 changes: 9 additions & 9 deletions lib/screens/markets/order_book_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _OrderBookTableState extends State<OrderBookTable> {
alignment: Alignment.centerRight,
child: Text(
AppLocalizations.of(context)
.ordersTableTotal(orderBookProvider.activePair.sell.abbr),
.ordersTableAmount(orderBookProvider.activePair.buy.abbr),
maxLines: 1,
style: const TextStyle(fontSize: 14),
),
Expand All @@ -111,13 +111,13 @@ class _OrderBookTableState extends State<OrderBookTable> {
List<TableRow> _buildBidsList() {
final List<Ask> _sortedBids = List.from(widget.sortedBids);
final List<TableRow> _bidsList = [];
double _bidTotal = 0;

for (int i = 0; i < _sortedBids.length; i++) {
final Ask bid = _sortedBids[i];
final double _bidVolume =
bid.maxvolume.toDouble() * double.parse(bid.price);
_bidTotal += _bidVolume;

final double _bidVolume = bid.maxvolume.toDouble();

final double convertedVolume = _bidVolume / bid.priceRat.toDouble();

_bidsList.add(TableRow(
children: <Widget>[
Expand Down Expand Up @@ -185,7 +185,7 @@ class _OrderBookTableState extends State<OrderBookTable> {
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 4),
child: Text(
formatPrice(_bidTotal.toString()),
formatPrice(convertedVolume.toString()),
maxLines: 1,
style: TextStyle(
color: Theme.of(context)
Expand Down Expand Up @@ -225,11 +225,11 @@ class _OrderBookTableState extends State<OrderBookTable> {
List<TableRow> _buildAsksList() {
final List<Ask> _sortedAsks = widget.sortedAsks;
List<TableRow> _asksList = [];
double _askTotal = 0;

for (int i = 0; i < _sortedAsks.length; i++) {
final Ask ask = _sortedAsks[i];
_askTotal += ask.maxvolume.toDouble();
final convertedVolume =
ask.maxvolume.toDouble() * ask.priceRat.toDouble();

_asksList.add(TableRow(
children: <Widget>[
Expand Down Expand Up @@ -297,7 +297,7 @@ class _OrderBookTableState extends State<OrderBookTable> {
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 4),
child: Text(
formatPrice(_askTotal.toString()),
formatPrice(convertedVolume.toString()),
maxLines: 1,
style: TextStyle(
color: Theme.of(context)
Expand Down

0 comments on commit 93c4041

Please sign in to comment.