question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MEXC v3 fetch_markets() returns both decimals and tick sizes for price and amount precisions

See original GitHub issue
  • OS: Linux Mint
  • Programming Language version: Python 3.10
  • CCXT version: 1.84.42
exchange = ccxt.mexc3()
print(exchange.fetch_markets())
...
{'id': 'ORBUSDT', 'symbol': 'ORB/USDT', 'base': 'ORB', 'quote': 'USDT', 'settle': None, 'baseId': 'ORB', 'quoteId': 'USDT', 'settleId': None, 'type': 'spot', 'spot': True, 'margin': False, 'swap': False, 'future': False, 'option': False, 'active': True, 'contract': False, 'linear': None, 'inverse': None, 'taker': None, 'maker': None, 'contractSize': None, 'expiry': None, 'expiryDatetime': None, 'strike': None, 'optionType': None, 'precision': {'amount': 2, 'price': 4, 'base': 2, 'quote': 4}, 'limits': {'leverage': {'min': None, 'max': None}, 'amount': {'min': None, 'max': None}, 'price': {'min': None, 'max': None}, 'cost': {'min': None, 'max': None}}, 'info': {'symbol': 'ORBUSDT', 'status': 'ENABLED', 'baseAsset': 'ORB', 'baseAssetPrecision': '2', 'quoteAsset': 'USDT', 'quotePrecision': '4', 'quoteAssetPrecision': '4', 'baseCommissionPrecision': '2', 'quoteCommissionPrecision': '4', 'orderTypes': ['LIMIT', 'LIMIT_MAKER'], 'quoteOrderQtyMarketAllowed': False, 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '5', 'baseSizePrecision': '0.001', 'permissions': ['SPOT
...
{'id': 'XMR_USDT', 'symbol': 'XMR/USDT:USDT', 'base': 'XMR', 'quote': 'USDT', 'settle': 'USDT', 'baseId': 'XMR', 'quoteId': 'USDT', 'settleId': 'USDT', 'type': 'swap', 'spot': False, 'margin': False, 'swap': True, 'future': False, 'option': False, 'active': True, 'contract': True, 'linear': True, 'inverse': False, 'taker': 0.0006, 'maker': 0.0002, 'contractSize': 0.01, 'expiry': None, 'expiryDatetime': None, 'strike': None, 'optionType': None, 'precision': {'amount': 1.0, 'price': 0.01}, 'limits': {'leverage': {'min': 1.0, 'max': 50.0}, 'amount': {'min': 1.0, 'max': 100000.0}, 'price': {'min': None, 'max': None}, 'cost': {'min': None, 'max': None}}, 'info': {'symbol': 'XMR_USDT', 'displayName': 'XMR_USDT永续', 'displayNameEn': 'XMR_USDT PERPETUAL', 'positionOpenType': '3', 'baseCoin': 'XMR', 'quoteCoin': 'USDT', 'baseCoinName': 'XMR', 'quoteCoinName': 'USDT', 'futureType': '1', 'settleCoin': 'USDT', 'contractSize': '0.01', 'minLeverage': '1', 'maxLeverage': '50', 'priceScale': '2', 'volScale': '0', 'amountScale': '4', 'priceUnit': '0.01', 'volUnit': '1', 'minVol': '1', 'maxVol': '100000', 'bidLimitPriceRate': '0.2', 'askLimitPriceRate': '0.2', 'takerFeeRate': '0.0006', 'makerFeeRate': '0.0002', 'maintenanceMarginRate': '0.01', 'initialMarginRate': '0.02', 'riskBaseVol': '40000', 'riskIncrVol': '40000', 'riskIncrMmr': '0.005', 'riskIncrImr': '0.005', 'riskLevelLimit': '5', 'priceCoefficientVariation': '0.1', 'indexOrigin': ['BINANCE', 'HUOBI', 'MEXC'], 'state': '0', 'isNew': False, 'isHot': False, 'isHidden': False, 'conceptPlate': ['mc-trade-zone-privity'], 'riskLimitType': 'BY_VOLUME', 'triggerProtect': '0.1', 'maxNumOrders': ['200', '30']}}
...

mexc3 fetch_markets has both number of decimals and tick sizes as price and amount precisions. The logic seems to be that spot markets use decimals and swap markets tick sizes, and both market types are returned with the same fetch_markets call. exchange.precisionMode is equal to 2 aka DECIMAL_PLACES constant. Is there any unified way of telling what precision mode each market uses? If not, is there something that could be done about it?

I was also wondering what is the meaning of ‘base’ and ‘quote’ in the ‘ORB/USDT’ market and how do they work in combination with ‘amount’ and ‘price’? 'precision': {'amount': 2, 'price': 4, 'base': 2, 'quote': 4}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ttoduacommented, Jun 5, 2022

@ttodua Can I ask what how using the scientific notation changes things when exchange.number=float? I think 1e-4 is just a shorthand way of writing 0.0001, and 1e-4 == 0.0001 is True at least when I test it with Python 3.10. And 0.0001 does not have an exact floating point presentation, so 1e-4 shouldn’t have either.

I personally use Decimal class for handling the numbers provided by ccxt. I’m not sure what that class internally does to floats, but when printed out I get this kind of stuff:

from decimal import Decimal

print(Decimal('0.0001'))
print(Decimal('1e-4'))
print(Decimal(0.0001))
print(Decimal(1e-4))
0.0001
0.0001
0.000100000000000000004792173602385929598312941379845142364501953125
0.000100000000000000004792173602385929598312941379845142364501953125

The same kind of behavior for the two floats can be seen with this way also:

print("{:.30f}".format(0.0001))
print("{:.30f}".format(1e-4))
0.000100000000000000004792173602
0.000100000000000000004792173602

floating-point notation is a common problem in computer world, which has different ways to solve (which I can’t suggest in this post as it depends on your custom implementations and goals). you can read more here: https://0.30000000000000004.com/

so, if you want more accuracy, you might use string for exchange.number.

1reaction
ttoduacommented, Jun 4, 2022

Above, I’ve linked a PR. when it’s merged, the issue will be fixed and mexc3 will use TICK_SIZE. I made a mistake delibeartely when I said DECIMAL_PLACES should have 0 and TICK_SIZE should have 2 - because these values were correct for JS version, but in python, you are right - they are with those opposite values as you noted.

when that PR is merged, the base & quote keys will be removed from precision and thus, you will have price and amount and cost keys.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction – API Document - GitHub Pages
Documentation for the mexc global API. ... 3.Deposit Address: The return parameter tag is changed to memo , and the memo ... price,...
Read more >
Binance API : How i get Price Digits and Lots size Digits
You can get the decimal information from exchange_info API: spot: /api/v3/ ... and baseAssetPrecision to indicate the decimal precision.
Read more >
LOT_SIZE step size not correct on all pairs - Spot/Margin API
So basically why is there 2 decimals instead of one, and if I should not use the LOT_SIZE.tick_size as base asset amount precision,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found