ccxt: BIBOX exchange: wrong constant precision values for amount and price

  • OS: independent
  • Programming Language version: Python
  • CCXT version: latest 1.49.58

I found that constant values for amount and price precision used in fetch_markets() method for Bibox exchange is wrong.

    def fetch_markets(self, params={}):
        request = {
            'cmd': 'marketAll',
        }
        response = self.publicGetMdata(self.extend(request, params))

        markets = self.safe_value(response, 'result')
        result = []
        
        for i in range(0, len(markets)):
            market = markets[i]

            .....
            
           ### !!! This walues is wrong ###
           precision = {
                'amount': 4,
                'price': 8,
            }
            .....
        return result

The exchange does not return these values explicitly, but you can calculate this values from amount and high/low returned values.

Data returned by exchange:

        #
        #     {
        #         "result": [
        #             {
        #                 "is_hide":0,
        #                 "high_cny":"1.9478",
        #                 "amount":"272.41",
        #                 "coin_symbol":"BIX",
        #                 "last":"0.00002487",
        #                 "currency_symbol":"BTC",
        #                 "change":"+0.00000073",
        #                 "low_cny":"1.7408",
        #                 "base_last_cny":"1.84538041",
        #                 "area_id":7,
        #                 "percent":"+3.02%",
        #                 "last_cny":"1.8454",
        #                 "high":"0.00002625",
        #                 "low":"0.00002346",
        #                 "pair_type":0,
        #                 "last_usd":"0.2686",
        #                 "vol24H":"10940613",
        #                 "id":1,
        #                 "high_usd":"0.2835",
        #                 "low_usd":"0.2534"
        #             }
        #         ],
        #         "cmd":"marketAll",
        #         "ver":"1.1"
        #     }
        #

I calculate precisions for the all markets and get only one value {2} for amount and seven {1, 2, 3, 4, 6, 7, 8} values for price.

        markets = self.safe_value(response, 'result')

        all_amounts_prec = [len(market['amount'].split('.')[1]) for market in markets]
        all_price_prec = [len(market['high'].split('.')[1]) for market in markets]

        print(set(all_amounts_prec))  # {2}
        print(set(all_price_prec))  # {1, 2, 3, 4, 6, 7, 8}

So I think it’s better to calculate amount and price precisions for every market. Something like this:

           precision = {
                'amount': len(market['amount'].split('.')[1]),
                'price': len(market['high'].split('.')[1]),
            }

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 18 (18 by maintainers)

Most upvoted comments

In v3 API it looks like Bibox gives right precisions https://api.bibox.com/v3/mdata/pairList

yes, v4 has more info. you are right, I missed the current code, as the v4 markets PR is yet not merged, sorry. You might check that PR and comment there. it will be merged soon.

@ttodua I see that ccxt uses v1 endpoints for fetchMarkets v1: https://api.bibox.com/v1/mdata?cmd=pairList v4: https://api.bibox.com/api/v4/marketdata/pairs

v1: {"id":478,"pair":"ANT_USDT","pair_type":6,"area_id":15,"is_hide":0,"decimal":4,"alias":null,"amount_scale":4}, v4: {"symbol":"ANT_USDT","base":"ANT","quote":"USDT","min_price":0.00000001,"max_price":1000000,"min_quantity":0.0000001,"max_quantity":1000000,"price_scale":6,"quantity_scale":4,"price_increment":"0.000001","quantity_increment":"0.0001","min_order_value":"1"}, even price precision is different in this versions for some pairs. And v4 has more info.

there is also v1 method with right precisions: https://api.bibox.com/v1/mdata?cmd=pairList

I know you get Python code stanspiled from JS, unfortunatelly I don’t know JS, but on Python it will be something like this:

Index: bibox.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/bibox.py b/bibox.py
--- a/bibox.py	(revision 6eaf0e7148494e347669466379526850ec2a2172)
+++ b/bibox.py	(revision 5ba12038df79592423ca277713f07cef91d5997b)
@@ -199,6 +199,13 @@
         #     }
         #
         markets = self.safe_value(response, 'result')
+
+        # get precision data
+        request = {'cmd': 'pairList',}
+        response = self.publicGetMdata(self.extend(request, params))
+        pairs_list = self.safe_value(response, 'result')
+        precisions = {item['pair']: {'price': int(item['decimal']), 'amount': int(item['amount_scale'])} for item in pairs_list}
+
         result = []
         for i in range(0, len(markets)):
             market = markets[i]
@@ -210,8 +217,8 @@
             symbol = base + '/' + quote
             id = baseId + '_' + quoteId
             precision = {
-                'amount': 4,
-                'price': 8,
+                'amount': precisions[id]['amount'],
+                'price': precisions[id]['price'],
             }
             result.append({
                 'id': id,

But in UI on some reasons they displayed only precision 4. It’s the old bibox bug (or feature).

Confirm. I have checked UI again and found that the price showed in trade history section with full (right) precision.

изображение

So, it means https://api.bibox.com/v3/mdata/pairList can be used to get right precisions for amount and price

Do you think decimal isn’t right precision for price?

For some USDT markets, like BTC\USDT, ETH\USDT, LTC\USDT and etc. decimal is actual precision for price. But for another markets decimal is not correct.

For example:

id | 90
-- | --
pair | "BIX_USDT"
pair_type | 0
area_id | 15
is_hide | 0
decimal | 6
amount_scale | 2

The real price precision is 4: изображение

id | 273
-- | --
pair | "FTM_USDT"
pair_type | 0
area_id | 15
is_hide | 0
decimal | 6
amount_scale | 4

The real price precision is 4:

изображение

I don’t think so. Just try to create order on FTM/USDT and BIX/USDT with price precision 6 and it will be correctly created via API. But in UI on some reasons they displayed only precision 4. It’s the old bibox bug (or feature).

Do you think decimal isn’t right precision for price?

For some USDT markets, like BTC\USDT, ETH\USDT, LTC\USDT and etc. decimal is actual precision for price. But for another markets decimal is not correct.

For example:

id | 90
-- | --
pair | "BIX_USDT"
pair_type | 0
area_id | 15
is_hide | 0
decimal | 6
amount_scale | 2

The real price precision is 4: изображение

id | 273
-- | --
pair | "FTM_USDT"
pair_type | 0
area_id | 15
is_hide | 0
decimal | 6
amount_scale | 4

The real price precision is 4:

изображение

       precision = {
            'amount': len(market['amount'].split('.')[1]),
            'price': len(market['high'].split('.')[1]),
        }

Update for this approach.

In some cases we can get IndexError exception, trying to find fraction length for values like this 'high': '479'

{‘is_hide’: ‘0’, ‘high_cny’: ‘3123.3291’, ‘amount’: ‘302616892.00’, ‘coin_symbol’: ‘5AAVE’, ‘last’: ‘437.58’, ‘currency_symbol’: ‘USD’, ‘change’: ‘-36’, ‘low_cny’: ‘2821.5594’, ‘base_last_cny’: ‘2853.24917661’, ‘area_id’: ‘16’, ‘percent’: ‘-7.60%’, ‘last_cny’: ‘2853.2492’, ‘high’: ‘479’, ‘low’: ‘432.72’, ‘pair_type’: ‘7’, ‘last_usd’: ‘437.5800’, ‘vol24H’: ‘302616892’, ‘id’: ‘718’, ‘time’: ‘1620361595166’, ‘high_usd’: ‘479.0000’, ‘low_usd’: ‘432.7200’}

In v3 API it looks like Bibox gives right precisions https://api.bibox.com/v3/mdata/pairList

Confirm, v3 gives right precisions for amount. Unfortunatelly we still need price precision values.