From cf93eca5df0834c663f31722d174f58c48bb002c Mon Sep 17 00:00:00 2001 From: naezith Date: Thu, 5 Oct 2023 16:54:37 +0300 Subject: [PATCH 1/7] GetOrderbook mmrpc 2.0 --- lib/model/get_orderbook.dart | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/model/get_orderbook.dart b/lib/model/get_orderbook.dart index be07acf16..36c8b6cc5 100644 --- a/lib/model/get_orderbook.dart +++ b/lib/model/get_orderbook.dart @@ -13,6 +13,7 @@ class GetOrderbook { GetOrderbook({ this.userpass, this.method = 'orderbook', + this.mmrpc = '2.0', this.base, this.rel, }); @@ -20,19 +21,24 @@ class GetOrderbook { factory GetOrderbook.fromJson(Map json) => GetOrderbook( userpass: json['userpass'] ?? '', method: json['method'] ?? '', - base: json['base'] ?? '', - rel: json['rel'] ?? '', + mmrpc: json['mmrpc'] ?? '', + base: json['params']['base'] ?? '', + rel: json['params']['rel'] ?? '', ); String userpass; String method; + String mmrpc; String base; String rel; Map toJson() => { 'userpass': userpass ?? '', 'method': method ?? '', - 'base': base ?? '', - 'rel': rel ?? '', + 'mmrpc': mmrpc, + 'params': { + 'base': base ?? '', + 'rel': rel ?? '', + } }; } From 122aa92ca8fba953555f670d44fdb8318d45ffe8 Mon Sep 17 00:00:00 2001 From: naezith Date: Thu, 5 Oct 2023 16:54:56 +0300 Subject: [PATCH 2/7] orderbook response data is in result field --- lib/services/mm.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/services/mm.dart b/lib/services/mm.dart index 5390f30f0..c7a2b7e29 100644 --- a/lib/services/mm.dart +++ b/lib/services/mm.dart @@ -453,7 +453,9 @@ class ApiProvider { ) .then((Response res) { _assert200(res); - return orderbookFromJson(res.body); + return orderbookFromJson( + json.encode(json.decode(res.body)['result']), + ); }), ); } catch (e) { From 0812b5c479e4516759d3795ae2d222817f9f2826 Mon Sep 17 00:00:00 2001 From: naezith Date: Thu, 5 Oct 2023 16:56:30 +0300 Subject: [PATCH 3/7] rename num_asks, num_bids, net_id fields --- lib/model/orderbook.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/model/orderbook.dart b/lib/model/orderbook.dart index 052571264..ac6760f41 100644 --- a/lib/model/orderbook.dart +++ b/lib/model/orderbook.dart @@ -40,19 +40,19 @@ class Orderbook { .map((dynamic x) => Ask.fromJson(x, json['rel']))) .where((Ask bid) => bid != null) .toList(), - numbids: json['numbids'] ?? 0, + numbids: json['num_bids'] ?? 0, asks: json['asks'] == null ? null : List.from(json['asks'] .map((dynamic x) => Ask.fromJson(x, json['base']))) .where((Ask ask) => ask != null) .toList(), - numasks: json['numasks'] ?? 0, + numasks: json['num_asks'] ?? 0, askdepth: json['askdepth'] ?? 0, base: json['base'] ?? '', rel: json['rel'] ?? '', timestamp: json['timestamp'] ?? DateTime.now().millisecond, - netid: json['netid'] ?? 0, + netid: json['net_id'] ?? 0, ); List bids; @@ -69,16 +69,16 @@ class Orderbook { 'bids': bids == null ? null : List.from(bids.map((Ask x) => x.toJson())), - 'numbids': numbids ?? 0, + 'num_bids': numbids ?? 0, 'asks': asks == null ? null : List.from(asks.map((Ask x) => x.toJson())), - 'numasks': numasks ?? 0, + 'num_asks': numasks ?? 0, 'askdepth': askdepth ?? 0, 'base': base ?? '', 'rel': rel ?? '', 'timestamp': timestamp ?? DateTime.now().millisecond, - 'netid': netid ?? 0, + 'net_id': netid ?? 0, }; } From e2d94e332c14d1809a90a91bfd08c2dc9ee1d2fe Mon Sep 17 00:00:00 2001 From: naezith Date: Thu, 5 Oct 2023 17:01:18 +0300 Subject: [PATCH 4/7] orderbook v2 price and price_fraction --- lib/model/orderbook.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/model/orderbook.dart b/lib/model/orderbook.dart index ac6760f41..cb2aad24d 100644 --- a/lib/model/orderbook.dart +++ b/lib/model/orderbook.dart @@ -97,14 +97,14 @@ class Ask { }); factory Ask.fromJson(Map json, [String coin]) { - if (isInfinite(json['price'])) return null; + if (isInfinite(json['price']['decimal'])) return null; if (isInfinite(json['maxvolume'])) return null; return Ask( coin: coin ?? json['coin'] ?? '', address: json['address'] ?? '', - price: json['price'] ?? 0.0, - priceFract: json['price_fraction'], + price: json['price']['decimal'] ?? 0.0, + priceFract: json['price']['fraction'], maxvolume: deci(json['maxvolume']), maxvolumeFract: json['max_volume_fraction'], minVolume: fract2rat(json['min_volume_fraction']) ?? @@ -133,8 +133,7 @@ class Ask { Map toJson() => { 'coin': coin ?? '', 'address': address ?? '', - 'price': price ?? 0.0, - 'price_fraction': priceFract, + 'price': {'decimal': price ?? 0.0, 'fraction': priceFract}, 'maxvolume': maxvolume.toString(), 'max_volume_fraction': maxvolumeFract, 'min_volume_fraction': rat2fract(minVolume), From 4959e324db515606cf88ceac7bfb690453c3dd97 Mon Sep 17 00:00:00 2001 From: naezith Date: Thu, 5 Oct 2023 17:15:17 +0300 Subject: [PATCH 5/7] orderbook v2 volume fields --- lib/model/orderbook.dart | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/model/orderbook.dart b/lib/model/orderbook.dart index cb2aad24d..c952c6738 100644 --- a/lib/model/orderbook.dart +++ b/lib/model/orderbook.dart @@ -98,17 +98,17 @@ class Ask { factory Ask.fromJson(Map json, [String coin]) { if (isInfinite(json['price']['decimal'])) return null; - if (isInfinite(json['maxvolume'])) return null; + if (isInfinite(json['base_min_volume']['decimal'])) return null; return Ask( coin: coin ?? json['coin'] ?? '', address: json['address'] ?? '', price: json['price']['decimal'] ?? 0.0, priceFract: json['price']['fraction'], - maxvolume: deci(json['maxvolume']), - maxvolumeFract: json['max_volume_fraction'], - minVolume: fract2rat(json['min_volume_fraction']) ?? - Rational.parse(json['min_volume']), + maxvolume: deci(json['base_max_volume']['decimal']), + maxvolumeFract: json['base_max_volume']['fraction'], + minVolume: fract2rat(json['base_min_volume']['fraction']) ?? + Rational.parse(json['base_min_volume']['decimal']), pubkey: json['pubkey'] ?? '', age: json['age'] ?? 0, zcredits: json['zcredits'] ?? 0, @@ -134,9 +134,13 @@ class Ask { 'coin': coin ?? '', 'address': address ?? '', 'price': {'decimal': price ?? 0.0, 'fraction': priceFract}, - 'maxvolume': maxvolume.toString(), - 'max_volume_fraction': maxvolumeFract, - 'min_volume_fraction': rat2fract(minVolume), + 'base_max_volume': { + 'decimal': maxvolume.toString(), + 'fraction': maxvolumeFract, + }, + 'base_min_volume': { + 'fraction': rat2fract(minVolume), + }, 'pubkey': pubkey ?? '', 'age': age ?? 0, 'zcredits': zcredits ?? 0, From cd349748d0fde9252273610d7fe8011449cbb657 Mon Sep 17 00:00:00 2001 From: naezith Date: Thu, 5 Oct 2023 17:28:15 +0300 Subject: [PATCH 6/7] orderbook v2 address field --- lib/model/orderbook.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/model/orderbook.dart b/lib/model/orderbook.dart index c952c6738..dd4cab835 100644 --- a/lib/model/orderbook.dart +++ b/lib/model/orderbook.dart @@ -102,7 +102,7 @@ class Ask { return Ask( coin: coin ?? json['coin'] ?? '', - address: json['address'] ?? '', + address: json['address']['address_data'] ?? 'Shielded', price: json['price']['decimal'] ?? 0.0, priceFract: json['price']['fraction'], maxvolume: deci(json['base_max_volume']['decimal']), @@ -132,7 +132,9 @@ class Ask { Map toJson() => { 'coin': coin ?? '', - 'address': address ?? '', + 'address': address == 'Shielded' + ? {'address_type': 'Shielded'} + : {'address_data': address}, 'price': {'decimal': price ?? 0.0, 'fraction': priceFract}, 'base_max_volume': { 'decimal': maxvolume.toString(), From 7fe0b94fce2ad96c277e51d49173f3ec53bbd45b Mon Sep 17 00:00:00 2001 From: CharlVS <77973576+CharlVS@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:48:57 +0200 Subject: [PATCH 7/7] Fix order book incorrect amounts --- lib/screens/markets/order_book_chart.dart | 6 ++---- lib/screens/markets/order_book_table.dart | 18 +++++++++--------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/screens/markets/order_book_chart.dart b/lib/screens/markets/order_book_chart.dart index 6030ece94..53aa08241 100644 --- a/lib/screens/markets/order_book_chart.dart +++ b/lib/screens/markets/order_book_chart.dart @@ -16,7 +16,6 @@ class OrderBookChart extends StatelessWidget { Widget build(BuildContext context) { final List _askTotals = []; final List _bidTotals = []; - double _maxAmount; for (int i = 0; i < sortedAsks.length; i++) { final double prevTotal = i > 0 ? _askTotals[_askTotals.length - 1] : 0; @@ -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, ); diff --git a/lib/screens/markets/order_book_table.dart b/lib/screens/markets/order_book_table.dart index b947b2802..c2abbe09d 100644 --- a/lib/screens/markets/order_book_table.dart +++ b/lib/screens/markets/order_book_table.dart @@ -99,7 +99,7 @@ class _OrderBookTableState extends State { 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), ), @@ -111,13 +111,13 @@ class _OrderBookTableState extends State { List _buildBidsList() { final List _sortedBids = List.from(widget.sortedBids); final List _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: [ @@ -185,7 +185,7 @@ class _OrderBookTableState extends State { 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) @@ -225,11 +225,11 @@ class _OrderBookTableState extends State { List _buildAsksList() { final List _sortedAsks = widget.sortedAsks; List _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: [ @@ -297,7 +297,7 @@ class _OrderBookTableState extends State { 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)