Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Order book showing incorrect values #89

Merged
merged 8 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading