IDEX fetch_markets() problems
See original GitHub issue- OS: Linux Mint
- Programming Language version: Python 3.10
- CCXT version: 1.83.32
exchange = ccxt.idex({...})
print(exchange.fetch_markets())
...
{'id': 'AAVE-ETH', 'symbol': 'AAVE/ETH', 'base': 'AAVE', 'quote': 'ETH', 'settle': None, 'baseId': 'AAVE', 'quoteId': 'ETH', 'settleId': None, 'type': 'spot', 'spot': True, 'margin': False, 'swap': False, 'future': False, 'option': False, 'active': False, 'contract': False, 'linear': None, 'inverse': None, 'taker': 0.0025, 'maker': 0.0, 'contractSize': None, 'expiry': None, 'expiryDatetime': None, 'strike': None, 'optionType': None, 'precision': {'amount': 8, 'price': 8}, 'limits': {'leverage': {'min': None, 'max': None}, 'amount': {'min': 1e-08, 'max': None}, 'price': {'min': 1e-08, 'max': None}, 'cost': {'min': 1.0, 'max': None}}, 'info': {'market': 'AAVE-ETH', 'type': 'hybrid', 'status': 'activeHybrid', 'baseAsset': 'AAVE', 'baseAssetPrecision': '8', 'quoteAsset': 'ETH', 'quoteAssetPrecision': '8', 'makerFeeRate': '0.0000', 'takerFeeRate': '0.2500', 'takerIdexFeeRate': '0.0500', 'takerLiquidityProviderFeeRate': '0.2000', 'tickSize': '0.00010000'}}
...
First problem with the dictionaries returned by fetch_markets
is that ‘active’ is False for every currency pair. Assuming the data is fetched from https://api-matic.idex.io/v1/markets then according to IDEX v3 API documentation (https://api-docs-v3.idex.io/#api-request-amp-response-values) both ‘active’ and ‘activeHybrid’ ‘status’ values in the original dictionary could perhaps be counted as market being active. At the moment ccxt only counts ‘active’ towards the market being active at line 245 of idex.py:
'active': (status == 'active'),
The second problem might be a bit harder to solve. It seems that IDEX has added ‘tickSize’ to the markets dictionary. By doing a quick glance at the markets on the IDEX trading website, it would seem that this tick size matches the price precision they are using. It’s even undocumented (https://api-docs-v3.idex.io/#get-markets). If I try to make a limit order with too much precision in the price (8 decimals according to ‘precision’ part of the dictionary), I get an error (or two):
exchange = ccxt.idex({...})
exchange.create_limit_buy_order('AAVE/ETH', '0.1', '0.04410001')
Traceback (most recent call last):
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 657, in fetch
response.raise_for_status()
File "/home/xyz/.local/lib/python3.10/site-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api-matic.idex.io/v1/orders
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
exchange.create_limit_buy_order('AAVE/ETH', '0.1', '0.04410001')
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 2398, in create_limit_buy_order
return self.create_order(symbol, 'limit', 'buy', amount, price, params)
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/idex.py", line 1140, in create_order
response = self.privatePostOrders(request)
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 497, in inner
return entry(_self, **inner_kwargs)
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 548, in request
return self.fetch2(path, api, method, params, headers, body, config, context)
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 544, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/base/exchange.py", line 673, in fetch
skip_further_error_handling = self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
File "/home/xyz/.local/lib/python3.10/site-packages/ccxt/idex.py", line 1219, in handle_errors
raise Exception(self.id + ' ' + message)
ccxt.base.errors.BadRequest: idex invalid value provided for request parameter "price": all quantities and prices must be below 100 billion, above 0, need to be provided as strings, and always require 4 decimals ending with 4 zeroes
If I use only 4 decimals in the price as indicated by ‘tickSize’, the order goes through just fine.
In the end the problem here is that the ccxt user could assume that more decimals can be used in the price than actually can be if they rely on the unified values in fetch_markets
dictionaries (the ‘precision’ values). I don’t know what the good/correct solution is here. The easiest way out would probably be to use the ‘tickSize’ in the ‘precision’ for the ‘price’ and use the other precision (which I presume should be the ‘quoteAssetPrecision’) internally in the idex/exchange class to pad the price correctly with zeroes.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
@kroitor Thank you too! Seems fine now with 1.83.56
@kroitor I have some good news and some bad news! The good news is that the price precision seems to be correct in
fetch_markets
return dictionary, the rounding with priceToPrecision is working fine and thus the orders go through such prices as ‘0.0441’ for AAVE/ETH. The bad news is that all markets fromfetch_markets
dictionary still show False for ‘active’…