ccxt: decimal.InvalidOperation with okex.create_order()
- OS: Linux
- Programming Language version: Python 3.6
- CCXT version:ccxt==1.27.54
Hello, I’m facing an error with OKEx when trying to create a new order. Here is my code and the error message, I’m very curious to know what could be the reason since I did many tries and I can’t find a solution.
Thank you,
import ccxt
ok = ccxt.okex()
ok.secret = ''
ok.apiKey = ''
ok.password = ''
args = {'amount': 18, 'side': 'sell', 'symbol': 'ETH-USDT-SWAP', 'type': 'market'}
ok.options['defaultType'] = 'swap'
ok.create_order(**args)
---------------------------------------------------------------------------
InvalidOperation Traceback (most recent call last)
<ipython-input-42-58965134a2db> in <module>
1 args = {'amount': 18, 'side': 'sell', 'symbol': 'ETH-USDT-SWAP', 'type': 'market'}
2 ok.options['defaultType'] = 'swap'
----> 3 ok.create_order(**args)
~/python/envdev/lib/python3.6/site-packages/ccxt/okex.py in create_order(self, symbol, type, side, amount, price, params)
1766 'type': type, # 1:open long 2:open short 3:close long 4:close short for futures
1767 'size': size,
-> 1768 'price': self.price_to_precision(symbol, price),
1769 # 'match_price': '0', # Order at best counter party price?(0:no 1:yes). The default is 0. If it is set as 1, the price parameter will be ignored. When posting orders at best bid price, order_type can only be 0(regular order).
1770 })
~/python/envdev/lib/python3.6/site-packages/ccxt/base/exchange.py in price_to_precision(self, symbol, price)
1219
1220 def price_to_precision(self, symbol, price):
-> 1221 return self.decimal_to_precision(price, ROUND, self.markets[symbol]['precision']['price'], self.precisionMode)
1222
1223 def amount_to_precision(self, symbol, amount):
~/python/envdev/lib/python3.6/site-packages/ccxt/base/decimal_to_precision.py in decimal_to_precision(n, rounding_mode, precision, counting_mode, padding_mode)
53 context.rounding = decimal.ROUND_HALF_UP # rounds 0.5 away from zero
54
---> 55 dec = decimal.Decimal(str(n))
56 precision_dec = decimal.Decimal(str(precision))
57 string = '{:f}'.format(dec) # convert to string using .format to avoid engineering notation
InvalidOperation: [<class 'decimal.ConversionSyntax'>]
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (8 by maintainers)
@Kinzowa yes, this aspect is still subject to change, we’re working on a unification schema for it.
@Kinzowa
This should work:
Let me know if you still have difficulties with it.
This code sample you just provided still generates a ConversionSyntax and no verbose output is displayed. Please find bellow the code sample that generates
Invalid order typeerror.This is how I generate the
Invalid order typeerror :Thanks it works like a charm now 😃
@Kinzowa ok, please, update to 1.32.56 (it will arrive in 15 minutes), and let me know if this does not work: