Here is a sample article explaining the issue:
Ethereum: Problem with “code” and “message” when creating futures orders on CCTX Binance
As an Ethereum developer, you are probably familiar with trading on cryptocurrency exchanges such as Binance. This article will address a common issue that occurs when trying to create simple futures orders on the CCTX (Coincheck Trade) exchange using Ethereum’s ccxt library.
Code and Configuration
Here is some sample code showing how to create a futures order on CCTX using ccxt:
import ccxt
Exchange = ccxt.binance({
'apiKey': config.api_key,
'apiSecret': config.api_secret,
})
Define Ethereum contract and symbolcontract = exchange.getContract('ethusd', 'USDT')
symbol = 'USD/ETH'
Define future orderfuture = {
'type': 'future',
'symbol': symbol,
'side': 'buy',
'timeInForce': 'gtc',
'expiration': '2024-03-01T23:59:00Z',
expiration date and time'amount': 10,0,
amount of ETH to trade}
Create the future orderresult = Exchange.createOrder(future)
print(result)
The Problem
Now that we have our code set up, let’s address the “code” and “message” issue mentioned in the error message.
When creating a future order in ccxt, it is possible to specify the code' field as an integer. However, the problem arises when this code does not match the code specified in the contract (in this case, CCTX). If the code does not match, ccxt returns an error message in the following format:
{"error": {"msg": "The order position does not match the user's settings."}}
Solution
To fix this problem, you need to make sure that the code’ field matches the code specified in the contract. In this case, the CCTX contract uses a different symbol (e.g. “ETHUSDT”) than what was specified in the “future” object.
One possible solution is to use the “symbol” and “contractSymbol” parameters provided by ccxt when creating a future order:
Define the future orderfuture = {
'type': 'future',
'symbol': symbol,
replace with the actual CCTX contract symbol'contractSymbol': 'ETHUSDT',
replace with the actual CCTX contract symbol'side': 'buy',
'timeInForce': 'gtc',
'expiration': '2024-03-01T23:59:00Z',
expiration date and time'amount': 10.0,
amount of ETH to trade}
Using thesymbolparameter, we can ensure that the
code` field matches the code specified in the contract.
Example use case
To demonstrate the solution in practice, let’s update our sample code:
import ccxt
Exchange = ccxt.binance({
'apiKey': config.api_key,
'apiSecret': config.api_secret,
})
Define the CCTX contract symbol and exchange settingscontractSymbol = 'ETHUDT'
Exchange.symbol = contractSymbol
Define the future orderfuture = {
'type': 'future',
'symbol': contractSymbol,
replace with the actual CCTX contract symbol'side': 'buy',
'timeInForce': 'gtc',
'expiration': '2024-03-01T23:59:00Z',
expiration date and time'amount': 10.0,
ETH to trade quantity}
Create the future orderresult = Exchange.createOrder(future)
print(result)
With this updated code, we will no longer get the “code” and “message” error messages when creating a future order on CCTX Binance using ccxt.
Hope this helps! If you have any further questions or if there is anything else I can help with, please contact me.